]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Add UI controls for route view to activate/deactivate route mode
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 4 Jun 2019 16:51:22 +0000 (19:51 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 31 Aug 2019 20:08:42 +0000 (23:08 +0300)
gitlab #48
APROS-15258

Change-Id: I019b76cbdfd095e2be667e6865ae5fc48d75a738

org.simantics.district.route.ui/META-INF/MANIFEST.MF
org.simantics.district.route.ui/fragment.e4xmi
org.simantics.district.route.ui/src/org/simantics/district/route/ui/RouteView.java
org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/ActivateCreateRoute.java [new file with mode: 0644]
org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/DeactivateCreateRoute.java [new file with mode: 0644]

index 3b531e707da2667c7b3ab10fd3a4a29617ced9c8..700455198b5e54308b0e508da060bbcfe903f082 100644 (file)
@@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.e4.core.di,
  org.simantics.ui,
  org.simantics.district.route,
  org.simantics.district.network.ui;bundle-version="1.0.0",
- org.slf4j.api
+ org.slf4j.api,
+ org.simantics.modeling.ui;bundle-version="1.1.1"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Automatic-Module-Name: fi.vtt.apros.district.route.ui
 Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
index 16c774b371847e9122cde24c406815259a984db3..291140d8190e800246a0e52eb9c530812c423543 100644 (file)
@@ -6,12 +6,16 @@
     <elements xsi:type="commands:Command" xmi:id="_k63rkP6zEeiBo8tg-6EPYA" elementId="org.simantics.district.route.ui.command.selectRouteOnDiagram" commandName="Select Route on Diagram"/>
     <elements xsi:type="commands:Command" xmi:id="_bA61IAI7EemGocelWS26pQ" elementId="org.simantics.district.route.ui.command.discardRoute" commandName="Discard Route"/>
     <elements xsi:type="commands:Command" xmi:id="_bfN6sAI7EemGocelWS26pQ" elementId="org.simantics.district.route.ui.command.renameRoute" commandName="Rename Route"/>
+    <elements xsi:type="commands:Command" xmi:id="_Of1BQGp0EemcK4j7CyatJA" elementId="org.simantics.district.route.ui.command.activatecreateroute" commandName="Activate Create Route"/>
+    <elements xsi:type="commands:Command" xmi:id="_QSvwYGp0EemcK4j7CyatJA" elementId="org.simantics.district.route.ui.command.deactivatecreateroute" commandName="Deactivate Create Route"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_1Ds_gMqVEeeUz6Cs9kKeKg" featurename="handlers" parentElementId="xpath:/">
     <elements xsi:type="commands:Handler" xmi:id="_1G5RYH4WEei74IuRct85qQ" elementId="org.simantics.district.route.ui.handlers.openRouteView" contributionURI="bundleclass://org.simantics.district.route.ui/org.simantics.district.route.ui.OpenRouteView" command="_x1nG0H4WEei74IuRct85qQ"/>
     <elements xsi:type="commands:Handler" xmi:id="_O9tbQP60EeiBo8tg-6EPYA" elementId="org.simantics.district.route.ui.handlers.selectRouteOnDiagram" contributionURI="bundleclass://org.simantics.district.route.ui/org.simantics.district.route.ui.handlers.SelectRouteOnDiagram" command="_k63rkP6zEeiBo8tg-6EPYA"/>
     <elements xsi:type="commands:Handler" xmi:id="_mRg_oAI7EemGocelWS26pQ" elementId="org.simantics.district.route.ui.handler.discardRoute" contributionURI="bundleclass://org.simantics.district.route.ui/org.simantics.district.route.ui.handlers.DiscardRoute" command="_bA61IAI7EemGocelWS26pQ"/>
     <elements xsi:type="commands:Handler" xmi:id="_mh_EkAI7EemGocelWS26pQ" elementId="org.simantics.district.route.ui.handler.renameRoute" contributionURI="bundleclass://org.simantics.district.route.ui/org.simantics.district.route.ui.handlers.RenameRoute" command="_bfN6sAI7EemGocelWS26pQ"/>
+    <elements xsi:type="commands:Handler" xmi:id="_YkoHAGp0EemcK4j7CyatJA" elementId="org.simantics.district.route.ui.handler.0" contributionURI="bundleclass://org.simantics.district.route.ui/org.simantics.district.route.ui.handlers.ActivateCreateRoute" command="_Of1BQGp0EemcK4j7CyatJA"/>
+    <elements xsi:type="commands:Handler" xmi:id="_aQl5kGp0EemcK4j7CyatJA" elementId="org.simantics.district.route.ui.handler.1" contributionURI="bundleclass://org.simantics.district.route.ui/org.simantics.district.route.ui.handlers.DeactivateCreateRoute" command="_QSvwYGp0EemcK4j7CyatJA"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Fso08MrIEeeUz6Cs9kKeKg" featurename="toolBarContributions" parentElementId="xpath:/"/>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_WNB8EH4oEei74IuRct85qQ" featurename="trimContributions" parentElementId="xpath:/">
index 4499782d100860411da25f878a6ee1c9da8074be..78b6be9e2f25f5478b0aa37366f0cd8749b8a5b6 100644 (file)
@@ -10,9 +10,11 @@ import org.eclipse.e4.core.services.events.IEventBroker;
 import org.eclipse.e4.ui.di.Focus;
 import org.eclipse.e4.ui.model.application.MApplication;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem;
 import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
 import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
 import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
+import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
 import org.eclipse.e4.ui.services.EMenuService;
 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
 import org.eclipse.swt.widgets.Composite;
@@ -52,6 +54,37 @@ public class RouteView {
             }
         }
         part.getMenus().add(popupMenu);
