--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in 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.objmap.annotations;\r
+\r
+import java.lang.annotation.ElementType;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.RetentionPolicy;\r
+import java.lang.annotation.Target;\r
+\r
+import org.simantics.objmap.annotations.factories.RelatedOrderedSetElementsRuleFactory;\r
+import org.simantics.objmap.annotations.meta.HasFieldRuleFactory;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@Target(ElementType.FIELD)\r
+@HasFieldRuleFactory(RelatedOrderedSetElementsRuleFactory.class)\r
+public @interface RelatedOrderedSetElements {\r
+ boolean composition() default false;\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in 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.objmap.annotations.factories;\r
+\r
+import java.lang.annotation.Annotation;\r
+import java.lang.reflect.Field;\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.ResourceNotFoundException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.exception.ValidationException;\r
+import org.simantics.objmap.IMappingRule;\r
+import org.simantics.objmap.annotations.RelatedOrderedSetElements;\r
+import org.simantics.objmap.rules.MappedElementsRule;\r
+import org.simantics.objmap.rules.domain.RelatedOrderedSetElementsAccessor;\r
+import org.simantics.objmap.rules.factory.IFieldRuleFactory;\r
+import org.simantics.objmap.rules.range.FieldAccessor;\r
+\r
+public class RelatedOrderedSetElementsRuleFactory implements IFieldRuleFactory {\r
+\r
+ @Override\r
+ public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException {\r
+ RelatedOrderedSetElements annotation = (RelatedOrderedSetElements)_annotation;\r
+ return new MappedElementsRule(\r
+ new RelatedOrderedSetElementsAccessor(annotation.composition()),\r
+ new FieldAccessor<Collection<Object>>(field)\r
+ );\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in 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.objmap.rules.domain;\r
+\r
+import java.util.Collection;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.objmap.MappingException;\r
+\r
+/**\r
+ * Accesses the set of objects attached to the element by the given relation.\r
+ * @author Hannu Niemistö\r
+ */\r
+public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Collection<Resource>> {\r
+\r
+ static Logger LOGGER = Logger.getLogger("org.simantics.objmap");\r
+ \r
+ boolean deleteExtraObjects;\r
+\r
+ public RelatedOrderedSetElementsAccessor(boolean deleteExtraObjects) {\r
+ super();\r
+ this.deleteExtraObjects = deleteExtraObjects;\r
+ }\r
+\r
+ @Override\r
+ public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {\r
+ try {\r
+ LOGGER.info(" RelatedOrderedSetElementsAccessor.get");\r
+ return OrderedSetUtils.toList(g, element);\r
+ } catch (DatabaseException e) {\r
+ throw new MappingException(e);\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public boolean set(WriteGraph g, Resource element, Collection<Resource> value)\r
+ throws MappingException {\r
+ try {\r
+ LOGGER.info(" RelatedOrderedSetElementsAccessor.set");\r
+ return OrderedSetUtils.set(g, element, value);\r
+ // FIXME Implement deleteExtraObjects\r
+ } catch (DatabaseException e) {\r
+ throw new MappingException(e);\r
+ }\r
+ \r
+ }\r
+\r
+}\r
SYSDYN.Variable <T STR.Component
@L0.singleProperty L0.HasType
- @L0.singleProperty SYSDYN.HasX
- @L0.singleProperty SYSDYN.HasY
-SYSDYN.HasX <R L0.HasProperty : L0.FunctionalRelation
- L0.HasRange L0.Double
-SYSDYN.HasY <R L0.HasProperty : L0.FunctionalRelation
- L0.HasRange L0.Double
SYSDYN.HasExpression <R L0.IsComposedOf : L0.FunctionalRelation
L0.HasRange SYSDYN.Expression
-
SYSDYN.HasUnit <R L0.HasProperty
L0.HasRange L0.String
@L0.optionalProperty SYSDYN.HasUnit
@L0.assert SYSDYN.HasDefaultInputValue 0.0
@L0.assert L0.HasType "Real"
+
+SYSDYN.Enumeration <T SYSDYN.Variable
+ @L0.singleProperty SYSDYN.HasEnumerationIndexes
+ @L0.assert L0.HasType "type"
+
//#####################################################################
// Modules
SYSDYN.HasDefaultInputValue <R L0.HasProperty : L0.FunctionalRelation
L0.HasRange L0.Double
+SYSDYN.HasEnumerationIndexes <R L0.DependsOn : L0.FunctionalRelation
+ L0.HasDomain SYSDYN.Enumeration
+ L0.HasRange SYSDYN.EnumerationIndexes
+
+SYSDYN.EnumerationIndexes <T L0.OrderedSet <R L0.HasNext
+
+SYSDYN.EnumerationIndex <T L0.Entity
+ L0.singleProperty L0.HasName
//#####################################################################
// Experiments
//#####################################################################
WC.Work2Amount : SYSDYN.Auxiliary\r
@L0.tag MOD.Mapped \r
SYSDYN.HasExpression _ : SYSDYN.ParameterExpression\r
- SYSDYN.HasEquation "700" \r
+ SYSDYN.HasEquation "700" \r
+ \r
+// Enumeration Test\r
+WC.EnumerationTest : SYSDYN.Enumeration\r
+ SYSDYN.HasEnumerationIndexes _ : SYSDYN.EnumerationIndexes\r
+ @L0.list\r
+ _ : SYSDYN.EnumerationIndex\r
+ L0.HasName "Moro" : L0.String\r
+ _ : SYSDYN.EnumerationIndex\r
+ L0.HasName "Tere" : L0.String \r
\r
// Inputs\r
WC.TotalPossibleWorkingSpeedInput : SYSDYN.Input\r
public final Resource DevelopmentProject_WorkModel;\r
public final Resource DevelopmentProject_WorkModel_Experiment;\r
public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration;\r
+ public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration_EnumerationTest;\r
public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed1;\r
public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed2;\r
public final Resource DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeedTotal;\r
public final Resource DevelopmentProject_dependency;\r
public final Resource DevelopmentProject_flow;\r
public final Resource DiagramToCompositeMapping;\r
+ public final Resource Enumeration;\r
+ public final Resource EnumerationIndex;\r
+ public final Resource EnumerationIndexes;\r
+ public final Resource EnumerationIndexes_Inverse;\r
public final Resource Experiment;\r
public final Resource Expression;\r
public final Resource Flow;\r
public final Resource GameExperiment;\r
public final Resource HasDefaultInputValue;\r
public final Resource HasDefaultInputValue_Inverse;\r
+ public final Resource HasEnumerationIndexes;\r
+ public final Resource HasEnumerationIndexes_Inverse;\r
public final Resource HasEquation;\r
public final Resource HasEquation_Inverse;\r
public final Resource HasExpression;\r
public final Resource HasTolerance_Inverse;\r
public final Resource HasUnit;\r
public final Resource HasUnit_Inverse;\r
- public final Resource HasX;\r
- public final Resource HasX_Inverse;\r
- public final Resource HasY;\r
- public final Resource HasY_Inverse;\r
public final Resource HistoryRealization;\r
public final Resource ImportedOntologies;\r
public final Resource IndependentVariable;\r
public static final String DevelopmentProject_WorkModel = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel";\r
public static final String DevelopmentProject_WorkModel_Experiment = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/Experiment";\r
public static final String DevelopmentProject_WorkModel_WorkModelConfiguration = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration";\r
+ public static final String DevelopmentProject_WorkModel_WorkModelConfiguration_EnumerationTest = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration/EnumerationTest";\r
public static final String DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed1 = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration/RequiredWorkingSpeed1";\r
public static final String DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed2 = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration/RequiredWorkingSpeed2";\r
public static final String DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeedTotal = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/WorkModel/WorkModelConfiguration/RequiredWorkingSpeedTotal";\r
public static final String DevelopmentProject_dependency = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/dependency";\r
public static final String DevelopmentProject_flow = "http://www.simantics.org/Sysdyn-1.0/DevelopmentProject/flow";\r
public static final String DiagramToCompositeMapping = "http://www.simantics.org/Sysdyn-1.0/DiagramToCompositeMapping";\r
+ public static final String Enumeration = "http://www.simantics.org/Sysdyn-1.0/Enumeration";\r
+ public static final String EnumerationIndex = "http://www.simantics.org/Sysdyn-1.0/EnumerationIndex";\r
+ public static final String EnumerationIndexes = "http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes";\r
+ public static final String EnumerationIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes/Inverse";\r
public static final String Experiment = "http://www.simantics.org/Sysdyn-1.0/Experiment";\r
public static final String Expression = "http://www.simantics.org/Sysdyn-1.0/Expression";\r
public static final String Flow = "http://www.simantics.org/Sysdyn-1.0/Flow";\r
public static final String GameExperiment = "http://www.simantics.org/Sysdyn-1.0/GameExperiment";\r
public static final String HasDefaultInputValue = "http://www.simantics.org/Sysdyn-1.0/HasDefaultInputValue";\r
public static final String HasDefaultInputValue_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasDefaultInputValue/Inverse";\r
+ public static final String HasEnumerationIndexes = "http://www.simantics.org/Sysdyn-1.0/HasEnumerationIndexes";\r
+ public static final String HasEnumerationIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasEnumerationIndexes/Inverse";\r
public static final String HasEquation = "http://www.simantics.org/Sysdyn-1.0/HasEquation";\r
public static final String HasEquation_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasEquation/Inverse";\r
public static final String HasExpression = "http://www.simantics.org/Sysdyn-1.0/HasExpression";\r
public static final String HasTolerance_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasTolerance/Inverse";\r
public static final String HasUnit = "http://www.simantics.org/Sysdyn-1.0/HasUnit";\r
public static final String HasUnit_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasUnit/Inverse";\r
- public static final String HasX = "http://www.simantics.org/Sysdyn-1.0/HasX";\r
- public static final String HasX_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasX/Inverse";\r
- public static final String HasY = "http://www.simantics.org/Sysdyn-1.0/HasY";\r
- public static final String HasY_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasY/Inverse";\r
public static final String HistoryRealization = "http://www.simantics.org/Sysdyn-1.0/HistoryRealization";\r
public static final String ImportedOntologies = "http://www.simantics.org/Sysdyn-1.0/ImportedOntologies";\r
public static final String IndependentVariable = "http://www.simantics.org/Sysdyn-1.0/IndependentVariable";\r
DevelopmentProject_WorkModel = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel);\r
DevelopmentProject_WorkModel_Experiment = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_Experiment);\r
DevelopmentProject_WorkModel_WorkModelConfiguration = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration);\r
+ DevelopmentProject_WorkModel_WorkModelConfiguration_EnumerationTest = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration_EnumerationTest);\r
DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed1 = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed1);\r
DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed2 = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeed2);\r
DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeedTotal = getResourceOrNull(graph, URIs.DevelopmentProject_WorkModel_WorkModelConfiguration_RequiredWorkingSpeedTotal);\r
DevelopmentProject_dependency = getResourceOrNull(graph, URIs.DevelopmentProject_dependency);\r
DevelopmentProject_flow = getResourceOrNull(graph, URIs.DevelopmentProject_flow);\r
DiagramToCompositeMapping = getResourceOrNull(graph, URIs.DiagramToCompositeMapping);\r
+ Enumeration = getResourceOrNull(graph, URIs.Enumeration);\r
+ EnumerationIndex = getResourceOrNull(graph, URIs.EnumerationIndex);\r
+ EnumerationIndexes = getResourceOrNull(graph, URIs.EnumerationIndexes);\r
+ EnumerationIndexes_Inverse = getResourceOrNull(graph, URIs.EnumerationIndexes_Inverse);\r
Experiment = getResourceOrNull(graph, URIs.Experiment);\r
Expression = getResourceOrNull(graph, URIs.Expression);\r
Flow = getResourceOrNull(graph, URIs.Flow);\r
GameExperiment = getResourceOrNull(graph, URIs.GameExperiment);\r
HasDefaultInputValue = getResourceOrNull(graph, URIs.HasDefaultInputValue);\r
HasDefaultInputValue_Inverse = getResourceOrNull(graph, URIs.HasDefaultInputValue_Inverse);\r
+ HasEnumerationIndexes = getResourceOrNull(graph, URIs.HasEnumerationIndexes);\r
+ HasEnumerationIndexes_Inverse = getResourceOrNull(graph, URIs.HasEnumerationIndexes_Inverse);\r
HasEquation = getResourceOrNull(graph, URIs.HasEquation);\r
HasEquation_Inverse = getResourceOrNull(graph, URIs.HasEquation_Inverse);\r
HasExpression = getResourceOrNull(graph, URIs.HasExpression);\r
HasTolerance_Inverse = getResourceOrNull(graph, URIs.HasTolerance_Inverse);\r
HasUnit = getResourceOrNull(graph, URIs.HasUnit);\r
HasUnit_Inverse = getResourceOrNull(graph, URIs.HasUnit_Inverse);\r
- HasX = getResourceOrNull(graph, URIs.HasX);\r
- HasX_Inverse = getResourceOrNull(graph, URIs.HasX_Inverse);\r
- HasY = getResourceOrNull(graph, URIs.HasY);\r
- HasY_Inverse = getResourceOrNull(graph, URIs.HasY_Inverse);\r
HistoryRealization = getResourceOrNull(graph, URIs.HistoryRealization);\r
ImportedOntologies = getResourceOrNull(graph, URIs.ImportedOntologies);\r
IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable);\r
</with>\r
</visibleWhen>\r
</command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.newEnumeration"\r
+ id="org.simantics.sysdyn.ui.browser.newEnumeration"\r
+ label="Enumeration"\r
+ style="push">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
</menu>\r
<command\r
commandId="org.simantics.image.ui.importImage"\r
id="org.simantics.sysdyn.ui.importModel"\r
name="Import...">\r
</command>\r
+ <command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.NewEnumerationNodeHandler"\r
+ id="org.simantics.sysdyn.ui.newEnumeration"\r
+ name="New Enumeration">\r
+ </command>\r
</extension>\r
<extension\r
point="org.eclipse.ui.handlers">\r
args="org.simantics.image.ui.modelBrowser.ImageNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.EnumerationNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
</or>\r
</with>\r
</activeWhen>\r
package org.simantics.sysdyn.ui.browser;\r
\r
import org.eclipse.core.runtime.IAdaptable;\r
+import org.simantics.browsing.ui.NodeContext;\r
import org.simantics.db.Resource;\r
\r
public class BrowserSelection implements IAdaptable {\r
private Resource resource;\r
private Resource model;\r
private String URI;\r
+ private Object originalInput;\r
\r
- public BrowserSelection(Resource resource, String URI, Resource model) {\r
+ public BrowserSelection(Object originalInput, Resource resource, String URI, Resource model) {\r
+ this.originalInput = originalInput;\r
this.resource = resource;\r
this.URI = URI;\r
this.model = model;\r
public Object getAdapter(Class adapter) {\r
if (adapter == Resource.class)\r
return resource;\r
+ if (NodeContext.class.equals(adapter))\r
+ return originalInput;\r
+ if (originalInput instanceof IAdaptable) {\r
+ IAdaptable input = (IAdaptable)originalInput;\r
+ return input.getAdapter(adapter);\r
+ }\r
return null;\r
}\r
\r
if(vn != null) {\r
Resource resource = vn.getResource() == null ? vn.data : vn.getResource();\r
context = new AdaptableHintContext(SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY);\r
- context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(resource, vn.getURI(), vn.getModel()));\r
+ context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(objects[i], resource, vn.getURI(), vn.getModel()));\r
context.setHint(SelectionHints.KEY_SELECTION_PROPERTY, vn.getVariable());\r
} else {\r
context = new AdaptableHintContext(SelectionHints.KEY_MAIN);\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.EnumerationNode;\r
import org.simantics.sysdyn.ui.browser.nodes.InputNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
ArrayList<Resource> variables = new ArrayList<Resource>();\r
ArrayList<Resource> inputs = new ArrayList<Resource>();\r
ArrayList<Resource> modules = new ArrayList<Resource>();\r
+ ArrayList<Resource> enumerations = new ArrayList<Resource>();\r
\r
for(Resource r : graph.getObjects(configuration.data, l0.ConsistsOf)) {\r
Resource represents = graph.getSingleObject(r, l0.Represents);\r
inputs.add(r);\r
} else if (graph.isInstanceOf(represents, sr.Module)) {\r
modules.add(r);\r
+ } else if (graph.isInstanceOf(represents, sr.Enumeration)) {\r
+ enumerations.add(r);\r
}\r
}\r
\r
result.add(new InputNode(r));\r
for (Resource r : modules) \r
result.add(new ModuleNode(r));\r
+ for (Resource r : enumerations) \r
+ result.add(new EnumerationNode(r));\r
return result;\r
}\r
\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.CancelTransactionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+public class EnumerationNode extends VariableNode<Resource> implements IDeletableNode {\r
+\r
+ public EnumerationNode(Resource resource) {\r
+ super(resource);\r
+ }\r
+\r
+ @Override\r
+ public void delete() throws DeleteException {\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ graph.deny(resource, l0.PartOf); \r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ ExceptionUtils.logAndShowError(e);\r
+ } \r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+public class NewEnumerationNodeHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ \r
+ final Resource configuration = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph g) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+ Layer0 l0 = Layer0.getInstance(g);\r
+ \r
+\r
+ Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes);\r
+ \r
+ Resource enumeration = GraphUtils.create2(g, \r
+ sr.Enumeration,\r
+ l0.HasName, "Enumeration",\r
+ sr.HasEnumerationIndexes, enumerationIndexes);\r
+ \r
+ g.claim(configuration, l0.ConsistsOf, enumeration);\r
+ \r
+ }\r
+ });\r
+ return null;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.TableEditor;\r
+import org.eclipse.swt.events.FocusAdapter;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.ModifyEvent;\r
+import org.eclipse.swt.events.ModifyListener;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.TableItem;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.Table;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.databoard.binding.java.StringBindingDefault;\r
+import org.simantics.db.Builtins;\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.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+public class EnumerationTab extends PropertyTabContributorImpl {\r
+\r
+ Table table;\r
+ @Override\r
+ public void createControls(Composite body, IWorkbenchSite site,\r
+ final ISessionContext context, WidgetSupport support) {\r
+\r
+ Composite container = new Composite(body, SWT.None);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(container);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(container);\r
+\r
+ TrackedText nameText = new TrackedText(container, support, SWT.BORDER);\r
+ nameText.setTextFactory(new StringPropertyFactory(Builtins.URIs.HasName));\r
+ nameText.addModifyListener(new VariableNamePropertyModifier(context, Builtins.URIs.HasName));\r
+ nameText.setInputValidator(new VariableNameValidator(support));\r
+ GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(nameText.getWidget());\r
+\r
+\r
+ table = new Table(container, support, SWT.BORDER);\r
+ table.setItemFactory(new ReadFactoryImpl<Object, List<Pair<String,Object>>>() {\r
+\r
+ @Override\r
+ public List<Pair<String, Object>> perform(ReadGraph graph,\r
+ Object input) throws DatabaseException {\r
+ Resource enumeration = (Resource)input;\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource list = graph.getSingleObject(enumeration, sr.HasEnumerationIndexes);\r
+ List<Resource> resourceList = OrderedSetUtils.toList(graph, list);\r
+\r
+ List<Pair<String, Object>> result = new ArrayList<Pair<String, Object>>();\r
+ for(Resource r : resourceList) {\r
+ result.add(new Pair<String, Object>( \r
+ (String)graph.getRelatedValue(r, Layer0.getInstance(graph).HasName, StringBindingDefault.INSTANCE)\r
+ , r));\r
+ }\r
+ return result;\r
+ }\r
+ });\r
+ table.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+ return graph.getRelatedValue(input, Layer0.getInstance(graph).HasName);\r
+ }\r
+ });\r
+ GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(table.getWidget());\r
+ \r
+\r
+ final TableEditor editor = new TableEditor(table.getWidget());\r
+ // The editor must have the same size as the cell and must\r
+ // not be any smaller than 50 pixels.\r
+ editor.horizontalAlignment = SWT.LEFT;\r
+ editor.grabHorizontal = true;\r
+ editor.minimumWidth = 50;\r
+ // editing the second column\r
+ final int EDITABLECOLUMN = 0;\r
+\r
+ table.addSelectionListener(new SelectionAdapter() {\r
+ public void widgetSelected(SelectionEvent e) {\r
+ // Clean up any previous editor control\r
+ Control oldEditor = editor.getEditor();\r
+ if (oldEditor != null)\r
+ oldEditor.dispose();\r
+\r
+ // Identify the selected row\r
+ final TableItem item = (TableItem) e.item;\r
+ if (item == null)\r
+ return;\r
+\r
+ // The control that will be the editor must be a child of the\r
+ // Table\r
+ Text newEditor = new Text(item.getParent(), SWT.NONE);\r
+ final String originalText = item.getText(EDITABLECOLUMN);\r
+ final Resource resource = (Resource) item.getData();\r
+ newEditor.setText(originalText);\r
+ newEditor.addModifyListener(new ModifyListener() {\r
+ public void modifyText(ModifyEvent me) {\r
+ Text text = (Text) editor.getEditor();\r
+ if(!text.isDisposed()) {\r
+ TableItem item = editor.getItem();\r
+ if(!item.isDisposed())\r
+ item.setText(EDITABLECOLUMN, text.getText());\r
+ }\r
+ }\r
+ });\r
+ newEditor.addFocusListener(new FocusAdapter() {\r
+ @Override\r
+ public void focusLost(FocusEvent e) {\r
+ final Text text = (Text) editor.getEditor();\r
+ if(!text.getText().equals(originalText)) {\r
+ final String newText = text.getText();\r
+ try {\r
+ context.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ graph.claimLiteral(\r
+ resource, \r
+ Layer0.getInstance(graph).HasName, \r
+ newText);\r
+ }\r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ });\r
+ newEditor.selectAll();\r
+ newEditor.setFocus();\r
+ editor.setEditor(newEditor, item, EDITABLECOLUMN);\r
+ }\r
+ });\r
+\r
+\r
+ Button add = new Button(container, support, SWT.None);\r
+ add.setText("Add index");\r
+ add.addSelectionListener(new addEnumerationIndexListener(support));\r
+\r
+ Button remove = new Button(container, support, SWT.None);\r
+ remove.setText("Remove");\r
+ remove.addSelectionListener(new removeEnumerationIndexListener(support));\r
+ }\r
+\r
+ private class addEnumerationIndexListener implements SelectionListener, Widget {\r
+\r
+ Resource enumerationIndexes;\r
+\r
+ public addEnumerationIndexListener(WidgetSupport support) {\r
+ support.register(this);\r
+ }\r
+\r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+ try {\r
+ context.getSession().syncRequest(new ReadRequest() {\r
+\r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ enumerationIndexes = graph.getSingleObject(enumeration, SysdynResource.getInstance(graph).HasEnumerationIndexes);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+\r
+ Resource ei = GraphUtils.create2(graph, \r
+ sr.EnumerationIndex,\r
+ l0.HasName, "index");\r
+ OrderedSetUtils.add(graph, enumerationIndexes, ei);\r
+ }\r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+\r
+ }\r
+\r
+ }\r
+\r
+ private class removeEnumerationIndexListener implements SelectionListener, Widget {\r
+\r
+ Resource enumerationIndexes;\r
+\r
+ public removeEnumerationIndexListener(WidgetSupport support) {\r
+ support.register(this);\r
+ }\r
+\r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+ try {\r
+ context.getSession().syncRequest(new ReadRequest() {\r
+\r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ enumerationIndexes = graph.getSingleObject(enumeration, SysdynResource.getInstance(graph).HasEnumerationIndexes);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ TableItem[] items = table.getWidget().getSelection();\r
+ final ArrayList<Resource> resources = new ArrayList<Resource>();\r
+ for(int i = 0; i < items.length; i++) {\r
+ if(items[i].getData() instanceof Resource)\r
+ resources.add((Resource)items[i].getData());\r
+ }\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ for(Resource r : resources)\r
+ OrderedSetUtils.remove(graph, enumerationIndexes, r);\r
+ }\r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+\r
+ }\r
+\r
+ }\r
+}\r
r,\r
"Input"));\r
}\r
+ if (backend.isInstanceOf(r, sr.Enumeration)) {\r
+ return Collections.singleton(new ComparableTabContributor(\r
+ new EnumerationTab(),\r
+ 2,\r
+ r,\r
+ "Enumeration"));\r
+ }\r
if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) {\r
if(!backend.isInstanceOf(r, sr.SysdynModel))\r
r = backend.getPossibleObject(r, SimulationResource.getInstance(backend).IsConfigurationOf);\r
\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.Dependency;\r
+import org.simantics.sysdyn.representation.Enumeration;\r
import org.simantics.sysdyn.representation.IElement;\r
import org.simantics.sysdyn.representation.Input;\r
import org.simantics.sysdyn.representation.Module;\r
ArrayList<Input> inputs = new ArrayList<Input>();\r
ArrayList<Module> modules = new ArrayList<Module>();\r
ArrayList<Stock> stocks = new ArrayList<Stock>();\r
+ ArrayList<Enumeration> enumerations = new ArrayList<Enumeration>();\r
ArrayList<Dependency> inputDependencies = new ArrayList<Dependency>();\r
ArrayList<Dependency> outputDependencies = new ArrayList<Dependency>();\r
HashMap<String, ArrayList<Input>> moduleInputs = new HashMap<String, ArrayList<Input>>();\r
}\r
} else if (element instanceof Input) {\r
inputs.add((Input)element);\r
+ } else if (element instanceof Enumeration) {\r
+ enumerations.add((Enumeration)element);\r
} else if (element instanceof Dependency && ((Dependency)element).refersTo() != null) {\r
Dependency dependency = (Dependency)element;\r
if(dependency.getHead() instanceof Module) {\r
b.append(" " + i.getType() + " " + i.getName() + ";\n");\r
}\r
}\r
+ \r
+ if(!enumerations.isEmpty()) {\r
+ b.append("// Enumeration definitions\n");\r
+ for(Enumeration e : enumerations) {\r
+ b.append(e.getDeclaration());\r
+ }\r
+ }\r
\r
for(Stock stock : stocks) {\r
IExpression expr = stock.getExpression();\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/Enumeration")\r
+public class Enumeration extends Variable {\r
+ \r
+ @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasEnumerationIndexes")\r
+ private EnumerationIndexes enumerationIndexes;\r
+\r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ v.visit(this); \r
+ }\r
+ \r
+ public String getDeclaration() {\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append(" " + this.getType());\r
+ sb.append(" " + this.name);\r
+ sb.append(" = enumeration(");\r
+ for(int i = 0; i < enumerationIndexes.getEnumerationIndexes().size(); i++) {\r
+ sb.append(enumerationIndexes.getEnumerationIndexes().get(i).getName());\r
+ if(i < enumerationIndexes.getEnumerationIndexes().size() - 1)\r
+ sb.append(", ");\r
+ }\r
+ sb.append(");\n");\r
+ return sb.toString();\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/EnumerationIndex")\r
+public class EnumerationIndex {\r
+\r
+ @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
+ protected String name;\r
+ \r
+ public String getName() {\r
+ return this.name;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedOrderedSetElements;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes")\r
+public class EnumerationIndexes {\r
+ \r
+ @RelatedOrderedSetElements\r
+ private ArrayList<EnumerationIndex> enumerationIndexes = new ArrayList<EnumerationIndex>();\r
+\r
+ public ArrayList<EnumerationIndex> getEnumerationIndexes() {\r
+ return enumerationIndexes;\r
+ }\r
+}\r
addLinkType(MappingSchemas.fromAnnotations(g, Input.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, ModuleType.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, Model.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Enumeration.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, EnumerationIndex.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, EnumerationIndexes.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, NormalExpression.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, ParameterExpression.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, StockExpression.class));\r
import org.simantics.sysdyn.representation.Cloud;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.Dependency;\r
+import org.simantics.sysdyn.representation.Enumeration;\r
import org.simantics.sysdyn.representation.Flow;\r
import org.simantics.sysdyn.representation.Input;\r
import org.simantics.sysdyn.representation.Module;\r
@Override\r
public void visit(Configuration configuration) {\r
}\r
+ \r
+ @Override\r
+ public void visit(Enumeration enumeration) {\r
+ }\r
}\r
import org.simantics.sysdyn.representation.Cloud;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.Dependency;\r
+import org.simantics.sysdyn.representation.Enumeration;\r
import org.simantics.sysdyn.representation.Flow;\r
import org.simantics.sysdyn.representation.Input;\r
import org.simantics.sysdyn.representation.Module;\r
void visit(Flow flow); \r
void visit(Module module);\r
void visit(Configuration configuration);\r
+ void visit(Enumeration enumeration);\r
}\r