s.print("buildModel("+modelName+\r
",startTime="+inits.get("start value")+\r
",stopTime="+inits.get("stop value")+\r
-// ",numberOfIntervals="+inits.get("step value")+\r
- ",method=\"euler\""\r
+ ",method="+inits.get("method")\r
);\r
if(inits.containsKey("tolerance")) {\r
s.print(",tolerance="+inits.get("tolerance"));\r
package org.simantics.sysdyn.ui.properties;\r
\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
import org.eclipse.jface.dialogs.IInputValidator;\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.ComboStringPropertyModifier;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
\r
outputInterval.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasOutputInterval));\r
outputInterval.setInputValidator(new DoubleValidator());\r
GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(outputInterval.getWidget());\r
+ \r
+ label = new Label(composite, SWT.NONE);\r
+ label.setText("Method");\r
+ \r
+ TrackedCombo method = new TrackedCombo(composite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);\r
+ method.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
+\r
+ @Override\r
+ public Map<String, Object> perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+\r
+ Map<String, Object> map = new HashMap<String, Object>();\r
+ map.put("euler", "euler");\r
+ map.put("rungekutta", "rungekutta");\r
+ map.put("dassl", "dassl");\r
+ map.put("dassl2", "dassl2");\r
+ map.put("inline-euler", "inline-euler");\r
+ map.put("inline-rungekutta", "inline-rungekutta");\r
+ return map;\r
+ }\r
+ });\r
+ \r
+ method.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+ return graph.getRelatedValue(input, SysdynResource.getInstance(graph).HasSolver);\r
+ }\r
+ });\r
+ \r
+ method.addModifyListener(new ComboStringPropertyModifier<Resource>() {\r
+\r
+ @Override\r
+ public void applyText(WriteGraph graph, Resource input, String text)\r
+ throws DatabaseException {\r
+ graph.claimLiteral(input, SysdynResource.getInstance(graph).HasSolver, text);\r
+ }\r
+ });\r
+ \r
+ label = new Label(composite, SWT.NONE);\r
+ label.setText("Tolerance");\r
+\r
+ TrackedText tolerance = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT);\r
+ tolerance.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasTolerance));\r
+ tolerance.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasTolerance));\r
+ tolerance.setInputValidator(new DoubleValidator());\r
+ GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(tolerance.getWidget());\r
+\r
+ \r
}\r
\r
private class DoubleValidator implements IInputValidator {\r
import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
import org.simantics.db.exception.ServiceException;\r
import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
SysdynResource sr = SysdynResource.getInstance(backend);\r
DiagramResource dr = DiagramResource.getInstance(backend);\r
ModelingResources mr = ModelingResources.getInstance(backend);\r
- Layer0 l0 = Layer0.getInstance(backend);\r
Collection<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
if (backend.isInstanceOf(r, dr.Element)) {\r
Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
r,\r
"Input"));\r
}\r
- Resource represents = backend.getPossibleObject(r, l0.Represents);\r
- if ((represents != null && backend.isInstanceOf(represents, sr.Configuration)) || (backend.isInstanceOf(r, sr.SysdynModel))) {\r
- Resource model;\r
- if (represents != null)\r
- model = backend.getPossibleObject(represents, SimulationResource.getInstance(backend).IsConfigurationOf);\r
- else\r
- model = r;\r
- if (model != null)\r
+ if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) {\r
+ if(!backend.isInstanceOf(r, sr.SysdynModel))\r
+ r = backend.getPossibleObject(r, SimulationResource.getInstance(backend).IsConfigurationOf);\r
+ if (r != null)\r
return Collections.singleton(\r
new ComparableTabContributor(\r
new ConfigurationTab(),\r
0,\r
- model,\r
+ r,\r
"Model Properties"));\r
}\r
if (backend.isInstanceOf(r, sr.Module)){\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties.widgets.factories;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.widgets.Combo;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.utils.ReflectionUtils;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+abstract public class ComboStringPropertyModifier<T> implements TextModifyListener, Widget {\r
+\r
+ private ISessionContext context;\r
+ private Object lastInput = null;\r
+ \r
+ final private Class<?> clazz;\r
+ \r
+ public ComboStringPropertyModifier() {\r
+ clazz = ReflectionUtils.getSingleParameterType(getClass());\r
+ }\r
+ \r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ this.context = context;\r
+ lastInput = input;\r
+ }\r
+\r
+ @Override\r
+ public void modifyText(TrackedModifyEvent e) {\r
+ Combo text = (Combo)e.getWidget();\r
+ final String textValue = text.getText();\r
+ final Object input = lastInput;\r
+ \r
+ try {\r
+ context.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+\r
+ T single = (T) ISelectionUtils.filterSingleSelection((ISelection)input, clazz);\r
+ applyText(graph, single, textValue);\r
+ \r
+ }\r
+ \r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ \r
+ }\r
+ \r
+ abstract public void applyText(WriteGraph graph, T input, String text) throws DatabaseException;\r
+\r
+}\r
TableColumn column = new TableColumn (table, SWT.NONE);\r
column.setText (titles [i]);\r
column.addListener(SWT.Selection, sortListener);\r
+ column.setMoveable(true);\r
} \r
\r
table.setSortColumn(table.getColumn(0));\r
} else {\r
inits.put("step value", "" + (stopTime - startTime) / 500);\r
}\r
- if(model.getSolver() != null)\r
- inits.put("solver", model.getSolver());\r
+ String method = "\"" + model.getSolver() + "\"";\r
+ inits.put("method", method);\r
if(model.getTolerance() != null)\r
inits.put("tolerance", model.getTolerance().toString());\r
\r
previousImportantInits.clear();\r
previousImportantInits.put("start value", startTime.toString());\r
previousImportantInits.put("stop value", stopTime.toString());\r
+ previousImportantInits.put("method", method);\r
} catch (ModelicaException e) {\r
monitor.showConsole();\r
canceled = true;\r
MessageConsoleStream out = this.console.newMessageStream();\r
if(message.length() > 1)\r
out.println("[" + time +"] " + message);\r
- if(message.contains("Error:"))\r
+ if(message.contains("Error"))\r
showConsole();\r
}\r
\r