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,
<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:/">
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;
}
}
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
--- /dev/null
+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
--- /dev/null
+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