Search in sources :

Example 1 with EntityDefinitionServiceListener

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();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DisposeEvent(org.eclipse.swt.events.DisposeEvent) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) EntityDefinitionServiceListener(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionServiceListener) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Aggregations

EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 DefinitionComparator (eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator)1 SchemaPatternFilter (eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter)1 EntityDefinitionService (eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)1 EntityDefinitionServiceListener (eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionServiceListener)1 TreePathFilteredTree (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 Menu (org.eclipse.swt.widgets.Menu)1 FilteredTree (org.eclipse.ui.dialogs.FilteredTree)1