From 0b3812a5c75f703b2f4879149d56d3adaceb5dcb Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 27 Nov 2009 13:24:35 +0000 Subject: [PATCH] Equation editor sketch git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13197 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/equation/EquationView.java | 230 +++++++++++++----- 1 file changed, 171 insertions(+), 59 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java index 04474d57..84e67309 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java @@ -1,5 +1,8 @@ package org.simantics.sysdyn.ui.equation; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; @@ -8,7 +11,14 @@ import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.IWorkbenchPart; @@ -24,20 +34,100 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; public class EquationView extends ViewPart implements ISelectionListener { - + static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL); - + + Text nameText; + + Composite equationComposite; + Label equationLabel; Text text; - Resource auxiliary; + Resource variable; String originalText; - + TabFolder tabFolder; + TabItem variables; + TabItem functions; + Composite unitsAndRange; + Composite variableType; + + @Override public void createPartControl(Composite parent) { getSite().getPage().addPostSelectionListener(this); - text = new Text(parent, SWT.MULTI); + + GridLayoutFactory.fillDefaults().numColumns(4).margins(5, 5).applyTo(parent); + + // Upper part of the view: Name (and renaming) + nameText = new Text(parent, SWT.SINGLE | SWT.BORDER); + nameText.setFont(FONT); + GridDataFactory.fillDefaults().span(2, 1).applyTo(nameText); + + // Center side of the view: (related) variables and possible functions + TabFolder tabFolder = new TabFolder (parent, SWT.NONE); + GridDataFactory.fillDefaults().span(1, 4).applyTo(tabFolder); + variables = new TabItem(tabFolder, SWT.NULL); + variables.setText("Variables"); + Table table = new Table (tabFolder, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); + TableItem item = new TableItem(table, SWT.NONE); + item.setText("auxiliary21"); + item = new TableItem(table, SWT.NONE); + item.setText("stock5"); + item = new TableItem(table, SWT.NONE); + item.setText("valve2"); + variables.setControl(table); + + functions = new TabItem(tabFolder, SWT.NULL); + functions.setText("Functions"); + table = new Table (tabFolder, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); + item = new TableItem(table, SWT.NONE); + item.setText("min"); + item = new TableItem(table, SWT.NONE); + item.setText("max"); + item = new TableItem(table, SWT.NONE); + item.setText("abs"); + functions.setControl(table); + + // Right side of the view: Details, comments + Composite emptyComposite = new Composite(parent, SWT.NONE); + GridDataFactory.fillDefaults().span(1,4).grab(true, true).applyTo(emptyComposite); + + // Below the variable name: Variable type + variableType = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(5).spacing(3, 0).applyTo(variableType); + GridDataFactory.fillDefaults().span(2, 1).applyTo(variableType); + Label label = new Label(variableType, SWT.SINGLE); + label.setText("Type:"); + Combo comboDropDown = new Combo(variableType, SWT.DROP_DOWN | SWT.BORDER); + comboDropDown.add("Auxiliary"); + comboDropDown.add("Lookup"); + comboDropDown.add("Delay"); + comboDropDown = new Combo(variableType, SWT.DROP_DOWN | SWT.BORDER); + comboDropDown.add("Normal"); + comboDropDown.add("With Lookup"); + + label = new Label(variableType, SWT.SINGLE ); + label.setText("Unit:"); + label.setAlignment(SWT.RIGHT); + GridDataFactory.fillDefaults().grab(true, false).align(SWT.END, SWT.CENTER).applyTo(label); + comboDropDown = new Combo(variableType, SWT.DROP_DOWN | SWT.BORDER); + comboDropDown.add("m"); + comboDropDown.add("V"); + comboDropDown.add("euro"); + + // Below variable type: Equation + equationComposite = new Composite(parent, SWT.NONE); + GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(equationComposite); + GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(equationComposite); + equationLabel = new Label(equationComposite, SWT.NONE); + equationLabel.setFont(FONT); + equationLabel.setText("="); + GridDataFactory.fillDefaults().applyTo(equationLabel); + + text = new Text(equationComposite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); text.setFont(FONT); + GridDataFactory.fillDefaults().grab(true, true).applyTo(text); text.addFocusListener(new FocusAdapter() { - + @Override public void focusLost(FocusEvent e) { final String currentText = text.getText(); @@ -46,92 +136,114 @@ public class EquationView extends ViewPart implements ISelectionListener { @Override public void perform(WriteGraph g) - throws DatabaseException { + throws DatabaseException { Builtins b = g.getBuiltins(); SysdynResource sr = SysdynResource.getInstance(g); - - Resource expression = g.getPossibleObject(auxiliary, sr.HasExpression); + + Resource expression = g.getPossibleObject(variable, sr.HasExpression); if(expression == null) { expression = g.newResource(); g.claim(expression, b.InstanceOf, sr.Expression); - g.claim(auxiliary, sr.HasExpression, expression); + g.claim(variable, sr.HasExpression, expression); } g.claimValue(expression, sr.HasText, currentText); } - + }); } } - + }); text.addKeyListener(new KeyAdapter() { - + @Override public void keyPressed(KeyEvent e) { if(e.keyCode == SWT.ESC) { text.setText(originalText); } } - + }); + + // Lower part of the view: Units and Range + unitsAndRange = new Composite(parent, SWT.NONE); + GridDataFactory.fillDefaults().span(2, 1).applyTo(unitsAndRange); + RowLayout layout = new RowLayout(); + layout.spacing = 3; + unitsAndRange.setLayout(layout); + label = new Label(unitsAndRange, SWT.SINGLE); + label.setText("Range:"); + label.setAlignment(SWT.RIGHT); + Composite c = new Composite(unitsAndRange, SWT.NONE); + layout = new RowLayout(); + layout.spacing = 2; + c.setLayout(layout); + Text text1 = new Text(c, SWT.SINGLE | SWT.BORDER); + text1.setToolTipText("Start"); + text1 = new Text(c, SWT.SINGLE | SWT.BORDER); + text1.setToolTipText("Stop"); + text1 = new Text(c, SWT.SINGLE | SWT.BORDER); + text1.setToolTipText("Step"); } class UpdateViewRequest extends ReadRequest { Resource resource; - + public UpdateViewRequest(Resource resource) { this.resource = resource; } - + @Override public void run(ReadGraph g) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(g); Builtins b = g.getBuiltins(); - if(g.isInstanceOf(resource, sr.Auxiliary) || g.isInstanceOf(resource, sr.Valve)) { - auxiliary = resource; - final String name = g.getRelatedValue(resource, b.HasName); - Resource expression = g.getPossibleObject(resource, sr.HasExpression); - final String value = expression == null ? null : - (String)g.getPossibleRelatedValue(expression, sr.HasText); - text.getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - if(value == null) - originalText = ""; - else - originalText = value; - text.setText(originalText); - setPartName("Value of " + name); - } - - }); - } - else if(g.isInstanceOf(resource, sr.Stock)) { - auxiliary = resource; - final String name = g.getRelatedValue(resource, b.HasName); - Resource expression = g.getPossibleObject(resource, sr.HasExpression); - final String value = expression == null ? null : - (String)g.getPossibleRelatedValue(expression, sr.HasText); - text.getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - if(value == null) - originalText = ""; - else - originalText = value; - text.setText(originalText); - setPartName("Initial value of " + name); - } - - }); - } + final String eqLabel; + if (g.isInstanceOf(resource, sr.Auxiliary) || g.isInstanceOf(resource, sr.Valve)) + eqLabel = "="; + else if (g.isInstanceOf(resource, sr.Stock)) + eqLabel = "initial ="; + else + return; + variable = resource; + final String name = g.getRelatedValue(resource, b.HasName); + Resource expression = g.getPossibleObject(resource, sr.HasExpression); + final String value = expression == null ? null : + (String)g.getPossibleRelatedValue(expression, sr.HasText); + text.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(value == null) + originalText = ""; + else + originalText = value; + text.setText(originalText); + } + + }); + nameText.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + nameText.setText(name); + } + }); + equationComposite.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + equationLabel.setText(eqLabel); + equationComposite.layout(); + } + }); + } - + + + } - + @Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { if(selection instanceof IStructuredSelection) { @@ -150,4 +262,4 @@ public class EquationView extends ViewPart implements ISelectionListener { text.setFocus(); } -} +} \ No newline at end of file -- 2.47.1