From: miettinen Date: Tue, 19 Nov 2013 10:58:55 +0000 (+0000) Subject: Modify the styles of multiple selected dependencies. (refs #4554) X-Git-Tag: 1.8.1~191 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=50fdb0e79171d7b4ad3c89a1857291eb5aefb968;p=simantics%2Fsysdyn.git Modify the styles of multiple selected dependencies. (refs #4554) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28322 ac1ea38d-2e2b-0410-8846-a27921b304fc --- 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 new file mode 100644 index 00000000..247d1d50 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java @@ -0,0 +1,277 @@ +/******************************************************************************* + * 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; + +import java.util.ArrayList; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.util.ObjectUtils; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +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.utils.datastructures.Pair; +import org.simantics.utils.datastructures.Triple; + +/** + * Tab for multiple dependencies. + * @author Tuomas Miettinen + * + */ +public class ArrayDependencyTab extends LabelPropertyTabContributor { + + Button none, plus, minus, other, inside, outside; + TrackedText polarityText, polarityLocationText; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(composite); + + /* Add a dummy button at the begin to suck in the nonsense selection events that + * the first radio button in the group of ALL the radio buttons receives when no + * radio is selected and then one is selected in other group than where the first + * radio button lies. + */ + Group hiddenDefaultbuttonGroup = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().exclude(true).applyTo(hiddenDefaultbuttonGroup); + GridLayoutFactory.fillDefaults().applyTo(hiddenDefaultbuttonGroup); + new Button(hiddenDefaultbuttonGroup, support, SWT.RADIO); + + Group polarityGroup = new Group(composite, SWT.NONE); + polarityGroup.setText("Polarity"); + GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityGroup); + GridLayoutFactory.fillDefaults().numColumns(5).applyTo(polarityGroup); + + none = new Button(polarityGroup, support, SWT.RADIO); + none.setText("None"); + none.setSelectionFactory(new PolarityRadioSelectionFactory("")); + none.addSelectionListener(new PolaritySelectionListener(context, "")); + + plus = new Button(polarityGroup, support, SWT.RADIO); + plus.setText("+"); + plus.setSelectionFactory(new PolarityRadioSelectionFactory("+")); + plus.addSelectionListener(new PolaritySelectionListener(context, "+")); + + minus = new Button(polarityGroup, support, SWT.RADIO); + minus.setText("-"); + minus.setSelectionFactory(new PolarityRadioSelectionFactory("-")); + minus.addSelectionListener(new PolaritySelectionListener(context, "-")); + + other = new Button(polarityGroup, support, SWT.RADIO); + other.setText("other"); + other.setSelectionFactory(new OtherPolaritySelectionFactory(new String[] {null, "+", "-", ""})); + + polarityText = new TrackedText(polarityGroup, support, SWT.BORDER); + polarityText.setTextFactory(new OtherPolarityStringPropertyFactory()); + polarityText.addModifyListener(new OtherPolarityStringPropertyModifier()); + GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityText.getWidget()); + + Group locationGroup = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(locationGroup); + GridLayoutFactory.fillDefaults().applyTo(locationGroup); + locationGroup.setText("Location"); + + inside = new Button(locationGroup, support, SWT.RADIO); + inside.setText("Inside"); + inside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.INSIDE)); + inside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.INSIDE)); + + outside = new Button(locationGroup, support, SWT.RADIO); + outside.setText("Outside"); + outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE)); + outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE)); + } + + class OtherPolarityStringPropertyFactory extends ReadFactoryImpl, String> { + + private final String propertyURI; + + public OtherPolarityStringPropertyFactory() { + this.propertyURI = SysdynResource.URIs.DependencyConnection_polarity; + } + + @SuppressWarnings("unchecked") + @Override + public Object getIdentity(Object inputContents) { + return new Triple, String, Object>((ArrayList) inputContents, propertyURI, getClass()); + } + + @Override + public String perform(ReadGraph graph, ArrayList resources) throws DatabaseException { + String value = graph.getPossibleRelatedValue(resources.get(0), graph.getResource(propertyURI));; + if (value == null) + return ""; + for (Resource r : resources) { + String s = graph.getPossibleRelatedValue(r, graph.getResource(propertyURI)); + if (!value.equals(s)) + return ""; + } + return value; + } + } + + class OtherPolarityStringPropertyModifier extends TextModifyListenerImpl> { + + final private String propertyURI; + + public OtherPolarityStringPropertyModifier() { + this.propertyURI = SysdynResource.URIs.DependencyConnection_polarity; + } + + @Override + public void applyText(WriteGraph graph, ArrayList resources, String text) throws DatabaseException { + for (Resource r : resources) + graph.claimLiteral(r, graph.getResource(propertyURI), text, Bindings.STRING); + } + + } + + class PolarityLocationSelectionListener extends SelectionListenerImpl> { + private String location; + + public PolarityLocationSelectionListener(ISessionContext context, String location) { + super(context); + this.location = location; + } + + @Override + public void apply(WriteGraph graph, ArrayList connectionElements) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + for (Resource r : connectionElements) + graph.claimLiteral(r, sr.DependencyConnection_polarityLocation, location); + } + + } + + class PolarityLocationRadioSelectionFactory extends ReadFactoryImpl, Boolean> { + private String location; + + public PolarityLocationRadioSelectionFactory(String location) { + this.location = location; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Triple>(inputContents, location, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, ArrayList dependencyConnections) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + for (Resource r : dependencyConnections) { + String location = graph.getPossibleRelatedValue(r, sr.DependencyConnection_polarityLocation, Bindings.STRING); + if (DependencyNode.OUTSIDE.equals(this.location)) { + if (ObjectUtils.objectEquals(this.location, location)) + continue; + } else { + if (location == null) { + continue; + } else { + if (ObjectUtils.objectEquals(this.location, location)) + continue; + } + } + return false; + } + return true; + } + } + + class PolaritySelectionListener extends SelectionListenerImpl> { + private String polarity; + + public PolaritySelectionListener(ISessionContext context, String polarity) { + super(context); + this.polarity = polarity; + } + + @Override + public void apply(WriteGraph graph, ArrayList connectionElements) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + for (Resource r : connectionElements) + graph.claimLiteral(r, sr.DependencyConnection_polarity, polarity.trim()); + } + + } + + class PolarityRadioSelectionFactory extends ReadFactoryImpl, Boolean> { + private String polarity; + + public PolarityRadioSelectionFactory(String polarity) { + this.polarity = polarity; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Triple>(inputContents, polarity, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, ArrayList dependencyConnections) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + for (Resource r : dependencyConnections) { + String polarity = graph.getPossibleRelatedValue(r, sr.DependencyConnection_polarity, Bindings.STRING); + if (polarity == null && this.polarity.equals("")) + continue; + if (ObjectUtils.objectEquals(polarity, this.polarity)) + continue; + return false; + } + return true; + } + } + + class OtherPolaritySelectionFactory extends ReadFactoryImpl, Boolean> { + + String[] limits; + + public OtherPolaritySelectionFactory(String[] limits) { + this.limits = limits; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Pair>(inputContents, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, ArrayList dependencyConnections) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + for (Resource r : dependencyConnections) { + String polarity = graph.getPossibleRelatedValue(r, sr.DependencyConnection_polarity, Bindings.STRING); + for(String s : limits) { + if(ObjectUtils.objectEquals(polarity, s)) + return false; + } + } + return true; + } + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 3b516bbb..20adbc43 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -75,7 +75,8 @@ public class ResourceSelectionProcessor implements SelectionProcessor && ((ArrayList) selection).size() > 1) { - List variables = new ArrayList(); + List variables = new ArrayList(); + List dependencies = new ArrayList(); Resource model = null; for(Object o : (ArrayList)selection) { Resource r = AdaptionUtils.adaptToSingle(o, Resource.class); @@ -84,21 +85,42 @@ public class ResourceSelectionProcessor implements SelectionProcessor