Search in sources :

Example 1 with InstanceSelection

use of eu.esdihumboldt.hale.ui.selection.InstanceSelection in project hale by halestudio.

the class InstanceValidationReportDetailsPage method showSelectionInDataView.

/**
 * Shows the current selection (if valid) in the transformed data view.
 */
private void showSelectionInDataView() {
    InstanceSelection selection = getValidSelection();
    if (selection != null) {
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        // pin the property sheet if possible
        IViewReference ref = page.findViewReference(IPageLayout.ID_PROP_SHEET);
        if (ref != null) {
            IViewPart part = ref.getView(true);
            if (part instanceof PropertySheet)
                ((PropertySheet) part).setPinned(true);
        }
        // show transformed data view with selection if possible
        try {
            TransformedDataView transformedDataView = (TransformedDataView) page.showView(TransformedDataView.ID);
            transformedDataView.showSelection(selection, reportImage);
        } catch (PartInitException e) {
        // if it's not there, we cannot do anything
        }
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) PropertySheet(org.eclipse.ui.views.properties.PropertySheet) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) InstanceSelection(eu.esdihumboldt.hale.ui.selection.InstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection) PartInitException(org.eclipse.ui.PartInitException) TransformedDataView(eu.esdihumboldt.hale.ui.views.data.TransformedDataView)

Example 2 with InstanceSelection

use of eu.esdihumboldt.hale.ui.selection.InstanceSelection in project hale by halestudio.

the class SimpleInstanceSelectionProvider method updateSelection.

/**
 * Update the instance selection.
 *
 * @param instances the selected instances
 */
public void updateSelection(Iterable<Instance> instances) {
    InstanceSelection selection;
    if (instances != null) {
        selection = new DefaultInstanceSelection(Iterables.toArray(instances, Instance.class));
    } else {
        selection = new DefaultInstanceSelection();
    }
    fireSelectionChange(selection);
}
Also used : InstanceSelection(eu.esdihumboldt.hale.ui.selection.InstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)

Example 3 with InstanceSelection

use of eu.esdihumboldt.hale.ui.selection.InstanceSelection in project hale by halestudio.

the class AbstractInstancePainter method selectionChanged.

