]> 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 77725b7c0d6f6c874f738e95e468e0d318c9c4d6..78b6be9e2f25f5478b0aa37366f0cd8749b8a5b6 100644 (file)
@@ -10,11 +10,16 @@ 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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Tuukka Lehtonen
@@ -22,6 +27,8 @@ import org.eclipse.swt.widgets.Composite;
  */
 public class RouteView {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(RouteView.class);
+
     private static final String POPUP_CONTRIBUTION_ID = "org.simantics.district.route.ui.contextMenu";
     public static final String POPUP_ELEMENT_ID = "org.simantics.district.route.ui.popup";
 
@@ -47,11 +54,44 @@ 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
-    public void postConstruct(Composite parent) {
+    public void postConstruct(Composite parent, EMenuService menuService) {
         this.ui = new RouteTree(parent, 0, selectionService);
+        if (!(menuService.registerContextMenu(this.ui.getTree(), POPUP_ELEMENT_ID)))
+            LOGGER.warn("Could not register context menu {}", POPUP_ELEMENT_ID);
     }
 
     @PreDestroy
@@ -64,4 +104,8 @@ public class RouteView {
         ui.setFocus();
     }
 
+    public void editCurrentSelection() {
+        ui.editCurrentSelection();
+    }
+
 }
\ No newline at end of file