package org.simantics.sysdyn.ui.properties;\r
\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.FocusListener;\r
+import org.eclipse.swt.events.VerifyEvent;\r
+import org.eclipse.swt.events.VerifyListener;\r
import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Text;\r
import org.eclipse.ui.IWorkbenchSite;\r
import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.Builtins;\r
import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.TextWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
\r
public class ConfigurationTab extends PropertyTabContributorImpl {\r
\r
+ TextWidget name, startTime, stopTime;\r
+ \r
+ \r
@Override\r
public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
- // TODO Auto-generated method stub\r
+ Composite composite = new Composite(body, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite);\r
+\r
+ Label label = new Label(composite, SWT.NONE);\r
+ label.setText("Name");\r
+ \r
+ name = new TextWidget(composite, support, SWT.BORDER);\r
+ name.setTextFactory(new StringPropertyFactory(context, Builtins.URIs.HasName));\r
+ name.addFocusListener(new SaveListener());\r
+ name.addVerifyListener(new VerifyListener() {\r
+\r
+ @Override\r
+ public void verifyText(VerifyEvent e) {\r
+ e.doit = false;\r
+ String s = e.text; \r
+ if(!s.contains(" ")) {\r
+ e.doit = true;\r
+ }\r
+ }\r
+ });\r
+ GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(name.getTextWidget());\r
+\r
+ label = new Label(composite, SWT.NONE);\r
+ label.setText("Start time");\r
+\r
+ startTime = new TextWidget(composite, support, SWT.BORDER | SWT.RIGHT);\r
+ startTime.setTextFactory(new DoublePropertyFactory(context, SysdynResource.URIs.HasStartTime));\r
+ startTime.addVerifyListener(new DoubleVerify());\r
+ startTime.addFocusListener(new SaveListener());\r
+ GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(startTime.getTextWidget());\r
+\r
+ label = new Label(composite, SWT.NONE);\r
+ label.setText("Stop time");\r
+\r
+ stopTime = new TextWidget(composite, support, SWT.BORDER | SWT.RIGHT);\r
+ stopTime.setTextFactory(new DoublePropertyFactory(context, SysdynResource.URIs.HasStopTime));\r
+ stopTime.addVerifyListener(new DoubleVerify());\r
+ stopTime.addFocusListener(new SaveListener());\r
+ GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(stopTime.getTextWidget());\r
\r
}\r
\r
+ private class DoubleVerify implements VerifyListener {\r
\r
+ @Override\r
+ public void verifyText(VerifyEvent e) {\r
+ e.doit = true;\r
+ for(int i = 0; i < e.text.length(); i++){\r
+ if(!Character.isDigit(e.text.charAt(i))){\r
+ if(e.text.charAt(i) != '.') {\r
+ e.doit = false;\r
+ break; \r
+ } else if(e.text.indexOf('.') != e.text.lastIndexOf('.')) {\r
+ e.doit = false;\r
+ break; \r
+ } else if(((Text)e.widget).getText().substring(0, e.start).contains(".") ||\r
+ ((Text)e.widget).getText().substring(e.end, ((Text)e.widget).getText().length()).contains(".")) {\r
+ e.doit = false;\r
+ break; \r
+ }\r
+ } \r
+ }\r
+ }\r
+ }\r
+ \r
+ private class SaveListener implements FocusListener {\r
+\r
+ @Override\r
+ public void focusGained(FocusEvent e) {\r
+ }\r
+\r
+ @Override\r
+ public void focusLost(FocusEvent e) {\r
+ save();\r
+ }\r
+ \r
+ }\r
+ \r
+ private void save() {\r
+ this.name.save();\r
+ this.startTime.save();\r
+ this.stopTime.save();\r
+ }\r
+ \r
+ \r
}\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypeWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.ExpressionWidget;\r
-import org.simantics.sysdyn.ui.properties.widgets.NameWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.VariableNameWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.ShortcutTabWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.UnitWidget;\r
\r
public class EquationTab extends PropertyTabContributorImpl {\r
\r
- NameWidget nameWidget;\r
+ VariableNameWidget nameWidget;\r
ExpressionTypeWidget expressionTypeWidget;\r
UnitWidget unitWidget;\r
ShortcutTabWidget shortcutTabWidget;\r
Composite composite = new Composite(body, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(composite);\r
- nameWidget = new NameWidget(composite, support, SWT.BORDER);\r
+ nameWidget = new VariableNameWidget(composite, support, SWT.BORDER);\r
nameWidget.setTextFactory(new StringPropertyFactory(context, Builtins.URIs.HasName));\r
\r
\r
package org.simantics.sysdyn.ui.properties;\r
\r
-import java.util.ArrayList;\r
import java.util.Collection;\r
import java.util.Collections;\r
\r
if(r != null)\r
try {\r
SysdynResource sr = SysdynResource.getInstance(backend);\r
- ArrayList<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
+// ArrayList<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
if (backend.isInstanceOf(r, sr.IndependentVariable))\r
return Collections.singleton(\r
new ComparableTabContributor(\r
if (backend.isInstanceOf(r, sr.Experiment))\r
return Collections.singleton(\r
new ComparableTabContributor(\r
- new ConfigurationTab(),\r
+ new ExperimentTab(),\r
0,\r
r,\r
"Experiment Properties"));\r
if (backend.isInstanceOf(r, sr.SysdynModel))\r
return Collections.singleton(\r
new ComparableTabContributor(\r
- new ConfigurationTab(),\r
+ new ModelTab(),\r
0,\r
r,\r
"Model Properties"));\r
if (backend.isInstanceOf(r, sr.Result))\r
return Collections.singleton(\r
new ComparableTabContributor(\r
- new ConfigurationTab(),\r
+ new ResultTab(),\r
0,\r
r,\r
"Result Properties"));\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties;\r
+\r
+public class VariableCommentTab {\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.FocusListener;\r
+import org.eclipse.swt.events.KeyEvent;\r
+import org.eclipse.swt.events.KeyListener;\r
+import org.eclipse.swt.events.VerifyListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory;\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.Resource;\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.procedure.Listener;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Triple;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+public class TextWidget implements Widget {\r
+\r
+ private Text textWidget;\r
+ private String originalText = "";\r
+ private ReadFactory<?, String> readFactory;\r
+ private Resource resource;\r
+\r
+ public TextWidget(Composite parent, WidgetSupport support, int style) {\r
+ support.register(this);\r
+ textWidget = new Text(parent, style);\r
+ textWidget.addKeyListener(new KeyListener() {\r
+\r
+ @Override\r
+ public void keyReleased(KeyEvent e) {\r
+ }\r
+\r
+ @Override\r
+ public void keyPressed(KeyEvent e) {\r
+ if(e.keyCode == SWT.ESC) {\r
+ Text text = (Text)e.widget;\r
+ text.setText(originalText);\r
+ text.setSelection(text.getCharCount());\r
+ }\r
+ }\r
+ });\r
+ }\r
+\r
+ public void setTextFactory(ReadFactory<?, String> textFactory) {\r
+ this.readFactory = textFactory;\r
+ }\r
+\r
+ @Override\r
+ public void setInput(Object input) {\r
+ if(input instanceof ISelection)\r
+ resource = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+\r
+ if(readFactory != null) {\r
+ readFactory.listen(input, new Listener<String>() {\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public void execute(final String text) {\r
+\r
+ if(text == null) return;\r
+\r
+ textWidget.getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+\r
+ if(isDisposed()) return;\r
+ textWidget.setText(text);\r
+ originalText = text;\r
+\r
+ }\r
+\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return textWidget.isDisposed();\r
+ }\r
+\r
+ });\r
+ }\r
+\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ public void save() {\r
+ if(originalText.equals(textWidget.getText())) return;\r
+ \r
+ final String text = textWidget.getText();\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ \r
+ Triple triple = null;\r
+ Object object = null;\r
+ \r
+ if(readFactory instanceof DoublePropertyFactory) {\r
+ DoublePropertyFactory factory = (DoublePropertyFactory)readFactory;\r
+ triple = (Triple) factory.getIdentity(null);\r
+ object = Double.parseDouble(text);\r
+ } else if (readFactory instanceof StringPropertyFactory) {\r
+ StringPropertyFactory factory = (StringPropertyFactory)readFactory;\r
+ triple = (Triple) factory.getIdentity(null);\r
+ object = text;\r
+ }\r
+ \r
+ if(triple == null || object == null) return;\r
+ graph.claimValue(resource, graph.getResource((String)triple.second), object);\r
+ }\r
+ });\r
+ \r
+ }\r
+\r
+ public void addKeyListener(KeyListener listener) {\r
+ this.textWidget.addKeyListener(listener);\r
+ }\r
+\r
+ public void addVerifyListener(VerifyListener listener) {\r
+ this.textWidget.addVerifyListener(listener);\r
+ }\r
+ \r
+ public void addFocusListener(FocusListener listener) {\r
+ this.textWidget.addFocusListener(listener);\r
+ }\r
+\r
+ public String getText() {\r
+ return textWidget.getText();\r
+ }\r
+\r
+ public Text getTextWidget() {\r
+ return textWidget;\r
+ }\r
+}\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.ui.ISelectionUtils;\r
\r
-public class NameWidget implements Widget {\r
+public class VariableNameWidget implements Widget {\r
\r
private org.eclipse.swt.widgets.Text nameText;\r
private String originalName = "";\r
private Resource variable;\r
private Resource configuration;\r
\r
- public NameWidget(Composite parent, WidgetSupport support, int style) {\r
+ public VariableNameWidget(Composite parent, WidgetSupport support, int style) {\r
support.register(this);\r
nameText = new org.eclipse.swt.widgets.Text(parent, style);\r
\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties.widgets.factories;\r
+\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\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.utils.datastructures.Triple;\r
+\r
+public class DoublePropertyFactory extends ReadFactoryImpl<Resource, String> {\r
+\r
+ final private String propertyURI;\r
+ \r
+ public DoublePropertyFactory(ISessionContext context, String propertyURI) {\r
+ super(context);\r
+ this.propertyURI = propertyURI;\r
+ }\r
+\r
+ @Override\r
+ public Object getIdentity(Object inputContents) {\r
+ return new Triple<Resource, String, Object>((Resource)inputContents, propertyURI, getClass());\r
+ }\r
+ \r
+ @Override\r
+ public String perform(ReadGraph graph, Resource issue) throws DatabaseException {\r
+ \r
+ Double value = graph.getPossibleRelatedValue(issue, graph.getResource(propertyURI));\r
+ return value.toString();\r
+ \r
+ }\r
+ \r
+}\r