From: Reino Ruusu Date: Tue, 8 Oct 2019 14:10:04 +0000 (+0300) Subject: Some tweaks to the element selection query view X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F20%2F3320%2F1;p=simantics%2Fdistrict.git Some tweaks to the element selection query view gitlab #62 * View name change to "Element selection queries" * View marked as closeable * Explicit context menu command for performing the query Change-Id: I186d35c27452b804ebef8d60d4e703d4f738c4a9 (cherry picked from commit c27c9900e0ac0e6cb89c0d052f53e2eac5605aed) --- diff --git a/org.simantics.district.selection.ui/fragment.e4xmi b/org.simantics.district.selection.ui/fragment.e4xmi index 123c9976..3b6a9456 100644 --- a/org.simantics.district.selection.ui/fragment.e4xmi +++ b/org.simantics.district.selection.ui/fragment.e4xmi @@ -1,7 +1,7 @@ - + View categoryTag:District @@ -11,6 +11,7 @@ + diff --git a/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/PerformSelectionQueryHandler.java b/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/PerformSelectionQueryHandler.java new file mode 100644 index 00000000..1288d8e1 --- /dev/null +++ b/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/PerformSelectionQueryHandler.java @@ -0,0 +1,49 @@ +package org.simantics.district.selection.ui.handlers; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.workbench.IWorkbench; +import org.eclipse.e4.ui.workbench.modeling.EPartService; +import org.eclipse.e4.ui.workbench.modeling.ESelectionService; +import org.eclipse.swt.widgets.Display; +import org.simantics.district.selection.ElementSelector; +import org.simantics.district.selection.ui.parts.ElementSelectionView; + +public class PerformSelectionQueryHandler { + + @Inject + EPartService partService; + + @CanExecute + public boolean canExecute(ESelectionService selectionService) { + MPart part = partService.getActivePart(); + if (part == null) return false; + + Object object = part.getObject(); + if (object == null || !(object instanceof ElementSelectionView)) + return false; + + ElementSelectionView view = (ElementSelectionView)object; + return view.getSelectedItem() != null; + } + + @Execute + public void performElementSelection(IEclipseContext context, IWorkbench workbench) { + MPart part = partService.getActivePart(); + if (part == null) return; + + Object object = part.getObject(); + if (object == null || !(object instanceof ElementSelectionView)) + return; + + ElementSelectionView view = (ElementSelectionView)object; + ElementSelector selectedItem = view.getSelectedItem(); + + Display display = context.getActive(Display.class); + view.performSelection(display, selectedItem); + } +}