import org.eclipse.swt.widgets.Label;\r
import org.eclipse.swt.widgets.Table;\r
import org.eclipse.swt.widgets.TableItem;\r
+import org.eclipse.ui.IWorkbenchPartReference;\r
import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.platform.PropertyPageView;\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.TrackedCombo;\r
TrackedCombo expressionTypeCombo, unitCombo;\r
ShortcutTabWidget shortcutTabWidget;\r
ExpressionWidget expressionWidget;\r
+ org.eclipse.ui.IPartListener2 focusLostListener; \r
+ IWorkbenchSite site;\r
\r
@Override\r
public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+ this.site = site;\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
\r
@Override\r
public void modifyText(TrackedModifyEvent e) {\r
- System.out.println(e.getText());\r
expressionWidget.displayExpression(e.getText(), false);\r
expressionWidget.save(); \r
}\r
expressionWidget.validateFields();\r
}\r
});\r
-\r
- expressionWidget.addFocusListener(new FocusListener() {\r
-\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- expressionWidget.save();\r
- }\r
-\r
- @Override\r
- public void focusGained(FocusEvent e) {\r
- expressionWidget.validateFields();\r
+ \r
+ focusLostListener = new org.eclipse.ui.IPartListener2()\r
+ {\r
+ public void partInputChanged(IWorkbenchPartReference partRef) {}\r
+ public void partVisible(IWorkbenchPartReference partRef) {}\r
+ public void partHidden(IWorkbenchPartReference partRef) {}\r
+ public void partOpened(IWorkbenchPartReference partRef) {}\r
+ public void partDeactivated(IWorkbenchPartReference partRef)\r
+ {\r
+ if(partRef.getPart(false) instanceof PropertyPageView) {\r
+ // Save expressions\r
+ if(expressionWidget != null) {\r
+ expressionWidget.save();\r
+ }\r
+ }\r
}\r
- }); \r
+ public void partClosed(IWorkbenchPartReference partRef) {}\r
+ public void partBroughtToTop(IWorkbenchPartReference partRef) {}\r
+ public void partActivated(IWorkbenchPartReference partRef) {}\r
+ };\r
+ site.getPage().addPartListener(focusLostListener);\r
+ }\r
+ \r
+ @Override\r
+ public void dispose() {\r
+ if(focusLostListener != null && site != null)\r
+ site.getPage().removePartListener(focusLostListener);\r
+ super.dispose();\r
}\r
}\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.ConstantExpression;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.DelayExpression;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.EmptyExpression;\r
-import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionValidation;\r
+import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionUtils;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupExpression;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.ParameterExpression;\r
\r
exp.createExpressionFields(parent, data);\r
exp.addModifyListener(modifyListener);\r
- exp.addFocusListener(focusListener);\r
+ if(focusListener != null)\r
+ exp.addFocusListener(focusListener);\r
this.expression = exp;\r
this.parent.layout();\r
validateFields();\r
return null;\r
}\r
});\r
- ExpressionValidation.validateExpressionFields(expression, connectedVariables, configuration);\r
+ ExpressionUtils.validateExpressionFields(expression, connectedVariables, configuration);\r
} catch (DatabaseException e1) {\r
e1.printStackTrace();\r
}\r
@Override\r
public void readData(final Resource variable, Map<String, Object> data) {\r
String equation = null;\r
- if (variable != null && data.get("equation") == null && expressionType != null) {\r
+ if (variable != null && data.get("equation") == null) {\r
try {\r
equation = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
\r
public String perform(ReadGraph graph) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Resource expression = graph.getPossibleObject(variable, sr.HasExpression);\r
- if (expression != null && graph.isInstanceOf(expression, expressionType)) {\r
- return graph.getRelatedValue(expression, sr.HasEquation);\r
- } else {\r
- return "";\r
+ if (expression != null) {\r
+ String equation = graph.getPossibleRelatedValue(expression, sr.HasEquation);\r
+ if(equation != null)\r
+ return equation;\r
}\r
+ \r
+ return "";\r
+ \r
}\r
\r
});\r
throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(g);\r
Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
+ if(ExpressionUtils.isParameter(currentText)) {\r
+ System.out.println(expressionType);\r
+ if(!expressionType.equals(sr.ConstantExpression))\r
+ expressionType = sr.ParameterExpression;\r
+ } else {\r
+ expressionType = sr.NormalExpression;\r
+ }\r
if (oldEquation != null \r
&& expression != null \r
&& g.isInstanceOf(expression, expressionType) \r
import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression;\r
import org.simantics.ui.SimanticsUI;\r
\r
-public class ExpressionValidation {\r
+public class ExpressionUtils {\r
+ \r
+ /**\r
+ * Determines if the given expression is a parameter expression. Parameters are numbers.\r
+ * If the expression contains anything other than numbers, it is not a parameter.\r
+ * \r
+ * @param expression The expression to be checked\r
+ * @return is the expression a parameter\r
+ */\r
+ static public boolean isParameter(String expression) {\r
+ try {\r
+ Double.parseDouble(expression);\r
+ return true;\r
+ } catch (NumberFormatException e) {\r
+ return false;\r
+ }\r
+ }\r
\r
static public void validateExpressionFields(IExpression expression, TableItem[] connectedVariables, Resource configuration) {\r
ExpressionParser parser = new ExpressionParser(new StringReader(""));\r
@Override\r
public void focusLost(FocusEvent e) {\r
lastSelectedText = lookup;\r
+ save(variable, data);\r
}\r
});\r
\r