tableColumn.setText("");
tableColumn.setToolTipText(Messages.getString("encounter.tracker.view.table.column.marker.tooltip"));
tableColumn.setResizable(false);
tableColumn.setMoveable(false);
tableColumn.setWidth(25);
viewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
if(element instanceof EncounterParticipant) {
logger.debug("element is an encounter participant");
EncounterParticipant current = getCurrentParticipant();
if(current == element) {
return markerImage;
}
}
return null;
}
@Override
public String getText(Object element) {
return null;
}
});
// colLayout.setColumnData(col, new ColumnWeightData(10, 35, true));
viewerColumn = new TableViewerColumn(viewer, SWT.LEFT);
tableColumn = viewerColumn.getColumn();
tableColumn.setText(Messages.getString("encounter.tracker.view.table.column.order.label"));
tableColumn.setToolTipText(Messages.getString("encounter.tracker.view.table.column.order.tooltip"));
tableColumn.setResizable(true);
tableColumn.setMoveable(false);
tableColumn.setWidth(45);
viewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if(element instanceof EncounterParticipant) {
return String.valueOf(((EncounterParticipant)element).getOrder());
}
return null;
}
});
colLayout.setColumnData(tableColumn, new ColumnWeightData(10, 45, true));
editSupport = new EncounterTrackerEditingSupport(viewer) {
@Override
protected Object getValue(Object element) {
logger.debug("get value for editor: " + element);
if(element instanceof EncounterParticipant) {
return String.valueOf(((EncounterParticipant)element).getOrder());
}
return null;
}
@Override
protected void setValue(Object element, Object value) {
logger.debug("set value from editor: " + element + "; value: " + value);
if(element instanceof EncounterParticipant) {
if(value instanceof Integer) {
logger.debug("setting encounter participant value as integer");
((EncounterParticipant)element).setOrder((Integer)value);
}
else {
try {
logger.debug("setting encounter participant value as parsed integer from string");
((EncounterParticipant)element).setOrder(Integer.parseInt((String)value));
}
catch(NumberFormatException e) {
logger.debug("Exception while parsing integer: " + e.getLocalizedMessage(), e);
// ignore
}
}
if(autoSort) {
sort(sortAscending);
}
else {
viewer.update(element, null);
}
}
}
};
viewerColumn.setEditingSupport(editSupport);
viewerColumn = new TableViewerColumn(viewer, SWT.LEFT);
tableColumn = viewerColumn.getColumn();
tableColumn.setText(Messages.getString("encounter.tracker.view.table.column.name.label"));
tableColumn.setToolTipText(Messages.getString("encounter.tracker.view.table.column.name.tooltip"));
tableColumn.setResizable(true);
tableColumn.setMoveable(false);
tableColumn.setWidth(200);
viewerColumn.setLabelProvider(new EncounterTrackerViewParticipantLabelProvider(this));
colLayout.setColumnData(tableColumn, new ColumnWeightData(35, 200, true));
editSupport = new EncounterTrackerEditingSupport(viewer) {
@Override
protected boolean canEdit(Object element) {
logger.debug("can edit? " + element);
return (element instanceof EncounterParticipant);
}
@Override
protected Object getValue(Object element) {
logger.debug("get value for editor: " + element);
if(element instanceof EncounterParticipant) {
logger.debug("getting label from encounter participant");
return ((EncounterParticipant)element).getLabel();
}
return "";
}
@Override
protected void setValue(Object element, Object value) {
logger.debug("set value from editor: " + element + "; value: " + value);
if(element instanceof EncounterParticipant) {
logger.debug("setting value on encounter participant");
// set the label, no matter what
((EncounterParticipant)element).setLabel(value.toString());
// lookup name in instance list and if there's a match, assign that object
if(selectedCampaign != null) {
logger.debug("get instance from campaign: " + selectedCampaign);
// get instance list
Set<ObjectInstance> instances = selectedCampaign.getObjectInstances();
logger.trace("instances: " + instances);
for(ObjectInstance instance : instances) {
logger.trace("instance: " + instance);
String label = instance.getLabel();
logger.trace("label: " + label);
if(StringUtils.stripToEmpty(label).equalsIgnoreCase(
StringUtils.stripToEmpty(value.toString()))) {
logger.debug("instance label matches input string");
((EncounterParticipant)element).setParticipant(instance);
break;
}
}
}
}
logger.debug("update viewer element: " + element);
viewer.update(element, null);
}
// @Override
// protected CellEditor getCellEditor(Object element) {
// ComboBoxCellEditor editor = new ComboBoxCellEditor();
// editor.setStyle(SWT.DROP_DOWN);
// editor.set
//
// return editor;
// }
};
viewerColumn.setEditingSupport(editSupport);
// viewerColumn = new TableViewerColumn(viewer, SWT.LEFT);
// tableColumn = viewerColumn.getColumn();
// tableColumn.setText(Messages.getString("encounter.tracker.view.table.column.status.label"));
// tableColumn.setToolTipText(Messages.getString("encounter.tracker.view.table.column.status.tooltip"));
// tableColumn.setResizable(true);
// tableColumn.setMoveable(false);
// tableColumn.setWidth(100);
// viewerColumn.setLabelProvider(columnLabelProvider);
// colLayout.setColumnData(tableColumn, new ColumnWeightData(15, 100, true));
viewerColumn = new TableViewerColumn(viewer, SWT.LEFT);
tableColumn = viewerColumn.getColumn();
tableColumn.setText(Messages.getString("encounter.tracker.view.table.column.target.label"));
tableColumn.setToolTipText(Messages.getString("encounter.tracker.view.table.column.target.tooltip"));
tableColumn.setResizable(true);
tableColumn.setMoveable(false);
tableColumn.setWidth(100);
viewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Font getFont(Object element) {
if(element instanceof EncounterParticipant) {
Object obj = ((EncounterParticipant)element).getParticipant();
logger.trace("obj: " + obj);
if(obj == null) {
// bold the font if there is an associated object
return JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT);
}
}
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
if(element instanceof EncounterParticipant) {
Object target = ((EncounterParticipant)element).getTarget();
logger.trace("target: " + target);
if(target instanceof EncounterParticipant) {
logger.debug("target is an encounter participant");
return ((EncounterParticipant)target).getLabel();
}
else if(target instanceof String) {
return (String)target;
}
}
return null;
}
});
colLayout.setColumnData(tableColumn, new ColumnWeightData(20, 50, true));
editSupport = new EncounterTrackerEditingSupport(viewer) {
@Override
protected Object getValue(Object element) {
logger.debug("get value for editor: " + element);
if(element instanceof EncounterParticipant) {
Object obj = ((EncounterParticipant)element).getTarget();
logger.trace("obj: " + obj);
if(obj instanceof String) {
return obj;
}
else if(obj instanceof EncounterParticipant) {
return ((EncounterParticipant)obj).getLabel();
}
}
return null;
}
@Override
protected void setValue(Object element, Object value) {
logger.debug("set value from editor: " + element + "; value: " + value);
if(element instanceof EncounterParticipant) {
logger.debug("setting value on encounter target");
Object target = null;
// check if the input name matches an encounter participant name
for(EncounterParticipant ep : participants) {
logger.trace("ep: " + ep);
if(ep.getLabel().equalsIgnoreCase(StringUtils.stripToEmpty(value.toString()))) {
logger.debug("input value matches encounter participant, setting target: " + ep);
target = ep;
break;
}
}
if(target == null) {
logger.debug("no target set; convert to string");
target = value.toString();
}
logger.debug("setting target value: " + target);
((EncounterParticipant)element).setTarget(target);
}
viewer.update(element, null);
}
// @Override
// protected CellEditor getCellEditor(Object element) {
// CellEditor editor = new ComboBoxViewerCellEditor() {};
// editor.setStyle(SWT.DROP_DOWN);
// return editor;
// }
};
viewerColumn.setEditingSupport(editSupport);
viewerColumn = new TableViewerColumn(viewer, SWT.LEFT);
tableColumn = viewerColumn.getColumn();
tableColumn.setText(Messages.getString("encounter.tracker.view.table.column.notes.label"));
tableColumn.setToolTipText(Messages.getString("encounter.tracker.view.table.column.notes.tooltip"));
tableColumn.setResizable(true);
tableColumn.setMoveable(false);
tableColumn.setWidth(350);
viewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if(element instanceof EncounterParticipant) {
return ((EncounterParticipant)element).getNotes();
}