/**
 * @see ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
 */
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (!(selection instanceof InstanceSelection)) {
        // only accept instance selections
        return;
    }
    // called when the selection has changed, to update the state of the
    // way-points
    Refresher refresh = prepareRefresh(false);
    refresh.setImageOp(new FastBlurFilter(2));
    // collect instance references that are in the new selection
    Set<InstanceReference> selected = collectReferences(selection);
    Set<InstanceReference> toSelect = new HashSet<InstanceReference>();
    toSelect.addAll(selected);
    toSelect.removeAll(lastSelected);
    // selection
    for (InstanceReference selRef : toSelect) {
        InstanceWaypoint wp = findWaypoint(selRef);
        if (wp != null) {
            wp.setSelected(true, refresh);
        }
    }
    // unselect all that have previously been selected but are not in the
    // new selection
    lastSelected.removeAll(selected);
    for (InstanceReference selRef : lastSelected) {
        InstanceWaypoint wp = findWaypoint(selRef);
        if (wp != null) {
            wp.setSelected(false, refresh);
        }
    }
    lastSelected = selected;
    refresh.execute();
}
Also used : Refresher(de.fhg.igd.mapviewer.Refresher) PseudoInstanceReference(eu.esdihumboldt.hale.common.instance.model.impl.PseudoInstanceReference) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) InstanceSelection(eu.esdihumboldt.hale.ui.selection.InstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection) FastBlurFilter(org.jdesktop.swingx.image.FastBlurFilter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with InstanceSelection

use of eu.esdihumboldt.hale.ui.selection.InstanceSelection in project hale by halestudio.

the class StyledMapView method createPartControl.

/**
 * @see MapView#createPartControl(Composite)
 */
@Override
public void createPartControl(Composite parent) {
    HaleUI.registerWorkbenchUndoRedo(getViewSite());
    super.createPartControl(parent);
    Control mainControl = null;
    // try to get the Swing embedding composite
    Control[] children = parent.getChildren();
    if (children != null && children.length > 0) {
        for (Control child : children) {
            // find based on class name (class from CityServer3D)
            if (child.getClass().getSimpleName().equals("SwingComposite")) {
                mainControl = child;
                break;
            }
        }
        if (mainControl == null) {
            if (children.length >= 2) {
                // Eclipse 4 - the first composite is the toolbar
                mainControl = children[0];
            } else {
                mainControl = children[0];
            }
        }
    } else {
        mainControl = parent;
    }
    new ViewContextMenu(getSite(), getSite().getSelectionProvider(), mainControl) {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            ISelection sel = getSite().getSelectionProvider().getSelection();
            // show summary about selected instances
            if (sel != null && !sel.isEmpty() && sel instanceof InstanceSelection) {
                List<Object> source = new ArrayList<Object>();
                List<Object> transformed = new ArrayList<Object>();
                for (Object object : ((InstanceSelection) sel).toArray()) {
                    DataSet ds = null;
                    if (object instanceof Instance) {
                        ds = ((Instance) object).getDataSet();
                    }
                    if (object instanceof InstanceReference) {
                        ds = ((InstanceReference) object).getDataSet();
                    }
                    if (ds != null) {
                        switch(ds) {
                            case SOURCE:
                                source.add(object);
                                break;
                            case TRANSFORMED:
                                transformed.add(object);
                                break;
                        }
                    }
                }
                if (!source.isEmpty() || !transformed.isEmpty()) {
                    Action noAction = new Action("Selection:") {
                    };
                    noAction.setEnabled(false);
                    manager.add(noAction);
                }
                if (!source.isEmpty()) {
                    Action selectAction = new SelectInstancesAction(source, DataSet.SOURCE);
                    selectAction.setEnabled(!transformed.isEmpty());
                    manager.add(selectAction);
                }
                if (!transformed.isEmpty()) {
                    Action selectAction = new SelectInstancesAction(transformed, DataSet.TRANSFORMED);
                    selectAction.setEnabled(!source.isEmpty());
                    manager.add(selectAction);
                }
            }
            super.menuAboutToShow(manager);
        }
    };
    final Menu swtMenu = mainControl.getMenu();
    getMapKit().getMainMap().addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            mouseReleased(e);
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (Platform.WS_GTK.equals(Platform.getWS())) {
                            /*
								 * Work-around (or rather hack) for Eclipse Bug
								 * 233450
								 */
                            GTKAWTBridgePopupFix.showMenu(swtMenu);
                        } else {
                            swtMenu.setLocation(e.getXOnScreen(), e.getYOnScreen());
                            swtMenu.setVisible(true);
                        }
                    }
                });
            }
        }
    });
}
Also used : Action(org.eclipse.jface.action.Action) MouseEvent(java.awt.event.MouseEvent) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ArrayList(java.util.ArrayList) MouseAdapter(java.awt.event.MouseAdapter) InstanceSelection(eu.esdihumboldt.hale.ui.selection.InstanceSelection) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection) Control(org.eclipse.swt.widgets.Control) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) ISelection(org.eclipse.jface.viewers.ISelection) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) ViewContextMenu(eu.esdihumboldt.hale.ui.util.ViewContextMenu) ViewContextMenu(eu.esdihumboldt.hale.ui.util.ViewContextMenu)

Aggregations

InstanceSelection (eu.esdihumboldt.hale.ui.selection.InstanceSelection)4 DefaultInstanceSelection (eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)4 InstanceReference (eu.esdihumboldt.hale.common.instance.model.InstanceReference)2 Refresher (de.fhg.igd.mapviewer.Refresher)1 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 PseudoInstanceReference (eu.esdihumboldt.hale.common.instance.model.impl.PseudoInstanceReference)1 ViewContextMenu (eu.esdihumboldt.hale.ui.util.ViewContextMenu)1 TransformedDataView (eu.esdihumboldt.hale.ui.views.data.TransformedDataView)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Action (org.eclipse.jface.action.Action)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 ISelection (org.eclipse.jface.viewers.ISelection)1 Control (org.eclipse.swt.widgets.Control)1 Menu (org.eclipse.swt.widgets.Menu)1 IViewPart (org.eclipse.ui.IViewPart)1