use of eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionServiceListener in project hale by halestudio.
the class EntityDialog method createViewer.
/**
* @see AbstractViewerSelectionDialog#createViewer(Composite)
*/
@Override
protected TreeViewer createViewer(Composite parent) {
// create viewer
SchemaPatternFilter patternFilter = new SchemaPatternFilter() {
@Override
protected boolean matches(Viewer viewer, Object element) {
boolean superMatches = super.matches(viewer, element);
if (!superMatches)
return false;
return acceptObject(viewer, getFilters(), ((TreePath) element).getLastSegment());
}
};
patternFilter.setUseEarlyReturnIfMatcherIsNull(false);
patternFilter.setIncludeLeadingWildcard(true);
FilteredTree tree = new TreePathFilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
tree.getViewer().setComparator(new DefinitionComparator());
// create context menu
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(this);
Menu targetMenu = menuManager.createContextMenu(tree.getViewer().getControl());
tree.getViewer().getControl().setMenu(targetMenu);
if (SchemaSpaceID.SOURCE.equals(ssid)) {
// condition contexts only supported for source schema
// ensure viewer is updated on context changes
final EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
eds.addListener(entityDefinitionListener = new EntityDefinitionServiceListener() {
@Override
public void contextsAdded(Iterable<EntityDefinition> contextEntities) {
refreshInDisplayThread();
}
@Override
public void contextRemoved(EntityDefinition contextEntity) {
refreshInDisplayThread();
}
@Override
public void contextAdded(EntityDefinition contextEntity) {
refreshInDisplayThread();
}
});
// remove listener from entity def service
tree.getViewer().getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (entityDefinitionListener != null) {
eds.removeListener(entityDefinitionListener);
}
}
});
}
return tree.getViewer();
}
Aggregations