From: miettinen Date: Tue, 7 Jan 2014 06:26:14 +0000 (+0000) Subject: Checkbox to dependencies to show or hide the arrow head (refs #4619). X-Git-Tag: 1.8.1~173 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=531aca1ffa833e73e4313b03d2459207184a094d;p=simantics%2Fsysdyn.git Checkbox to dependencies to show or hide the arrow head (refs #4619). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28591 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index c232a28f..9e286494 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 8ccf63a5..ce5012f7 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -581,6 +581,8 @@ SYSDYN.DependencyConnection -- SYSDYN.DependencyConnection.polarity --> L0.String -- SYSDYN.DependencyConnection.polarityLocation --> L0.String -- SYSDYN.DependencyConnection.hideArrow --> SYSDYN.DependencyConnection -- SYSDYN.DependencyConnection.delayMark --> SYSDYN.DependencyConnection polarityPair = (Pair)properties.get("polarity"); Pair polarityLocationPair = (Pair)properties.get("polarityLocation"); boolean delayMark = properties.containsKey("delayMark"); + boolean arrowHead = !properties.containsKey("hideArrow"); String location; if(polarityLocationPair == null) @@ -139,7 +140,7 @@ public class DependencyEdgeClass { location = (String) polarityLocationPair.second; String text = polarityPair != null ? (String) polarityPair.second : ""; - node.init(text, location, delayMark, font, color, 0, 0, 0.235); + node.init(text, location, delayMark, arrowHead, font, color, 0, 0, 0.235); update(e); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyNode.java index ec84bbde..3b2bea29 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyNode.java @@ -66,13 +66,14 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode { private double angle = 0.1; private String side; private boolean delayMark = false; + private boolean arrowHead = true; private transient Triple shapes = new Triple(new Arc2D.Double(), new Path2D.Double(), new Path2D.Double()); transient public boolean hover = false; private boolean dragging = false; private transient PropertyChangeListener fieldListener = null; - + @Override public void init() { super.init(); @@ -91,10 +92,11 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode { * @param y Text initial location y * @param scale Scale */ - public void init(String text, String side, boolean delayMark, Font font, Color color, double x, double y, double scale) { + public void init(String text, String side, boolean delayMark, boolean arrowHead, Font font, Color color, double x, double y, double scale) { super.init(text, font, color, x, y, scale); this.side = side; this.delayMark = delayMark; + this.arrowHead = arrowHead; setHorizontalAlignment((byte) Alignment.CENTER.ordinal()); setVerticalAlignment((byte) Alignment.CENTER.ordinal()); } @@ -196,7 +198,7 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode { if(color != null) g.setColor(color); g.setStroke(stroke); g.draw(shapes.first); - g.fill(shapes.second); + if (arrowHead) g.fill(shapes.second); if (delayMark) g.draw(shapes.third); } else if (hover){ g.setColor(Color.LIGHT_GRAY); @@ -206,13 +208,13 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode { if(color != null) g.setColor(color); g.setStroke(stroke); g.draw(shapes.first); - g.fill(shapes.second); + if (arrowHead) g.fill(shapes.second); if (delayMark) g.draw(shapes.third); } else { if(color != null) g.setColor(color); if(stroke != null) g.setStroke(stroke); g.draw(shapes.first); - g.fill(shapes.second); + if (arrowHead) g.fill(shapes.second); if (delayMark) g.draw(shapes.third); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java index b31a23ea..95b66dce 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java @@ -34,6 +34,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.elements.connections.DependencyNode; +import org.simantics.sysdyn.ui.properties.widgets.ArrowHeadWidget; import org.simantics.sysdyn.ui.properties.widgets.DelayMarkWidget; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.datastructures.Triple; @@ -48,6 +49,7 @@ public class ArrayDependencyTab extends LabelPropertyTabContributor { Button none, plus, minus, other, inside, outside; TrackedText polarityText, polarityLocationText; private DelayMarkWidget delayMark; + private ArrowHeadWidget arrowhead; @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { @@ -109,7 +111,13 @@ public class ArrayDependencyTab extends LabelPropertyTabContributor { outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE)); outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE)); - delayMark = new DelayMarkWidget(composite, support, SWT.NULL); + Composite misc = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(misc); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(misc); + + arrowhead = new ArrowHeadWidget(misc, support, SWT.NULL); + GridDataFactory.fillDefaults().applyTo(arrowhead.getWidget()); + delayMark = new DelayMarkWidget(misc, support, SWT.NULL); GridDataFactory.fillDefaults().applyTo(delayMark.getWidget()); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java index 659180bb..615c7ad4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java @@ -33,6 +33,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.elements.connections.DependencyNode; +import org.simantics.sysdyn.ui.properties.widgets.ArrowHeadWidget; import org.simantics.sysdyn.ui.properties.widgets.DelayMarkWidget; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.datastructures.Triple; @@ -42,6 +43,7 @@ public class DependencyTab extends LabelPropertyTabContributor { Button none, plus, minus, other, inside, outside; TrackedText polarityText, polarityLocationText; private DelayMarkWidget delayMark; + private ArrowHeadWidget arrowhead; @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { @@ -93,7 +95,13 @@ public class DependencyTab extends LabelPropertyTabContributor { outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE)); outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE)); - delayMark = new DelayMarkWidget(composite, support, SWT.NULL); + Composite misc = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(misc); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(misc); + + arrowhead = new ArrowHeadWidget(misc, support, SWT.NULL); + GridDataFactory.fillDefaults().applyTo(arrowhead.getWidget()); + delayMark = new DelayMarkWidget(misc, support, SWT.NULL); GridDataFactory.fillDefaults().applyTo(delayMark.getWidget()); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrowHeadWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrowHeadWidget.java new file mode 100644 index 00000000..76981357 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrowHeadWidget.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.ui.ISelectionUtils; + +/** + * Widget for showing arrow head in dependencies. + * @author Tuomas Miettinen + * + */ +public class ArrowHeadWidget implements Widget{ + + List variables = null; + org.simantics.browsing.ui.swt.widgets.Button arrowheadButton; + + public ArrowHeadWidget(Composite parent, WidgetSupport support, int style) { + support.register(this); + arrowheadButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK); + arrowheadButton.setText("Arrowhead"); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void setInput(ISessionContext context, Object input) { + if(input instanceof ISelection) { + ISelection selection = (ISelection)input; + if(selection instanceof IStructuredSelection) { + List resources = ISelectionUtils.filterSelection(selection, Resource.class); + if(resources != null && !resources.isEmpty()) { + variables = resources; + } else { + List resourceLists = ISelectionUtils.filterSelection(selection, ArrayList.class); + variables = resourceLists.get(0); + } + } + } + + if(variables == null) return; + + try { + context.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + + // Determine if there are arrowheads in some of the variables. + boolean hasArrowheads = false, hasNotArrowheads = false; + for (Resource variable : variables) { + if (!graph.hasStatement(variable, sr.DependencyConnection_hideArrow)) { + hasArrowheads = true; + } else { + hasNotArrowheads = true; + } + } + + // If some have arrowheads but others don't, the check box is grayed. + final Button button = getWidget(); + final boolean arrowhead = hasArrowheads; + final boolean mixedArrowheads = hasArrowheads && hasNotArrowheads; + button.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(button.isDisposed()) return; + button.setSelection(arrowhead); + button.setGrayed(mixedArrowheads); + } + }); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + // Multiple selections + arrowheadButton.addSelectionListener(new SelectionListenerImpl>(context) { + + @Override + public void apply(WriteGraph graph, ArrayList inputs) throws DatabaseException { + if (inputs == null) + return; + + final SysdynResource sr = SysdynResource.getInstance(graph); + boolean nextState = true; // The next state of the checkbox + for (Resource variable : variables) { + if (!graph.hasStatement(variable, sr.DependencyConnection_hideArrow)) { + nextState = false; // The next state is true iff all have hideArrow. + break; + } + } + + try { + if (nextState) { + for (Resource input : inputs) { + graph.deny(input, sr.DependencyConnection_hideArrow); + } + } else { + for (Resource input : inputs) { + graph.claim(input, SysdynResource.getInstance(graph).DependencyConnection_hideArrow, null, input); + } + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + + // Get the button out of the grayed state. + final Button button = getWidget(); + button.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + button.setGrayed(false); + } + }); + } + }); + + // One selection + arrowheadButton.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + if (input == null) + return; + + final SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.hasStatement(input, sr.DependencyConnection_hideArrow)) { + graph.deny(input, sr.DependencyConnection_hideArrow); + } else { + graph.claim(input, SysdynResource.getInstance(graph).DependencyConnection_hideArrow, null, input); + } + } + }); + } + + public Button getWidget() { + return arrowheadButton.getWidget(); + } + +}