From 6bddfb06c0d593f7397805c73b3620ad354ed166 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Wed, 16 Jul 2014 13:24:34 +0000 Subject: [PATCH] Merged trunk @29712, 29717, 29863, 29865, 29867, 29869, 29870, 29871, 29878, 29887, 29891, 29900, 29904 refs #4950 refs #5005 refs #5091 refs #5093 refs #5096 refs #5097 refs #5106 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches@29909 ac1ea38d-2e2b-0410-8846-a27921b304fc --- 1.8/org.simantics.sysdyn.ontology/graph.tg | Bin 182687 -> 182684 bytes .../graph/svg/loop.svg | 12 +- 1.8/org.simantics.sysdyn.ui/plugin.xml | 33 +++- .../sysdyn/ui/PropertyViewUndoHandler.java | 51 ++++++ .../ui/browser/contributions/Project.java | 5 +- .../ui/browser/nodes/AbstractChartNode.java | 6 + .../ui/browser/nodes/EnumerationNode.java | 6 +- .../ui/browser/nodes/ExperimentNode.java | 5 + .../sysdyn/ui/browser/nodes/ModelNode.java | 23 ++- .../ui/browser/nodes/ModuleTypeNode.java | 12 +- .../sysdyn/ui/browser/nodes/SCLModule.java | 4 + .../nodes/SharedFunctionLibraryNode.java | 12 +- .../ui/browser/nodes/SharedOntologyNode.java | 10 +- .../participant/SysdynConnectionBuilder.java | 12 ++ .../sysdyn/ui/elements/LoopFactory.java | 19 ++- .../ui/elements/SysdynElementFactory.java | 2 +- .../elements/SysdynTextElementNoBounds.java | 10 ++ .../newComponents/NewBarChartHandler.java | 7 +- .../NewEnumerationNodeHandler.java | 4 + .../NewExperimentNodeHandler.java | 3 + .../newComponents/NewFunctionHandler.java | 6 +- .../NewFunctionLibraryHandler.java | 4 + .../newComponents/NewModuleNodeHandler.java | 6 +- .../newComponents/NewPieChartHandler.java | 8 +- .../NewSensitivityChartHandler.java | 7 +- .../newComponents/NewSpreadSheetHandler.java | 6 +- .../newComponents/NewXYLineChartHandler.java | 9 +- .../ui/properties/ArrayDependencyTab.java | 7 +- .../sysdyn/ui/properties/ArrayFlowTab.java | 5 +- .../sysdyn/ui/properties/ArrayIndexesTab.java | 120 +++++++++++--- .../sysdyn/ui/properties/CommentTab.java | 6 +- .../ui/properties/ConfigurationTab.java | 8 +- .../sysdyn/ui/properties/DependencyTab.java | 16 +- .../sysdyn/ui/properties/EnumerationTab.java | 8 +- .../sysdyn/ui/properties/EquationTab.java | 11 +- .../sysdyn/ui/properties/ExperimentTab.java | 4 + .../ui/properties/ExternalFilesTab.java | 149 +++++++++++------- .../sysdyn/ui/properties/FlowTab.java | 4 + .../ui/properties/FunctionLibraryTab.java | 6 +- .../sysdyn/ui/properties/FunctionTab.java | 28 +++- .../ui/properties/GameExperimentTab.java | 6 +- .../sysdyn/ui/properties/HistoryDataTab.java | 4 + .../ui/properties/InputVariableTab.java | 6 +- .../sysdyn/ui/properties/LookupTableTab.java | 6 +- .../sysdyn/ui/properties/LoopTab.java | 11 +- .../sysdyn/ui/properties/ModuleInputTab.java | 4 + .../sysdyn/ui/properties/ModuleOutputTab.java | 4 + .../ui/properties/ModuleParameterTab.java | 4 + .../sysdyn/ui/properties/ModuleTab.java | 7 +- .../sysdyn/ui/properties/ModuleTypeTab.java | 4 + .../ui/properties/PlaybackExperimentTab.java | 4 + .../ui/properties/ReferenceDependencyTab.java | 4 + .../ResourceSelectionProcessor.java | 77 ++++----- .../sysdyn/ui/properties/ResultTab.java | 4 + .../SensitivityAnalysisExperimentTab.java | 4 + .../SharedFunctionLibrariesTab.java | 25 ++- .../ui/properties/VariableInformationTab.java | 19 ++- .../properties/widgets/DelayMarkWidget.java | 5 + .../ui/properties/widgets/IsOutputWidget.java | 5 + .../widgets/expressions/BasicExpression.java | 7 + .../widgets/expressions/DelayExpression.java | 7 + .../widgets/expressions/EmptyExpression.java | 7 + .../widgets/expressions/IExpression.java | 3 + .../widgets/expressions/LookupExpression.java | 7 + .../widgets/expressions/StockExpression.java | 34 ++-- .../expressions/WithLookupExpression.java | 7 + .../ComboStringPropertyModifier.java | 3 +- .../widgets/functions/FunctionCodeWidget.java | 15 ++ .../SensitivityChartAxisAndVariablesTab.java | 3 +- .../SensitivitySeriesPropertyComposite.java | 7 +- .../sysdyn/utils/SelectionUtils.java | 24 +++ 71 files changed, 792 insertions(+), 189 deletions(-) create mode 100644 1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/PropertyViewUndoHandler.java create mode 100644 1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SelectionUtils.java diff --git a/1.8/org.simantics.sysdyn.ontology/graph.tg b/1.8/org.simantics.sysdyn.ontology/graph.tg index 98d3e2d9d3c08048e17df94d6c693b6727ff0474..cde7423cbcea2477c7c58042b99fff81ce0618bd 100644 GIT binary patch delta 123 zcmbO~nS0J;?uHh|EldKd7`JT~T*dU4SIt<@#MH>l$jCy8O92Ej^RkPR6AMzUk}GYM zEcDEbEzONhO{bgfU|Py-YG^S1;0`8nR-lxL@%G<4m>5}kEc6V`%?*sqbPNrQw{z@c ZVrSwu(lawOF*LEzF*DyTb%3dr69D1pB69!$ delta 126 zcmbO;nS1_Z?uHh|EldKd7 + transform="matrix(0.00747689,-0.00472065,0.00249533,0.01414476,8.177026,1038.1856)" /> diff --git a/1.8/org.simantics.sysdyn.ui/plugin.xml b/1.8/org.simantics.sysdyn.ui/plugin.xml index ee0afef0..7b06dd5b 100644 --- a/1.8/org.simantics.sysdyn.ui/plugin.xml +++ b/1.8/org.simantics.sysdyn.ui/plugin.xml @@ -2504,7 +2504,26 @@ - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/PropertyViewUndoHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/PropertyViewUndoHandler.java new file mode 100644 index 00000000..9fc3a966 --- /dev/null +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/PropertyViewUndoHandler.java @@ -0,0 +1,51 @@ +package org.simantics.sysdyn.ui; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Widget; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField; +import org.simantics.ui.workbench.handler.SessionUndoHandler; + +public class PropertyViewUndoHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + String id = event.getCommand().getId(); + + Event e = (Event)event.getTrigger(); + Widget w = e.widget; + Object data = w.getData(TrackedText.ID); + if (data != null) { + TrackedText text = (TrackedText) data; + if (id.equals("org.eclipse.ui.edit.undo")) + text.undo(); + else + text.redo(); + return null; + } + + + Composite c = ((Control)((Event)event.getTrigger()).widget).getParent(); + if (c instanceof ExpressionField) { + ExpressionField f = (ExpressionField)c; + if (id.equals("org.eclipse.ui.edit.undo")) { + f.getSourceViewer().getUndoManager().undo(); + } + else { + f.getSourceViewer().getUndoManager().redo(); + } + } else { + SessionUndoHandler suh = new SessionUndoHandler(); + suh.execute(event); + //Layer0Utils.undo(); + + } + return null; + } + +} diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java index 73725ccb..0d381be5 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java @@ -48,7 +48,10 @@ public class Project extends ViewpointContributor { ProjectResource PROJ = ProjectResource.getInstance(graph); if(!graph.isInstanceOf(project, PROJ.Project)) return Collections.emptyList(); Collection ontologies = Simantics.applySCL("Simantics/SharedOntologies", "traverseSharedOntologies", graph, graph.getRootLibrary()); - for(Resource o : ontologies) result.add(new SharedOntologyNode(o)); + for(Resource o : ontologies) { + if(!graph.isImmutable(o)) + result.add(new SharedOntologyNode(o)); + } return result; diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java index 61eb1850..0d17007c 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java @@ -19,13 +19,16 @@ import org.simantics.browsing.ui.common.node.AbstractNode; import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IDropTargetNode; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; import org.simantics.ui.SimanticsUI; import org.simantics.utils.ui.ExceptionUtils; @@ -67,7 +70,10 @@ public abstract class AbstractChartNode extends AbstractNode implem SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + graph.markUndoPoint(); + String chartName = graph.getRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed chart '" + chartName +"' " + data); } }); } catch (DatabaseException e) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java index 7d7ee9dc..bfa2943d 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java @@ -5,6 +5,7 @@ import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; @@ -13,6 +14,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.layer0.variable.Variable; import org.simantics.layer0.Layer0; @@ -76,6 +78,7 @@ public class EnumerationNode extends VariableNode implements IModifiab SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + graph.markUndoPoint(); SysdynResource sr = SysdynResource.getInstance(graph); for(Resource redeclaration : graph.getObjects(data, sr.Redeclaration_replacedEnumeration_Inverse)) { graph.deny(redeclaration, sr.Module_redeclaration_Inverse); @@ -96,8 +99,9 @@ public class EnumerationNode extends VariableNode implements IModifiab } } + String enumerationName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); - + Layer0Utils.addCommentMetadata(graph, "Removed Enumeration " + enumerationName + " "+ data.toString()); } }); } catch (DatabaseException e) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java index deeb8dd7..e059b644 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java @@ -20,12 +20,15 @@ import org.simantics.browsing.ui.common.node.IDoubleClickableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.layer0.Layer0; import org.simantics.project.IProject; import org.simantics.simulation.project.IExperimentManager; import org.simantics.sysdyn.SysdynResource; @@ -81,7 +84,9 @@ public class ExperimentNode extends AbstractNode implements IDoubleCli if(resultSets != null) for(Resource resultSet : resultSets) SimulationResultSetNode.unlinkResultSet(graph, resultSet); + String ontologyName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed experiment " + ontologyName + " "+ data.toString()); } }); } catch (DatabaseException e) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java index 660fe185..13971866 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.browser.nodes; +import org.simantics.Simantics; import org.simantics.browsing.ui.common.node.AbstractNode; import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDeletableNode; @@ -18,6 +19,7 @@ import org.simantics.browsing.ui.common.node.IDoubleClickableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -25,6 +27,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; @@ -49,14 +52,22 @@ public class ModelNode extends AbstractNode implements IDoubleClickabl @Override public void execute(final String result) { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + if (result == null) + return; + Simantics.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { Layer0 l0 = Layer0.getInstance(graph); SimulationResource sim = SimulationResource.getInstance(graph); Resource configuration = graph.getPossibleObject(data, sim.HasConfiguration); + + String label = graph.getPossibleRelatedValue2(configuration, l0.HasLabel, Bindings.STRING); + if (label != null) + return; + graph.claimLiteral(configuration, l0.HasLabel, result); + Layer0Utils.addCommentMetadata(graph, "Created ModelNode to model browser for model " + result); } }); } @@ -98,10 +109,13 @@ public class ModelNode extends AbstractNode implements IDoubleClickabl return new WriteRequest() { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); + String oldName = g.getPossibleRelatedValue2(data, l0.HasLabel, Bindings.STRING); g.claimLiteral(data, l0.HasLabel, label); String safeName = NameUtils.findFreshName(g, label, g.getSingleObject(data, l0.PartOf), l0.ConsistsOf, "%s%d"); g.claimLiteral(data, l0.HasName, safeName); + Layer0Utils.addCommentMetadata(g, "Renamed model " + oldName + " to " + label + " " + data.toString()); } }; } @@ -116,13 +130,20 @@ public class ModelNode extends AbstractNode implements IDoubleClickabl SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + + graph.markUndoPoint(); + Layer0 l0 = Layer0.getInstance(graph); for(Resource r : graph.getObjects(data, l0.ConsistsOf)) if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).Result)) SimulationResultNode.deleteResultFiles(graph, r); + String modelName = graph.getPossibleRelatedValue2(data, l0.HasName, Bindings.STRING); + String modelResource = data.toString(); RemoverUtil.remove(graph, data); + + Layer0Utils.addCommentMetadata(graph, "Removed model '" + modelName +"' " + modelResource); } }); } catch (DatabaseException e) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java index 6d773446..06e93bd0 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java @@ -23,6 +23,7 @@ import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -34,6 +35,7 @@ import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.adapter.PasteHandler; import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; @@ -78,8 +80,12 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable @Override public void perform(WriteGraph graph) throws DatabaseException { - if(configuration != null) - graph.claimLiteral(configuration, Layer0.getInstance(graph).HasLabel, result); + if(configuration != null) { + Layer0 L0 = Layer0.getInstance(graph); + String currentLabel = graph.getRelatedValue2(configuration, L0.HasLabel, Bindings.STRING); + if (!currentLabel.equals(result)) + graph.claimLiteral(configuration, L0.HasLabel, result); + } } }); } @@ -150,6 +156,7 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable @Override public void perform(WriteGraph graph) throws DatabaseException{ + graph.markUndoPoint(); Layer0 l0 = Layer0.getInstance(graph); StructuralResource2 st = StructuralResource2.getInstance(graph); ModelingResources mr = ModelingResources.getInstance(graph); @@ -175,6 +182,7 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable RemoverUtil.remove(graph, issue); } } + Layer0Utils.addCommentMetadata(graph, "Removed Module Type " + graph.getRelatedValue2(type, l0.HasName, Bindings.STRING) + " " + type.toString()); RemoverUtil.remove(graph, type); } }); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java index 70815ee4..9307287e 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java @@ -17,12 +17,14 @@ import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.layer0.Layer0; import org.simantics.ui.SimanticsUI; @@ -40,7 +42,9 @@ public class SCLModule extends AbstractNode implements IDeletableNode, SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + String ontologyName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed SCL Module " + ontologyName + " "+ data.toString()); } }); } catch (DatabaseException e) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java index e2269eba..b5082277 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java @@ -15,10 +15,13 @@ import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDropTargetNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.utils.SharedFunctionLibraryNameValidator; @@ -37,12 +40,9 @@ public class SharedFunctionLibraryNode extends FunctionLibraryNode imp @Override public void perform(WriteGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - - graph.deny(data, l0.PartOf); - graph.deny(data, l0.IsLinkedTo_Inverse); - - // TODO: remove file + String ontologyName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); + RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed Shared Function Library " + ontologyName + " "+ data.toString()); } }); } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java index 6e6d5951..678a4c05 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java @@ -1,17 +1,20 @@ package org.simantics.sysdyn.ui.browser.nodes; +import org.simantics.Simantics; import org.simantics.browsing.ui.common.node.AbstractNode; import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; -import org.simantics.ui.SimanticsUI; +import org.simantics.layer0.Layer0; import org.simantics.utils.ui.ExceptionUtils; public class SharedOntologyNode extends AbstractNode implements IDeletableNode, IModifiableNode { @@ -23,10 +26,13 @@ public class SharedOntologyNode extends AbstractNode implements IDelet @Override public void delete() throws DeleteException { try { - SimanticsUI.getSession().syncRequest(new WriteRequest() { + Simantics.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + graph.markUndoPoint(); + String ontologyName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed Shared Ontology " + ontologyName + " "+ data.toString()); } }); } catch (DatabaseException e) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java index 159abc54..5f3c3259 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java @@ -22,6 +22,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.diagram.content.ConnectionUtil; import org.simantics.diagram.participant.ConnectionBuilder; import org.simantics.diagram.participant.ControlPoint; @@ -65,6 +66,9 @@ public class SysdynConnectionBuilder extends ConnectionBuilder{ */ public void create(WriteGraph graph, ConnectionJudgement judgment, Deque controlPoints, TerminalInfo startTerminal, TerminalInfo endTerminal) throws DatabaseException { + + graph.markUndoPoint(); + // If needs a valve, we will create two separate connections if(needsValve(startTerminal, endTerminal)) { createValveAndConnections(graph, judgment, controlPoints, startTerminal, endTerminal); @@ -73,6 +77,14 @@ public class SysdynConnectionBuilder extends ConnectionBuilder{ else { createConnection(graph, judgment, controlPoints, startTerminal, endTerminal, false); } + + String startElementName = startTerminal.e.getHint(ElementHints.KEY_TEXT); + String endElementName = endTerminal.e.getHint(ElementHints.KEY_TEXT); + + String startElementResource = startTerminal.e.getHint(ElementHints.KEY_OBJECT).toString(); + String endElementResource = endTerminal.e.getHint(ElementHints.KEY_OBJECT).toString(); + + Layer0Utils.addCommentMetadata(graph, "Created dependency starting from " + startElementName + " " + startElementResource + " and ending to " + endElementName + " " + endElementResource); } /** * @param graph diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/LoopFactory.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/LoopFactory.java index 473ee7a1..2498e4a4 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/LoopFactory.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/LoopFactory.java @@ -62,10 +62,14 @@ import org.simantics.g2d.svg.SVGImage; import org.simantics.g2d.utils.Alignment; import org.simantics.modeling.ModelingResources; import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.events.MouseEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseEnterEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseExitEvent; import org.simantics.scenegraph.g2d.nodes.SVGNode; import org.simantics.scenegraph.g2d.nodes.ShapeNode; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.properties.LoopTab; +import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils; import org.simantics.sysdyn.utils.LoopUtils; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.Callback; @@ -116,13 +120,14 @@ public class LoopFactory extends SysdynElementFactory { static Shape getLoopShape() { // Used in shortcut. + double x0 = 5, y0 = 2; Path2D loop = new Path2D.Double(); - loop.moveTo(1, 2); - loop.lineTo(0, 0); - loop.lineTo(-1, 2); + loop.moveTo(x0 + 1, y0 + 2); + loop.lineTo(x0 + 0, y0 + 0); + loop.lineTo(x0 -1, y0 + 2); loop.closePath(); - loop.append(new Arc2D.Double(-10, -3, 10, 10, 0, -270, Arc2D.OPEN), false); + loop.append(new Arc2D.Double(x0 -10, y0 -3, 10, 10, 0, -270, Arc2D.OPEN), false); return loop; } @@ -201,7 +206,7 @@ public class LoopFactory extends SysdynElementFactory { SVGNode image = e.getHint(getNodeKey()); if (clockwise != null && clockwise) { Point2D imageParent = (Point2D) image.localToParent(new Point2D.Double(0.0,0.0)).clone(); - AffineTransform at = new AffineTransform(-1.0, 0.0, 0.0, 1.0, imageParent.getX(), imageParent.getY()); + AffineTransform at = new AffineTransform(-1.0, 0.0, 0.0, 1.0, imageParent.getX()+12.34, imageParent.getY()); image.setTransform(at); } @@ -292,12 +297,12 @@ public class LoopFactory extends SysdynElementFactory { private static double getXCoordShift(IElement e) { //String location = e.getHint(SysdynElementHints.KEY_LOCATION); - return 0; + return 6.3; } private static double getYCoordShift(IElement e) { //String location = e.getHint(SysdynElementHints.KEY_LOCATION); - return 9.7; + return -0.3; } @Override diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementFactory.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementFactory.java index 174ae574..a3c3be2c 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementFactory.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementFactory.java @@ -157,7 +157,7 @@ public abstract class SysdynElementFactory extends SyncElementFactory { Resource component = graph.getPossibleObject(element, mr.ElementToComponent); if (component != null && graph.hasStatement(component, SysdynResource.getInstance(graph).IsOutput)) { Font font = ElementUtils.getTextFont(e); - font = font.deriveFont(Font.BOLD); + font = font.deriveFont(font.isItalic() ? Font.ITALIC | Font.BOLD : Font.BOLD); ElementUtils.setTextFont(e, font); } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynTextElementNoBounds.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynTextElementNoBounds.java index 3d6eda9e..3e2f4f52 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynTextElementNoBounds.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynTextElementNoBounds.java @@ -41,6 +41,7 @@ import org.simantics.modeling.ModelingResources; import org.simantics.modeling.ui.diagramEditor.DiagramEditor; import org.simantics.modeling.ui.diagramEditor.DiagramViewer; import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.events.MouseEvent; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils; import org.simantics.sysdyn.ui.utils.VariableNameValidator; @@ -145,6 +146,7 @@ public class SysdynTextElementNoBounds extends TextElementNoBounds { String text = node.getText(); if(!new VariableNameValidator().isValid(component, text, false)) { text = textBeforeEdit; + node.setEditMode(false); node.setText(text); if(new VariableNameValidator().isValid(component, text, false)) node.setColor(ElementUtils.getTextColor(e, Color.BLACK)); @@ -304,5 +306,13 @@ public class SysdynTextElementNoBounds extends TextElementNoBounds { unflipText(e); } + + @Override + public boolean handleMouseEvent(IElement e, final ICanvasContext ctx, MouseEvent me) { + //if (!(me instanceof MouseEnterEvent) && !(me instanceof MouseMovedEvent) && !(me instanceof MouseExitEvent)) + //System.out.println(me instanceof MouseDragBegin ? "drag begin" : "no drag begin"); + //SysdynWorkbenchUtils.setHoveringHint(ctx, me, SysdynTextElementNoBounds.this); + return super.handleMouseEvent(e, ctx, me); + } } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java index 88aa7eb7..1e342142 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java @@ -25,6 +25,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.diagram.stubs.G2DResource; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -55,13 +56,16 @@ public class NewBarChartHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); JFreeChartResource jfree = JFreeChartResource.getInstance(g); G2DResource g2d = G2DResource.getInstance(g); + String label = NameUtils.findFreshLabel(g, "Bar Chart", model); + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, l0.HasName, "BarChart" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(g, "Bar Chart", model), + l0.HasLabel, label, l0.PartOf, model, jfree.Chart_visibleBorder, true, jfree.Chart_borderWidth, 3, @@ -100,6 +104,7 @@ public class NewBarChartHandler extends AbstractHandler { l0.ConsistsOf, dataset, l0.ConsistsOf, domainAxis, l0.ConsistsOf, rangeAxis); + Layer0Utils.addCommentMetadata(g, "Created new Bar Chart " + label + " " + jfreechart); } }); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java index 6801225c..81128020 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java @@ -18,12 +18,14 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.modeling.ModelingResources; @@ -51,6 +53,7 @@ public class NewEnumerationNodeHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); SysdynResource sr = SysdynResource.getInstance(g); Layer0 l0 = Layer0.getInstance(g); @@ -79,6 +82,7 @@ public class NewEnumerationNodeHandler extends AbstractHandler { l0.HasName, name, sr.Enumeration_enumerationIndexList, ListUtils.create(g, new ArrayList()), l0.PartOf, configuration); + Layer0Utils.addCommentMetadata(g, "Created new Enumeration " + name + " to " + g.getRelatedValue2(configuration, l0.HasLabel, Bindings.STRING)); } }); return null; diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java index 0ddf1a3b..ddfc2b1d 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java @@ -24,6 +24,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; @@ -56,6 +57,7 @@ public class NewExperimentNodeHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); String label = NameUtils.findFreshName(g, getNameSuggestion(), model, l0.ConsistsOf, l0.HasLabel, "%s%d"); Resource experiment = GraphUtils.create2(g, getExperimentType(g), @@ -63,6 +65,7 @@ public class NewExperimentNodeHandler extends AbstractHandler { l0.HasLabel, label, l0.PartOf, model); configureExperiment(g, experiment); + Layer0Utils.addCommentMetadata(g, "Created new experiment " + label + " " + experiment.toString()); } }); return null; diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java index 7acab21e..e048657c 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java @@ -22,6 +22,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; @@ -55,6 +56,7 @@ public class NewFunctionHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); SysdynResource sr = SysdynResource.getInstance(g); @@ -71,11 +73,13 @@ public class NewFunctionHandler extends AbstractHandler { String name = NameUtils.findFreshName(g, "Function", library, l0.ConsistsOf, "%s%d"); - GraphUtils.create2(g, sr.SysdynModelicaFunction, + Resource func = GraphUtils.create2(g, sr.SysdynModelicaFunction, l0.HasName, name, l0.HasDescription, "", sr.SysdynModelicaFunction_modelicaFunctionCode, "", l0.PartOf, library); + + Layer0Utils.addCommentMetadata(g, "Created new Function " + name + " " + func.toString()); } }); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java index bf62f3ef..62d88a4a 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java @@ -23,6 +23,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; @@ -63,6 +64,7 @@ public class NewFunctionLibraryHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); SysdynResource sr = SysdynResource.getInstance(g); @@ -100,6 +102,8 @@ public class NewFunctionLibraryHandler extends AbstractHandler { if(shared) g.claim(model, l0.IsLinkedTo, functionLibrary); + + Layer0Utils.addCommentMetadata(g, "Created new Function Library " + name + " " + functionLibrary.toString()); } }); } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java index 60170f7e..b5939cb7 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java @@ -23,6 +23,7 @@ import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Template; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -33,8 +34,8 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.browser.actions.newActions.NewModuleTypeAction; import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; import org.simantics.ui.SimanticsUI; -import org.simantics.utils.ui.AdaptionUtils; import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.ui.AdaptionUtils; /** * Creates a new module node for a model. @@ -62,6 +63,7 @@ public class NewModuleNodeHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); SysdynResource sr = SysdynResource.getInstance(g); Layer0 l0 = Layer0.getInstance(g); Layer0X L0X = Layer0X.getInstance(g); @@ -122,7 +124,7 @@ public class NewModuleNodeHandler extends AbstractHandler { g.claim(moduleSymbol, sr2.IsDefinedBy, OrderedSetUtils.create(g, sr2.Composite, terminal, terminal2)); - + Layer0Utils.addCommentMetadata(g, "Created new Module Type " + name + " " + moduleType.toString()); } }); return null; diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java index 3f17f995..0d386c7b 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java @@ -25,6 +25,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.diagram.stubs.G2DResource; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -55,13 +56,16 @@ public class NewPieChartHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); JFreeChartResource jfree = JFreeChartResource.getInstance(g); G2DResource g2d = G2DResource.getInstance(g); + String label = NameUtils.findFreshLabel(g, "Pie Chart", model); + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, l0.HasName, "PieChart" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(g, "Pie Chart", model), + l0.HasLabel, label, l0.PartOf, model, jfree.Chart_visibleBorder, true, jfree.Chart_borderWidth, 3); @@ -83,6 +87,8 @@ public class NewPieChartHandler extends AbstractHandler { l0.PartOf, jfreechart, l0.ConsistsOf, dataset ); + Layer0Utils.addCommentMetadata(g, "Created new Pie Chart " + label + " " + jfreechart); + } }); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityChartHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityChartHandler.java index 013c5602..7bc7a370 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityChartHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityChartHandler.java @@ -27,6 +27,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.diagram.stubs.G2DResource; import org.simantics.jfreechart.chart.ChartUtils; import org.simantics.layer0.Layer0; @@ -54,14 +55,17 @@ public class NewSensitivityChartHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); JFreeChartResource jfree = JFreeChartResource.getInstance(g); G2DResource g2d = G2DResource.getInstance(g); SysdynResource SR = SysdynResource.getInstance(g); + String label = NameUtils.findFreshLabel(g, "SensitivityChart", model); + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, l0.HasName, "SensitivityChart" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(g, "SensitivityChart", model), + l0.HasLabel, label, l0.PartOf, model, jfree.Chart_visibleBorder, true, jfree.Chart_borderWidth, 3); @@ -143,6 +147,7 @@ public class NewSensitivityChartHandler extends AbstractHandler { l0.ConsistsOf, dataset, l0.ConsistsOf, domainAxis, l0.ConsistsOf, rangeAxis); + Layer0Utils.addCommentMetadata(g, "Created new Sensitivity Chart " + label + " " + jfreechart); } }); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java index 3a64607a..5a612a49 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java @@ -19,7 +19,9 @@ import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.sysdyn.utils.SheetUtils; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; @@ -44,7 +46,9 @@ public class NewSpreadSheetHandler extends AbstractHandler { @Override public void perform(WriteGraph graph) throws DatabaseException { - SheetUtils.createSheet(graph, book, null, new String[] {}, new int[] {50}); + graph.markUndoPoint(); + Resource sheet = SheetUtils.createSheet(graph, book, null, new String[] {}, new int[] {50}); + Layer0Utils.addCommentMetadata(graph, "Created new Spreadsheet " + NameUtils.getSafeName(graph, sheet) + " " + sheet.toString()); } }); return null; diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java index 2f06ce81..9c2e675e 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java @@ -26,6 +26,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.diagram.stubs.G2DResource; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -58,13 +59,16 @@ public class NewXYLineChartHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); JFreeChartResource jfree = JFreeChartResource.getInstance(g); G2DResource g2d = G2DResource.getInstance(g); - + + String label = NameUtils.findFreshLabel(g, "Chart", model); + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, l0.HasName, "Chart" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(g, "Chart", model), + l0.HasLabel, label, l0.PartOf, model, jfree.Chart_visibleBorder, true, jfree.Chart_borderWidth, 3); @@ -102,6 +106,7 @@ public class NewXYLineChartHandler extends AbstractHandler { l0.ConsistsOf, dataset, l0.ConsistsOf, domainAxis, l0.ConsistsOf, rangeAxis); + Layer0Utils.addCommentMetadata(g, "Created new Line Chart " + label + " " + jfreechart); } }); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java index bd1c1bfd..1e780884 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java @@ -268,7 +268,11 @@ public class ArrayDependencyTab extends AdjustableTab { } } - @Override + public ArrayDependencyTab(Object dependencies) { + super(dependencies); + } + + @Override protected void createAndAddControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { composite = new Composite(body, SWT.NONE); @@ -387,5 +391,4 @@ public class ArrayDependencyTab extends AdjustableTab { GridDataFactory.fillDefaults().span(1, 1).applyTo(lineThicknessGroup); GridLayoutFactory.fillDefaults().applyTo(lineThicknessGroup); } - } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayFlowTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayFlowTab.java index ad02e9ad..47238fb4 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayFlowTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayFlowTab.java @@ -42,6 +42,10 @@ public class ArrayFlowTab extends LabelPropertyTabContributor { private Scale lineThicknessScale; + public ArrayFlowTab(Object input) { + super(input); + } + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { Composite composite = new Composite(body, SWT.NONE); @@ -102,5 +106,4 @@ public class ArrayFlowTab extends LabelPropertyTabContributor { return (int)Math.round(FlowConnectionStyle.DEFAULT_LINE_WIDTH * 3); } } - } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java index e97de85e..741cfcc2 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java @@ -29,13 +29,16 @@ import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.ResourceArray; +import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor; import org.simantics.layer0.Layer0; @@ -43,6 +46,7 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; import org.simantics.utils.RunnableWithObject; import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.threads.SWTThread; public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widget{ @@ -50,8 +54,16 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg GraphExplorerComposite usedEnumerationsExplorer; private WidgetSupportImpl buttonSupport; private org.simantics.browsing.ui.swt.widgets.Label usedEnumerationsLabel; + private Button down; + private Button up; + private Button remove; - @Override + public ArrayIndexesTab(Object variables) { + super(variables); + } + + + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { support.register(this); @@ -93,7 +105,7 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg List enumerationResources; @Override - public void beforeApply() { + public void beforeApply() { enumerationResources = getSelectedResources(availableEnumerationsExplorer); } @@ -103,16 +115,27 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg SysdynResource sr = SysdynResource.getInstance(graph); for(Resource r : input.resources) { Resource arrayIndexes = graph.getPossibleObject(r, sr.Variable_arrayIndexesList); + StringBuilder sb = new StringBuilder(); + sb.append("Added new enumeration(s) "); if(arrayIndexes == null) { - graph.claim(r, sr.Variable_arrayIndexesList, ListUtils.create(graph, enumerationResources)); + arrayIndexes = ListUtils.create(graph, enumerationResources); + graph.claim(r, sr.Variable_arrayIndexesList, arrayIndexes); + sb.append(enumerationResources.toString() + " "); } else { ArrayList filtered = new ArrayList(); for(Resource enumeration : enumerationResources) { - if(ListUtils.getNode(graph, arrayIndexes, enumeration) == null) + if(ListUtils.getNode(graph, arrayIndexes, enumeration) == null) { filtered.add(enumeration); + sb.append(graph.getPossibleRelatedValue2(enumeration, Layer0.getInstance(graph).HasName, Bindings.STRING) + " "); + } } + if (filtered.isEmpty()) + return; ListUtils.insertBack(graph, arrayIndexes, filtered); } + sb.append("to " + graph.getPossibleRelatedValue2(r, Layer0.getInstance(graph).HasName, Bindings.STRING)); + Layer0Utils.addCommentMetadata(graph, sb.toString()); + updateUsedButtons(graph, arrayIndexes); } } }); @@ -166,7 +189,7 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg Composite buttons = new Composite(body, SWT.None); GridLayoutFactory.fillDefaults().applyTo(buttons); - Button up = new Button(buttons, buttonSupport, SWT.NONE); + up = new Button(buttons, buttonSupport, SWT.NONE); up.setText("Up"); up.addSelectionListener(new SelectionListenerImpl(context) { @@ -189,6 +212,8 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg if(arrayIndexes != null) { List enumerations = ListUtils.toList(graph, arrayIndexes); List toBeMoved = new ArrayList(); + StringBuilder sb = new StringBuilder(); + sb.append("Moved enumeration(s) "); for(Integer index : selectedIndexes) { if(index < enumerations.size()) { Resource enumeration = enumerations.get(index); @@ -196,14 +221,20 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg } } - + boolean moved = false; for(Resource enumeration : toBeMoved) { Resource node = ListUtils.getNode(graph, arrayIndexes, enumeration); Resource prev = graph.getSingleObject(node, L0.List_Previous); if(!arrayIndexes.equals(prev) && !toBeMoved.contains(graph.getPossibleObject(prev, L0.List_Element))) { - ListUtils.swapWithPrevious(graph, arrayIndexes, enumeration); + sb.append(graph.getPossibleRelatedValue2(enumeration, Layer0.getInstance(graph).HasName, Bindings.STRING) + " "); + moved = ListUtils.swapWithPrevious(graph, arrayIndexes, enumeration); } } + if (moved) { + sb.append("up"); + Layer0Utils.addCommentMetadata(graph, sb.toString()); + } + } } @@ -235,7 +266,7 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg } }); - Button down = new Button(buttons, buttonSupport, SWT.NONE); + down = new Button(buttons, buttonSupport, SWT.NONE); down.setText("Down"); down.addSelectionListener(new SelectionListenerImpl(context) { @@ -259,21 +290,28 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg if(arrayIndexes != null) { List enumerations = ListUtils.toList(graph, arrayIndexes); List toBeMoved = new ArrayList(); + StringBuilder sb = new StringBuilder(); + sb.append("Moved enumeration(s) "); for(Integer index : selectedIndexes) { if(index < enumerations.size()) { Resource enumeration = enumerations.get(index); toBeMoved.add(0, enumeration); // Make an inverted list. } - } - + boolean moved = false; for(Resource enumeration : toBeMoved) { Resource node = ListUtils.getNode(graph, arrayIndexes, enumeration); Resource next = graph.getSingleObject(node, L0.List_Next); + if(!arrayIndexes.equals(next) && !toBeMoved.contains(graph.getPossibleObject(next, L0.List_Element))) { - ListUtils.swapWithNext(graph, arrayIndexes, enumeration); + sb.append(graph.getPossibleRelatedValue2(enumeration, Layer0.getInstance(graph).HasName, Bindings.STRING) + " "); + moved = ListUtils.swapWithNext(graph, arrayIndexes, enumeration); } } + if (moved) { + sb.append("down"); + Layer0Utils.addCommentMetadata(graph, sb.toString()); + } } } @@ -307,7 +345,7 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg }); - Button remove = new Button(buttons, buttonSupport, SWT.NONE); + remove = new Button(buttons, buttonSupport, SWT.NONE); remove.setText("Remove"); remove.addSelectionListener(new SelectionListenerImpl(context) { @@ -335,9 +373,15 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg } } - - for(Resource enumeration : toBeRemoved) + StringBuilder sb = new StringBuilder(); + sb.append("Removed enumeration(s) "); + for(Resource enumeration : toBeRemoved) { ListUtils.removeElement(graph, arrayIndexes, enumeration); + sb.append(graph.getPossibleRelatedValue2(enumeration, Layer0.getInstance(graph).HasName, Bindings.STRING) + " "); + } + sb.append("from " + graph.getPossibleRelatedValue2(variable, Layer0.getInstance(graph).HasName, Bindings.STRING)); + Layer0Utils.addCommentMetadata(graph, sb.toString()); + updateUsedButtons(graph, arrayIndexes); } } } @@ -345,6 +389,33 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg } + protected void updateUsedButtons(ReadGraph graph, Resource arrayIndexes) { + boolean enabled = false; + if (arrayIndexes == null) + enabled = false; + else { + try { + List currEnumerations = ListUtils.toList(graph, arrayIndexes); + if (!currEnumerations.isEmpty()) { + enabled = true; + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + final boolean finalEnabled = enabled; + SWTThread.getThreadAccess().asyncExec(new Runnable() { + + @Override + public void run() { + up.getControl().setEnabled(finalEnabled); + down.getControl().setEnabled(finalEnabled); + remove.getControl().setEnabled(finalEnabled); + } + }); + } + + private List getSelectedResources(GraphExplorerComposite explorer) { List result = new ArrayList(); @@ -395,16 +466,27 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg resourceArray = new ResourceArray((Resource)first); else if( first instanceof Collection) resourceArray = new ResourceArray(((Collection)first).toArray(new Resource[((Collection)first).size()])); - + final ResourceArray finalResourceArray = resourceArray; if(resourceArray != null) { - StructuredSelection selection = new StructuredSelection(resourceArray); + StructuredSelection selection = new StructuredSelection(finalResourceArray); availableEnumerationsExplorer.setInput(context, selection); usedEnumerationsExplorer.setInput(context, selection); buttonSupport.fireInput(context, selection); + + try { + context.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource r = finalResourceArray.resources[0]; + Resource arrayIndexes = graph.getPossibleObject(r, SysdynResource.getInstance(graph).Variable_arrayIndexesList); + updateUsedButtons(graph, arrayIndexes); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } } } - - } - } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/CommentTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/CommentTab.java index 0b6c00c1..cc4838c7 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/CommentTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/CommentTab.java @@ -34,7 +34,11 @@ import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor; */ public class CommentTab extends LabelPropertyTabContributor { - @Override + public CommentTab(Object id) { + super(id); + } + + @Override public String getPartName(ISelection forSelection) { return "Comment"; } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java index 33ad0ea6..36e3fa14 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java @@ -38,6 +38,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.PossibleObjectWithType; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; import org.simantics.issues.ontology.IssueResource; import org.simantics.jfreechart.chart.properties.AdjustableTab; @@ -59,7 +60,11 @@ import org.simantics.sysdyn.ui.properties.widgets.factories.ModelNameInputValida */ public class ConfigurationTab extends AdjustableTab { - private ScrolledComposite sc; + public ConfigurationTab(Object id) { + super(id); + } + + private ScrolledComposite sc; private Label nameLabel, startTimeLabel, stopTimeLabel, stepLengthLabel, outputIntervalLabel, methodLabel, toleranceLabel, variableFilterLabel; private TrackedText name, startTime, stopTime, stepLength, outputInterval, tolerance, variableFilter; @@ -259,6 +264,7 @@ public class ConfigurationTab extends AdjustableTab { public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException { graph.claimLiteral(input, SysdynResource.getInstance(graph).SysdynModel_timeUnit, text); + Layer0Utils.addCommentMetadata(graph, "Modified " + graph.getRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING) + " time unit to " + text); } }); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java index 1acc0212..666d1008 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java @@ -31,8 +31,10 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; import org.simantics.jfreechart.chart.properties.AdjustableTab; +import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.elements.connections.DependencyEdgeClass; import org.simantics.sysdyn.ui.elements.connections.DependencyNode; @@ -50,6 +52,10 @@ import org.simantics.utils.datastructures.Triple; */ public class DependencyTab extends AdjustableTab { + public DependencyTab(Object id) { + super(id); + } + Button none, plus, minus, other, inside, outside; TrackedText polarityText, polarityLocationText; Scale lineThicknessScale; @@ -79,6 +85,7 @@ public class DependencyTab extends AdjustableTab { SysdynResource sr = SysdynResource.getInstance(graph); float width = ((float)selection) / 10.0f; graph.claimLiteral(connectionElement, sr.DependencyConnection_strokeWidth, width); + Layer0Utils.addCommentMetadata(graph, "Modified Line thickness for connection " + graph.getPossibleRelatedValue2(connectionElement, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to " + width); } } @@ -110,9 +117,12 @@ public class DependencyTab extends AdjustableTab { @Override public void apply(WriteGraph graph, Resource connectionElement) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); + String currentLocation = graph.getPossibleRelatedValue2(connectionElement, sr.DependencyConnection_polarityLocation, Bindings.STRING); + if (currentLocation != null && currentLocation.equals(location)) + return; graph.claimLiteral(connectionElement, sr.DependencyConnection_polarityLocation, location); + Layer0Utils.addCommentMetadata(graph, "Modified Location for connection " + graph.getPossibleRelatedValue2(connectionElement, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to " + location); } - } class PolarityLocationRadioSelectionFactory extends ReadFactoryImpl { @@ -153,7 +163,11 @@ public class DependencyTab extends AdjustableTab { @Override public void apply(WriteGraph graph, Resource connectionElement) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); + String currentPolarity = graph.getPossibleRelatedValue2(connectionElement, sr.DependencyConnection_polarity, Bindings.STRING); + if (currentPolarity != null && currentPolarity.equals(polarity)) + return; graph.claimLiteral(connectionElement, sr.DependencyConnection_polarity, polarity.trim()); + Layer0Utils.addCommentMetadata(graph, "Modified Polarity for connection " + graph.getPossibleRelatedValue2(connectionElement, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to " + polarity.trim()); } } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java index 833a6261..7514f47c 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java @@ -60,15 +60,19 @@ import org.simantics.sysdyn.manager.SysdynModel; import org.simantics.sysdyn.manager.SysdynModelManager; import org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationIndexNode; import org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableIndexesWidget; -import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier; import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameInputValidator; +import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.ArrayMap; import org.simantics.utils.ui.AdaptionUtils; public class EnumerationTab extends LabelPropertyTabContributor implements Widget { - GraphExplorerComposite indexExplorer; + public EnumerationTab(Object id) { + super(id); + } + + GraphExplorerComposite indexExplorer; Button showAll; Variable variable; diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java index 633cdfa3..4d45a5cb 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java @@ -46,6 +46,7 @@ import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.databoard.Bindings; import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -56,6 +57,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.AsyncListener; @@ -104,7 +106,11 @@ public class EquationTab extends AdjustableTab implements Widget { private Label unitLabel; private IsOutputWidget isOutput; - @Override + public EquationTab(Object input) { + super(input); + } + + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport _support) { _support.register(this); setSupport(); @@ -468,6 +474,7 @@ public class EquationTab extends AdjustableTab implements Widget { ); } }); + Layer0Utils.addCommentMetadata(graph, "Deleted Expression " + activeExpression + " from " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING)); } }); @@ -492,10 +499,12 @@ public class EquationTab extends AdjustableTab implements Widget { graph.claim(newExpression, l0.InstanceOf, graph.getSingleObject(activeExpression, l0.InstanceOf)); if(graph.isInstanceOf(newExpression, sr.StockExpression)) { graph.claimLiteral(newExpression, sr.StockExpression_initialEquation, ""); + Layer0Utils.addCommentMetadata(graph, "Created new Stock Expression " + newExpression + " for " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING)); } } else { // If there was no active expression, create a normal expression graph.claim(newExpression, l0.InstanceOf, sr.NormalExpression); + Layer0Utils.addCommentMetadata(graph, "Created new Normal Expression " + newExpression + " for " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING)); } ArrayList addition = new ArrayList(1); addition.add(newExpression); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExperimentTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExperimentTab.java index 0c291db7..d1bb32f5 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExperimentTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExperimentTab.java @@ -19,6 +19,10 @@ import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor; public class ExperimentTab extends LabelPropertyTabContributor { + public ExperimentTab(Object id) { + super(id); + } + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java index a4a91c9f..fb32aa51 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java @@ -12,6 +12,7 @@ package org.simantics.sysdyn.ui.properties; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.eclipse.jface.dialogs.MessageDialog; @@ -23,6 +24,8 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.IWorkbenchSite; @@ -35,17 +38,18 @@ import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.management.ISessionContext; import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor; import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.handlers.RemoveNodeHandler; import org.simantics.sysdyn.ui.handlers.exports.ExportExternalFunctionFilesHandler; import org.simantics.sysdyn.ui.handlers.imports.ImportExternalFunctionFilesHandler; -import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.ArrayMap; import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.threads.SWTThread; /** * Tab for properties of a SysdynModelicaFunction containing all external files added to that function @@ -55,7 +59,11 @@ import org.simantics.utils.datastructures.Pair; */ public class ExternalFilesTab extends LabelPropertyTabContributor implements Widget { - GraphExplorerComposite externalFilesExplorer; + public ExternalFilesTab(Object id) { + super(id); + } + + GraphExplorerComposite externalFilesExplorer; Button importButton, exportButton, removeButton; @Override @@ -77,8 +85,17 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid Resource.class)); externalFilesExplorer.setContextMenuId("#ExternalFunctionFileBrowser"); + + externalFilesExplorer.addListenerToControl(SWT.Selection, new Listener() { + + @Override + public void handleEvent(Event event) { + updateButtons(externalFilesExplorer); + } + }); + externalFilesExplorer.finish(); - + GridDataFactory.fillDefaults().grab(true, true).applyTo( externalFilesExplorer); @@ -96,34 +113,26 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid importButton.setText("Import"); importButton.addSelectionListener(new SelectionListenerImpl(context) { + private Pair importedFiles; + + @Override + public void beforeApply() { + Shell shell = importButton.getWidget().getShell(); + importedFiles = ImportExternalFunctionFilesHandler.importFiles(shell, "Import files", ImportExternalFunctionFilesHandler.C_EXTENSIONS); + } + @Override - public void apply(WriteGraph graph, final Resource input) - throws DatabaseException { - - importButton.getWidget().getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - Shell shell = importButton.getWidget().getShell(); - - final Pair importedFiles = ImportExternalFunctionFilesHandler.importFiles(shell, "Import files", ImportExternalFunctionFilesHandler.C_EXTENSIONS); - - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - ImportExternalFunctionFilesHandler.addFilesToFunction(graph, input, importedFiles); - } - }); - } - }); - - + public void apply(WriteGraph graph, final Resource input) throws DatabaseException { + graph.markUndoPoint(); + ImportExternalFunctionFilesHandler.addFilesToFunction(graph, input, importedFiles); + Layer0Utils.addCommentMetadata(graph, "Imported External File(s) " + Arrays.toString(importedFiles.second) + " to " + NameUtils.getSafeName(graph, input)); + updateButtons(externalFilesExplorer); } }); exportButton = new Button(buttonRow, support, SWT.NONE); exportButton.setText("Export"); + exportButton.getControl().setEnabled(false); exportButton.addSelectionListener(new SelectionListenerImpl(context) { @Override @@ -141,39 +150,46 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid ExportExternalFunctionFilesHandler.exportFiles(shell, resources); } }); - - } }); removeButton = new Button(buttonRow, support, SWT.NONE); removeButton.setText("Remove"); + removeButton.getControl().setEnabled(false); removeButton.addSelectionListener(new SelectionListenerImpl(context) { + private int delete; + private List resourceList; + + @Override + public void beforeApply() { + Shell shell = removeButton.getWidget().getShell(); + + resourceList = getSelectedResources(externalFilesExplorer); + Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]); + if(resources.length > 0) { + MessageDialog dialog = new MessageDialog(shell, resources.length > 1 ? "Remove selected items" : "Remove selected item" , null, "Are you sure?", 0, + new String[] { "OK", "Cancel" }, 0); + dialog.create(); + delete = dialog.open(); + } + } + @Override - public void apply(WriteGraph graph, final Resource input) - throws DatabaseException { - - removeButton.getWidget().getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - Shell shell = removeButton.getWidget().getShell(); - - List resourceList = getSelectedResources(externalFilesExplorer); - Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]); - if(resources.length > 0) { - MessageDialog dialog = new MessageDialog(shell, resources.length > 1 ? "Remove selected items" : "Remove selected item" , null, "Are you sure?", 0, - new String[] { "OK", "Cancel" }, 0); - dialog.create(); - if (dialog.open() == 0) { - RemoveNodeHandler.deleteItem(resources); - } - } - } - }); - - + public void apply(WriteGraph graph, final Resource input) throws DatabaseException { + if (delete == 0) { + Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]); + StringBuilder sb = new StringBuilder(); + sb.append("Removed External File(s) "); + for (Resource resource : resources) { + RemoverUtil.remove(graph, resource); + sb.append(NameUtils.getSafeName(graph, resource) + " "); + } + sb.append("from " + NameUtils.getSafeName(graph, input)); + Layer0Utils.addCommentMetadata(graph, sb.toString()); + + updateButtons(externalFilesExplorer); + } } }); } @@ -181,6 +197,7 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid @Override public void setInput(ISessionContext context, Object input) { externalFilesExplorer.setInput(context, input); + updateButtons(externalFilesExplorer); } /** @@ -190,7 +207,6 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid */ private List getSelectedResources(GraphExplorerComposite explorer) { List result = new ArrayList(); - ISelection selection = ((ISelectionProvider) explorer .getAdapter(ISelectionProvider.class)).getSelection(); if (selection == null) @@ -204,5 +220,30 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid } return result; } - + + protected void updateButtons(final GraphExplorerComposite explorer) { + if (SWTThread.getThreadAccess().currentThreadAccess()) { + runnable.run(); + } else { + SWTThread.getThreadAccess().asyncExec(runnable); + } + } + + Runnable runnable = new Runnable() { + + @Override + public void run() { + ISelection selection = ((ISelectionProvider) externalFilesExplorer.getAdapter(ISelectionProvider.class)).getSelection(); + + IStructuredSelection iss = (IStructuredSelection) selection; + @SuppressWarnings("unchecked") + List selections = iss.toList(); + + boolean enabled = false; + if (!selections.isEmpty()) + enabled = true; + removeButton.getControl().setEnabled(enabled); + exportButton.getControl().setEnabled(enabled); + } + }; } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FlowTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FlowTab.java index 885d4ab9..1eee34ca 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FlowTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FlowTab.java @@ -33,6 +33,10 @@ import org.simantics.sysdyn.ui.elements.connections.FlowConnectionStyle; public class FlowTab extends LabelPropertyTabContributor { + public FlowTab(Object id) { + super(id); + } + Scale lineThicknessScale; @Override diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionLibraryTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionLibraryTab.java index 9704d074..567d57bb 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionLibraryTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionLibraryTab.java @@ -27,7 +27,11 @@ import org.simantics.sysdyn.ui.properties.widgets.factories.FunctionLibraryNameI public class FunctionLibraryTab extends LabelPropertyTabContributor { - @Override + public FunctionLibraryTab(Object id) { + super(id); + } + + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { Composite composite = new Composite(body, SWT.NONE); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java index c20ede21..c4564eaf 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java @@ -22,17 +22,26 @@ import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; import org.simantics.browsing.ui.swt.widgets.TrackedText; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; import org.simantics.jfreechart.chart.properties.AdjustableTab; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.ui.properties.widgets.FunctionLabelFactory; import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField; import org.simantics.sysdyn.ui.properties.widgets.factories.FunctionNameInputValidator; import org.simantics.sysdyn.ui.properties.widgets.functions.FunctionCodeWidget; +import org.simantics.sysdyn.utils.SelectionUtils; public class FunctionTab extends AdjustableTab { - ExpressionField modelicaCode; + public FunctionTab(Object id) { + super(id); + } + + ExpressionField modelicaCode; private TrackedText nameText; private Group modelicaGroup; private Label startLabel; @@ -81,6 +90,23 @@ public class FunctionTab extends AdjustableTab { information = new TrackedText(documentationGroup, support, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP); information.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasDescription)); information.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasDescription)); + + if (id instanceof Resource) { + final Resource r = (Resource) id; + try { + boolean editable = context.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + return SelectionUtils.canEdit(graph, r); + } + }); + information.setEditable(editable); + nameText.setEditable(editable); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } } @Override diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/GameExperimentTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/GameExperimentTab.java index 8e26cc3f..ea4941fe 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/GameExperimentTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/GameExperimentTab.java @@ -29,7 +29,11 @@ import org.simantics.utils.ui.validators.DoubleValidator; */ public class GameExperimentTab extends LabelPropertyTabContributor { - @Override + public GameExperimentTab(Object id) { + super(id); + } + + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/HistoryDataTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/HistoryDataTab.java index ceed5ad2..2b4883ea 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/HistoryDataTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/HistoryDataTab.java @@ -63,6 +63,10 @@ import org.simantics.utils.ui.ISelectionUtils; */ public class HistoryDataTab extends LabelPropertyTabContributor { + public HistoryDataTab(Object id) { + super(id); + } + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java index fd5480ee..5da056d0 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java @@ -41,8 +41,8 @@ import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget; import org.simantics.sysdyn.ui.properties.widgets.UnitComboWidget; import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; -import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier; import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameInputValidator; +import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.ui.validators.DoubleValidator; @@ -55,6 +55,10 @@ import org.simantics.utils.ui.validators.DoubleValidator; public class InputVariableTab extends LabelPropertyTabContributor { + public InputVariableTab(Object id) { + super(id); + } + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { Composite composite = new Composite(body, SWT.NONE); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java index 25de7c92..ec059e69 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java @@ -28,7 +28,11 @@ import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactor import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; public class LookupTableTab extends LabelPropertyTabContributor { - + + public LookupTableTab(Object id) { + super(id); + } + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java index ee43cbb4..ffec528d 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java @@ -56,7 +56,11 @@ import org.simantics.utils.datastructures.Triple; */ public class LoopTab extends AdjustableTab { - private Label loopItemsLabel; + public LoopTab(Object id) { + super(id); + } + + private Label loopItemsLabel; private TrackedCombo loopItemsDropdown; Button auto, balancing, reinforcing, other, inside, outside; TrackedText loopComment, polarityLocationText; @@ -64,8 +68,8 @@ public class LoopTab extends AdjustableTab { Group commentGroup, rotationGroup; protected Resource resource; public static final String AUTO = "$$AUTO$$"; - - @Override + + @Override protected void createAndAddControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { composite = new Composite(body, SWT.NONE); @@ -402,5 +406,4 @@ public class LoopTab extends AdjustableTab { return true; } } - } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java index 320fb907..0455d0e3 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java @@ -36,6 +36,10 @@ import org.simantics.sysdyn.ui.properties.widgets.modules.RowProvider; public class ModuleInputTab extends LabelPropertyTabContributor { + public ModuleInputTab(Object id) { + super(id); + } + public static final String FIRSTCOLUMN = "Input in Module"; public static final String SECONDCOLUMN = "Refers to output"; diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java index 9691f7e7..d35bc406 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java @@ -36,6 +36,10 @@ import org.simantics.sysdyn.ui.properties.widgets.modules.RowProvider; public class ModuleOutputTab extends LabelPropertyTabContributor { + public ModuleOutputTab(Object id) { + super(id); + } + public static final String FIRSTCOLUMN = "Output in module"; public static final String SECONDCOLUMN = "Referes to input"; diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleParameterTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleParameterTab.java index 5e3f1246..e80cf205 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleParameterTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleParameterTab.java @@ -30,6 +30,10 @@ import org.simantics.utils.datastructures.ArrayMap; public class ModuleParameterTab extends LabelPropertyTabContributor { + public ModuleParameterTab(Object id) { + super(id); + } + GraphExplorerComposite explorer; @Override diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTab.java index 64a558bf..0a6ed536 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTab.java @@ -37,7 +37,12 @@ import org.simantics.utils.datastructures.ArrayMap; public class ModuleTab extends LabelPropertyTabContributor implements Widget { - GraphExplorerComposite enumerationRedeclarationExplorer; + public ModuleTab(Object id) { + super(id); + } + + + GraphExplorerComposite enumerationRedeclarationExplorer; @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTypeTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTypeTab.java index 918dafd2..69976cc3 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTypeTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTypeTab.java @@ -27,6 +27,10 @@ import org.simantics.sysdyn.ui.properties.widgets.factories.ModuleTypeNameInputV public class ModuleTypeTab extends LabelPropertyTabContributor { + public ModuleTypeTab(Object id) { + super(id); + } + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { Composite composite = new Composite(body, SWT.NONE); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java index a1038bc5..0c595db9 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java @@ -43,6 +43,10 @@ import org.simantics.utils.ui.color.ColorValue; public class PlaybackExperimentTab extends LabelPropertyTabContributor { + public PlaybackExperimentTab(Object id) { + super(id); + } + private static int gradientWidth = 250; private static int gradientHeight = 20; diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java index 55c4ce95..369a8da4 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java @@ -19,6 +19,10 @@ import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor; public class ReferenceDependencyTab extends LabelPropertyTabContributor { + public ReferenceDependencyTab(Object id) { + super(id); + } + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 49407d6b..ab129cfb 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -44,6 +44,7 @@ import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; import org.simantics.sysdyn.ui.trend.SensitivityChartAxisAndVariablesTab; +import org.simantics.sysdyn.utils.SelectionUtils; import org.simantics.ui.selection.AnyVariable; import org.simantics.ui.selection.WorkbenchSelectionElement; import org.simantics.utils.ui.AdaptionUtils; @@ -114,14 +115,14 @@ public class ResourceSelectionProcessor implements SelectionProcessor equations = null; if (expression != null && data.get("initialEquation") == null) { try { - equations = SimanticsUI.getSession().syncRequest(new Read>() { + equations = Simantics.getSession().syncRequest(new Read>() { @Override public Pair perform(ReadGraph graph) throws DatabaseException { @@ -176,7 +184,7 @@ public class StockExpression implements IExpression { if (equations.first == null) { try { - SimanticsUI.getSession().syncRequest(new WriteRequest() { + Simantics.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { @@ -197,7 +205,7 @@ public class StockExpression implements IExpression { } else { try { final String integral = equations.first; - SimanticsUI.getSession().syncRequest(new ReadRequest() { + Simantics.getSession().syncRequest(new ReadRequest() { @Override public void run(ReadGraph graph) throws DatabaseException { @@ -242,7 +250,7 @@ public class StockExpression implements IExpression { if(!currentInitial.equals(data.get("initialEquation")) || currentIntegral == null || !currentIntegral.equals(data.get("integral"))) { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + Simantics.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph g) @@ -275,10 +283,11 @@ public class StockExpression implements IExpression { } g.claimLiteral(expression, sr.StockExpression_integralEquation, currentIntegral); + updateData(data); + g.markUndoPoint(); - CommentMetadata cm = g.getMetadata(CommentMetadata.class); - g.addMetadata(cm.add("Save")); - + + Layer0Utils.addCommentMetadata(g, "Saved Stock Expression " + currentIntegral + " " + expression.toString() + " with Initial Value " + currentInitial); } }); @@ -336,7 +345,7 @@ public class StockExpression implements IExpression { if(expression == null) return integral; try { - integral = SimanticsUI.getSession().syncRequest(new Read() { + integral = Simantics.getSession().syncRequest(new Read() { @Override public String perform(ReadGraph graph) throws DatabaseException { @@ -376,4 +385,9 @@ public class StockExpression implements IExpression { this.integralExpression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); } + @Override + public IUndoManager getUndoManager() { + return undoManager; + } + } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java index 66132ab9..5051f5c1 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java @@ -28,6 +28,7 @@ import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IUndoManager; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.custom.VerifyKeyListener; @@ -459,4 +460,10 @@ public class WithLookupExpression implements IExpression { smallPanel.getChart().getXYPlot().setDataset(dataset); } + @Override + public IUndoManager getUndoManager() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java index a029acd3..27b49076 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java @@ -52,10 +52,9 @@ abstract public class ComboStringPropertyModifier implements TextModifyListen @SuppressWarnings("unchecked") @Override public void perform(WriteGraph graph) throws DatabaseException { - + graph.markUndoPoint(); T single = (T) ISelectionUtils.filterSingleSelection((ISelection)input, clazz); applyText(graph, single, textValue); - } }); diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java index 696f4815..18294955 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java @@ -34,6 +34,7 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.IsParent; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; @@ -152,6 +153,16 @@ public class FunctionCodeWidget implements Widget { }); if(code != null) { modelicaCode.setExpression(code); + + boolean editable = context.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + boolean asd = new IsParent(SysdynResource.getInstance(graph).Built$in_Functions, function).perform(graph); + return !asd; + } + }); + modelicaCode.getSourceViewer().setEditable(editable); validate(); } } catch (DatabaseException e) { @@ -206,6 +217,10 @@ public class FunctionCodeWidget implements Widget { } private void save() { + + if (!modelicaCode.getSourceViewer().isEditable()) + return; + final String code = modelicaCode.getExpression(); // Update input and output lists. diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityChartAxisAndVariablesTab.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityChartAxisAndVariablesTab.java index ab53b0f8..c414bf94 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityChartAxisAndVariablesTab.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityChartAxisAndVariablesTab.java @@ -48,7 +48,8 @@ public class SensitivityChartAxisAndVariablesTab extends AdjustableTab { private ScrolledComposite propertyContainer; private WidgetSupportImpl additionalSupport; - public SensitivityChartAxisAndVariablesTab() { + public SensitivityChartAxisAndVariablesTab(Object id) { + super(id); additionalSupport = new WidgetSupportImpl(); } diff --git a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivitySeriesPropertyComposite.java b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivitySeriesPropertyComposite.java index 4be6de7f..b6c5aed9 100644 --- a/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivitySeriesPropertyComposite.java +++ b/1.8/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivitySeriesPropertyComposite.java @@ -23,7 +23,9 @@ import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; import org.simantics.jfreechart.chart.properties.xyline.SeriesPropertyComposite; import org.simantics.layer0.Layer0; @@ -81,9 +83,10 @@ public class SensitivitySeriesPropertyComposite extends SeriesPropertyComposite Boolean result = graph.getPossibleRelatedValue(dataset, SR.Charts_SensitivityDataset_median, Bindings.BOOLEAN); if(result == null) result = false; - graph.claimLiteral(dataset, SR.Charts_SensitivityDataset_median, Boolean.FALSE.equals(result)); + boolean newValue = Boolean.FALSE.equals(result); + graph.claimLiteral(dataset, SR.Charts_SensitivityDataset_median, newValue); + Layer0Utils.addCommentMetadata(graph, "Display Median for " + NameUtils.getSafeName(graph, series) + " to " + newValue); } - }); Composite c = new Composite(this, SWT.NONE); diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SelectionUtils.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SelectionUtils.java new file mode 100644 index 00000000..bb9272c0 --- /dev/null +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SelectionUtils.java @@ -0,0 +1,24 @@ +package org.simantics.sysdyn.utils; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; + +/** + * @author Jani Simomaa + * + */ +public class SelectionUtils { + + /** + * Checks whether resource can be edited + * + * @param graph + * @param resource + * @return + * @throws DatabaseException + */ + public static boolean canEdit(ReadGraph graph, Resource resource) throws DatabaseException { + return !graph.isImmutable(resource); + } +} -- 2.47.1