Search in sources :

Example 1 with ViewerMenu

use of eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu in project hale by halestudio.

the class AbstractMappingView method createViewControl.

@Override
public void createViewControl(Composite parent) {
    viewer = new GraphViewer(parent, SWT.BORDER);
    viewer.setContentProvider(createContentProvider());
    // viewer.setContentProvider(new CellRelationshipContentProvider());
    // viewer.setContentProvider(new NestedCellRelationshipContentProvider());
    viewer.setLabelProvider(createLabelProvider(viewer));
    viewer.setInput(null);
    LayoutAlgorithm layout = createLayout();
    viewer.setLayoutAlgorithm(layout, true);
    viewer.applyLayout();
    fillToolBar();
    // set selection provider
    selectionFacade = new SelectionProviderFacade();
    selectionFacade.setSelectionProvider(getViewer());
    getSite().setSelectionProvider(new PostSelectionSupport(selectionFacade));
    viewer.getControl().addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == 'a' && (e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
                // XXX even though getSelection returns the current state, a
                // selection update is not triggered by the control
                // -> force selection change event after Ctrl+A
                ISelection sel = viewer.getSelection();
                selectionFacade.setSelection(sel);
            }
        }

        @Override
        public void keyPressed(KeyEvent e) {
        // nothing to do
        }
    });
    // create context menu
    new ViewerMenu(getSite(), getViewer()) {

        /**
         * @see eu.esdihumboldt.hale.ui.util.ViewContextMenu#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
         */
        @Override
        public void menuAboutToShow(IMenuManager manager) {
            super.menuAboutToShow(manager);
            AbstractMappingView.this.menuAboutToShow(manager);
        }
    };
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) SelectionProviderFacade(eu.esdihumboldt.hale.ui.util.selection.SelectionProviderFacade) ISelection(org.eclipse.jface.viewers.ISelection) KeyListener(org.eclipse.swt.events.KeyListener) IMenuManager(org.eclipse.jface.action.IMenuManager) PostSelectionSupport(eu.esdihumboldt.hale.ui.util.viewer.PostSelectionSupport) ViewerMenu(eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu)

Example 2 with ViewerMenu

use of eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu in project hale by halestudio.

the class FunctionsView method createViewControl.

