]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Some tweaks to the element selection query view 20/3320/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Tue, 8 Oct 2019 14:10:04 +0000 (17:10 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 8 Oct 2019 14:46:35 +0000 (14:46 +0000)
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)

org.simantics.district.selection.ui/fragment.e4xmi
org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/PerformSelectionQueryHandler.java [new file with mode: 0644]

index 123c99760c3f8d4365c0ff196da5f5eb331b7676..3b6a9456ce87b439f575ecf769e14018869bb111 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="ASCII"?>
 <fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/descriptor/basic" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_BxaXACerEeWxCPrV0pAZQQ">
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_EI7oACerEeWxCPrV0pAZQQ" featurename="descriptors" parentElementId="xpath:/">
-    <elements xsi:type="basic:PartDescriptor" xmi:id="_KMklcCerEeWxCPrV0pAZQQ" elementId="org.simantics.district.selection.ui.parts.elementSelectionView" label="Diagram Element Selections" iconURI="platform:/plugin/org.simantics.silk.ontology/graph/images/table_go.png" tooltip="" category="District Network" contributionURI="bundleclass://org.simantics.district.selection.ui/org.simantics.district.selection.ui.parts.ElementSelectionView">
+    <elements xsi:type="basic:PartDescriptor" xmi:id="_KMklcCerEeWxCPrV0pAZQQ" elementId="org.simantics.district.selection.ui.parts.elementSelectionView" label="Element Selection Queries" iconURI="platform:/plugin/org.simantics.silk.ontology/graph/images/table_go.png" tooltip="" category="District Network" closeable="true" contributionURI="bundleclass://org.simantics.district.selection.ui/org.simantics.district.selection.ui.parts.ElementSelectionView">
       <tags>View</tags>
       <tags>categoryTag:District</tags>
     </elements>
@@ -11,6 +11,7 @@
       <children xsi:type="menu:HandledMenuItem" xmi:id="_403skCVaEem-kMBxWCWPIg" elementId="org.simantics.district.selection.ui.handledmanuitem.openview" label="Open Diagram Element Selection View" iconURI="platform:/plugin/com.famfamfam.silk/icons/table_key.png" command="_OdOfoCVcEem-kMBxWCWPIg"/>
     </elements>
     <elements xsi:type="menu:MenuContribution" xmi:id="_QOvjwCVgEem-kMBxWCWPIg" elementId="org.simantics.district.selection.ui.menucontribution.selectionView.contextMenu" parentId="org.simantics.district.selection.ui.contextMenu">
+      <children xsi:type="menu:DirectMenuItem" xmi:id="_bjEA4OnSEemDQq3ncfg9zg" elementId="org.simantics.district.selection.ui.directmenuitem.performselection" label="Perform Selection" contributionURI="bundleclass://org.simantics.district.selection.ui/org.simantics.district.selection.ui.handlers.PerformSelectionQueryHandler"/>
       <children xsi:type="menu:HandledMenuItem" xmi:id="_ZKWM0CVgEem-kMBxWCWPIg" elementId="org.simantics.district.selection.ui.contextMenu.createNewSelection" label="Create New Selection" iconURI="platform:/plugin/com.famfamfam.silk/icons/table_add.png" command="_rH7MsCVgEem-kMBxWCWPIg"/>
       <children xsi:type="menu:HandledMenuItem" xmi:id="_Gl5QAC9tEem4UIS68e_fsw" elementId="org.simantics.district.selection.ui.contextMenu.editSelection" label="Edit Element Selection" iconURI="platform:/plugin/org.simantics.silk.ontology/graph/images/pencil.png" command="_dL1xIC7IEem4UIS68e_fsw"/>
       <children xsi:type="menu:HandledMenuItem" xmi:id="_bVDmsC9tEem4UIS68e_fsw" elementId="org.simantics.district.selection.ui.contextMenu.deleteSelection" label="Delete Element Selection" iconURI="platform:/plugin/org.simantics.silk.ontology/graph/images/cross.png" command="_RfOU0C7PEem4UIS68e_fsw"/>
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 (file)
index 0000000..1288d8e
--- /dev/null
@@ -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);
+       }
+}