From: lempinen Date: Tue, 1 Nov 2011 14:15:28 +0000 (+0000) Subject: Valve horizontal and vertical orientation and text locations X-Git-Tag: simantics-1.6~113 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=d16be2975c96c850f60d4814a5f97f7e80303458;p=simantics%2Fsysdyn.git Valve horizontal and vertical orientation and text locations git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23151 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 1d3d856b..3863b84b 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 e35c30e6..35980897 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -400,15 +400,26 @@ SYSDYN.Valve >(uri, defaultSelected, getClass()); + return new Quad>(button, uri, defaultSelected, getClass()); } @Override @@ -129,6 +131,12 @@ public class ValveOrientationGroup extends WidgetImpl { if(graph.hasStatement(symbol, sr.HasValveOrientation)) graph.deny(symbol, sr.HasValveOrientation); graph.claim(symbol, sr.HasValveOrientation, graph.getResource(uri)); + + if(graph.hasStatement(symbol, sr.HasTextLocation)) + graph.deny(symbol, sr.HasTextLocation); + if(sr.Vertical.equals(graph.getResource(uri))) + graph.claim(symbol, sr.HasTextLocation, sr.Right); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java new file mode 100644 index 00000000..04252f0a --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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 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.Control; +import org.eclipse.swt.widgets.Group; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.WidgetImpl; +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.WidgetSupport; +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.modeling.ModelingResources; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.Quad; + +public class ValveTextLocationGroup extends WidgetImpl { + + Group group; + Button top, bottom, left, right; + + public ValveTextLocationGroup(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(support); + + group = new Group(parent, SWT.NONE); + group.setText("Text location"); + GridDataFactory.fillDefaults().applyTo(group); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(group); + + top = new Button(group, support, SWT.RADIO); + top.setText("Top"); + top.setSelectionFactory(new LocationSelectionFactory(top, SysdynResource.URIs.Top)); + top.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Top)); + + bottom = new Button(group, support, SWT.RADIO); + bottom.setText("Bottom"); + bottom.setSelectionFactory(new LocationSelectionFactory(bottom, SysdynResource.URIs.Bottom, true)); + bottom.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Bottom)); + + left = new Button(group, support, SWT.RADIO); + left.setText("Left"); + left.setSelectionFactory(new LocationSelectionFactory(left, SysdynResource.URIs.Left)); + left.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Left)); + + right = new Button(group, support, SWT.RADIO); + right.setText("Right"); + right.setSelectionFactory(new LocationSelectionFactory(right, SysdynResource.URIs.Right)); + right.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Right)); + + } + + @Override + public void setInput(ISessionContext context, Object input) { + // TODO Auto-generated method stub + + } + + @Override + public Control getControl() { + return this.group; + } + + + private class LocationSelectionFactory extends ReadFactoryImpl { + + boolean defaultSelected; + String uri; + Button button; + + public LocationSelectionFactory(Button button, String uri) { + this(button, uri, false); + } + + public LocationSelectionFactory(Button button, String uri, boolean defaultSelected) { + this.uri = uri; + this.defaultSelected = defaultSelected; + this.button = button; + } + + public Object getIdentity(Object inputContents) { + return new Quad>(button, uri, defaultSelected, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, Resource valve) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + if(!graph.isInstanceOf(valve, sr.Valve)) + return Boolean.FALSE; + + Resource symbol = graph.getPossibleObject(valve, mr.ComponentToElement); + if(symbol == null) + return Boolean.FALSE; + + Resource location = graph.getPossibleObject(symbol, sr.HasTextLocation); + + if(location == null) + return defaultSelected; + + return location.equals(graph.getResource(uri)); + } + + } + + + private class LocationSelectionListener extends SelectionListenerImpl { + + String uri; + + public LocationSelectionListener(ISessionContext context, String uri) { + super(context); + this.uri = uri; + } + + @Override + public void apply(WriteGraph graph, Resource valve) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + if(!graph.isInstanceOf(valve, sr.Valve)) + return; + + Resource symbol = graph.getPossibleObject(valve, mr.ComponentToElement); + if(symbol == null) + return; + + if(graph.hasStatement(symbol, sr.HasTextLocation)) + graph.deny(symbol, sr.HasTextLocation); + graph.claim(symbol, sr.HasTextLocation, graph.getResource(uri)); + } + + } + +}