use of eu.esdihumboldt.hale.common.instance.extension.metadata.MetadataActionExtension in project hale by halestudio.
the class MetadataActionProvider method setup.
/**
* Adds the action to the certain TreeViewer cell
*/
public void setup() {
final TreeEditor metaEditor = new TreeEditor(treeViewer.getTree());
metaEditor.horizontalAlignment = SWT.LEFT;
metaEditor.verticalAlignment = SWT.TOP;
treeViewer.getTree().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
final ViewerCell cell = treeViewer.getCell(new Point(e.x, e.y));
// Selected cell changed?
if (cell == null || metaEditor.getItem() != cell.getItem() || metaEditor.getColumn() != cell.getColumnIndex()) {
// Clean up any previous editor control
Control oldmetaEditor = metaEditor.getEditor();
if (oldmetaEditor != null) {
oldmetaEditor.dispose();
metaEditor.setEditor(null, null, 0);
}
}
// No selected cell or selected cell didn't change.
if (cell == null || cell.getColumnIndex() == 0 || (metaEditor.getItem() == cell.getItem() && metaEditor.getColumn() == cell.getColumnIndex())) {
return;
}
// Initiate the extension-point
MetadataActionExtension mae = MetadataActionExtension.getInstance();
final Pair<Object, Object> data = retrieveMetadata(cell);
if (data == null) {
return;
}
// get all defined actions
final List<MetadataActionFactory> actionSources = mae.getMetadataActions(data.getFirst().toString());
if (actionSources == null || actionSources.isEmpty()) {
return;
}
// Tool-bar used to view and trigger the different possible
// actions
ToolBar tooli = new ToolBar(treeViewer.getTree(), SWT.NONE);
for (final MetadataActionFactory source : actionSources) {
ToolItem actionItem = new ToolItem(tooli, SWT.PUSH);
// get the Icon of the action
URL iconURL = source.getIconURL();
Image image = ImageDescriptor.createFromURL(iconURL).createImage();
actionItem.setImage(image);
actionItem.setToolTipText(source.getDisplayName());
actionItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
source.createExtensionObject().execute(data.getFirst(), data.getSecond());
} catch (Exception e1) {
_log.userError("error creating metadata action", e1);
}
}
});
}
metaEditor.setEditor(tooli, (TreeItem) cell.getItem(), cell.getColumnIndex());
tooli.pack();
}
});
}
Aggregations