From 9d961a489f75c242d43621ae561eeb2ed451b254 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Tue, 8 Oct 2019 17:10:04 +0300 Subject: [PATCH] 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) --- .../fragment.e4xmi | 3 +- .../PerformSelectionQueryHandler.java | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/PerformSelectionQueryHandler.java 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); + } +} -- 2.45.2