<?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>
<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"/>
--- /dev/null
+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);
+ }
+}