+        
+        /**
+         * See
+         * http://www.vogella.com/tutorials/EclipsePlugin/article.html#adding-eclipse-4-x-parts-to-eclipse-3-x-applications-via-the-code-org-eclipse-ui-views-code-extension-point
+         * 
+         * Cannot contribute toolbar items via fragment at this point
+         */
+        MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar();
+        toolBar.setToBeRendered(true);
+        toolBar.getChildren().add(createActivateRouteToolItem(app));
+        toolBar.getChildren().add(createDeactivateRouteToolItem(app));
+        part.setToolbar(toolBar);
+    }
+
+
+    private static MHandledToolItem createActivateRouteToolItem(MApplication app) {
+        MHandledToolItem createHandledToolItem = MMenuFactory.INSTANCE.createHandledToolItem();
+        createHandledToolItem.setCommand(app.getCommand("org.simantics.district.route.ui.command.activatecreateroute")); // Command is contributed via fragment //$NON-NLS-1$
+        createHandledToolItem.setLabel("Activate create route");
+        createHandledToolItem.setIconURI("platform:/plugin/com.famfamfam.silk/icons/table_add.png"); //$NON-NLS-1$
+        createHandledToolItem.setEnabled(true);
+        return createHandledToolItem;
+    }
+
+    private static MHandledToolItem createDeactivateRouteToolItem(MApplication app) {
+        MHandledToolItem createHandledToolItem = MMenuFactory.INSTANCE.createHandledToolItem();
+        createHandledToolItem.setCommand(app.getCommand("org.simantics.district.route.ui.command.deactivatecreateroute")); // Command is contributed via fragment //$NON-NLS-1$
+        createHandledToolItem.setLabel("Deactivate create route");
+        createHandledToolItem.setIconURI("platform:/plugin/com.famfamfam.silk/icons/table_edit.png"); //$NON-NLS-1$
+        createHandledToolItem.setEnabled(true);
+        return createHandledToolItem;
     }
 
     @PostConstruct
diff --git a/org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/ActivateCreateRoute.java b/org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/ActivateCreateRoute.java
new file mode 100644 (file)
index 0000000..0dc2135
--- /dev/null
@@ -0,0 +1,53 @@
+package org.simantics.district.route.ui.handlers;
+
+import javax.inject.Named;
+
+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.services.IServiceConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.district.network.ui.DistrictDiagramEditor;
+import org.simantics.district.network.ui.participants.RoutingMode;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.modeling.ui.diagramEditor.DiagramViewer;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+/**
+ * @author Jani Simomaa
+ */
+public class ActivateCreateRoute {
+
+    @CanExecute
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
+        IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
+        if (activeEditor != null && activeEditor instanceof DistrictDiagramEditor) {
+            DistrictDiagramEditor editor = (DistrictDiagramEditor) activeEditor;
+            DiagramViewer viewer = editor.getAdapter(DiagramViewer.class);
+            ICanvasContext context = viewer.getAdapter(ICanvasContext.class);
+            RoutingMode routingMode = context.getAtMostOneItemOfClass(RoutingMode.class);
+            return routingMode == null;
+        }
+        return false;
+    }
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell,
+            @Named(IServiceConstants.ACTIVE_PART) MPart part,
+            @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
+        
+        IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
+        if (activeEditor != null && activeEditor instanceof DistrictDiagramEditor) {
+            DistrictDiagramEditor editor = (DistrictDiagramEditor) activeEditor;
+            DiagramViewer viewer = editor.getAdapter(DiagramViewer.class);
+            ICanvasContext context = viewer.getAdapter(ICanvasContext.class);
+            RoutingMode routingMode = context.getAtMostOneItemOfClass(RoutingMode.class);
+            if (routingMode == null || routingMode.isRemoved()) {
+                routingMode = new RoutingMode(0);
+                context.add(routingMode);
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/DeactivateCreateRoute.java b/org.simantics.district.route.ui/src/org/simantics/district/route/ui/handlers/DeactivateCreateRoute.java
new file mode 100644 (file)
index 0000000..a60478d
--- /dev/null
@@ -0,0 +1,56 @@
+package org.simantics.district.route.ui.handlers;
+
+import javax.inject.Named;
+
+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.services.IServiceConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.district.network.ui.DistrictDiagramEditor;
+import org.simantics.district.network.ui.participants.RoutingMode;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.modeling.ui.diagramEditor.DiagramViewer;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+/**
+ * @author Jani Simomaa
+ */
+public class DeactivateCreateRoute {
+
+    @CanExecute
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
+        IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
+        if (activeEditor != null && activeEditor instanceof DistrictDiagramEditor) {
+            DistrictDiagramEditor editor = (DistrictDiagramEditor) activeEditor;
+            DiagramViewer viewer = editor.getAdapter(DiagramViewer.class);
+            ICanvasContext context = viewer.getAdapter(ICanvasContext.class);
+            RoutingMode routingMode = context.getAtMostOneItemOfClass(RoutingMode.class);
+            return routingMode != null;
+        }
+        return false;
+    }
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell,
+            @Named(IServiceConstants.ACTIVE_PART) MPart part,
+            @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
+        
+        IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
+        if (activeEditor != null && activeEditor instanceof DistrictDiagramEditor) {
+            DistrictDiagramEditor editor = (DistrictDiagramEditor) activeEditor;
+            DiagramViewer viewer = editor.getAdapter(DiagramViewer.class);
+            ICanvasContext context = viewer.getAdapter(ICanvasContext.class);
+            
+//            context.getSceneGraph
+//            
+//            RoutingMode routingMode = context.getAtMostOneItemOfClass(RoutingMode.class);
+//            if (routingMode == null || routingMode.isRemoved()) {
+//                routingMode = new RoutingMode(0);
+//                context.add(routingMode);
+//            }
+        }
+    }
+}
\ No newline at end of file