updateNode();
setDirty();
return true;
+ } else if (e.command.equals( Commands.ENABLE_PAINTING )) {
+ enablePainting();
+ updateNode();
+ setDirty();
+ return true;
}
return false;
}
setHint(KEY_MAP_ENABLED, enabled);
}
+ private void enablePainting() {
+ setHint(Hints.KEY_DISABLE_PAINTING, false);
+ }
}
L0.HasLabel "Node Scale Bias"
>-- DN.Diagram.nodeScaleProperty --> DN.Vertex.ScaleProperty <R L0.HasProperty : DN.VertexScalePropertyParameterType
L0.HasLabel "Node Scale Property"
+ >-- DN.Diagram.backgroundColor ==> "String" <R L0.HasProperty : SEL.GenericParameterType
+ L0.HasLabel "Diagram Background Color"
+ >-- DN.Diagram.drawMapEnabled ==> "Boolean" <R L0.HasProperty : SEL.GenericParameterType
+ L0.HasLabel "Draw Map"
@L0.assert DN.Diagram.elementColoringGradientHue
0.0 : L0.Float
L0.HasDataType $(Float(unit="deg",range=[0..360]))
@L0.assert DN.Diagram.nodeScaleGain 1.0
@L0.assert DN.Diagram.nodeScaleBias 0.0
@L0.assert DN.Diagram.nodeScaleProperty DN.Vertex.ScaleProperty.NominalSupplyPressure
+ @L0.assert DN.Diagram.drawMapEnabled true
// ----------------------------------------------------------------------------
// Built-in enumerated ScaleProperty & ThicknessProperty instances
public final Resource Diagram;
public final Resource Diagram_MappedDiagram;
public final Resource Diagram_MappedFromDiagram;
+ public final Resource Diagram_backgroundColor;
+ public final Resource Diagram_backgroundColor_Inverse;
+ public final Resource Diagram_drawMapEnabled;
+ public final Resource Diagram_drawMapEnabled_Inverse;
public final Resource Diagram_edgeThicknessBias;
public final Resource Diagram_edgeThicknessBias_Inverse;
public final Resource Diagram_edgeThicknessGain;
public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram";
public static final String Diagram_MappedDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/MappedDiagram";
public static final String Diagram_MappedFromDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/MappedFromDiagram";
+ public static final String Diagram_backgroundColor = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/backgroundColor";
+ public static final String Diagram_backgroundColor_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/backgroundColor/Inverse";
+ public static final String Diagram_drawMapEnabled = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/drawMapEnabled";
+ public static final String Diagram_drawMapEnabled_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/drawMapEnabled/Inverse";
public static final String Diagram_edgeThicknessBias = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/edgeThicknessBias";
public static final String Diagram_edgeThicknessBias_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/edgeThicknessBias/Inverse";
public static final String Diagram_edgeThicknessGain = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/edgeThicknessGain";
Diagram = getResourceOrNull(graph, URIs.Diagram);
Diagram_MappedDiagram = getResourceOrNull(graph, URIs.Diagram_MappedDiagram);
Diagram_MappedFromDiagram = getResourceOrNull(graph, URIs.Diagram_MappedFromDiagram);
+ Diagram_backgroundColor = getResourceOrNull(graph, URIs.Diagram_backgroundColor);
+ Diagram_backgroundColor_Inverse = getResourceOrNull(graph, URIs.Diagram_backgroundColor_Inverse);
+ Diagram_drawMapEnabled = getResourceOrNull(graph, URIs.Diagram_drawMapEnabled);
+ Diagram_drawMapEnabled_Inverse = getResourceOrNull(graph, URIs.Diagram_drawMapEnabled_Inverse);
Diagram_edgeThicknessBias = getResourceOrNull(graph, URIs.Diagram_edgeThicknessBias);
Diagram_edgeThicknessBias_Inverse = getResourceOrNull(graph, URIs.Diagram_edgeThicknessBias_Inverse);
Diagram_edgeThicknessGain = getResourceOrNull(graph, URIs.Diagram_edgeThicknessGain);
<elements xsi:type="commands:Command" xmi:id="_A1HBQOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.joinVertices" commandName="Join Vertices"/>
<elements xsi:type="commands:Command" xmi:id="_QzdUQOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.setFocusable" commandName="Set Focusable"/>
<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"/>
</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">
<children xsi:type="menu:HandledMenuItem" xmi:id="_VCxYIN8NEeaigNyzMJBOrg" elementId="org.simantics.district.network.ui.handledmenuitem.importImage" label="Import PNG/SVG Image" iconURI="platform:/plugin/org.simantics.modeling.ui/icons/image_add.png" tooltip="Import PNG/SVG Image as a layout" command="_luNasN8NEeaigNyzMJBOrg"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_O_UgUOIgEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handledmenuitem.joinvertices" label="Join Vertices" iconURI="platform:/plugin/org.simantics.ui/icons/etool16/arrow_join.png" tooltip="Join multiple vertices as one" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
<children xsi:type="menu:DynamicMenuContribution" xmi:id="_dieAsOIgEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.dynamicmenucontribution.setFocusable" label="Set Focusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableDynamicMenuContribution"/>
- <children xsi:type="menu:HandledMenuItem" xmi:id="_QbF4UDWyEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.handledmenuitem.changemapping" label="Change Mapping" tooltip="Change mapping of multiple elements" command="_4wJtADWxEeeVXaXEq4_qpA"/>
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_QbF4UDWyEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.handledmenuitem.changemapping" label="Change Mapping" iconURI="platform:/plugin/com.famfamfam.silk/icons/arrow_switch.png" tooltip="Change mapping of multiple elements" command="_4wJtADWxEeeVXaXEq4_qpA"/>
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_ZE-9sOGeEei2MexsDMErvQ" elementId="org.simantics.district.network.ui.handledmenuitem.toggledrawmap" label="Toggle Draw Map" iconURI="platform:/plugin/com.famfamfam.silk/icons/map_add.png" command="_qillYOGQEeiIMuq1qhQJRQ"/>
</elements>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_dbiHcMMBEea1mdgpHNVHMA" featurename="handlers" parentElementId="xpath:/">
<elements xsi:type="commands:Handler" xmi:id="_DPcVsOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.joinVertices" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.JoinVerticesHandler" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
<elements xsi:type="commands:Handler" xmi:id="_VPgBwOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.setFocusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableHandler" command="_QzdUQOIcEeaJP6VyXP72Jw"/>
<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"/>
</fragments>
</fragment:ModelFragments>
import java.util.concurrent.TimeUnit;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Listener;
+import org.simantics.district.network.DistrictNetworkUtil;
import org.simantics.district.network.ui.participants.DNPointerInteractor;
import org.simantics.district.network.ui.participants.MapRulerPainter;
import org.simantics.g2d.canvas.ICanvasContext;
import org.simantics.maps.MapScalingTransform;
import org.simantics.maps.eclipse.MapPainter;
import org.simantics.modeling.ui.diagramEditor.DiagramViewer;
+import org.simantics.scenegraph.g2d.events.command.CommandEvent;
+import org.simantics.scenegraph.g2d.events.command.Commands;
import org.simantics.utils.datastructures.hints.IHintContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DistrictDiagramViewer extends DiagramViewer {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DistrictDiagramViewer.class);
+
@Override
protected void addDiagramParticipants(ICanvasContext ctx) {
ctx.add(new ZOrderHandler());
ctx.add(new ZoomToAreaHandler());
}
+ @Override
+ protected void loadPageSettings(ICanvasContext ctx) {
+ super.loadPageSettings(ctx);
+ // this might be the wrong place to start such listening but at least
+ // super.loadPageSettings() does async-db-operations
+ sessionContext.getSession().asyncRequest(new UniqueRead<Boolean>() {
+
+ @Override
+ public Boolean perform(ReadGraph graph) throws DatabaseException {
+ return DistrictNetworkUtil.drawMapEnabled(graph, getInputResource());
+ }
+ }, new Listener<Boolean>() {
+
+ @Override
+ public void execute(Boolean result) {
+ canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), result ? Commands.MAP_ENABLE : Commands.MAP_DISABLE));
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ LOGGER.error("Could not listen draw map for {}", getInputResource(), t);
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return DistrictDiagramViewer.this.isDisposed();
+ }
+ });
+ }
}
--- /dev/null
+package org.simantics.district.network.ui.contributions;
+
+import java.util.List;
+
+import javax.inject.Named;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.SelectionHints;
+import org.simantics.district.network.DistrictNetworkUtil;
+import org.simantics.district.network.ui.internal.Activator;
+import org.simantics.utils.ui.ISelectionUtils;
+
+public class DrawMapToggleHandler {
+
+ @CanExecute
+ public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
+ final List<Resource> diagrams = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
+ return diagrams.size() > 0;
+ }
+
+ @Execute
+ public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Object selection) {
+ final List<Resource> diagrams = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
+ Job job = new DatabaseJob("Toggle draw map") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ Simantics.getSession().syncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ DistrictNetworkUtil.toggleDrawMap(graph, diagrams.get(0));
+ }
+ });
+ } catch (DatabaseException e) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setUser(true);
+ job.schedule();
+ }
+}
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.utils.OrderedSetUtils;
+import org.simantics.db.exception.BindingException;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
+import org.simantics.db.exception.ServiceException;
import org.simantics.db.layer0.request.PossibleVariable;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.diagram.stubs.DiagramResource;
return null;
}
+ public static void toggleDrawMap(WriteGraph graph, Resource diagram) throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException {
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ Boolean current = graph.getPossibleRelatedValue(diagram, DN.Diagram_drawMapEnabled, Bindings.BOOLEAN);
+ if (current == null)
+ current = true;
+ graph.claimLiteral(diagram, DN.Diagram_drawMapEnabled, !current, Bindings.BOOLEAN);
+ }
+
+ public static Boolean drawMapEnabled(ReadGraph graph, Resource diagram) throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException {
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ Boolean current = graph.getPossibleRelatedValue(diagram, DN.Diagram_drawMapEnabled, Bindings.BOOLEAN);
+ return current != null ? current : true;
+ }
}
@Override
public void doubleClick(DoubleClickEvent event) {
- LOGGER.info("event " + event);
TreeSelection selection = (TreeSelection) viewer.getSelection();
DiagramRegion region = (DiagramRegion) selection.getFirstElement();
ZoomToRegionHandler.zoomTo(viewer.getControl(), getDisplay(), region.getResource());
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 Jani Simomaa
*/
public class DiagramRegionsTableView {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DiagramRegionsTableView.class);
+
DiagramRegionsTableUI ui;
/**
public void postConstruct(ESelectionService selectionService, Composite parent, EMenuService menuService) {
// System.out.println("construct MPTV");
this.ui = new DiagramRegionsTableUI(selectionService, parent, 0);
- menuService.registerContextMenu(this.ui.getTree(), POPUP_ID);
+ if (!(menuService.registerContextMenu(this.ui.getTree(), POPUP_ID)))
+ LOGGER.warn("Could not register context menu {}", POPUP_ID);
}
@PreDestroy
@Named(IServiceConstants.ACTIVE_PART) MPart part,
@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
DiagramRegion region = ISelectionUtils.filterSingleSelection(selection, DiagramRegion.class);
- zoomTo(part, activeShell.getDisplay(), region.getResource());
+ zoomTo((Control) part.getWidget(), activeShell.getDisplay(), region.getResource());
}
- public static void zoomTo(MPart part, Display display, Resource region) {
+ public static void zoomTo(Control control, Display display, Resource region) {
Resource dia;
try {
dia = Simantics.getSession().syncRequest(new UniqueRead<Resource>() {
IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
LOGGER.info("activeWorkbenchPart {}", beforePerformingDefaultAction);
LOGGER.info("activeEditor {}", activeEditor);
- DefaultActions.performDefaultAction((Control)part.getWidget(), dia);
+ DefaultActions.performDefaultAction(control, dia);
Simantics.getSession().asyncRequest(new ReadRequest() {
@Override
try {
Thread.sleep(150);
} catch (InterruptedException e) {
- e.printStackTrace();
+ LOGGER.error("Could not sleep", e);
}
afterPerformingDefaultAction = WorkbenchUtils.getActiveEditor();
LOGGER.info("afterActiveWorkbenchPart {}", afterPerformingDefaultAction);
}
});
} catch (DatabaseException e) {
- e.printStackTrace();
+ LOGGER.error("Could not zoom to region", e);
}
}
}
points[0] = moveX;
points[1] = moveY;
// Fall into....
-
+ break;
case PathIterator.SEG_LINETO:
thisX = points[0];
thisY = points[1];