]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Lookup Popup
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 31 May 2010 12:07:33 +0000 (12:07 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 31 May 2010 12:07:33 +0000 (12:07 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@15995 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ExpressionComposite.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartInfo.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartPanel.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupInputOutputTable.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupPopup.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/WithLookupExpressionViewFactor.java
org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java
sysdyn_ontologies/sysdyn.graph

index d89ec1a123a634e01066e151d6f7fcf9efa3ef88..33ccb1e80725be5b46394a8969aef8bcb77d1a19 100644 (file)
@@ -107,7 +107,7 @@ public class ExpressionComposite extends Composite {
             case Lookup: \r
                 evf = new LookupExpressionViewFactor(); break;\r
             case WithLookup: \r
-                evf = new WithLookupExpressionViewFactor(); break;\r
+                evf = new WithLookupExpressionViewFactor(variable); break;\r
             case Stock: \r
                 evf = new StockExpressionViewFactor(); break;\r
             case Delay: \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartInfo.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupChartInfo.java
new file mode 100644 (file)
index 0000000..237eff3
--- /dev/null
@@ -0,0 +1,63 @@
+package org.simantics.sysdyn.ui.equation.expressions;\r
+\r
+import java.util.Map;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class LookupChartInfo {\r
+\r
+    String lookupTable, expression;\r
+    Double minX, maxX, minY, maxY;\r
+\r
+    private static Double MINX = 0.0;\r
+    private static Double MAXX = 10.0;\r
+    private static Double MINY = 0.0;\r
+    private static Double MAXY = 10.0;\r
+\r
+    public LookupChartInfo(String expression, String lookupTable, final Resource variable, Map<String, Object> data) {\r
+        this.lookupTable = lookupTable != null ? lookupTable : "";\r
+        this.expression = expression != null ? expression : "";\r
+        this.minX = (Double)data.get("minX");\r
+        this.maxX = (Double)data.get("maxX");\r
+        this.minY = (Double)data.get("minY");\r
+        this.maxY = (Double)data.get("maxY");\r
+        if(variable != null && (minX == null || maxX == null || minY == null || maxY == null)) {\r
+            try {\r
+                SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+                    @Override\r
+                    public void run(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, sr.WithLookupExpression)) { \r
+                            minX = graph.getPossibleRelatedValue(expression, sr.HasMinX);  \r
+                            if(minX == null) minX = MINX;\r
+                            maxX = graph.getPossibleRelatedValue(expression, sr.HasMaxX); \r
+                            if(maxX == null) maxX = MAXX;\r
+                            minY = graph.getPossibleRelatedValue(expression, sr.HasMinY); \r
+                            if(minY == null) minY = MINY;\r
+                            maxY = graph.getPossibleRelatedValue(expression, sr.HasMaxY);\r
+                            if(maxY == null) maxY = MAXY;\r
+                        } else {\r
+                            defaultValues();\r
+                        }\r
+\r
+                    }\r
+                });\r
+            } catch (DatabaseException e) {\r
+                e.printStackTrace();\r
+            }\r
+        }\r
+    }\r
+    \r
+    private void defaultValues() {\r
+        minX = MINX;\r
+        maxX = MAXX;\r
+        minY = MINY;\r
+        maxY = MAXY;\r
+    }\r
+}\r
index da6b23722715fd5e0c1d65cd8aba3f11deeb4de9..c08fbf9ff4da695e8a42640b470369baaa2a80e8 100644 (file)
@@ -18,7 +18,7 @@ import org.jfree.data.xy.XYSeriesCollection;
 \r
 @SuppressWarnings("serial")\r
 public class LookupChartPanel extends ChartPanel {\r
-    \r
+\r
     private XYItemEntity dragPrevEntity;\r
     private boolean drawing;\r
     private XYSeries series; \r
@@ -31,7 +31,7 @@ public class LookupChartPanel extends ChartPanel {
         XYSeriesCollection collection = (XYSeriesCollection) ((XYPlot)chart.getPlot()).getDataset();\r
         series = collection.getSeries(0); \r
     }\r
-    \r
+\r
     public void setTable(LookupInputOutputTable table) {\r
         this.table = table;\r
     }\r
@@ -87,7 +87,7 @@ public class LookupChartPanel extends ChartPanel {
     }\r
 \r
     public void mouseReleased(MouseEvent e) {\r
-        \r
+\r
         dragPrevEntity = null;\r
         drawing = false;\r
     }\r
@@ -128,10 +128,12 @@ public class LookupChartPanel extends ChartPanel {
     }\r
 \r
     public void addLocationToSeries(Point2D location) {\r
-        series.add(location.getX(), location.getY());\r
-        table.addLocation(location);\r
+        if(series.indexOf(location.getX()) < 0) {\r
+            series.add(location.getX(), location.getY());\r
+            table.addLocation(location);\r
+        }\r
     }\r
-    \r
+\r
     public void removeItemFromSeries(int item){\r
         Point2D location = new Point2D.Double(series.getX(item).doubleValue(),series.getY(item).doubleValue()); \r
         series.remove(item);\r
index 4a63d81831d5a93295be62abac50faccb542b129..585ac91cb3d4e1e1a5f6766772408d5a95cb766b 100644 (file)
@@ -30,7 +30,6 @@ public class LookupInputOutputTable extends Composite {
     TableViewer tableViewer;\r
     List<InputOutput> tableRows;\r
 \r
-\r
     public LookupInputOutputTable(Composite parent, int style) {\r
         super(parent, style);\r
 \r
@@ -40,14 +39,14 @@ public class LookupInputOutputTable extends Composite {
         GridDataFactory.fillDefaults().grab(true, true).applyTo(table);\r
         table.setHeaderVisible (true);\r
         table.setLinesVisible(true);\r
-\r
-        TableColumn column = new TableColumn (table, SWT.LEFT);\r
-        column.setText (INPUT);\r
-        column.setWidth (60);\r
-\r
-        column = new TableColumn (table, SWT.LEFT);\r
-        column.setText (OUTPUT);\r
-        column.setWidth (60);\r
+        table.getVerticalBar().setVisible(true);\r
+        TableColumn column1 = new TableColumn (table, SWT.LEFT);\r
+        column1.setText (INPUT);\r
+        column1.setWidth (85);\r
+        \r
+        TableColumn column2 = new TableColumn (table, SWT.LEFT);\r
+        column2.setText (OUTPUT);\r
+        column2.setWidth (85);\r
 \r
         // Create the viewer and connect it to the view\r
         tableViewer = new TableViewer (table);\r
index 34fe9ad29a4cda44ffcdf5b482b82690f98e70fe..57b290454686cded28b12f2cb5adc4883caf25b7 100644 (file)
@@ -9,18 +9,24 @@ import java.awt.geom.Point2D;
 import java.io.StringReader;\r
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
-\r
 import javax.swing.JComponent;\r
 import javax.swing.JPanel;\r
-\r
 import org.eclipse.jface.dialogs.Dialog;\r
+import org.eclipse.jface.dialogs.IDialogConstants;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.viewers.ICellModifier;\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.KeyEvent;\r
+import org.eclipse.swt.events.KeyListener;\r
 import org.eclipse.swt.events.ModifyEvent;\r
 import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.events.MouseListener;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
 import org.eclipse.swt.widgets.Display;\r
@@ -41,38 +47,28 @@ import org.jfree.data.xy.XYDataItem;
 import org.jfree.data.xy.XYDataset;\r
 import org.jfree.data.xy.XYSeries;\r
 import org.jfree.data.xy.XYSeriesCollection;\r
-import org.simantics.db.Resource;\r
 import org.simantics.g2d.chassis.SWTAWTComponent;\r
 import org.simantics.sysdyn.tableParser.ParseException;\r
 import org.simantics.sysdyn.tableParser.Token;\r
 import org.simantics.sysdyn.tableParser.TableParser;\r
 import org.simantics.sysdyn.ui.equation.expressions.LookupInputOutputTable.InputOutput;\r
 \r
-/**\r
- * should do something in format {{0,1},{1,2},{2,3}}\r
- * @author TLTEEMU\r
- *\r
- */\r
-\r
 public class LookupPopup extends Dialog {\r
 \r
     JFreeChart chart;\r
-    LookupChartPanel chartPanel;\r
-    SWTAWTComponent c;\r
-    JPanel panel;\r
-    Resource variable;\r
     LookupInputOutputTable table;\r
     ArrayList<Point2D> dataPoints;\r
-    \r
+    Text input, output;\r
     Text minX, maxX, minY, maxY;\r
+    Label unit;\r
+    LookupChartInfo chartInfo;\r
 \r
-    protected LookupPopup(Shell parentShell, Resource variable, String tableAsString) {\r
+    protected LookupPopup(Shell parentShell, LookupChartInfo chartInfo) {\r
         super(parentShell);\r
-        this.variable = variable;\r
+        this.chartInfo = chartInfo;\r
         this.dataPoints = new ArrayList<Point2D>();\r
-        \r
         TableParser parser = new TableParser(new StringReader(""));\r
-        parser.ReInit(new StringReader(tableAsString));\r
+        parser.ReInit(new StringReader(chartInfo.lookupTable));\r
         try {\r
             parser.table();\r
             ArrayList<Token> xTokens = parser.getXTokens();\r
@@ -82,15 +78,25 @@ public class LookupPopup extends Dialog {
                         Double.parseDouble(token.next.next.image)));\r
             }\r
         } catch (ParseException e1) {\r
-            \r
         }\r
-        \r
+\r
     }\r
 \r
     @Override\r
     protected Control createDialogArea(Composite parent) {\r
+        KeyListener enterListener = new KeyListener() {\r
+\r
+            @Override\r
+            public void keyReleased(KeyEvent e) {}\r
 \r
-        chartPanel = new LookupChartPanel(createChart());\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if(e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR)\r
+                    getButton(IDialogConstants.OK_ID).forceFocus();\r
+            }\r
+        };\r
+\r
+        final LookupChartPanel chartPanel = new LookupChartPanel(createChart());\r
         chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));\r
         chartPanel.setMouseZoomable(true, false);\r
         chartPanel.setDomainZoomable(false);\r
@@ -108,19 +114,26 @@ public class LookupPopup extends Dialog {
         GridDataFactory.fillDefaults().grab(false, true).applyTo(yAxis);\r
         maxY = new Text(yAxis, SWT.BORDER | SWT.RIGHT);\r
         GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(maxY);\r
+        maxY.addKeyListener(enterListener);\r
         maxY.addModifyListener(getAxisBoundModifyListener());\r
         maxY.setText("" + rangeAxis.getUpperBound());\r
         Composite fillY = new Composite(yAxis, SWT.NONE);\r
-        GridDataFactory.fillDefaults().grab(false, true).applyTo(fillY);\r
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(false, true).applyTo(fillY);\r
+        GridLayoutFactory.fillDefaults().applyTo(fillY);\r
+        unit = new Label(fillY, SWT.RIGHT);\r
+        GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(unit);\r
+        unit.setText(""); //TODO: how to get and update units?\r
+        unit.addKeyListener(enterListener);\r
         minY = new Text(yAxis, SWT.BORDER | SWT.RIGHT);\r
         GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(minY);\r
+        minY.addKeyListener(enterListener);\r
         minY.addModifyListener(getAxisBoundModifyListener());\r
         minY.setText("" + rangeAxis.getLowerBound());\r
 \r
-        c = new SWTAWTComponent(container, SWT.BORDER) {\r
+        SWTAWTComponent c = new SWTAWTComponent(container, SWT.BORDER) {\r
             @Override\r
             protected JComponent createSwingComponent() {\r
-                panel = new JPanel();\r
+                JPanel panel = new JPanel();\r
                 panel.setLayout(new GridLayout(1, 1));\r
                 panel.setPreferredSize(new java.awt.Dimension(500, 270));\r
                 panel.add(chartPanel);\r
@@ -133,16 +146,16 @@ public class LookupPopup extends Dialog {
 \r
 \r
         Composite valueTableComposite = new Composite(container, SWT.NONE);\r
-        GridDataFactory.fillDefaults().grab(true, true).applyTo(valueTableComposite);\r
-        GridLayoutFactory.fillDefaults().applyTo(valueTableComposite);\r
+        GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(valueTableComposite);\r
+        GridLayoutFactory.fillDefaults().numColumns(3).applyTo(valueTableComposite);\r
 \r
 \r
         table = new LookupInputOutputTable(valueTableComposite, SWT.NONE);\r
-        GridDataFactory.fillDefaults().grab(true, true).applyTo(table);\r
+        GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(table);\r
         chartPanel.setTable(table);\r
         table.getTableViewer().setCellModifier(new InputOutputCellModifier());\r
         table.getTableViewer().getTable().addMouseListener(new MouseListener() {\r
-            \r
+\r
             @Override\r
             public void mouseUp(org.eclipse.swt.events.MouseEvent e) {\r
                 if(e.button == MouseEvent.BUTTON3) {\r
@@ -160,6 +173,74 @@ public class LookupPopup extends Dialog {
             chartPanel.addLocationToSeries(location);\r
         }\r
 \r
+        input = new Text(valueTableComposite, SWT.BORDER | SWT.RIGHT);\r
+        GridDataFactory.fillDefaults().hint(60, SWT.DEFAULT).applyTo(input);\r
+        input.setText("");\r
+        output = new Text(valueTableComposite, SWT.BORDER | SWT.RIGHT);\r
+        GridDataFactory.fillDefaults().hint(60, SWT.DEFAULT).applyTo(output);\r
+        output.setText("");\r
+\r
+        Button add = new Button(valueTableComposite, SWT.None);\r
+        add.setText("Add");\r
+        add.addSelectionListener(new SelectionListener() {\r
+\r
+            @Override\r
+            public void widgetSelected(SelectionEvent e) {\r
+                try {\r
+                    Double in = Double.parseDouble(input.getText());\r
+                    Double out = Double.parseDouble(output.getText());\r
+                    chartPanel.addLocationToSeries(new Point2D.Double(in, out));\r
+                } catch (NumberFormatException e1) {\r
+                    input.setText("");\r
+                    output.setText("");\r
+                }\r
+            }\r
+\r
+            @Override\r
+            public void widgetDefaultSelected(SelectionEvent e) {}\r
+        });\r
+\r
+        FocusListener flistener = new FocusListener() {\r
+            @Override\r
+            public void focusGained(FocusEvent e) {\r
+                Text text = (Text)e.widget;\r
+                text.setSelection(0, text.getCharCount());\r
+            }\r
+            @Override\r
+            public void focusLost(FocusEvent e) { }\r
+        };\r
+\r
+\r
+        KeyListener listener = new KeyListener() {\r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {\r
+                    try {\r
+                        Double in = Double.parseDouble(input.getText());\r
+                        Double out = Double.parseDouble(output.getText());\r
+                        chartPanel.addLocationToSeries(new Point2D.Double(in, out));\r
+                    } catch (NumberFormatException e1) {\r
+                        if(input.getText().isEmpty() && output.getText().isEmpty()) {\r
+                            getButton(IDialogConstants.OK_ID).forceFocus();\r
+                            return;\r
+                        }\r
+                    }\r
+                    input.setText("");\r
+                    output.setText("");\r
+                    input.setFocus();\r
+                }          \r
+            }\r
+\r
+            @Override\r
+            public void keyReleased(KeyEvent e) { }\r
+\r
+        };\r
+\r
+        input.addFocusListener(flistener);\r
+        input.addKeyListener(listener);\r
+        output.addFocusListener(flistener);\r
+        output.addKeyListener(listener);\r
 \r
         Label l = new Label(container, SWT.NONE);\r
         l.setText("");\r
@@ -168,23 +249,33 @@ public class LookupPopup extends Dialog {
         GridDataFactory.fillDefaults().grab(true, false).applyTo(xAxis);\r
         GridLayoutFactory.fillDefaults().numColumns(3).applyTo(xAxis);\r
         minX = new Text(xAxis, SWT.BORDER | SWT.RIGHT);\r
-        GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(minX);\r
+        GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(minX); \r
+        minX.addKeyListener(enterListener);\r
         minX.addModifyListener(getAxisBoundModifyListener());\r
         minX.setText("" + domainAxis.getLowerBound());\r
-        Composite fillX = new Composite(xAxis, SWT.NONE);\r
-        GridDataFactory.fillDefaults().grab(true, false).applyTo(fillX);\r
+        Composite fillX = new Composite(xAxis, SWT.CENTER);\r
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false).applyTo(fillX);\r
         GridLayoutFactory.fillDefaults().applyTo(fillX);\r
         l = new Label(fillX, SWT.NONE);\r
+        l.setText(chartInfo.expression);\r
         maxX = new Text(xAxis, SWT.BORDER | SWT.RIGHT);\r
         GridDataFactory.fillDefaults().hint(40, SWT.DEFAULT).applyTo(maxX);\r
+        maxX.addKeyListener(enterListener);\r
         maxX.addModifyListener(getAxisBoundModifyListener());\r
         maxX.setText("" + domainAxis.getUpperBound());\r
 \r
         return null;\r
     }\r
 \r
+    protected void createButtonsForButtonBar(Composite parent) {\r
+        // create OK and Cancel buttons by default\r
+        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,\r
+                false);\r
+        createButton(parent, IDialogConstants.CANCEL_ID,\r
+                IDialogConstants.CANCEL_LABEL, false);\r
+    }\r
 \r
-    public String open(boolean moi) {\r
+    public LookupChartInfo open(Boolean bool) {\r
         Shell shell = this.getShell();\r
         if (shell == null || shell.isDisposed()) {\r
             shell = null;\r
@@ -192,17 +283,27 @@ public class LookupPopup extends Dialog {
             shell = this.getShell();\r
         }\r
         constrainShellSize();\r
-\r
         shell.open();\r
+        getButton(IDialogConstants.OK_ID).setFocus();\r
         Display display = getParentShell().getDisplay();\r
         while (!shell.isDisposed()) {\r
             if (!display.readAndDispatch()) {\r
                 display.sleep();\r
             }\r
         }\r
-        return graphToModelicaTable();\r
+        return chartInfo;\r
     }\r
-\r
+   \r
+    @Override\r
+    public void okPressed() {\r
+        chartInfo.lookupTable = graphToModelicaTable();\r
+        chartInfo.minX = Double.parseDouble(minX.getText());\r
+        chartInfo.maxX = Double.parseDouble(maxX.getText());\r
+        chartInfo.minY = Double.parseDouble(minY.getText());\r
+        chartInfo.maxY = Double.parseDouble(maxY.getText());\r
+        super.okPressed();\r
+    }\r
+    \r
     @SuppressWarnings("unchecked")\r
     private String graphToModelicaTable() {\r
         StringBuilder b = new StringBuilder();\r
@@ -224,7 +325,7 @@ public class LookupPopup extends Dialog {
 \r
     private JFreeChart createChart() {\r
         XYDataset dataset = createDataset();\r
-        chart = ChartFactory.createXYLineChart("Lookup", "X", "Y",\r
+        chart = ChartFactory.createXYLineChart(null, null, null,\r
                 dataset, PlotOrientation.VERTICAL, false, true, false);\r
         XYPlot plot = (XYPlot) chart.getPlot();\r
         XYLineAndShapeRenderer renderer\r
@@ -239,11 +340,10 @@ public class LookupPopup extends Dialog {
 \r
         ValueAxis rangeAxis = plot.getRangeAxis();\r
         rangeAxis.setAutoRange(false);\r
-        rangeAxis.setRange(0, 40);\r
-\r
+        rangeAxis.setRange(chartInfo.minY, chartInfo.maxY);\r
         ValueAxis domainAxis = plot.getDomainAxis();\r
         domainAxis.setAutoRange(false);\r
-        domainAxis.setRange(0, 30);\r
+        domainAxis.setRange(chartInfo.minX, chartInfo.maxX);\r
         return chart;\r
     }\r
 \r
@@ -284,9 +384,9 @@ public class LookupPopup extends Dialog {
             }\r
         };\r
     }\r
-    \r
+\r
     private class InputOutputCellModifier implements ICellModifier {\r
-        \r
+\r
         XYSeries series;\r
 \r
         public InputOutputCellModifier() {\r
@@ -310,12 +410,12 @@ public class LookupPopup extends Dialog {
 \r
         public void modify(Object element, String property, Object value) {\r
             if (element instanceof Item) element = ((Item) element).getData();\r
-            \r
+\r
             InputOutput io = (InputOutput)element;\r
             Double x = (Double)io.getInput(Double.class);\r
             int item = series.indexOf(x);\r
             series.remove(item);\r
-            \r
+\r
             if (LookupInputOutputTable.INPUT.equals(property)) {\r
                 Double newX = io.setInput((String)value);\r
                 // if has the same x-value, revert back\r
@@ -325,16 +425,11 @@ public class LookupPopup extends Dialog {
             } else if (LookupInputOutputTable.OUTPUT.equals(property)) {\r
                 io.setOutput((String)value);\r
             }\r
-            \r
+\r
             series.add((Double)io.getInput(Double.class), (Double)io.getOutput(Double.class));\r
-            \r
-            table.refresh();\r
 \r
+            table.refresh();\r
         }\r
     }\r
 \r
-\r
-\r
-\r
-\r
 }\r
index 288fd3b358f8cfb730ad82c423d796017f787b25..43218e06c4704066bcb45a57b713e9855f1ac4bf 100644 (file)
@@ -48,12 +48,17 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
     private Button asGraph;\r
     private ExpressionField lastSelectedText = expression;\r
     private Resource variable;\r
+    private LookupChartInfo chartInfo;\r
 \r
+    public WithLookupExpressionViewFactor(Resource variable) {\r
+        super();\r
+        this.variable = variable;\r
+    }\r
+    \r
     @Override\r
-    public void createView(Composite parent, Map<String, Object> data) {\r
-\r
-        final String equation = data.get("equation") != null ? (String)data.get("equation") : "";\r
-        final String lookupTable = data.get("lookup") != null ? (String)data.get("lookup") : "";\r
+    public void createView(Composite parent, final Map<String, Object> data) {\r
+        String equation = data.get("equation") != null ? (String)data.get("equation") : "";\r
+        String lookupTable = data.get("lookup") != null ? (String)data.get("lookup") : "";\r
 \r
         GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(parent);\r
 \r
@@ -99,11 +104,17 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
         asGraph.addSelectionListener(new SelectionAdapter() {\r
             public void widgetSelected(SelectionEvent e) {\r
                 if(e.widget == asGraph) {\r
-                    LookupPopup pud = new LookupPopup(asGraph.getParent().getShell(), variable, lookup.getExpression());\r
-                    lookup.setExpression(pud.open(false));\r
+                    if(chartInfo == null) chartInfo = new LookupChartInfo(expression.getExpression(), lookup.getExpression(), variable, data);\r
+                    LookupPopup pud = new LookupPopup(asGraph.getParent().getShell(), chartInfo);\r
+                    LookupChartInfo newInfo = pud.open(false);\r
+                    if(pud.getReturnCode() == org.eclipse.jface.window.Window.OK) {\r
+                        chartInfo = newInfo;\r
+                        lookup.setExpression(chartInfo.lookupTable);\r
+                    }\r
                 }\r
             }\r
         });\r
+\r
     }\r
 \r
     @Override\r
@@ -134,7 +145,6 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
             }\r
             data.put("equation", results[0]);\r
             data.put("lookup", results[1]);\r
-            this.variable = variable;\r
         }\r
     }\r
 \r
@@ -144,6 +154,7 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
         final String currentLookupTable = lookup.getExpression();\r
 \r
         if(currentExpression != null && currentLookupTable != null) {\r
+            data.putAll(data);\r
             data.put("equation", currentExpression);\r
             data.put("lookup", currentLookupTable);\r
             SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
@@ -161,8 +172,11 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
                     g.claim(variable, sr.HasExpression, expression);\r
                     g.claimValue(expression, sr.HasEquation, currentExpression);\r
                     g.claimValue(expression, sr.HasLookup, currentLookupTable);\r
+                    g.claimValue(expression, sr.HasMinX, chartInfo.minX);\r
+                    g.claimValue(expression, sr.HasMaxX, chartInfo.maxX);\r
+                    g.claimValue(expression, sr.HasMinY, chartInfo.minY);\r
+                    g.claimValue(expression, sr.HasMaxY, chartInfo.maxY);\r
                 }\r
-\r
             });\r
         }\r
     }\r
@@ -192,6 +206,12 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
             data.put("equation", this.expression.getExpression());\r
         if(this.lookup != null && this.lookup.getExpression() != null)\r
             data.put("lookup", this.lookup.getExpression());\r
+        if(this.chartInfo != null) {\r
+            data.put("minX", chartInfo.minX);\r
+            data.put("maxX", chartInfo.maxX);\r
+            data.put("minY", chartInfo.minY);\r
+            data.put("maxY", chartInfo.maxY);\r
+        }\r
     }\r
 \r
     @Override\r
index d24dac9a9a5d74a8c581218519ed0bdd0bb40421..c8231e16abdc74c8c58b252addefa842146f9270 100644 (file)
@@ -37,6 +37,10 @@ public class SysdynResource {
     public final Resource HasHead;\r
     public final Resource HasInitialEquation;\r
     public final Resource HasLookup;\r
+    public final Resource HasMaxX;\r
+    public final Resource HasMaxY;\r
+    public final Resource HasMinX;\r
+    public final Resource HasMinY;\r
     public final Resource HasStartTime;\r
     public final Resource HasStopTime;\r
     public final Resource HasTail;\r
@@ -85,6 +89,10 @@ public class SysdynResource {
         public static final String HasHead = "http://www.simantics.org/Sysdyn-1.0/HasHead";\r
         public static final String HasInitialEquation = "http://www.simantics.org/Sysdyn-1.0/HasInitialEquation";\r
         public static final String HasLookup = "http://www.simantics.org/Sysdyn-1.0/HasLookup";\r
+        public static final String HasMaxX = "http://www.simantics.org/Sysdyn-1.0/HasMaxX";\r
+        public static final String HasMaxY = "http://www.simantics.org/Sysdyn-1.0/HasMaxY";\r
+        public static final String HasMinX = "http://www.simantics.org/Sysdyn-1.0/HasMinX";\r
+        public static final String HasMinY = "http://www.simantics.org/Sysdyn-1.0/HasMinY";\r
         public static final String HasStartTime = "http://www.simantics.org/Sysdyn-1.0/HasStartTime";\r
         public static final String HasStopTime = "http://www.simantics.org/Sysdyn-1.0/HasStopTime";\r
         public static final String HasTail = "http://www.simantics.org/Sysdyn-1.0/HasTail";\r
@@ -143,6 +151,10 @@ public class SysdynResource {
         HasHead = getResourceOrNull(graph, URIs.HasHead);\r
         HasInitialEquation = getResourceOrNull(graph, URIs.HasInitialEquation);\r
         HasLookup = getResourceOrNull(graph, URIs.HasLookup);\r
+        HasMaxX = getResourceOrNull(graph, URIs.HasMaxX);\r
+        HasMaxY = getResourceOrNull(graph, URIs.HasMaxY);\r
+        HasMinX = getResourceOrNull(graph, URIs.HasMinX);\r
+        HasMinY = getResourceOrNull(graph, URIs.HasMinY);\r
         HasStartTime = getResourceOrNull(graph, URIs.HasStartTime);\r
         HasStopTime = getResourceOrNull(graph, URIs.HasStopTime);\r
         HasTail = getResourceOrNull(graph, URIs.HasTail);\r
index 1b9d238878d95d70358d865fe0e5d6b1d2f1f4c8..1256c67ed5ca5282031afbaca4d62b2aa3f4b99b 100644 (file)
@@ -190,6 +190,18 @@ HasInitialEquation <R L0.HasProperty
     \r
 HasLookup <R L0.HasProperty\r
     L0.HasRange L0.String  \r
+\r
+HasMinX <R L0.HasProperty\r
+    L0.HasRange L0.Double\r
+    \r
+HasMaxX <R L0.HasProperty\r
+    L0.HasRange L0.Double\r
+\r
+HasMinY <R L0.HasProperty\r
+    L0.HasRange L0.Double\r
+\r
+HasMaxY <R L0.HasProperty\r
+    L0.HasRange L0.Double\r
     \r
 Expression <T L0.Entity\r
 \r
@@ -214,6 +226,11 @@ LookupExpression <T Expression
 WithLookupExpression <T Expression\r
     [HasLookup card "1"]  \r
     [HasEquation card "1"]    \r
+    [HasMinX card "1"]\r
+    [HasMaxX card "1"]\r
+    [HasMinY card "1"]\r
+    [HasMaxY card "1"]\r
+    \r
       \r
 ######################################################################\r
 # Symbols\r