SYSDYN.Enumeration <T SYSDYN.Variable
@L0.singleProperty SYSDYN.HasEnumerationIndexes
@L0.assert L0.HasType "type"
+ @L0.assert SYSDYN.IsReplaceable false
//#####################################################################
SYSDYN.Module <T STR.Component
// TODO [STR.IsDefinedBy all Configuration]
@L0.singleProperty L0.HasLabel
+ @L0.property SYSDYN.HasRedeclaration
SYSDYN.ModuleSymbol <T DIA.FontProvider <T DIA.ColorProvider
@MOD.defSymbol "ModuleSymbol" SYSDYN.Module
SYSDYN.HasArrayIndexes <R L0.DependsOn : L0.FunctionalRelation
L0.HasDomain SYSDYN.Variable
- L0.HasRange SYSDYN.Enumeration
+ L0.HasRange SYSDYN.ArrayIndexes
SYSDYN.ArrayIndexes <T L0.OrderedSet <R L0.HasNext
SYSDYN.EnumerationIndexes <T L0.OrderedSet <R L0.HasNext
SYSDYN.EnumerationIndex <T L0.Entity
- L0.singleProperty L0.HasName
+ @L0.singleProperty L0.HasName
@L0.assert SYSDYN.ShowEnumerationIndexInCharts true
SYSDYN.ShowEnumerationIndexInCharts <R L0.HasProperty : L0.FunctionalRelation
L0.HasRange L0.Boolean
+//#####################################################################
+// Redeclarations
+//#####################################################################
+
+SYSDYN.IsReplaceable <R L0.HasProperty : L0.FunctionalRelation
+ L0.HasDomain SYSDYN.Enumeration
+ L0.HasRange L0.Boolean
+
+SYSDYN.ReplacedEnumeration <R L0.HasProperty : L0.FunctionalRelation
+ L0.HasDomain SYSDYN.Redeclaration
+ L0.HasRange SYSDYN.Enumeration
+
+SYSDYN.ReplacingEnumeration <R L0.HasProperty : L0.FunctionalRelation
+ L0.HasDomain SYSDYN.Redeclaration
+ L0.HasRange SYSDYN.Enumeration
+
+SYSDYN.Redeclaration <T L0.Entity
+ @L0.singleProperty SYSDYN.ReplacedEnumeration
+ @L0.singleProperty SYSDYN.ReplacingEnumeration
+
+SYSDYN.HasRedeclaration <R L0.IsComposedOf
+ L0.HasRange SYSDYN.Redeclaration
+
+
//#####################################################################
// Experiments
//#####################################################################
public final Resource HasRangeStart_Inverse;\r
public final Resource HasRangeStep;\r
public final Resource HasRangeStep_Inverse;\r
+ public final Resource HasRedeclaration;\r
+ public final Resource HasRedeclaration_Inverse;\r
public final Resource HasResult;\r
public final Resource HasResultFile;\r
public final Resource HasResultFile_Inverse;\r
public final Resource IsHeadOf;\r
public final Resource IsHeadOfTerminal;\r
public final Resource IsOutput;\r
+ public final Resource IsReplaceable;\r
+ public final Resource IsReplaceable_Inverse;\r
public final Resource IsTailOf;\r
public final Resource IsTailOfTerminal;\r
public final Resource LookupExpression;\r
public final Resource ModuleSymbol;\r
public final Resource NormalExpression;\r
public final Resource ParameterExpression;\r
+ public final Resource Redeclaration;\r
public final Resource RefersTo;\r
+ public final Resource ReplacedEnumeration;\r
+ public final Resource ReplacedEnumeration_Inverse;\r
+ public final Resource ReplacingEnumeration;\r
+ public final Resource ReplacingEnumeration_Inverse;\r
public final Resource Result;\r
public final Resource ShowEnumerationIndexInCharts;\r
public final Resource ShowEnumerationIndexInCharts_Inverse;\r
public static final String HasRangeStart_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasRangeStart/Inverse";\r
public static final String HasRangeStep = "http://www.simantics.org/Sysdyn-1.0/HasRangeStep";\r
public static final String HasRangeStep_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasRangeStep/Inverse";\r
+ public static final String HasRedeclaration = "http://www.simantics.org/Sysdyn-1.0/HasRedeclaration";\r
+ public static final String HasRedeclaration_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasRedeclaration/Inverse";\r
public static final String HasResult = "http://www.simantics.org/Sysdyn-1.0/HasResult";\r
public static final String HasResultFile = "http://www.simantics.org/Sysdyn-1.0/HasResultFile";\r
public static final String HasResultFile_Inverse = "http://www.simantics.org/Sysdyn-1.0/HasResultFile/Inverse";\r
public static final String IsHeadOf = "http://www.simantics.org/Sysdyn-1.0/IsHeadOf";\r
public static final String IsHeadOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsHeadOfTerminal";\r
public static final String IsOutput = "http://www.simantics.org/Sysdyn-1.0/IsOutput";\r
+ public static final String IsReplaceable = "http://www.simantics.org/Sysdyn-1.0/IsReplaceable";\r
+ public static final String IsReplaceable_Inverse = "http://www.simantics.org/Sysdyn-1.0/IsReplaceable/Inverse";\r
public static final String IsTailOf = "http://www.simantics.org/Sysdyn-1.0/IsTailOf";\r
public static final String IsTailOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsTailOfTerminal";\r
public static final String LookupExpression = "http://www.simantics.org/Sysdyn-1.0/LookupExpression";\r
public static final String ModuleSymbol = "http://www.simantics.org/Sysdyn-1.0/ModuleSymbol";\r
public static final String NormalExpression = "http://www.simantics.org/Sysdyn-1.0/NormalExpression";\r
public static final String ParameterExpression = "http://www.simantics.org/Sysdyn-1.0/ParameterExpression";\r
+ public static final String Redeclaration = "http://www.simantics.org/Sysdyn-1.0/Redeclaration";\r
public static final String RefersTo = "http://www.simantics.org/Sysdyn-1.0/RefersTo";\r
+ public static final String ReplacedEnumeration = "http://www.simantics.org/Sysdyn-1.0/ReplacedEnumeration";\r
+ public static final String ReplacedEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.0/ReplacedEnumeration/Inverse";\r
+ public static final String ReplacingEnumeration = "http://www.simantics.org/Sysdyn-1.0/ReplacingEnumeration";\r
+ public static final String ReplacingEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.0/ReplacingEnumeration/Inverse";\r
public static final String Result = "http://www.simantics.org/Sysdyn-1.0/Result";\r
public static final String ShowEnumerationIndexInCharts = "http://www.simantics.org/Sysdyn-1.0/ShowEnumerationIndexInCharts";\r
public static final String ShowEnumerationIndexInCharts_Inverse = "http://www.simantics.org/Sysdyn-1.0/ShowEnumerationIndexInCharts/Inverse";\r
HasRangeStart_Inverse = getResourceOrNull(graph, URIs.HasRangeStart_Inverse);\r
HasRangeStep = getResourceOrNull(graph, URIs.HasRangeStep);\r
HasRangeStep_Inverse = getResourceOrNull(graph, URIs.HasRangeStep_Inverse);\r
+ HasRedeclaration = getResourceOrNull(graph, URIs.HasRedeclaration);\r
+ HasRedeclaration_Inverse = getResourceOrNull(graph, URIs.HasRedeclaration_Inverse);\r
HasResult = getResourceOrNull(graph, URIs.HasResult);\r
HasResultFile = getResourceOrNull(graph, URIs.HasResultFile);\r
HasResultFile_Inverse = getResourceOrNull(graph, URIs.HasResultFile_Inverse);\r
IsHeadOf = getResourceOrNull(graph, URIs.IsHeadOf);\r
IsHeadOfTerminal = getResourceOrNull(graph, URIs.IsHeadOfTerminal);\r
IsOutput = getResourceOrNull(graph, URIs.IsOutput);\r
+ IsReplaceable = getResourceOrNull(graph, URIs.IsReplaceable);\r
+ IsReplaceable_Inverse = getResourceOrNull(graph, URIs.IsReplaceable_Inverse);\r
IsTailOf = getResourceOrNull(graph, URIs.IsTailOf);\r
IsTailOfTerminal = getResourceOrNull(graph, URIs.IsTailOfTerminal);\r
LookupExpression = getResourceOrNull(graph, URIs.LookupExpression);\r
ModuleSymbol = getResourceOrNull(graph, URIs.ModuleSymbol);\r
NormalExpression = getResourceOrNull(graph, URIs.NormalExpression);\r
ParameterExpression = getResourceOrNull(graph, URIs.ParameterExpression);\r
+ Redeclaration = getResourceOrNull(graph, URIs.Redeclaration);\r
RefersTo = getResourceOrNull(graph, URIs.RefersTo);\r
+ ReplacedEnumeration = getResourceOrNull(graph, URIs.ReplacedEnumeration);\r
+ ReplacedEnumeration_Inverse = getResourceOrNull(graph, URIs.ReplacedEnumeration_Inverse);\r
+ ReplacingEnumeration = getResourceOrNull(graph, URIs.ReplacingEnumeration);\r
+ ReplacingEnumeration_Inverse = getResourceOrNull(graph, URIs.ReplacingEnumeration_Inverse);\r
Result = getResourceOrNull(graph, URIs.Result);\r
ShowEnumerationIndexInCharts = getResourceOrNull(graph, URIs.ShowEnumerationIndexInCharts);\r
ShowEnumerationIndexInCharts_Inverse = getResourceOrNull(graph, URIs.ShowEnumerationIndexInCharts_Inverse);\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
checkEnabled="true">\r
</visibleWhen>\r
</command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.importMdl"\r
+ label="Import .mdl"\r
+ style="push">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ </visibleWhen>\r
+ </command>\r
</menuContribution>\r
<menuContribution\r
locationURI="popup:#SysdynDiagramPopup?after=wbStart">\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
+ <command\r
+ id="org.simantics.sysdyn.ui.importMdl"\r
+ name="Import .mdl">\r
+ </command>\r
</extension>\r
<extension\r
point="org.eclipse.ui.handlers">\r
</with>\r
</activeWhen>\r
</handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.handlers.ImportMdlHandler"\r
+ commandId="org.simantics.sysdyn.ui.importMdl">\r
+ </handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.handlers.NewEnumerationNodeHandler"\r
+ commandId="org.simantics.sysdyn.ui.newEnumeration">\r
+ <activeWhen>\r
+ <with\r
+ variable="selection">\r
+ <or>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </or>\r
+ </with>\r
+ </activeWhen>\r
+ </handler>\r
</extension>\r
<extension\r
point="org.simantics.browsing.ui.common.viewpointContributionBinding">\r
preference="2.0">\r
</implementation>\r
</binding>\r
+ <binding\r
+ browseContext="http://www.simantics.org/Sysdyn-1.0/EnumerationReplacement">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableEnumerations"\r
+ preference="2.0">\r
+ </implementation>\r
+ </binding>\r
</extension>\r
<extension\r
point="org.simantics.browsing.ui.common.labelerBinding">\r
preference="2.0">\r
</implementation>\r
</binding>\r
+ <binding\r
+ browseContext="http://www.simantics.org/Sysdyn-1.0/EnumerationReplacement">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableEnumerationsLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
+ </binding>\r
</extension>\r
<extension\r
point="org.simantics.browsing.ui.common.imagerBinding">\r
package org.simantics.sysdyn.ui.browser;\r
\r
import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.jface.viewers.ISelection;\r
import org.simantics.browsing.ui.NodeContext;\r
import org.simantics.db.Resource;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
\r
-public class BrowserSelection implements IAdaptable {\r
+public class BrowserSelection implements IAdaptable, ISelection {\r
private Resource resource;\r
private Resource model;\r
private String URI;\r
public String getURI() {\r
return this.URI;\r
}\r
+\r
+ @Override\r
+ public boolean isEmpty() {\r
+ if(originalInput == null)\r
+ return true;\r
+ return false;\r
+ }\r
\r
}\r
@SuppressWarnings("unchecked")\r
VariableNode<Resource> vn = (VariableNode<Resource>) ctx.getAdapter(VariableNode.class);\r
IHintContext context;\r
- if(vn != null) {\r
+ if(vn != null && vn.getResource() != null) {\r
context = new AdaptableHintContext(SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY);\r
context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(objects[i], vn));\r
context.setHint(SelectionHints.KEY_SELECTION_PROPERTY, vn.getVariable());\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\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.ModuleTypeNode;\r
for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Module))) {\r
result.add(new ModuleNode(r));\r
}\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Enumeration))) {\r
+ result.add(new EnumerationNode(r));\r
+ }\r
return result;\r
}\r
\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.CancelTransactionException;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.ui.ExceptionUtils;\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
- graph.deny(resource, l0.PartOf); \r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ graph.deny(resource, l0.PartOf); \r
+ for(Resource redeclaration : graph.getObjects(resource, sr.ReplacedEnumeration_Inverse)) {\r
+ graph.deny(redeclaration, sr.HasRedeclaration_Inverse);\r
+ }\r
+ \r
+ for(Resource redeclaration : graph.getObjects(resource, sr.ReplacingEnumeration_Inverse)) {\r
+ graph.deny(redeclaration, sr.HasRedeclaration_Inverse);\r
+ }\r
+ \r
+ for(Resource list : OrderedSetUtils.getOwnerLists(graph, resource, sr.ArrayIndexes)) {\r
+ OrderedSetUtils.remove(graph, list, resource);\r
+ }\r
+ \r
}\r
});\r
} catch (DatabaseException e) {\r
.getCenterX() - FlowRouter.OFFSET, bounds\r
.getCenterY() - FlowRouter.OFFSET,\r
FlowRouter.OFFSET * 2, FlowRouter.OFFSET * 2);\r
-// c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG;\r
+ c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG;\r
} else {\r
c.parentObstacle = ElementUtils\r
.getElementBoundsOnDiagram(connection.node)\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.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
\r
ISelection sel = HandlerUtil.getCurrentSelection(event);\r
\r
- final Resource configuration = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+ final Resource resource = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
SysdynResource sr = SysdynResource.getInstance(g);\r
Layer0 l0 = Layer0.getInstance(g);\r
\r
+ Resource configuration = null;\r
+ if(g.isInstanceOf(resource, sr.Configuration)) {\r
+ configuration = resource;\r
+ } else if(g.isInheritedFrom(resource, sr.ModuleSymbol)) {\r
+ Resource module = g.getPossibleObject(resource,ModelingResources.getInstance(g).SymbolToComponentType);\r
+ configuration = g.getPossibleObject(module, StructuralResource2.getInstance(g).IsDefinedBy);\r
+ } else {\r
+ Resource instanceOf = g.getSingleObject(resource, l0.InstanceOf);\r
+ if(g.isInheritedFrom(instanceOf, sr.Module)) {\r
+ configuration = g.getPossibleObject(instanceOf, StructuralResource2.getInstance(g).IsDefinedBy);\r
+ } else {\r
+ return;\r
+ }\r
+ }\r
\r
Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes);\r
\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.ui.properties.widgets.arrays.Keys;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
import org.simantics.utils.datastructures.ArrayMap;\r
\r
public class ArrayIndexesTab extends PropertyTabContributorImpl implements Widget{\r
\r
availableEnumerationsExplorer\r
.setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/AvailableVariableIndexes");\r
- availableEnumerationsExplorer.setColumns(Keys.ENUMERATION_TABLE_COLUMNS);\r
+ availableEnumerationsExplorer.setColumns(ColumnKeys.ENUMERATION_TABLE_COLUMNS);\r
availableEnumerationsExplorer.setInputSource(new SingleSelectionInputSource(\r
Resource.class));\r
\r
\r
usedEnumerationsExplorer\r
.setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/UsedVariableIndexes");\r
- usedEnumerationsExplorer.setColumns(Keys.ENUMERATION_TABLE_COLUMNS);\r
+ usedEnumerationsExplorer.setColumns(ColumnKeys.ENUMERATION_TABLE_COLUMNS);\r
usedEnumerationsExplorer.setInputSource(new SingleSelectionInputSource(\r
Resource.class));\r
\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.jface.viewers.ISelectionProvider;\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
import org.eclipse.swt.SWT;\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.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.request.Read;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.manager.SysdynModelManager;\r
import org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationIndexNode;\r
+import org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableIndexesWidget;\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.ui.utils.AdaptionUtils;\r
import org.simantics.utils.datastructures.ArrayMap;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
\r
-public class EnumerationTab extends PropertyTabContributorImpl {\r
+public class EnumerationTab extends PropertyTabContributorImpl implements Widget {\r
\r
GraphExplorerComposite indexExplorer;\r
\r
Button showAll;\r
-\r
+ Variable variable;\r
\r
Table table;\r
@Override\r
public void createControls(Composite body, IWorkbenchSite site,\r
final ISessionContext context, WidgetSupport support) {\r
\r
+ support.register(this);\r
+ \r
Composite container = new Composite(body, SWT.None);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(container);\r
- GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(container);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).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(3,1).applyTo(nameText.getWidget());\r
-\r
-\r
- \r
+ GridDataFactory.fillDefaults().grab(true, false).span(4,1).applyTo(nameText.getWidget());\r
\r
indexExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
"displaySelectors", "displayFilter").values(false, false), site, container, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.CHECK);\r
SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- Resource enumeration = (Resource)indexExplorer.getExplorer().getRoot().getAdapter(Resource.class);\r
- Resource configuration = graph.getSingleObject(enumeration, l0.PartOf);\r
- SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
- // update results in graphs\r
- model.resultChanged();\r
+ Resource modelResource = Variables.getModel(graph, variable);\r
+ if(modelResource != null) {\r
+ Resource configuration = graph.getSingleObject(\r
+ modelResource, \r
+ SimulationResource.getInstance(graph).HasConfiguration);\r
+ SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
+ // update results in graphs\r
+ model.resultChanged();\r
+ }\r
}\r
});\r
}\r
\r
indexExplorer.finish();\r
\r
- GridDataFactory.fillDefaults().grab(true, true).span(3, 1).applyTo(\r
+ GridDataFactory.fillDefaults().grab(true, true).span(4, 1).applyTo(\r
indexExplorer);\r
\r
Control c = indexExplorer.getExplorerControl();\r
((Tree) c).setLinesVisible(true);\r
\r
\r
- Button add = new Button(container, support, SWT.None);\r
+ final Button add = new Button(container, support, SWT.None);\r
add.setText("Add");\r
add.addSelectionListener(new addEnumerationIndexListener(support));\r
\r
- Button remove = new Button(container, support, SWT.None);\r
+ final Button remove = new Button(container, support, SWT.None);\r
remove.setText("Remove");\r
remove.addSelectionListener(new removeEnumerationIndexListener(support));\r
\r
+ ReplaceableIndexesWidget externalIndexes = new ReplaceableIndexesWidget(container, support, SWT.NULL);\r
+ GridDataFactory.fillDefaults().applyTo(externalIndexes.getWidget());\r
+ \r
showAll = new Button(container, support, SWT.CHECK);\r
showAll.setText("Show all in charts");\r
showAll.addSelectionListener(new ShowAllIndexesListener(support));\r
+ \r
}\r
\r
private class addEnumerationIndexListener implements SelectionListener, Widget {\r
\r
@Override\r
public void setInput(ISessionContext context, Object input) {\r
- final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+ final Resource enumeration = AdaptionUtils.adaptToSingle(input, Resource.class);\r
try {\r
context.getSession().syncRequest(new ReadRequest() {\r
\r
\r
@Override\r
public void setInput(ISessionContext context, Object input) {\r
- final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+ final Resource enumeration = AdaptionUtils.adaptToSingle(input, Resource.class);\r
try {\r
context.getSession().syncRequest(new ReadRequest() {\r
\r
\r
@Override\r
public void setInput(ISessionContext context, Object input) {\r
- final Resource enumeration = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+ final Resource enumeration = AdaptionUtils.adaptToSingle(input, Resource.class);\r
\r
context.getSession().asyncRequest(new Read<Boolean>() {\r
\r
}\r
}\r
\r
- Resource enumeration = graph.getSingleObject(enumerationIndexes, sr.HasEnumerationIndexes_Inverse);\r
- Resource configuration = graph.getSingleObject(enumeration, Layer0.getInstance(graph).PartOf);\r
- SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
- // update results in graphs\r
- model.resultChanged();\r
+ \r
+ Resource modelResource = Variables.getModel(graph, variable);\r
+ if(modelResource != null) {\r
+ Resource configuration = graph.getSingleObject(\r
+ modelResource, \r
+ SimulationResource.getInstance(graph).HasConfiguration);\r
+ SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
+ // update results in graphs\r
+ model.resultChanged();\r
+ }\r
\r
}\r
});\r
}\r
\r
}\r
+\r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ variable = AdaptionUtils.adaptToSingle(input, Variable.class);\r
+ }\r
}\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Tree;\r
import org.eclipse.ui.IWorkbenchSite;\r
import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\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.Builtins;\r
+import org.simantics.db.Resource;\r
import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
\r
-public class ModuleTab extends PropertyTabContributorImpl {\r
+public class ModuleTab extends PropertyTabContributorImpl implements Widget {\r
\r
+ GraphExplorerComposite enumerationRedeclarationExplorer;\r
+ \r
@Override\r
public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+ support.register(this);\r
+ \r
Composite composite = new Composite(body, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
- GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite);\r
TrackedText nameText = new TrackedText(composite, support, SWT.BORDER);\r
nameText.setTextFactory(new StringPropertyFactory(Builtins.URIs.HasName));\r
nameText.addModifyListener(new StringPropertyModifier(context, Builtins.URIs.HasName));\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget());\r
+ \r
+ Label label = new Label(composite, SWT.NONE);\r
+ label.setText("Replaceable enumerations");\r
+ enumerationRedeclarationExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), site, composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI);\r
+ \r
+ enumerationRedeclarationExplorer\r
+ .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/EnumerationReplacement");\r
+ enumerationRedeclarationExplorer.setColumns(ColumnKeys.ENUMERATION_REDECLARATION_COLUMNS);\r
+ enumerationRedeclarationExplorer.setInputSource(new SingleSelectionInputSource(\r
+ Resource.class));\r
+\r
+ enumerationRedeclarationExplorer.finish();\r
+\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+ enumerationRedeclarationExplorer);\r
+ \r
+ Control c = enumerationRedeclarationExplorer.getExplorerControl();\r
+ if (c instanceof Tree)\r
+ ((Tree) c).setLinesVisible(true);\r
+ \r
}\r
+ \r
+ \r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ enumerationRedeclarationExplorer.setInput(context, input);\r
+ }\r
}\r
import java.util.Collections;\r
import java.util.List;\r
\r
+import org.eclipse.jface.viewers.ISelection;\r
import org.simantics.browsing.ui.SelectionProcessor;\r
import org.simantics.browsing.ui.swt.ComparableTabContributor;\r
import org.simantics.db.ReadGraph;\r
\r
// Single element\r
Resource r = AdaptionUtils.adaptToSingle(selection, Resource.class);\r
+ \r
if(r == null) \r
return Collections.emptyList();\r
\r
return tabs;\r
}\r
if (backend.isInstanceOf(r, sr.Input)) {\r
- return Collections.singleton(new ComparableTabContributor(\r
+ tabs.add(new ComparableTabContributor(\r
new InputVariableTab(),\r
2,\r
r,\r
"Input"));\r
+ \r
+ tabs.add(new ComparableTabContributor(\r
+ new ArrayIndexesTab(),\r
+ 1,\r
+ r,\r
+ "Indexes"));\r
+\r
+ tabs.add(new ComparableTabContributor(\r
+ new VariableInformationTab(),\r
+ 0,\r
+ r,\r
+ "Additional Information"));\r
+ return tabs;\r
}\r
if (backend.isInstanceOf(r, sr.Enumeration)) {\r
return Collections.singleton(new ComparableTabContributor(\r
new EnumerationTab(),\r
2,\r
- r,\r
+ AdaptionUtils.adaptToSingle(selection, ISelection.class),\r
"Enumeration"));\r
}\r
if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) {\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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 org.simantics.browsing.ui.Column;\r
+import org.simantics.browsing.ui.Column.Align;\r
+\r
+public class ColumnKeys {\r
+ \r
+ public static final String ENUMERATION = "Enumeration";\r
+ public static final String INDEXES = "Indexes";\r
+ public static final String SHOW_IN_CHARTS = "ShowInCharts";\r
+ public static final String REPLACED_WITH = "Replaced with";\r
+ \r
+ public static String[] ENUMERATION_COLUMNS_KEYS = { ENUMERATION, INDEXES };\r
+ public static Column[] ENUMERATION_TABLE_COLUMNS = new Column[] {\r
+ new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", false),\r
+ new Column(INDEXES, Align.LEFT, 100, "Indexes", true),\r
+ };\r
+ \r
+\r
+ public static String[] ENUMERATION_INDEX_COLUMNS_KEYS = { ENUMERATION, SHOW_IN_CHARTS };\r
+ public static Column[] ENUMERATION_INDEX_TABLE_COLUMNS = new Column[] {\r
+ new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", true),\r
+ new Column(SHOW_IN_CHARTS, Align.LEFT, 20, "Show in charts", false),\r
+ };\r
+ \r
+ public static String[] ENUMERATION_REDECLARATION_KEYS = { ENUMERATION, REPLACED_WITH };\r
+ public static Column[] ENUMERATION_REDECLARATION_COLUMNS = new Column[] {\r
+ new Column(ENUMERATION, Align.LEFT, 200, "Enumeration in module", false),\r
+ new Column(REPLACED_WITH, Align.LEFT, 200, "Replaced with", true),\r
+ };\r
+ \r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.widgets.Combo;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.common.modifiers.EnumeratedValue;\r
+import org.simantics.browsing.ui.common.modifiers.Enumeration;\r
+import org.simantics.browsing.ui.content.Labeler.CustomModifier;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.utils.ObjectUtils;\r
+\r
+public abstract class ComboBoxModifier<T> implements CustomModifier {\r
+\r
+ private final Enumeration<T> enumeration;\r
+ private final EnumeratedValue<T> value;\r
+ private final List<String> values;\r
+ private final Session session;\r
+ private Combo combo;\r
+ int select;\r
+\r
+ public ComboBoxModifier(Session session, Enumeration<T> enumeration, T value) {\r
+ this(session, enumeration, enumeration.find(value));\r
+ }\r
+\r
+ public ComboBoxModifier(Session session, Enumeration<T> enumeration,\r
+ EnumeratedValue<T> value) {\r
+ if (session == null)\r
+ throw new NullPointerException("null session");\r
+ if (enumeration == null)\r
+ throw new NullPointerException("null enumeration");\r
+ if (enumeration.size() == 0)\r
+ throw new IllegalArgumentException("");\r
+\r
+ this.enumeration = enumeration;\r
+ this.value = value;\r
+ this.session = session;\r
+\r
+ select = 0;\r
+ boolean found = false;\r
+ \r
+ this.values = new ArrayList<String>();\r
+ for (EnumeratedValue<T> v : enumeration.values()) {\r
+ values.add(v.getName());\r
+ \r
+ if(v == value) \r
+ found = true;\r
+ \r
+ if(found == false)\r
+ select++;\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Object createControl(Object parentControl, Object controlItem,\r
+ int columnIndex, NodeContext context) {\r
+\r
+ combo = new Combo((Composite) parentControl, SWT.DROP_DOWN\r
+ | SWT.BORDER | SWT.READ_ONLY);\r
+\r
+ for (String item : values) {\r
+ combo.add(item);\r
+ }\r
+ \r
+ combo.addSelectionListener(new SelectionAdapter() {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ String index = ((Combo) e.getSource()).getText();\r
+ modify(index);\r
+ }\r
+ });\r
+ \r
+ combo.select(select);\r
+ \r
+ return combo;\r
+\r
+ }\r
+\r
+ @Override\r
+ public String getValue() {\r
+ return enumeration.values().get(0).getName();\r
+ }\r
+\r
+ @Override\r
+ public final String isValid(String label) {\r
+ if (enumeration.findByName(label) == null)\r
+ return "Value '" + label + "' is not among the enumerated values " + enumeration.values();\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void modify(String label) {\r
+ \r
+ int index = values.indexOf(label);\r
+ if (index == -1)\r
+ throw new IllegalArgumentException("Cannot modify enumeration with value '" + label + "', not among the enumerated values " + values);\r
+ \r
+ EnumeratedValue<T> oldEnumValue = value;\r
+ EnumeratedValue<T> newEnumValue = enumeration.values().get(index);\r
+ \r
+ final T oldObject = oldEnumValue != null ? oldEnumValue.getObject() : null;\r
+ final T newObject = newEnumValue != null ? newEnumValue.getObject() : null;\r
+ \r
+ if (ObjectUtils.objectEquals(oldObject, newObject))\r
+ return;\r
+\r
+ try {\r
+ session.getSession().syncRequest(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ modifyWithObject(graph, oldObject, newObject);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ handleException(e);\r
+ }\r
+ \r
+ combo.dispose(); \r
+ }\r
+ \r
+ protected abstract void modifyWithObject(WriteGraph graph, T oldEnumObject, T enumObject) throws DatabaseException;\r
+ \r
+ protected void handleException(DatabaseException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+\r
+}\r
import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
\r
public class EnumerationLabeler extends ColumnLabelerContributorImpl<EnumerationNode>{\r
\r
\r
String name = NameUtils.getSafeName(graph, input.data);\r
HashMap<String, String> map = new HashMap<String, String>();\r
- map.put(Keys.ENUMERATION, name);\r
+ map.put(ColumnKeys.ENUMERATION, name);\r
\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
Resource enumerationIndexes = graph.getPossibleObject(input.data, sr.HasEnumerationIndexes);\r
ListIterator<Resource> indexes = OrderedSetUtils.iterator(graph, enumerationIndexes);\r
StringBuilder sb = new StringBuilder();\r
sb.append(", ");\r
}\r
sb.append("]");\r
- map.put(Keys.INDEXES, sb.toString());\r
+ \r
+ Boolean relaceable = graph.getPossibleRelatedValue(input.data, sr.IsReplaceable);\r
+ if(Boolean.TRUE.equals(relaceable)) {\r
+ sb.append(" Replaceable");\r
+ }\r
+ \r
+ map.put(ColumnKeys.INDEXES, sb.toString());\r
+ \r
return map;\r
}\r
\r
+++ /dev/null
-package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
-\r
-import org.simantics.browsing.ui.Column;\r
-import org.simantics.browsing.ui.Column.Align;\r
-\r
-public class Keys {\r
- \r
- public static final String ENUMERATION = "Enumeration";\r
- public static final String INDEXES = "Indexes";\r
- public static final String SHOW_IN_CHARTS = "ShowInCharts";\r
- \r
- public static String[] ENUMERATION_COLUMNS_KEYS = { ENUMERATION, INDEXES };\r
- public static Column[] ENUMERATION_TABLE_COLUMNS = new Column[] {\r
- new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", false),\r
- new Column(INDEXES, Align.LEFT, 100, "Indexes", true),\r
- };\r
- \r
-\r
- public static String[] ENUMERATION_INDEX_COLUMNS_KEYS = { ENUMERATION, SHOW_IN_CHARTS };\r
- public static Column[] ENUMERATION_INDEX_TABLE_COLUMNS = new Column[] {\r
- new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", true),\r
- new Column(SHOW_IN_CHARTS, Align.LEFT, 20, "Show in charts", false),\r
- };\r
- \r
-}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.arrays;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.browsing.ui.common.modifiers.EnumeratedValue;\r
+import org.simantics.browsing.ui.common.modifiers.Enumeration;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\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.ObjectsWithType;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\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.ColumnKeys;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class RedeclarationNode extends AbstractNode<Resource> implements IModifiableNode {\r
+\r
+ private Resource module;\r
+ \r
+ public RedeclarationNode(ReadGraph graph, final Resource module, Resource enumeration) {\r
+ super(enumeration);\r
+ this.module = module;\r
+ }\r
+ \r
+ /**\r
+ * \r
+ * @param graph\r
+ * @return\r
+ */\r
+ public Resource getReplacingEnumeration(ReadGraph graph) {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource result = null;\r
+ try {\r
+ Resource redeclaration = getRedeclaration(graph);\r
+ if(redeclaration != null) {\r
+ result = graph.getSingleObject(redeclaration, sr.ReplacingEnumeration);\r
+ }\r
+ } catch(DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ return result;\r
+ }\r
+ \r
+\r
+ public Resource getModule() {\r
+ return module;\r
+ }\r
+\r
+ public void setModule(Resource module) {\r
+ this.module = module;\r
+ }\r
+\r
+ public Resource getRedeclaration(ReadGraph graph) {\r
+ try {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ for(Resource redeclaration : graph.syncRequest(new ObjectsWithType(module, sr.HasRedeclaration, sr.Redeclaration))) {\r
+ Resource replacedEnumeration = graph.getPossibleObject(redeclaration, sr.ReplacedEnumeration);\r
+ if(replacedEnumeration != null && replacedEnumeration.equals(getReplacedEnumeration())) {\r
+ return redeclaration;\r
+ }\r
+ }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public void setRedeclaration(WriteGraph graph, Resource redeclaration) {\r
+ try {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource oldRedeclaration = getRedeclaration(graph);\r
+ if(oldRedeclaration != null || redeclaration == null) {\r
+ graph.deny(module, sr.HasRedeclaration, oldRedeclaration);\r
+ }\r
+ \r
+ if(redeclaration != null)\r
+ graph.claim(module, sr.HasRedeclaration, redeclaration);\r
+ \r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ public Resource getReplacedEnumeration() {\r
+ return this.data;\r
+ }\r
+\r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ \r
+ if(!ColumnKeys.REPLACED_WITH.equals(columnId))\r
+ return null;\r
+ \r
+ ComboBoxModifier<Resource> cbm = null;\r
+ \r
+ try {\r
+ cbm = SimanticsUI.getSession().syncRequest(new Read<ComboBoxModifier<Resource>>() {\r
+ \r
+ @Override\r
+ public ComboBoxModifier<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ \r
+ ArrayList<EnumeratedValue<Resource>> values = new ArrayList<EnumeratedValue<Resource>>();\r
+ \r
+ \r
+ Resource configuration = graph.getSingleObject(module, l0.PartOf);\r
+ \r
+ for(Resource enumeration : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
+ String name = NameUtils.getSafeName(graph, enumeration);\r
+ values.add(new EnumeratedValue<Resource>(name, enumeration)); \r
+ }\r
+\r
+ if(values.size() == 0)\r
+ return null;\r
+ \r
+ values.add(0, new EnumeratedValue<Resource>("", null));\r
+ Enumeration<Resource> enumeration = new Enumeration<Resource>(values); \r
+ \r
+ ComboBoxModifier<Resource> cbm = new ComboBoxModifier<Resource>(graph.getSession(), enumeration, getReplacingEnumeration(graph)) {\r
+ \r
+ @Override\r
+ protected void modifyWithObject(WriteGraph graph, Resource oldEnumObject,\r
+ Resource enumObject) throws DatabaseException {\r
+ \r
+ if(enumObject == null) {\r
+ setRedeclaration(graph, null);\r
+ } else if(!enumObject.equals(oldEnumObject)) {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource redeclaration = GraphUtils.create2(graph, \r
+ sr.Redeclaration, \r
+ sr.ReplacedEnumeration, getReplacedEnumeration(),\r
+ sr.ReplacingEnumeration, enumObject);\r
+ setRedeclaration(graph, redeclaration);\r
+ }\r
+ \r
+ }\r
+ };\r
+ \r
+ return cbm;\r
+ \r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+\r
+ return cbm;\r
+ }\r
+ \r
+ \r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.arrays;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class ReplaceableEnumerations extends ViewpointContributorImpl<Resource> {\r
+ \r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+ throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+ \r
+ Resource moduleType = graph.getSingleObject(input, l0.InstanceOf);\r
+ Resource configuration = graph.getSingleObject(moduleType, sr2.IsDefinedBy);\r
+ \r
+ ArrayList<RedeclarationNode> result = new ArrayList<RedeclarationNode>();\r
+ \r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
+ if(Boolean.TRUE.equals(graph.getRelatedValue(r, sr.IsReplaceable)))\r
+ result.add(new RedeclarationNode(graph, input, r));\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Replaceable enumerations";\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.arrays;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.ColumnLabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;\r
+\r
+public class ReplaceableEnumerationsLabeler extends ColumnLabelerContributorImpl<RedeclarationNode>{\r
+\r
+ @Override\r
+ public Map<String, String> getLabel(ReadGraph graph, RedeclarationNode input)\r
+ throws DatabaseException {\r
+ HashMap<String, String> map = new HashMap<String, String>();\r
+ \r
+ String name = NameUtils.getSafeName(graph, input.data);\r
+ map.put(ColumnKeys.ENUMERATION, name);\r
+ \r
+ Resource replacingEnumeration = input.getReplacingEnumeration(graph); \r
+ String replacingEnumerationName = "";\r
+ if(replacingEnumeration != null)\r
+ replacingEnumerationName = NameUtils.getSafeName(graph, replacingEnumeration);\r
+ \r
+ map.put(ColumnKeys.REPLACED_WITH, replacingEnumerationName);\r
+ return map;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.arrays;\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.events.SelectionListener;\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
+public class ReplaceableIndexesWidget implements Widget {\r
+ \r
+ Resource variable = null; \r
+ boolean selected = false;\r
+ org.simantics.browsing.ui.swt.widgets.Button isReplaceableButton;\r
+ \r
+ public ReplaceableIndexesWidget(Composite parent, WidgetSupport support, int style) {\r
+ support.register(this);\r
+ isReplaceableButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK);\r
+ isReplaceableButton.setText("Can be replaced by parent module");\r
+ }\r
+\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
+ Resource resource = ISelectionUtils.filterSingleSelection(selection, Resource.class);\r
+ if(resource != null) {\r
+ variable = resource;\r
+ }\r
+ }\r
+ }\r
+ \r
+ if(variable == 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
+ final Boolean replaceable = graph.getPossibleRelatedValue(variable, sr.IsReplaceable);\r
+ if(replaceable != null)\r
+ selected = replaceable;\r
+ final Button button = getWidget();\r
+ button.getDisplay().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ if(button.isDisposed()) return;\r
+ \r
+ if(replaceable)\r
+ button.setSelection(true);\r
+ else\r
+ button.setSelection(false);\r
+ }\r
+ });\r
+\r
+ \r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ isReplaceableButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Boolean replaceable = graph.getPossibleRelatedValue(input, sr.IsReplaceable);\r
+ if(Boolean.TRUE.equals(replaceable)) {\r
+ graph.claimLiteral(input, sr.IsReplaceable, false);\r
+ selected = false;\r
+ } else {\r
+ graph.claimLiteral(input, sr.IsReplaceable, true);\r
+ selected = true;\r
+ }\r
+ }\r
+ });\r
+ }\r
+ \r
+ public Button getWidget() {\r
+ return isReplaceableButton.getWidget();\r
+ }\r
+ \r
+ public boolean getSelection() {\r
+ return selected;\r
+ }\r
+ \r
+ public void addSelectionListener(SelectionListener listener) {\r
+ isReplaceableButton.addSelectionListener(listener);\r
+ }\r
+\r
+}\r
protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, Variable variable) throws DatabaseException {\r
ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
HashMap<String, String> rvis = new HashMap<String, String>();\r
- \r
String rvi = Variables.getRVI(g, variable);\r
if (rvi == null) \r
return dataSets;\r
org.simantics.layer0.utils;bundle-version="0.8.0",
org.simantics.layer0;bundle-version="1.0.0",
org.simantics.structural.ontology;bundle-version="1.0.0",
- org.simantics.sysdyn.ontology;bundle-version="1.0.0"
+ org.simantics.sysdyn.ontology;bundle-version="1.0.0",
+ org.simantics.modeling;bundle-version="1.1.1",
+ org.simantics.diagram;bundle-version="1.1.1",
+ org.simantics.diagram.ontology;bundle-version="1.1.1"
Export-Package: org.simantics.sysdyn,
org.simantics.sysdyn.expressionParser,
org.simantics.sysdyn.manager,
+ org.simantics.sysdyn.mdlImport,
+ org.simantics.sysdyn.mdlImport.mdlElements,
org.simantics.sysdyn.modelica,
org.simantics.sysdyn.representation,
org.simantics.sysdyn.representation.visitors,
if(!modules.isEmpty()) {\r
b.append("// Module definitions\n");\r
for(Module m : modules) {\r
- b.append(" " + m.getType().getName() + " " + m.getName() + ";\n");\r
+ b.append(m.getDeclaration());\r
}\r
}\r
\r
if(!inputs.isEmpty()) {\r
b.append("// Input definitions\n");\r
for(Input i : inputs) {\r
- b.append(" " + i.getType() + " " + i.getName() + ";\n");\r
+ b.append(i.getDeclaration());\r
}\r
}\r
\r
\r
import org.simantics.objmap.annotations.GraphType;\r
import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
\r
@GraphType("http://www.simantics.org/Sysdyn-1.0/Enumeration")\r
\r
@RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasEnumerationIndexes")\r
private EnumerationIndexes enumerationIndexes;\r
+ \r
+ @RelatedValue("http://www.simantics.org/Sysdyn-1.0/IsReplaceable")\r
+ private Boolean isReplaceable;\r
\r
@Override\r
public void accept(IElementVisitorVoid v) {\r
\r
public String getDeclaration() {\r
StringBuilder sb = new StringBuilder();\r
- sb.append(" " + this.getType());\r
+ sb.append(" ");\r
+ if(isReplaceable())\r
+ sb.append("replaceable ");\r
+ sb.append(this.getType());\r
sb.append(" " + this.name);\r
- sb.append(" = enumeration(");\r
+ sb.append(" = ");\r
+ sb.append(getEnumerationDefinition());\r
+ sb.append(";\n");\r
+ return sb.toString();\r
+ }\r
+ \r
+ public ArrayList<EnumerationIndex> getEnumerationIndexes() {\r
+ return enumerationIndexes.getEnumerationIndexes();\r
+ }\r
+ \r
+ public boolean isReplaceable() {\r
+ return Boolean.TRUE.equals(isReplaceable);\r
+ }\r
+ \r
+ public String getEnumerationDefinition() {\r
+ StringBuilder sb = new StringBuilder();\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
+ sb.append(")");\r
return sb.toString();\r
}\r
- \r
- public ArrayList<EnumerationIndex> getEnumerationIndexes() {\r
- return enumerationIndexes.getEnumerationIndexes();\r
- }\r
\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.representation;\r
\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
import java.util.List;\r
\r
import org.simantics.objmap.annotations.GraphType;\r
@RelatedElements("http://www.simantics.org/Sysdyn-1.0/IsHeadOf")\r
private List<IElement> isHeadOf;\r
\r
+ \r
+ \r
@Override\r
public void accept(IElementVisitorVoid v) {\r
v.visit(this);\r
}\r
\r
public String getDefaultInputValue() {\r
- return defaultInputValue.toString();\r
+ if( getArrayIndexes() == null || getArrayIndexes().getEnumerations().isEmpty()) {\r
+ return defaultInputValue.toString();\r
+ } else {\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("fill(");\r
+ sb.append(defaultInputValue);\r
+ sb.append(", ");\r
+ Iterator<Enumeration> i = getArrayIndexes().getEnumerations().iterator();\r
+ while(i.hasNext()) {\r
+ Enumeration e = i.next();\r
+ sb.append(e.getEnumerationIndexes().size());\r
+ if(i.hasNext())\r
+ sb.append(", ");\r
+ }\r
+ sb.append(")");\r
+ return sb.toString();\r
+ }\r
}\r
\r
public boolean isHeadOfDependency() {\r
return !isHeadOf.isEmpty();\r
}\r
+ \r
+ public String getDeclaration() {\r
+ ArrayIndexes ai = getArrayIndexes();\r
+ ArrayList<Enumeration> enumerations = null;\r
+ if(ai != null) \r
+ enumerations = ai.getEnumerations();\r
+ \r
+ String range = "";\r
+ if(enumerations != null && enumerations.size() > 0) {\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("[");\r
+ Iterator<Enumeration> iterator = enumerations.iterator();\r
+ while(iterator.hasNext()) {\r
+ sb.append(iterator.next().getName());\r
+ if(iterator.hasNext()) {\r
+ sb.append(", ");\r
+ }\r
+ }\r
+ sb.append("]");\r
+ range = sb.toString();\r
+ }\r
+ \r
+ return " " + getType() + " " + getName() + range + ";\n";\r
+ }\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.representation;\r
\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
import org.simantics.objmap.annotations.GraphType;\r
import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.objmap.annotations.RelatedElements;\r
import org.simantics.objmap.annotations.RelatedValue;\r
import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
\r
@RelatedElement("http://www.simantics.org/Layer0-1.0/InstanceOf")\r
private ModuleType type;\r
\r
+ @RelatedElements("http://www.simantics.org/Sysdyn-1.0/HasRedeclaration")\r
+ private List<Redeclaration> redeclarations;\r
+ \r
@Override\r
public void accept(IElementVisitorVoid v) {\r
v.visit(this);\r
public ModuleType getType() {\r
return type;\r
}\r
+ \r
+ /**\r
+ * Returns the declaration of a module with possible redeclared enumerations\r
+ * \r
+ * Module m(redeclare type E1 = enumeration(i1, i2, i3), redeclare type E2 = enumeration(i4, i5, i6));\r
+ * \r
+ * @return Declaration of a module instance\r
+ */\r
+ public String getDeclaration() {\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append(" ");\r
+ sb.append(getType().getName());\r
+ sb.append(" ");\r
+ sb.append(getName());\r
+ if(!getRedeclarations().isEmpty()) {\r
+ sb.append("(");\r
+ Iterator<Redeclaration> i = getRedeclarations().iterator();\r
+ while(i.hasNext()) {\r
+ Redeclaration rd = i.next();\r
+ sb.append(rd.getRedeclaration());\r
+ if(i.hasNext())\r
+ sb.append(",");\r
+ }\r
+ sb.append(")");\r
+ }\r
+ sb.append(";\n");\r
+ return sb.toString();\r
+ }\r
\r
public Configuration getParentConfiguration() {\r
return this.parentConfiguration;\r
}\r
+ \r
+ /**\r
+ * Return the list of the defined redeclarations for this module instance.\r
+ * \r
+ * @return List of the defined redeclarations or an empty list if redeclarations have not been set \r
+ */\r
+ public List<Redeclaration> getRedeclarations() {\r
+ if(redeclarations == null) {\r
+ redeclarations = new ArrayList<Redeclaration>();\r
+ }\r
+ return redeclarations;\r
+ }\r
\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElement;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/Redeclaration")\r
+public class Redeclaration {\r
+ \r
+ @RelatedElement("http://www.simantics.org/Sysdyn-1.0/ReplacedEnumeration")\r
+ private Enumeration replacedEnumeration;\r
+ \r
+ @RelatedElement("http://www.simantics.org/Sysdyn-1.0/ReplacingEnumeration")\r
+ private Enumeration replacingEnumeration;\r
+ \r
+ public String getRedeclaration() {\r
+ if(replacedEnumeration == null || replacingEnumeration == null) {\r
+ return "";\r
+ }\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("redeclare type ");\r
+ sb.append(replacedEnumeration.getName());\r
+ sb.append(" = ");\r
+ sb.append(replacingEnumeration.getEnumerationDefinition());\r
+ \r
+ return sb.toString();\r
+ }\r
+\r
+}\r
addLinkType(MappingSchemas.fromAnnotations(g, ConstantExpression.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, WithLookupExpression.class));\r
addLinkType(MappingSchemas.fromAnnotations(g, LookupExpression.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Redeclaration.class));\r
\r
\r
} catch (DatabaseException e) {\r