]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.route.ui/src/org/simantics/district/route/ui/RouteView.java
Add UI controls for route view to activate/deactivate route mode
[simantics/district.git] / org.simantics.district.route.ui / src / org / simantics / district / route / ui / RouteView.java
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