<elements xsi:type="commands:Command" xmi:id="_4wJtADWxEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.command.changemapping" commandName="Change Mapping"/>
<elements xsi:type="commands:Command" xmi:id="_qillYOGQEeiIMuq1qhQJRQ" elementId="org.simantics.district.network.ui.command.toggledrawmap" commandName="Toggle Draw Map"/>
<elements xsi:type="commands:Command" xmi:id="_Uv6NEOJdEei2MexsDMErvQ" elementId="org.simantics.district.network.ui.command.changemapbackgroundcolor" commandName="Change Map Background Color"/>
+ <elements xsi:type="commands:Command" xmi:id="_eTLe0PhxEeiSu98FclGtqA" elementId="org.simantics.district.network.ui.command.toggletrackchanges" commandName="Toggle Track Changes"/>
+ <elements xsi:type="commands:Command" xmi:id="_f4ugUPhxEeiSu98FclGtqA" elementId="org.simantics.district.network.ui.command.splittomultiplediagrams" commandName="Split to multiple diagrams"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_Js7rUMMAEea1mdgpHNVHMA" featurename="menuContributions" parentElementId="xpath:/">
<elements xsi:type="menu:MenuContribution" xmi:id="_T-jiEN8NEeaigNyzMJBOrg" elementId="org.simantics.district.network.ui.menucontribution.districtDiagramPopup" parentId="#DistrictDiagramPopup">
<elements xsi:type="commands:Handler" xmi:id="_LojWYDWyEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.handler.0" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.ChangeMappingTypeHandler" command="_4wJtADWxEeeVXaXEq4_qpA"/>
<elements xsi:type="commands:Handler" xmi:id="_ubB2kOGQEeiIMuq1qhQJRQ" elementId="org.simantics.district.network.ui.handler.1" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.DrawMapToggleHandler" command="_qillYOGQEeiIMuq1qhQJRQ"/>
<elements xsi:type="commands:Handler" xmi:id="_WmQDoOJdEei2MexsDMErvQ" elementId="org.simantics.district.network.ui.handler.2" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.ChangeMapBackgroundColorHandler" command="_Uv6NEOJdEei2MexsDMErvQ"/>
+ <elements xsi:type="commands:Handler" xmi:id="_h3ZzgPhxEeiSu98FclGtqA" elementId="org.simantics.district.network.ui.handler.3" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.ToggleTrackChanges" command="_eTLe0PhxEeiSu98FclGtqA"/>
+ <elements xsi:type="commands:Handler" xmi:id="_kc-uoPhxEeiSu98FclGtqA" elementId="org.simantics.district.network.ui.handler.4" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.ToggleSplitToMultipleDiagrams" command="_f4ugUPhxEeiSu98FclGtqA"/>
</fragments>
</fragment:ModelFragments>
--- /dev/null
+package org.simantics.district.network.ui.contributions;
+
+import java.util.List;
+
+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.di.AboutToShow;
+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.ItemType;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Write;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.ui.DistrictDiagramEditor;
+import org.simantics.district.network.ui.internal.Activator;
+import org.simantics.ui.workbench.IResourceEditorInput;
+import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ToggleSplitToMultipleDiagrams {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ToggleSplitToMultipleDiagrams.class);
+ private static final String COMMAND_ID = "org.simantics.district.network.ui.command.splittomultiplediagrams";
+
+ @AboutToShow
+ public void aboutToShow(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart, MApplication app, List<MMenuElement> items) {
+ Resource diagram = getDiagramFromEditorInput(mActiveEditorPart);
+ if (diagram != null) {
+ MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();
+ menuItem.setType(ItemType.CHECK);
+ menuItem.setLabel("Split to Multiple Diagrams");
+ menuItem.setContributorURI(Activator.PLUGIN_ID);
+ menuItem.setCommand(app.getCommand(COMMAND_ID));
+ menuItem.setSelected(isSplitToMultipleEnabled(diagram));
+ items.add(menuItem);
+ }
+ }
+
+ @CanExecute
+ public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
+ IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
+ if (activeEditorPart == null)
+ return false;
+ if (!(activeEditorPart instanceof DistrictDiagramEditor))
+ return false;
+ return true;
+ }
+
+ @Execute
+ public void toggleSplitToMultiple(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
+ Resource diagram = getDiagramFromEditorInput(mActiveEditorPart);
+ if (diagram != null) {
+ Simantics.getSession()
+ .asyncRequest((Write) graph -> graph.claimLiteral(diagram,
+ DistrictNetworkResource.getInstance(graph).Diagram_splitToMultipleEnabled,
+ !splitToMultipleEnabled(graph, diagram), Bindings.BOOLEAN));
+ }
+ }
+
+ private static boolean isSplitToMultipleEnabled(Resource diagram) {
+ try {
+ return Simantics.getSession().syncRequest(new SplitToMultipleEnabledRequest(diagram));
+ } catch (DatabaseException e) {
+ LOGGER.error("Could not check if split to multiple is enabled for diagram {}", diagram, e);
+ return false;
+ }
+ }
+
+ private static Boolean splitToMultipleEnabled(ReadGraph graph, Resource diagram) throws DatabaseException {
+ return Boolean.TRUE.equals(graph.getPossibleRelatedValue(diagram,
+ DistrictNetworkResource.getInstance(graph).Diagram_splitToMultipleEnabled));
+ }
+
+ private static Resource getDiagramFromEditorInput(MPart mActiveEditorPart) {
+ IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
+ if (activeEditorPart == null)
+ return null;
+ if (!(activeEditorPart instanceof DistrictDiagramEditor))
+ return null;
+ IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput();
+ return input.getResource();
+ }
+
+ private static class SplitToMultipleEnabledRequest extends UnaryRead<Resource, Boolean> {
+
+ public SplitToMultipleEnabledRequest(Resource diagram) {
+ super(diagram);
+ }
+
+ @Override
+ public Boolean perform(ReadGraph graph) throws DatabaseException {
+ return splitToMultipleEnabled(graph, parameter);
+ }
+ }
+}
--- /dev/null
+package org.simantics.district.network.ui.contributions;
+
+import java.util.List;
+
+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.di.AboutToShow;
+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.ItemType;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Write;
+import org.simantics.district.network.DistrictNetworkUtil;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.ui.DistrictDiagramEditor;
+import org.simantics.district.network.ui.internal.Activator;
+import org.simantics.ui.workbench.IResourceEditorInput;
+import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ToggleTrackChanges {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ToggleTrackChanges.class);
+ private static final String COMMAND_ID = "org.simantics.district.network.ui.command.toggletrackchanges";
+
+ @AboutToShow
+ public void aboutToShow(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart, MApplication app, List<MMenuElement> items) {
+ Resource diagram = getDiagramFromEditorInput(mActiveEditorPart);
+ if (diagram != null) {
+ MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();
+ menuItem.setType(ItemType.CHECK);
+ menuItem.setLabel("Track Changes");
+ menuItem.setContributorURI(Activator.PLUGIN_ID);
+ menuItem.setCommand(app.getCommand(COMMAND_ID));
+ menuItem.setSelected(isTrackChangesEnabled(diagram));
+ items.add(menuItem);
+ }
+ }
+
+ @CanExecute
+ public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
+ IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
+ if (activeEditorPart == null)
+ return false;
+ if (!(activeEditorPart instanceof DistrictDiagramEditor))
+ return false;
+ return true;
+ }
+
+ @Execute
+ public void toggleTrackChanges(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
+ Resource diagram = getDiagramFromEditorInput(mActiveEditorPart);
+ if (diagram != null) {
+ Simantics.getSession()
+ .asyncRequest((Write) graph -> graph.claimLiteral(diagram,
+ DistrictNetworkResource.getInstance(graph).Diagram_trackChangesEnabled,
+ !DistrictNetworkUtil.trackChangesEnabled(graph, diagram), Bindings.BOOLEAN));
+ }
+ }
+
+ private static boolean isTrackChangesEnabled(Resource diagram) {
+ try {
+ return Simantics.getSession().syncRequest(new TrackChangesEnabledRequest(diagram));
+ } catch (DatabaseException e) {
+ LOGGER.error("Could not check if track changes is enabled for diagram {}", diagram, e);
+ return false;
+ }
+ }
+
+ private static Resource getDiagramFromEditorInput(MPart mActiveEditorPart) {
+ IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
+ if (activeEditorPart == null)
+ return null;
+ if (!(activeEditorPart instanceof DistrictDiagramEditor))
+ return null;
+ IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput();
+ return input.getResource();
+ }
+
+ private static class TrackChangesEnabledRequest extends UnaryRead<Resource, Boolean> {
+
+ public TrackChangesEnabledRequest(Resource diagram) {
+ super(diagram);
+ }
+
+ @Override
+ public Boolean perform(ReadGraph graph) throws DatabaseException {
+ return DistrictNetworkUtil.trackChangesEnabled(graph, parameter);
+ }
+ }
+}