Resource domainAxis = GraphUtils.create2(g, jfree.NumberAxis,\r
l0.HasName, "NumberAxis" + UUID.randomUUID().toString());\r
Resource rangeAxis = GraphUtils.create2(g, jfree.NumberAxis,\r
- l0.HasName, "NumberAxis" + UUID.randomUUID().toString());\r
+ l0.HasName, "NumberAxis" + UUID.randomUUID().toString(),\r
+ l0.HasLabel, "Y-axis");\r
\r
Resource renderer = GraphUtils.create2(g, jfree.XYLineRenderer);\r
\r
// Create range axis\r
axis = GraphUtils.create2(graph, jfree.NumberAxis,\r
l0.HasName, "NumberAxis" + UUID.randomUUID().toString(),\r
- l0.HasLabel, NameUtils.findFreshLabel(graph, "Range", plot),\r
+ l0.HasLabel, NameUtils.findFreshLabel(graph, "Y-axis", plot),\r
jfree.Plot_rangeAxis_Inverse, plot,\r
l0.PartOf, plot);\r
\r
// Create series\r
Resource series = GraphUtils.create2(graph, jfree.Series,\r
l0.HasName, "Series" + UUID.randomUUID().toString(),\r
- jfree.variableRVI, rvi == null ? " Set variable" : rvi,\r
+ jfree.variableRVI, rvi == null ? " <Write variable name>" : rvi,\r
l0.PartOf, dataset);\r
\r
// Add series to the dataset's series list\r
--- /dev/null
+package org.simantics.sysdyn.ui.trend.chart.properties;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
+\r
+/**\r
+ * Request for getting all variables of a model in a String array. Includes also \r
+ * variables inside modules.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class AllVariablesOfModel implements Read<String[]>{\r
+ \r
+ private Resource model;\r
+ \r
+ public AllVariablesOfModel(Resource model) {\r
+ this.model = model;\r
+ }\r
+\r
+ @Override\r
+ public String[] perform(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SimulationResource simu = SimulationResource.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ // Find the model of this resource\r
+ Resource model = this.model;\r
+ while(model != null && !graph.isInstanceOf(model, sr.SysdynModel))\r
+ model = graph.getPossibleObject(model, l0.PartOf);\r
+ \r
+ if(model == null)\r
+ return new String[0];\r
+ \r
+ // Find the models configuration\r
+ Resource conf = graph.getSingleObject(model, simu.HasConfiguration);\r
+ List<String> items = new ArrayList<String>();\r
+ \r
+ // Recursively read all configurations and add items\r
+ ReadConfiguration(graph, conf, "", items);\r
+ \r
+ // Add time to the variable list\r
+ items.add("time");\r
+ \r
+ // Finally sort the results\r
+ Collections.sort(items, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+ return items.toArray(new String[items.size()]);\r
+ }\r
+ \r
+ /**\r
+ * Read components in a configuration and recursively all module configurations\r
+ * \r
+ * @param graph ReadGraph\r
+ * @param configuration Resource to be read\r
+ * @param path Current path from base realization\r
+ * @param items Found variables\r
+ * @throws DatabaseException\r
+ */\r
+ private void ReadConfiguration(ReadGraph graph, Resource configuration, String path, Collection<String> items) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+\r
+ String name;\r
+ for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.IndependentVariable))) {\r
+ name = path + NameUtils.getSafeName(graph, resource);\r
+ items.add(name);\r
+ }\r
+ \r
+ for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Input))) {\r
+ name = path + NameUtils.getSafeName(graph, resource);\r
+ items.add(name);\r
+ }\r
+\r
+ for(Resource module : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) {\r
+ Resource instanceOf = graph.getPossibleObject(module, l0.InstanceOf);\r
+ Resource conf = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy);\r
+ if(conf != null) {\r
+ String p = path + NameUtils.getSafeName(graph, module) + ".";\r
+ ReadConfiguration(graph, conf, p, items);\r
+ }\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.trend.chart.properties;\r
+\r
+import org.eclipse.jface.dialogs.IInputValidator;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+/**\r
+ * Variable exists validator for tracked text widgets. \r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class VariableExistsValidator implements IInputValidator, Widget {\r
+\r
+ private String[] names;\r
+ private TrackedText text;\r
+ private boolean allowEmpty;\r
+ \r
+ /**\r
+ * Validate against all variables\r
+ * \r
+ * Do not allow empty input\r
+ * @param support WidgetSupport\r
+ * @param text Text widget\r
+ */\r
+ public VariableExistsValidator(WidgetSupport support, TrackedText text) {\r
+ this(support, text, false);\r
+ }\r
+ \r
+ /**\r
+ * Validate against all variables\r
+ * \r
+ * @param support WidgetSupport\r
+ * @param text Text widget\r
+ * @param allowEmpty Allow empty input text\r
+ */\r
+ public VariableExistsValidator(WidgetSupport support, TrackedText text, boolean allowEmpty) {\r
+ support.register(this);\r
+ names = new String[] {"time"};\r
+ this.text = text;\r
+ this.allowEmpty = allowEmpty;\r
+ }\r
+ \r
+ /**\r
+ * Returns null if there is a variable named newText in the model\r
+ */\r
+ @Override\r
+ public String isValid(String newText) {\r
+ if(newText == null || newText.isEmpty()) {\r
+ if(allowEmpty)\r
+ return null;\r
+ else\r
+ return "Empty name not allowed";\r
+ }\r
+ \r
+ synchronized (names) {\r
+ for(String s : names) {\r
+ if(newText.equals(s))\r
+ return null;\r
+ }\r
+ }\r
+ \r
+ return "Not a valid variable name";\r
+ }\r
+\r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class);\r
+ \r
+ if(resource == null) {\r
+ names = new String[] {"time"};\r
+ return;\r
+ }\r
+ \r
+ Resource model = null;\r
+ try {\r
+ /* Find the model resource. It can be found with PartOf \r
+ relations from series resource in a chart */\r
+ model = context.getSession().syncRequest(new Read<Resource>() {\r
+\r
+ @Override\r
+ public Resource perform(ReadGraph graph) throws DatabaseException {\r
+ Resource r = resource;\r
+ while((r = graph.getPossibleObject(r, Layer0.getInstance(graph).PartOf)) != null) {\r
+ if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).SysdynModel))\r
+ return r;\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ });\r
+ \r
+ if(model != null) {\r
+ // Find all variables and set them as the reference for isValid(String)\r
+ SimanticsUI.getSession().asyncRequest(\r
+ new AllVariablesOfModel(model)\r
+ , new Listener<String[]>() {\r
+\r
+ @Override\r
+ public void execute(String[] result) {\r
+ names = result;\r
+ }\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return text.isDisposed();\r
+ }\r
+\r
+ }); \r
+ }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.trend.chart.properties;\r
\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;\r
import org.eclipse.swt.widgets.Control;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.procedure.Listener;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
-import org.simantics.utils.strings.AlphanumComparator;\r
\r
/**\r
* Provides all variables a model contains\r
return;\r
this.resource = resource;\r
\r
- SimanticsUI.getSession().asyncRequest(new Read<String[]>() {\r
-\r
- @Override\r
- public String[] perform(ReadGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- SimulationResource simu = SimulationResource.getInstance(graph);\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- \r
- // Find the model of this resource\r
- Resource model = resource;\r
- while(model != null && !graph.isInstanceOf(model, sr.SysdynModel))\r
- model = graph.getPossibleObject(model, l0.PartOf);\r
- \r
- if(model == null)\r
- return new String[0];\r
- \r
- // Find the models configuration\r
- Resource conf = graph.getSingleObject(model, simu.HasConfiguration);\r
- List<String> items = new ArrayList<String>();\r
- \r
- // Recursively read all configurations and add items\r
- ReadConfiguration(graph, conf, "", items);\r
- \r
- // Finally sort the results\r
- Collections.sort(items, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
- return items.toArray(new String[items.size()]);\r
- }\r
-\r
- }, new Listener<String[]>() {\r
+ SimanticsUI.getSession().asyncRequest(\r
+ new AllVariablesOfModel(resource)\r
+ , new Listener<String[]>() {\r
\r
@Override\r
public void execute(String[] result) {\r
\r
}\r
\r
- /**\r
- * Read components in a configuration and recursively all module configurations\r
- * \r
- * @param graph ReadGraph\r
- * @param configuration Resource to be read\r
- * @param path Current path from base realization\r
- * @param items Found variables\r
- * @throws DatabaseException\r
- */\r
- private void ReadConfiguration(ReadGraph graph, Resource configuration, String path, Collection<String> items) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
-\r
- String name;\r
- for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.IndependentVariable))) {\r
- name = path + NameUtils.getSafeName(graph, resource);\r
- items.add(name);\r
- }\r
- \r
- for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Input))) {\r
- name = path + NameUtils.getSafeName(graph, resource);\r
- items.add(name);\r
- }\r
-\r
- for(Resource module : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) {\r
- Resource instanceOf = graph.getPossibleObject(module, l0.InstanceOf);\r
- Resource conf = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy);\r
- if(conf != null) {\r
- String p = path + NameUtils.getSafeName(graph, module) + ".";\r
- ReadConfiguration(graph, conf, p, items);\r
- }\r
- }\r
- }\r
-\r
}\r
import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory;\r
import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier;\r
import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.VariableExistsValidator;\r
\r
/**\r
* Composite for modifying properties of a series in a bar chart\r
variable = new TrackedText(this, support, SWT.BORDER);\r
variable.setTextFactory(new RVIFactory());\r
variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
+ variable.setInputValidator(new VariableExistsValidator(support, variable));\r
variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
\r
import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory;\r
import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier;\r
import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.VariableExistsValidator;\r
\r
/**\r
* Composite containing the properties of a series\r
variable = new TrackedText(this, support, SWT.BORDER);\r
variable.setTextFactory(new RVIFactory());\r
variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
+ variable.setInputValidator(new VariableExistsValidator(support, variable));\r
variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
\r
import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier;\r
import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite;\r
import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.VariableExistsValidator;\r
import org.simantics.ui.utils.AdaptionUtils;\r
\r
/**\r
variable.setTextFactory(new RVIFactory());\r
variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
+ variable.setInputValidator(new VariableExistsValidator(support, variable));\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
\r
// Range\r
import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier;\r
import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory;\r
import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.VariableExistsValidator;\r
import org.simantics.ui.utils.AdaptionUtils;\r
\r
/**\r
xvariable.setTextFactory(new RVIFactory());\r
xvariable.addModifyListener(new RVIModifier(xvariable.getWidget(), domainAxisSupport));\r
xvariable.setColorProvider(new JFreeChartPropertyColorProvider(xvariable.getResourceManager()));\r
+ xvariable.setInputValidator(new VariableExistsValidator(support, xvariable, true));\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(xvariable.getWidget());\r
\r
Composite axisHide = new AxisHidePropertyComposite(xgroup, context, domainAxisSupport, SWT.NONE);\r