/**
 * @see eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart#createViewControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createViewControl(Composite parent) {
    viewer = new TreeViewer(parent);
    viewer.setLabelProvider(new FunctionLabelProvider());
    viewer.setContentProvider(new FunctionContentProvider(HaleUI.getServiceProvider()));
    IToolBarManager manager = getViewSite().getActionBars().getToolBarManager();
    IAction filterAction = new FilterAction("Filter incompatible functions", Action.AS_CHECK_BOX, CommonSharedImages.getImageRegistry().getDescriptor("IMG_FILTER_CLEAR"));
    manager.add(filterAction);
    filterAction.setChecked(true);
    filterAction.run();
    CompatibilityService cs = PlatformUI.getWorkbench().getService(CompatibilityService.class);
    cs.addListener(compListener = new ExclusiveExtensionListener<CompatibilityMode, CompatibilityModeFactory>() {

        @Override
        public void currentObjectChanged(CompatibilityMode current, CompatibilityModeFactory definition) {
            // refresh the viewer when the compatibility mode is
            // changed
            final Display display = PlatformUI.getWorkbench().getDisplay();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    viewer.refresh();
                }
            });
        }
    });
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    as.addListener(alignListener = new AlignmentServiceAdapter() {

        @Override
        public void alignmentCleared() {
            customFunctionsChanged();
        }

        @Override
        public void customFunctionsChanged() {
            // refresh the viewer when the compatibility mode is changed
            final Display display = PlatformUI.getWorkbench().getDisplay();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    viewer.refresh();
                }
            });
        }
    });
    // no input needed, but we have to set something
    viewer.setInput(Boolean.TRUE);
    new ViewerMenu(getSite(), viewer);
    getSite().setSelectionProvider(viewer);
}
Also used : IAction(org.eclipse.jface.action.IAction) CompatibilityModeFactory(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityModeFactory) CompatibilityMode(eu.esdihumboldt.hale.common.align.compatibility.CompatibilityMode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ExclusiveExtensionListener(de.fhg.igd.eclipse.util.extension.exclusive.ExclusiveExtension.ExclusiveExtensionListener) ViewerMenu(eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu) FunctionLabelProvider(eu.esdihumboldt.hale.ui.common.function.viewer.FunctionLabelProvider) IToolBarManager(org.eclipse.jface.action.IToolBarManager) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) CompatibilityService(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityService) FunctionContentProvider(eu.esdihumboldt.hale.ui.common.function.viewer.FunctionContentProvider) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) Display(org.eclipse.swt.widgets.Display)

Example 3 with ViewerMenu

use of eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu in project hale by halestudio.

the class SchemasView method createViewControl.

/**
 * @see eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart#createViewControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createViewControl(Composite _parent) {
    Composite modelComposite = new Composite(_parent, SWT.BEGINNING);
    GridLayout layout = new GridLayout(3, false);
    layout.verticalSpacing = 3;
    layout.horizontalSpacing = 0;
    modelComposite.setLayout(layout);
    // source schema toolbar, filter and explorer
    // sourceExplorer = new SchemaExplorer(modelComposite, "Source");
    sourceExplorer = new EntitySchemaExplorer(modelComposite, "Source", SchemaSpaceID.SOURCE);
    GridDataFactory.fillDefaults().grab(true, true).hint(400, 10).applyTo(sourceExplorer.getControl());
    sourceExplorerManager = new ServiceSchemaExplorer(sourceExplorer, SchemaSpaceID.SOURCE);
    // function button
    final Button functionButton = new Button(modelComposite, SWT.PUSH | SWT.FLAT);
    // $NON-NLS-1$
    functionImage = SchemasViewPlugin.getImageDescriptor("icons/mapping.gif").createImage();
    // $NON-NLS-1$
    augmentImage = SchemasViewPlugin.getImageDescriptor("icons/augment.gif").createImage();
    functionButton.setImage(functionImage);
    functionButton.setToolTipText(Messages.ModelNavigationView_FunctionButtonToolTipText);
    functionButton.setEnabled(false);
    functionButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    MenuManager manager = new MenuManager();
    manager.setRemoveAllWhenShown(true);
    final SchemaFunctionContribution functionContribution = new SchemaFunctionContribution();
    manager.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            // populate context menu
            manager.add(functionContribution);
        }
    });
    final Menu functionMenu = manager.createContextMenu(functionButton);
    functionButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // show menu on button press
            functionMenu.setLocation(Display.getCurrent().getCursorLocation());
            functionMenu.setVisible(true);
        }
    });
    // target schema toolbar, filter and explorer
    targetExplorer = new EntitySchemaExplorer(modelComposite, "Target", SchemaSpaceID.TARGET);
    GridDataFactory.fillDefaults().grab(true, true).hint(400, 10).applyTo(targetExplorer.getControl());
    targetExplorerManager = new ServiceSchemaExplorer(targetExplorer, SchemaSpaceID.TARGET);
    // source context menu
    new ViewerMenu(getSite(), sourceExplorer.getTreeViewer());
    // target context menu
    new ViewerMenu(getSite(), targetExplorer.getTreeViewer());
    // register selection provider
    getSite().setSelectionProvider(selectionProvider = new SchemasSelectionProvider());
    // listen for selection changes and update function button
    selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            functionButton.setEnabled(functionContribution.hasActiveFunctions());
            if (event.getSelection() instanceof SchemaSelection) {
                SchemaSelection selection = (SchemaSelection) event.getSelection();
                if (selection.getSourceItems().size() == 0 && selection.getTargetItems().size() > 0) {
                    // augmentation
                    functionButton.setImage(augmentImage);
                } else {
                    // function
                    functionButton.setImage(functionImage);
                }
            }
        }
    });
    // view toolbar
    getViewSite().getActionBars().getToolBarManager().add(cellSyncAction = new CellSyncAction(getSite().getPage().getWorkbenchWindow().getSelectionService(), sourceExplorer, targetExplorer));
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) ViewerMenu(eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu) GridLayout(org.eclipse.swt.layout.GridLayout) EntitySchemaExplorer(eu.esdihumboldt.hale.ui.views.schemas.explorer.EntitySchemaExplorer) Button(org.eclipse.swt.widgets.Button) ServiceSchemaExplorer(eu.esdihumboldt.hale.ui.views.schemas.explorer.ServiceSchemaExplorer) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IMenuManager(org.eclipse.jface.action.IMenuManager) ViewerMenu(eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu) Menu(org.eclipse.swt.widgets.Menu) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) DefaultSchemaSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection)

Example 4 with ViewerMenu

use of eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu in project hale by halestudio.

the class TypeHierarchyView method createViewControl.

/**
 * @see eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart#createViewControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createViewControl(Composite parent) {
    viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.setContentProvider(new TypeHierarchyContentProvider());
    viewer.setLabelProvider(new TypeHierarchyLabelProvider(viewer));
    viewer.setComparator(new DefinitionComparator());
    contributeToActionBars();
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            update(event.getSelection());
        }
    });
    getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (!(part instanceof PropertiesViewPart)) {
                // selections
                return;
            }
            if (part != TypeHierarchyView.this) {
                update(selection);
            }
        }
    });
    getSite().setSelectionProvider(selectionProvider = new SelectionFilter(viewer) {

        @Override
        protected ISelection filter(ISelection selection) {
            if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                List<Object> elements = new ArrayList<Object>();
                for (Object element : ((IStructuredSelection) selection).toList()) {
                    if (element instanceof ParentPath) {
                        // add parent path head instead of parent path
                        elements.add(((ParentPath) element).getHead());
                    } else {
                        elements.add(element);
                    }
                }
                return new StructuredSelection(elements);
            } else {
                return selection;
            }
        }
    });
    new ViewerMenu(getSite(), viewer);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionFilter(eu.esdihumboldt.hale.ui.util.selection.SelectionFilter) ISelectionListener(org.eclipse.ui.ISelectionListener) ViewerMenu(eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ParentPath(eu.esdihumboldt.hale.ui.views.typehierarchy.TypeHierarchyContentProvider.ParentPath) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelection(org.eclipse.jface.viewers.ISelection) PropertiesViewPart(eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart)

Example 5 with ViewerMenu

use of eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu in project hale by halestudio.

the class ResourcesView method createViewControl.

@Override
protected void createViewControl(Composite parent) {
    viewer = new TreeViewer(parent);
    viewer.setContentProvider(new ResourcesContentProvider());
    viewer.setLabelProvider(new ResourcesLabelProvider());
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    ps.addListener(projectServiceListener = new ProjectServiceAdapter() {

        @Override
        public void resourceAdded(String actionId, Resource resource) {
            updateInDisplayThread();
        }

        @Override
        public void resourcesRemoved(String actionId, List<Resource> resources) {
            updateInDisplayThread();
        }

        @Override
        public void afterLoad(ProjectService projectService) {
            updateInDisplayThread();
        }

        @Override
        public void projectInfoChanged(ProjectInfo info) {
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {
                    viewer.update(ProjectToken.TOKEN, null);
                    updateInDisplayThread();
                }
            });
        }
    });
    viewer.setUseHashlookup(true);
    viewer.setAutoExpandLevel(3);
    update();
    new ViewerMenu(getSite(), viewer);
    getSite().setSelectionProvider(viewer);
    // adding listener to refresh the resource view when any schema,
    // instance is added or cleared.
    SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
    ssListener = new SchemaServiceListener() {

        @Override
        public void schemaRemoved(SchemaSpaceID spaceID) {
            final Display display = PlatformUI.getWorkbench().getDisplay();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    updateInDisplayThread();
                }
            });
        }

        @Override
        public void schemasCleared(final SchemaSpaceID spaceID) {
            final Display display = PlatformUI.getWorkbench().getDisplay();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    updateInDisplayThread();
                }
            });
        }

        @Override
        public void schemaAdded(final SchemaSpaceID spaceID, Schema schema) {
            final Display display = PlatformUI.getWorkbench().getDisplay();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    updateInDisplayThread();
                }
            });
        }

        @Override
        public void mappableTypesChanged(final SchemaSpaceID spaceID, Collection<? extends TypeDefinition> types) {
            final Display display = PlatformUI.getWorkbench().getDisplay();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    updateInDisplayThread();
                }
            });
        }
    };
    ss.addSchemaServiceListener(ssListener);
    InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
    is.addListener(isa = new InstanceServiceAdapter() {

        @Override
        public void datasetChanged(DataSet type) {
            final Display display = PlatformUI.getWorkbench().getDisplay();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    updateInDisplayThread();
                }
            });
        }
    });
}
Also used : ProjectServiceAdapter(eu.esdihumboldt.hale.ui.service.project.ProjectServiceAdapter) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ResourcesLabelProvider(eu.esdihumboldt.hale.ui.views.resources.internal.ResourcesLabelProvider) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) ResourcesContentProvider(eu.esdihumboldt.hale.ui.views.resources.internal.ResourcesContentProvider) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) ViewerMenu(eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) ProjectInfo(eu.esdihumboldt.hale.common.core.io.project.ProjectInfo) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) List(java.util.List) InstanceServiceAdapter(eu.esdihumboldt.hale.ui.service.instance.InstanceServiceAdapter) SchemaServiceListener(eu.esdihumboldt.hale.ui.service.schema.SchemaServiceListener) Display(org.eclipse.swt.widgets.Display)

Aggregations

ViewerMenu (eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu)6 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 EntitySchemaExplorer (eu.esdihumboldt.hale.ui.views.schemas.explorer.EntitySchemaExplorer)2 ServiceSchemaExplorer (eu.esdihumboldt.hale.ui.views.schemas.explorer.ServiceSchemaExplorer)2 IMenuManager (org.eclipse.jface.action.IMenuManager)2 Composite (org.eclipse.swt.widgets.Composite)2 Display (org.eclipse.swt.widgets.Display)2 ExclusiveExtensionListener (de.fhg.igd.eclipse.util.extension.exclusive.ExclusiveExtension.ExclusiveExtensionListener)1 CompatibilityMode (eu.esdihumboldt.hale.common.align.compatibility.CompatibilityMode)1 ProjectInfo (eu.esdihumboldt.hale.common.core.io.project.ProjectInfo)1 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)1 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 SchemaSpaceID (eu.esdihumboldt.hale.common.schema.SchemaSpaceID)1 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)1 DefinitionComparator (eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator)1 FunctionContentProvider (eu.esdihumboldt.hale.ui.common.function.viewer.FunctionContentProvider)1 FunctionLabelProvider (eu.esdihumboldt.hale.ui.common.function.viewer.FunctionLabelProvider)1 CompatibilityModeFactory (eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityModeFactory)1 CompatibilityService (eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityService)1 SchemaSelection (eu.esdihumboldt.hale.ui.selection.SchemaSelection)1