@L0.singleProperty SYSDYN.Dependency.angle
>-- SYSDYN.DependencyConnection.polarity --> L0.String <R L0.HasProperty : L0.FunctionalRelation
>-- SYSDYN.DependencyConnection.polarityLocation --> L0.String <R L0.HasProperty : L0.FunctionalRelation
+ >-- SYSDYN.DependencyConnection.hideArrow --> SYSDYN.DependencyConnection <R L0.HasProperty : L0.Tag
+ @L0.symmetric
>-- SYSDYN.DependencyConnection.delayMark --> SYSDYN.DependencyConnection <R L0.HasProperty : L0.Tag
@L0.symmetric
@L0.assert SYSDYN.Dependency.angle 0.1
public final Resource Dependency;\r
public final Resource DependencyConnection;\r
public final Resource DependencyConnection_delayMark;\r
+ public final Resource DependencyConnection_hideArrow;\r
public final Resource DependencyConnection_polarity;\r
public final Resource DependencyConnection_polarityLocation;\r
public final Resource DependencyConnection_polarityLocation_Inverse;\r
public static final String Dependency = "http://www.simantics.org/Sysdyn-1.1/Dependency";\r
public static final String DependencyConnection = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection";\r
public static final String DependencyConnection_delayMark = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/delayMark";\r
+ public static final String DependencyConnection_hideArrow = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/hideArrow";\r
public static final String DependencyConnection_polarity = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/polarity";\r
public static final String DependencyConnection_polarityLocation = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/polarityLocation";\r
public static final String DependencyConnection_polarityLocation_Inverse = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection/polarityLocation/Inverse";\r
Dependency = getResourceOrNull(graph, URIs.Dependency);\r
DependencyConnection = getResourceOrNull(graph, URIs.DependencyConnection);\r
DependencyConnection_delayMark = getResourceOrNull(graph, URIs.DependencyConnection_delayMark);\r
+ DependencyConnection_hideArrow = getResourceOrNull(graph, URIs.DependencyConnection_hideArrow);\r
DependencyConnection_polarity = getResourceOrNull(graph, URIs.DependencyConnection_polarity);\r
DependencyConnection_polarityLocation = getResourceOrNull(graph, URIs.DependencyConnection_polarityLocation);\r
DependencyConnection_polarityLocation_Inverse = getResourceOrNull(graph, URIs.DependencyConnection_polarityLocation_Inverse);\r
Pair<?, ?> polarityPair = (Pair<?, ?>)properties.get("polarity");\r
Pair<?, ?> polarityLocationPair = (Pair<?, ?>)properties.get("polarityLocation");\r
boolean delayMark = properties.containsKey("delayMark");\r
+ boolean arrowHead = !properties.containsKey("hideArrow");\r
\r
String location;\r
if(polarityLocationPair == null)\r
location = (String) polarityLocationPair.second;\r
\r
String text = polarityPair != null ? (String) polarityPair.second : "";\r
- node.init(text, location, delayMark, font, color, 0, 0, 0.235);\r
+ node.init(text, location, delayMark, arrowHead, font, color, 0, 0, 0.235);\r
\r
update(e);\r
}\r
private double angle = 0.1;\r
private String side;\r
private boolean delayMark = false;\r
+ private boolean arrowHead = true;\r
private transient Triple<Arc2D, Path2D, Path2D> shapes = new Triple<Arc2D, Path2D, Path2D>(new Arc2D.Double(), new Path2D.Double(), new Path2D.Double());\r
\r
transient public boolean hover = false;\r
private boolean dragging = false;\r
\r
private transient PropertyChangeListener fieldListener = null;\r
-\r
+ \r
@Override\r
public void init() {\r
super.init();\r
* @param y Text initial location y\r
* @param scale Scale\r
*/\r
- public void init(String text, String side, boolean delayMark, Font font, Color color, double x, double y, double scale) {\r
+ public void init(String text, String side, boolean delayMark, boolean arrowHead, Font font, Color color, double x, double y, double scale) {\r
super.init(text, font, color, x, y, scale);\r
this.side = side;\r
this.delayMark = delayMark;\r
+ this.arrowHead = arrowHead;\r
setHorizontalAlignment((byte) Alignment.CENTER.ordinal());\r
setVerticalAlignment((byte) Alignment.CENTER.ordinal());\r
}\r
if(color != null) g.setColor(color);\r
g.setStroke(stroke);\r
g.draw(shapes.first);\r
- g.fill(shapes.second);\r
+ if (arrowHead) g.fill(shapes.second);\r
if (delayMark) g.draw(shapes.third);\r
} else if (hover){\r
g.setColor(Color.LIGHT_GRAY);\r
if(color != null) g.setColor(color);\r
g.setStroke(stroke);\r
g.draw(shapes.first);\r
- g.fill(shapes.second);\r
+ if (arrowHead) g.fill(shapes.second);\r
if (delayMark) g.draw(shapes.third);\r
} else {\r
if(color != null) g.setColor(color);\r
if(stroke != null) g.setStroke(stroke);\r
g.draw(shapes.first);\r
- g.fill(shapes.second);\r
+ if (arrowHead) g.fill(shapes.second);\r
if (delayMark) g.draw(shapes.third);\r
}\r
\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.elements.connections.DependencyNode;\r
+import org.simantics.sysdyn.ui.properties.widgets.ArrowHeadWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.DelayMarkWidget;\r
import org.simantics.utils.datastructures.Pair;\r
import org.simantics.utils.datastructures.Triple;\r
Button none, plus, minus, other, inside, outside;\r
TrackedText polarityText, polarityLocationText;\r
private DelayMarkWidget delayMark;\r
+ private ArrowHeadWidget arrowhead;\r
\r
@Override\r
public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE));\r
outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE));\r
\r
- delayMark = new DelayMarkWidget(composite, support, SWT.NULL);\r
+ Composite misc = new Composite(composite, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(misc);\r
+ GridLayoutFactory.fillDefaults().numColumns(2).applyTo(misc);\r
+ \r
+ arrowhead = new ArrowHeadWidget(misc, support, SWT.NULL);\r
+ GridDataFactory.fillDefaults().applyTo(arrowhead.getWidget());\r
+ delayMark = new DelayMarkWidget(misc, support, SWT.NULL);\r
GridDataFactory.fillDefaults().applyTo(delayMark.getWidget());\r
}\r
\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.elements.connections.DependencyNode;\r
+import org.simantics.sysdyn.ui.properties.widgets.ArrowHeadWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.DelayMarkWidget;\r
import org.simantics.utils.datastructures.Pair;\r
import org.simantics.utils.datastructures.Triple;\r
Button none, plus, minus, other, inside, outside;\r
TrackedText polarityText, polarityLocationText;\r
private DelayMarkWidget delayMark;\r
+ private ArrowHeadWidget arrowhead;\r
\r
@Override\r
public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE));\r
outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE));\r
\r
- delayMark = new DelayMarkWidget(composite, support, SWT.NULL);\r
+ Composite misc = new Composite(composite, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(misc);\r
+ GridLayoutFactory.fillDefaults().numColumns(2).applyTo(misc);\r
+ \r
+ arrowhead = new ArrowHeadWidget(misc, support, SWT.NULL);\r
+ GridDataFactory.fillDefaults().applyTo(arrowhead.getWidget());\r
+ delayMark = new DelayMarkWidget(misc, support, SWT.NULL);\r
GridDataFactory.fillDefaults().applyTo(delayMark.getWidget());\r
}\r
\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Button;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+/**\r
+ * Widget for showing arrow head in dependencies.\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class ArrowHeadWidget implements Widget{\r
+\r
+ List<Resource> variables = null; \r
+ org.simantics.browsing.ui.swt.widgets.Button arrowheadButton;\r
+ \r
+ public ArrowHeadWidget(Composite parent, WidgetSupport support, int style) {\r
+ support.register(this);\r
+ arrowheadButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK);\r
+ arrowheadButton.setText("Arrowhead");\r
+ }\r
+\r
+ @SuppressWarnings({ "rawtypes", "unchecked" })\r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ if(input instanceof ISelection) {\r
+ ISelection selection = (ISelection)input;\r
+ if(selection instanceof IStructuredSelection) {\r
+ List<Resource> resources = ISelectionUtils.filterSelection(selection, Resource.class);\r
+ if(resources != null && !resources.isEmpty()) {\r
+ variables = resources;\r
+ } else {\r
+ List<ArrayList> resourceLists = ISelectionUtils.filterSelection(selection, ArrayList.class);\r
+ variables = resourceLists.get(0);\r
+ }\r
+ }\r
+ }\r
+\r
+ if(variables == null) return;\r
+ \r
+ try {\r
+ context.getSession().syncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ // Determine if there are arrowheads in some of the variables.\r
+ boolean hasArrowheads = false, hasNotArrowheads = false;\r
+ for (Resource variable : variables) {\r
+ if (!graph.hasStatement(variable, sr.DependencyConnection_hideArrow)) {\r
+ hasArrowheads = true;\r
+ } else {\r
+ hasNotArrowheads = true;\r
+ }\r
+ }\r
+ \r
+ // If some have arrowheads but others don't, the check box is grayed.\r
+ final Button button = getWidget();\r
+ final boolean arrowhead = hasArrowheads;\r
+ final boolean mixedArrowheads = hasArrowheads && hasNotArrowheads;\r
+ button.getDisplay().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ if(button.isDisposed()) return;\r
+ button.setSelection(arrowhead);\r
+ button.setGrayed(mixedArrowheads);\r
+ }\r
+ });\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ // Multiple selections\r
+ arrowheadButton.addSelectionListener(new SelectionListenerImpl<ArrayList<Resource>>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, ArrayList<Resource> inputs) throws DatabaseException {\r
+ if (inputs == null)\r
+ return;\r
+ \r
+ final SysdynResource sr = SysdynResource.getInstance(graph);\r
+ boolean nextState = true; // The next state of the checkbox\r
+ for (Resource variable : variables) {\r
+ if (!graph.hasStatement(variable, sr.DependencyConnection_hideArrow)) {\r
+ nextState = false; // The next state is true iff all have hideArrow.\r
+ break;\r
+ }\r
+ }\r
+\r
+ try {\r
+ if (nextState) {\r
+ for (Resource input : inputs) {\r
+ graph.deny(input, sr.DependencyConnection_hideArrow);\r
+ }\r
+ } else {\r
+ for (Resource input : inputs) {\r
+ graph.claim(input, SysdynResource.getInstance(graph).DependencyConnection_hideArrow, null, input);\r
+ }\r
+ }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ // Get the button out of the grayed state.\r
+ final Button button = getWidget();\r
+ button.getDisplay().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ button.setGrayed(false);\r
+ }\r
+ });\r
+ }\r
+ });\r
+ \r
+ // One selection\r
+ arrowheadButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+ if (input == null)\r
+ return;\r
+ \r
+ final SysdynResource sr = SysdynResource.getInstance(graph);\r
+ if(graph.hasStatement(input, sr.DependencyConnection_hideArrow)) {\r
+ graph.deny(input, sr.DependencyConnection_hideArrow);\r
+ } else {\r
+ graph.claim(input, SysdynResource.getInstance(graph).DependencyConnection_hideArrow, null, input);\r
+ }\r
+ } \r
+ });\r
+ }\r
+ \r
+ public Button getWidget() {\r
+ return arrowheadButton.getWidget();\r
+ }\r
+\r
+}\r