]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16258 ac1ea38d-2e2b...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 21 Jun 2010 11:59:01 +0000 (11:59 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 21 Jun 2010 11:59:01 +0000 (11:59 +0000)
12 files changed:
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartTableWidget.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartWidget.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupChartInfo.java [deleted file]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupChartPanel.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupInputOutputTable.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupPopup.java [deleted file]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyModifier.java [new file with mode: 0644]

index 378ad63e17db338ed90a8ff96c149bc254fbdd82..ac34c633eea1852f1bdbfc9a0eda97a173e48ada 100644 (file)
@@ -78,6 +78,7 @@ public class EquationTab extends PropertyTabContributorImpl {
             @Override\r
             public void widgetSelected(SelectionEvent e) {\r
                 expressionWidget.displayExpression(expressionTypeWidget.getSelecetedType(), false);\r
+                expressionWidget.save();\r
             }\r
 \r
             @Override\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java
new file mode 100644 (file)
index 0000000..0fb17cf
--- /dev/null
@@ -0,0 +1,77 @@
+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.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.ChartTableWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.ChartWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
+\r
+public class LookupTableTab extends PropertyTabContributorImpl {\r
+    \r
+    @Override\r
+    public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+\r
+        \r
+        Composite baseContainer = new Composite(body, SWT.NONE);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(baseContainer);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(baseContainer);\r
+\r
+        Composite Ycontainer = new Composite(baseContainer, SWT.NONE);\r
+        GridLayoutFactory.fillDefaults().applyTo(Ycontainer);\r
+        GridDataFactory.fillDefaults().grab(false, true).applyTo(Ycontainer);\r
+\r
+        TrackedText maxYText = new TrackedText(Ycontainer, support, SWT.BORDER);\r
+        maxYText.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasMaxY));\r
+        maxYText.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasMaxY));\r
+\r
+        Label l = new Label(Ycontainer, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(false, true).applyTo(l);\r
+\r
+        TrackedText minYText = new TrackedText(Ycontainer, support, SWT.BORDER);\r
+        minYText.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasMinY));\r
+        minYText.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasMinY));\r
+\r
+\r
+        Composite chartContainer = new Composite(baseContainer, SWT.NONE);\r
+        GridLayoutFactory.fillDefaults().numColumns(2).applyTo(chartContainer);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(chartContainer);\r
+\r
+        @SuppressWarnings("unused")\r
+        ChartWidget chartWidget = new ChartWidget(chartContainer, support, SWT.NONE);\r
+             \r
+        Composite chartTableContainer = new Composite(baseContainer, SWT.NONE);\r
+        GridLayoutFactory.fillDefaults().applyTo(chartTableContainer);\r
+        GridDataFactory.fillDefaults().grab(false, true).span(1, 2).applyTo(chartTableContainer);       \r
+        \r
+        @SuppressWarnings("unused")\r
+        ChartTableWidget chartTableWidget = new ChartTableWidget(chartTableContainer, support, SWT.NONE);\r
+        \r
+        l = new Label(baseContainer, SWT.NONE);\r
+\r
+        Composite Xcontainer = new Composite(baseContainer, SWT.NONE);\r
+        GridLayoutFactory.fillDefaults().numColumns(3).applyTo(Xcontainer);\r
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(Xcontainer);\r
+\r
+        TrackedText minXText = new TrackedText(Xcontainer, support, SWT.BORDER);\r
+        minXText.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasMinX));\r
+        minXText.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasMinX));\r
+\r
+        l = new Label(Xcontainer, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false).applyTo(l);\r
+\r
+        TrackedText maxXText = new TrackedText(Xcontainer, support, SWT.BORDER);\r
+        maxXText.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasMaxX));\r
+        maxXText.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasMaxX));\r
+\r
+    }\r
+}\r
index 52404a86d61207d99e0d044b612a73ef0a7fae6a..18fd9e9181ebb7724d1499eb647d4b5da2933bcc 100644 (file)
@@ -40,9 +40,17 @@ public class ResourceSelectionProcessor implements SelectionProcessor<ISelection
                         2,\r
                         r,\r
                         "Equation"));\r
+                Resource expression = backend.getPossibleObject(r, sr.HasExpression);\r
+                if(expression != null && backend.isInstanceOf(expression, sr.WithLookupExpression)) {\r
+                    tabs.add(new ComparableTabContributor(\r
+                            new LookupTableTab(),\r
+                            1,\r
+                            expression,\r
+                    "Lookup Table"));\r
+                }\r
                 tabs.add(new ComparableTabContributor(\r
                         new VariableInformationTab(),\r
-                        1,\r
+                        0,\r
                         r,\r
                 "Additional Information"));\r
                 return tabs;\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartTableWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartTableWidget.java
new file mode 100644 (file)
index 0000000..d4552cb
--- /dev/null
@@ -0,0 +1,230 @@
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import java.awt.event.MouseEvent;\r
+import java.awt.geom.Point2D;\r
+import java.io.StringReader;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\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.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.Event;\r
+import org.eclipse.swt.widgets.Table;\r
+import org.eclipse.swt.widgets.TableItem;\r
+import org.eclipse.swt.widgets.Text;\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.ReadGraph;\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.management.ISessionContext;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.tableParser.ParseException;\r
+import org.simantics.sysdyn.tableParser.TableParser;\r
+import org.simantics.sysdyn.tableParser.Token;\r
+import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupInputOutputTable;\r
+import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupInputOutputTable.InputOutput;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+public class ChartTableWidget implements Widget {\r
+\r
+    Text input, output;\r
+    Button add;\r
+    LookupInputOutputTable table;\r
+    Resource expression;\r
+\r
+    public ChartTableWidget(Composite parent, WidgetSupport support, int style) {\r
+        support.register(this);\r
+        Composite valueTableComposite = new Composite(parent, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(valueTableComposite);\r
+        GridLayoutFactory.fillDefaults().numColumns(3).applyTo(valueTableComposite);\r
+\r
+        table = new LookupInputOutputTable(valueTableComposite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().span(3, 1).grab(false, true).applyTo(table);\r
+        table.getTableViewer().getTable().addMouseListener(new MouseListener() {\r
+\r
+            @Override\r
+            public void mouseUp(org.eclipse.swt.events.MouseEvent e) {\r
+                if(e.button == MouseEvent.BUTTON3) {\r
+                    Table t = (Table)e.widget;\r
+                    TableItem item = (TableItem)t.getItem(new org.eclipse.swt.graphics.Point(e.x, e.y));\r
+                    table.removeItem(t.indexOf(item));\r
+                    tableModified();\r
+                }\r
+            }\r
+            @Override\r
+            public void mouseDown(org.eclipse.swt.events.MouseEvent e) { }\r
+            @Override\r
+            public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent e) { }\r
+        });\r
+\r
+        input = new Text(valueTableComposite, SWT.BORDER | SWT.RIGHT);\r
+        input.setText("");\r
+        output = new Text(valueTableComposite, SWT.BORDER | SWT.RIGHT);\r
+        output.setText("");\r
+\r
+        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
+                    table.addLocation(new Point2D.Double(in, out));\r
+                    tableModified();\r
+                } catch (NumberFormatException e1) {\r
+                }\r
+                input.setText("");\r
+                output.setText("");\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
+                        table.addLocation(new Point2D.Double(in, out));\r
+                        tableModified();\r
+                    } catch (NumberFormatException e1) {\r
+                        if(input.getText().isEmpty() && output.getText().isEmpty()) {\r
+                            add.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
+\r
+    @Override\r
+    public void setInput(ISessionContext context, Object input) {\r
+\r
+        expression = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+\r
+\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+                @Override\r
+                public String perform(ReadGraph graph) throws DatabaseException {\r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    String lookup = graph.getRelatedValue(expression, sr.HasLookup);\r
+                    return lookup;\r
+                }\r
+            }, new Listener<String>() {\r
+\r
+                @Override\r
+                public void exception(Throwable t) {\r
+                    t.printStackTrace();\r
+                }\r
+\r
+                @Override\r
+                public void execute(String lookup) {\r
+                    TableParser parser = new TableParser(new StringReader(""));\r
+                    parser.ReInit(new StringReader(lookup));\r
+                    table.clearTable();\r
+                    try {\r
+                        parser.table();\r
+                        ArrayList<Token> xTokens = parser.getXTokens();\r
+                        for(Token token : xTokens) {\r
+                            table.addLocation(new Point2D.Double(\r
+                                    Double.parseDouble(token.image), \r
+                                    Double.parseDouble(token.next.next.image)));\r
+                        }\r
+                    } catch (ParseException e1) {\r
+                    }\r
+                }\r
+\r
+                @Override\r
+                public boolean isDisposed() {\r
+                    return table.isDisposed();\r
+                }\r
+\r
+            });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
+        table.addListener(SWT.Modify, new org.eclipse.swt.widgets.Listener() {\r
+\r
+            @Override\r
+            public void handleEvent(Event event) {\r
+                tableModified();\r
+            }\r
+        });\r
+    }\r
+    \r
+    \r
+    @SuppressWarnings("unchecked")\r
+    private void tableModified() {\r
+        StringBuilder b = new StringBuilder();\r
+        b.append("{");\r
+        Iterator<InputOutput> iterator = ((ArrayList<InputOutput>)table.getTableViewer().getInput()).iterator();\r
+        while(iterator.hasNext()){\r
+            InputOutput io = iterator.next();\r
+            b.append("{" + io.getInput(String.class) + "," + io.getOutput(String.class) + "}");\r
+            if(iterator.hasNext())\r
+                b.append(",");\r
+        }\r
+        b.append("}");\r
+        final String table =  b.toString();\r
+\r
+        SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+            @Override\r
+            public void perform(WriteGraph graph) throws DatabaseException {\r
+                SysdynResource sr = SysdynResource.getInstance(graph);\r
+                graph.claimValue(expression, sr.HasLookup, table);\r
+            }\r
+        });\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartWidget.java
new file mode 100644 (file)
index 0000000..0dbf66a
--- /dev/null
@@ -0,0 +1,219 @@
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.GridLayout;\r
+import java.awt.geom.Ellipse2D;\r
+import java.io.StringReader;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import javax.swing.JComponent;\r
+import javax.swing.JPanel;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.jfree.chart.ChartFactory;\r
+import org.jfree.chart.JFreeChart;\r
+import org.jfree.chart.axis.ValueAxis;\r
+import org.jfree.chart.plot.PlotOrientation;\r
+import org.jfree.chart.plot.XYPlot;\r
+import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;\r
+import org.jfree.data.general.SeriesChangeEvent;\r
+import org.jfree.data.general.SeriesChangeListener;\r
+import org.jfree.data.xy.XYDataItem;\r
+import org.jfree.data.xy.XYDataset;\r
+import org.jfree.data.xy.XYSeries;\r
+import org.jfree.data.xy.XYSeriesCollection;\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.ReadGraph;\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.management.ISessionContext;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.g2d.chassis.SWTAWTComponent;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.tableParser.ParseException;\r
+import org.simantics.sysdyn.tableParser.TableParser;\r
+import org.simantics.sysdyn.tableParser.Token;\r
+import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupChartPanel;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+public class ChartWidget implements Widget {\r
+\r
+    JFreeChart chart;\r
+    LookupChartPanel chartPanel;\r
+    SWTAWTComponent swtawtcomponent;\r
+\r
+    public ChartWidget(Composite parent, WidgetSupport support, int style) {\r
+        support.register(this);\r
+        chartPanel = new LookupChartPanel(createChart());\r
+        chartPanel.setMouseZoomable(true, false);\r
+        chartPanel.setDomainZoomable(false);\r
+        chartPanel.setRangeZoomable(false);\r
+\r
+        swtawtcomponent = new SWTAWTComponent(parent, SWT.BORDER) {\r
+            @Override\r
+            protected JComponent createSwingComponent() {\r
+                JPanel panel = new JPanel();\r
+                panel.setLayout(new GridLayout(1, 1));\r
+                panel.add(chartPanel);\r
+                panel.doLayout();\r
+                return panel;\r
+            }\r
+        };\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(swtawtcomponent);\r
+        swtawtcomponent.populate();\r
+\r
+    }\r
+\r
+    @Override\r
+    public void setInput(ISessionContext context, Object input) {\r
+\r
+        final Resource expression = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+\r
+        class Auxiliary {\r
+            Double minX, minY, maxX, maxY;\r
+            String table;\r
+        }\r
+\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new Read<Auxiliary>() {\r
+\r
+                @Override\r
+                public Auxiliary perform(ReadGraph graph) throws DatabaseException {\r
+                    Auxiliary auxiliary = new Auxiliary();\r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    auxiliary.minX = graph.getRelatedValue(expression, sr.HasMinX);\r
+                    auxiliary.maxX = graph.getRelatedValue(expression, sr.HasMaxX);\r
+                    auxiliary.minY = graph.getRelatedValue(expression, sr.HasMinY);\r
+                    auxiliary.maxY = graph.getRelatedValue(expression, sr.HasMaxY);\r
+                    auxiliary.table = graph.getRelatedValue(expression, sr.HasLookup);\r
+                    return auxiliary;\r
+                }\r
+            }, new Listener<Auxiliary>() {\r
+\r
+                @Override\r
+                public void exception(Throwable t) {\r
+                    t.printStackTrace();\r
+                }\r
+\r
+                @Override\r
+                public void execute(Auxiliary result) {\r
+\r
+                    XYDataset dataset = createDataset(result.table);\r
+                    chartPanel.resetChart(dataset);\r
+                    chartPanel.addSeriesChangeListener(new _SeriesChangeListener(expression));\r
+                    \r
+                    XYPlot plot = (XYPlot) chart.getPlot();\r
+                    ValueAxis rangeAxis = plot.getRangeAxis();\r
+                    rangeAxis.setAutoRange(false);\r
+                    rangeAxis.setRange(result.minY, result.maxY);\r
+                    ValueAxis domainAxis = plot.getDomainAxis();\r
+                    domainAxis.setAutoRange(false);\r
+                    domainAxis.setRange(result.minX, result.maxX);\r
+\r
+                }\r
+\r
+                @Override\r
+                public boolean isDisposed() {\r
+                    return swtawtcomponent.isDisposed();\r
+                }\r
+\r
+            });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
+    }\r
+\r
+    private JFreeChart createChart() {\r
+        XYDataset dataset = createDataset(null);\r
+        chart = ChartFactory.createXYLineChart(null, null, null,\r
+                dataset, PlotOrientation.VERTICAL, false, true, false);\r
+        XYPlot plot = (XYPlot) chart.getPlot();\r
+        XYLineAndShapeRenderer renderer\r
+        = (XYLineAndShapeRenderer) plot.getRenderer();\r
+        renderer.setBaseShapesVisible(true);\r
+        renderer.setDrawOutlines(true);\r
+        renderer.setUseFillPaint(true);\r
+        renderer.setBaseFillPaint(Color.white);\r
+        renderer.setSeriesStroke(0, new BasicStroke(3.0f));\r
+        renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));\r
+        renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));\r
+        return chart;\r
+    }\r
+\r
+    public XYDataset createDataset(String table) {\r
+        XYSeries series = new XYSeries("Series");\r
+        \r
+        if(table != null) {\r
+            TableParser parser = new TableParser(new StringReader(""));\r
+            parser.ReInit(new StringReader(table));\r
+            try {\r
+                parser.table();\r
+                ArrayList<Token> xTokens = parser.getXTokens();\r
+                for(Token token : xTokens) {\r
+                    series.add(Double.parseDouble(token.image), \r
+                            Double.parseDouble(token.next.next.image));\r
+                }\r
+            } catch (ParseException e1) {\r
+            }\r
+        }\r
+        \r
+        XYSeriesCollection dataset = new XYSeriesCollection();\r
+        dataset.addSeries(series);\r
+        return dataset;\r
+    }\r
+\r
+    public LookupChartPanel getChartPanel() {\r
+        return this.chartPanel;\r
+    }\r
+\r
+    public JFreeChart getChart() {\r
+        return this.chart;\r
+    }\r
+\r
+    private class _SeriesChangeListener implements SeriesChangeListener {\r
+\r
+        Resource expression;\r
+        \r
+        public _SeriesChangeListener(Resource expression) {\r
+            this.expression = expression;\r
+        }\r
+        @Override\r
+        public void seriesChanged(SeriesChangeEvent event) {\r
+            if(chartPanel.isDragging()) return;\r
+\r
+            StringBuilder b = new StringBuilder();\r
+            b.append("{");\r
+            XYSeriesCollection collection = (XYSeriesCollection) ((XYPlot)chart.getPlot()).getDataset();\r
+            XYSeries series = collection.getSeries(0);\r
+            if(series.isEmpty())\r
+                return;\r
+            Iterator<?> iterator = series.getItems().iterator();\r
+            while(iterator.hasNext()){\r
+                XYDataItem item = (XYDataItem)iterator.next();\r
+                b.append("{" + item.getX() + "," + item.getY() + "}");\r
+                if(iterator.hasNext())\r
+                    b.append(",");\r
+            }\r
+            b.append("}");\r
+            final String table = b.toString();\r
+\r
+            SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException {\r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    graph.claimValue(expression, sr.HasLookup, table);\r
+                }\r
+            });\r
+\r
+        }\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupChartInfo.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupChartInfo.java
deleted file mode 100644 (file)
index e556d04..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.simantics.sysdyn.ui.properties.widgets.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 21224331eea1e5c2ea6b39c58102ff3777cfc5ee..6258aea6c82fe9159c6fd311c5222817e77778b9 100644 (file)
@@ -13,6 +13,8 @@ import org.jfree.chart.entity.ChartEntity;
 import org.jfree.chart.entity.PlotEntity;\r
 import org.jfree.chart.entity.XYItemEntity;\r
 import org.jfree.chart.plot.XYPlot;\r
+import org.jfree.data.general.SeriesChangeListener;\r
+import org.jfree.data.xy.XYDataset;\r
 import org.jfree.data.xy.XYSeries;\r
 import org.jfree.data.xy.XYSeriesCollection;\r
 \r
@@ -23,7 +25,7 @@ public class LookupChartPanel extends ChartPanel {
     private boolean drawing;\r
     private XYSeries series; \r
     private JFreeChart chart;\r
-    private LookupInputOutputTable table;\r
+    private SeriesChangeListener changeListener;\r
 \r
     public LookupChartPanel(JFreeChart chart) {\r
         super(chart);\r
@@ -32,10 +34,6 @@ public class LookupChartPanel extends ChartPanel {
         series = collection.getSeries(0); \r
     }\r
 \r
-    public void setTable(LookupInputOutputTable table) {\r
-        this.table = table;\r
-    }\r
-\r
     public void mouseDragged(MouseEvent e)\r
     {\r
         if(dragPrevEntity != null) {\r
@@ -87,9 +85,13 @@ public class LookupChartPanel extends ChartPanel {
     }\r
 \r
     public void mouseReleased(MouseEvent e) {\r
-\r
-        dragPrevEntity = null;\r
+        if(isDragging()) {\r
+            dragPrevEntity = null;\r
+            if(changeListener != null)\r
+                changeListener.seriesChanged(null);\r
+        }\r
         drawing = false;\r
+\r
     }\r
 \r
     public void mouseClicked(MouseEvent e)\r
@@ -130,14 +132,18 @@ public class LookupChartPanel extends ChartPanel {
     public void addLocationToSeries(Point2D location) {\r
         if(series.indexOf(location.getX()) < 0) {\r
             series.add(location.getX(), location.getY());\r
-            table.addLocation(location);\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
-        table.removeLocation(location);\r
+    }\r
+    \r
+    public void resetChart(XYDataset dataset) {\r
+        XYPlot plot = (XYPlot)chart.getPlot();\r
+        plot.setDataset(dataset);\r
+        XYSeriesCollection collection = (XYSeriesCollection) plot.getDataset();\r
+        series = collection.getSeries(0); \r
     }\r
 \r
     private Point2D getMouseLocation(MouseEvent e) {\r
@@ -148,5 +154,12 @@ public class LookupChartPanel extends ChartPanel {
         return p;\r
     }\r
 \r
+    public void addSeriesChangeListener(SeriesChangeListener listener) {\r
+        this.changeListener = listener;\r
+        this.series.addChangeListener(changeListener);\r
+    }\r
 \r
+    public boolean isDragging() {\r
+        return dragPrevEntity != null;\r
+    }\r
 }\r
index 9ed5030f1a4420cb465a247fa9731149cc02a301..f9f5c03b42d78bfd357fd27d4fea16397444cd55 100644 (file)
@@ -8,6 +8,7 @@ import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.viewers.ArrayContentProvider;\r
 import org.eclipse.jface.viewers.CellEditor;\r
+import org.eclipse.jface.viewers.ICellModifier;\r
 import org.eclipse.jface.viewers.ITableLabelProvider;\r
 import org.eclipse.jface.viewers.LabelProvider;\r
 import org.eclipse.jface.viewers.TableViewer;\r
@@ -17,6 +18,9 @@ import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.graphics.Image;\r
 import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Event;\r
+import org.eclipse.swt.widgets.Item;\r
+import org.eclipse.swt.widgets.Listener;\r
 import org.eclipse.swt.widgets.Table;\r
 import org.eclipse.swt.widgets.TableColumn;\r
 \r
@@ -26,9 +30,9 @@ public class LookupInputOutputTable extends Composite {
     public static final String OUTPUT = "Output";\r
     public static final String[] PROPS = { INPUT, OUTPUT };\r
 \r
-    Table table;\r
-    TableViewer tableViewer;\r
-    List<InputOutput> tableRows;\r
+    private Table table;\r
+    private TableViewer tableViewer;\r
+    private List<InputOutput> tableRows;\r
 \r
     public LookupInputOutputTable(Composite parent, int style) {\r
         super(parent, style);\r
@@ -43,7 +47,7 @@ public class LookupInputOutputTable extends Composite {
         TableColumn column1 = new TableColumn (table, SWT.LEFT);\r
         column1.setText (INPUT);\r
         column1.setWidth (85);\r
-        \r
+\r
         TableColumn column2 = new TableColumn (table, SWT.LEFT);\r
         column2.setText (OUTPUT);\r
         column2.setWidth (85);\r
@@ -53,6 +57,7 @@ public class LookupInputOutputTable extends Composite {
 \r
         tableViewer.setContentProvider (new ArrayContentProvider());\r
         tableViewer.setLabelProvider (new InputOutputLabelProvider());\r
+        tableViewer.setCellModifier(new InputOutputCellModifier());\r
 \r
         tableRows = new ArrayList<InputOutput>();     \r
         tableViewer.setInput(tableRows);\r
@@ -62,7 +67,7 @@ public class LookupInputOutputTable extends Composite {
         editors[1] = new TextCellEditor(table);\r
         tableViewer.setCellEditors(editors);\r
         tableViewer.setColumnProperties(PROPS);\r
-        \r
+\r
     }\r
 \r
     private class InputOutputLabelProvider extends LabelProvider implements ITableLabelProvider {\r
@@ -93,25 +98,30 @@ public class LookupInputOutputTable extends Composite {
 \r
     }\r
 \r
-    public void removeLocation(Point2D location) {\r
-        for(InputOutput io : tableRows) {\r
-            if((Double)io.getInput(Double.class) == location.getX()) {\r
-                tableRows.remove(io);\r
-                tableViewer.getTable().getDisplay().asyncExec(new Runnable() {\r
-\r
-                    @Override\r
-                    public void run() {\r
-                        refresh();\r
-                    }\r
-                });\r
-                break;\r
+    public void removeItem(int index) {\r
+        tableRows.remove(index);\r
+        tableViewer.getTable().getDisplay().asyncExec(new Runnable() {\r
+\r
+            @Override\r
+            public void run() {\r
+                refresh();\r
             }\r
-        }\r
+        });\r
+    }\r
+\r
+    public void clearTable() {\r
+        this.tableRows.clear();\r
+        tableViewer.getTable().getDisplay().asyncExec(new Runnable() {\r
 \r
+            @Override\r
+            public void run() {\r
+                refresh();\r
+            }\r
+        });\r
     }\r
 \r
\r
-    class InputOutput {\r
+\r
+    public class InputOutput {\r
         private double input, output;\r
 \r
         public InputOutput(double input, double output) {\r
@@ -190,13 +200,60 @@ public class LookupInputOutputTable extends Composite {
             return 0;\r
         }\r
     }\r
-    \r
+\r
     public TableViewer getTableViewer() {\r
         return this.tableViewer;\r
     }\r
-    \r
+\r
     public void refresh() {\r
         tableViewer.setComparator(new InputOutputComparator());\r
         tableViewer.refresh();\r
     }\r
+\r
+    class InputOutputCellModifier implements ICellModifier {\r
+\r
+        public InputOutputCellModifier() {}\r
+\r
+        public boolean canModify(Object element, String property) {\r
+            return true;\r
+        }\r
+\r
+        public Object getValue(Object element, String property) {\r
+            InputOutput io = (InputOutput)element;\r
+            if (LookupInputOutputTable.INPUT.equals(property))\r
+                return (String)io.getInput(String.class);\r
+            else if (LookupInputOutputTable.OUTPUT.equals(property))\r
+                return (String)io.getOutput(String.class);\r
+            else\r
+                return null;\r
+        }\r
+\r
+        public void modify(Object element, String property, Object value) {\r
+            if (element instanceof Item) element = ((Item) element).getData();\r
+\r
+            InputOutput io = (InputOutput)element;\r
+\r
+            if (LookupInputOutputTable.INPUT.equals(property)) {\r
+                io.setInput((String)value);\r
+            } else if (LookupInputOutputTable.OUTPUT.equals(property)) {\r
+                io.setOutput((String)value);\r
+            }\r
+            tableModified();\r
+            refresh();\r
+        }\r
+    }\r
+    \r
+    private void tableModified() {\r
+        tableViewer.getTable().getDisplay().asyncExec(new Runnable() {\r
+\r
+            @Override\r
+            public void run() {\r
+                for (Listener listener : getListeners(SWT.Modify)) {\r
+                    Event e = new Event();\r
+                    listener.handleEvent(e);\r
+                }\r
+            }\r
+        });\r
+\r
+    }\r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupPopup.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupPopup.java
deleted file mode 100644 (file)
index c7d3cfd..0000000
+++ /dev/null
@@ -1,435 +0,0 @@
-package org.simantics.sysdyn.ui.properties.widgets.expressions;\r
-\r
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.GridLayout;\r
-import java.awt.event.MouseEvent;\r
-import java.awt.geom.Ellipse2D;\r
-import java.awt.geom.Point2D;\r
-import java.io.StringReader;\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import javax.swing.JComponent;\r
-import javax.swing.JPanel;\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
-import org.eclipse.swt.widgets.Item;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.swt.widgets.Table;\r
-import org.eclipse.swt.widgets.TableItem;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.eclipse.swt.widgets.Widget;\r
-import org.jfree.chart.ChartFactory;\r
-import org.jfree.chart.JFreeChart;\r
-import org.jfree.chart.axis.ValueAxis;\r
-import org.jfree.chart.plot.PlotOrientation;\r
-import org.jfree.chart.plot.XYPlot;\r
-import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;\r
-import org.jfree.data.xy.XYDataItem;\r
-import org.jfree.data.xy.XYDataset;\r
-import org.jfree.data.xy.XYSeries;\r
-import org.jfree.data.xy.XYSeriesCollection;\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.properties.widgets.expressions.LookupInputOutputTable.InputOutput;\r
-\r
-public class LookupPopup extends Dialog {\r
-\r
-    JFreeChart chart;\r
-    LookupInputOutputTable table;\r
-    ArrayList<Point2D> dataPoints;\r
-    Text input, output;\r
-    Text minX, maxX, minY, maxY;\r
-    Label unit;\r
-    LookupChartInfo chartInfo;\r
-\r
-    protected LookupPopup(Shell parentShell, LookupChartInfo chartInfo) {\r
-        super(parentShell);\r
-        this.chartInfo = chartInfo;\r
-        this.dataPoints = new ArrayList<Point2D>();\r
-        TableParser parser = new TableParser(new StringReader(""));\r
-        parser.ReInit(new StringReader(chartInfo.lookupTable));\r
-        try {\r
-            parser.table();\r
-            ArrayList<Token> xTokens = parser.getXTokens();\r
-            for(Token token : xTokens) {\r
-                dataPoints.add(new Point2D.Double(\r
-                        Double.parseDouble(token.image), \r
-                        Double.parseDouble(token.next.next.image)));\r
-            }\r
-        } catch (ParseException e1) {\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
-            @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
-        chartPanel.setRangeZoomable(false);\r
-\r
-        XYPlot plot = (XYPlot) chart.getPlot();\r
-        ValueAxis rangeAxis = plot.getRangeAxis();\r
-        ValueAxis domainAxis = plot.getDomainAxis();\r
-\r
-        Composite container = new Composite(parent, SWT.None);\r
-        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(container);\r
-\r
-        Composite yAxis = new Composite(container, SWT.NONE);\r
-        GridLayoutFactory.fillDefaults().applyTo(yAxis);\r
-        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().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
-        SWTAWTComponent c = new SWTAWTComponent(container, SWT.BORDER) {\r
-            @Override\r
-            protected JComponent createSwingComponent() {\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
-                panel.doLayout();\r
-                return panel;\r
-            }\r
-        };\r
-        GridDataFactory.fillDefaults().hint(500, 300).applyTo(c);\r
-        c.populate();\r
-\r
-\r
-        Composite valueTableComposite = new Composite(container, SWT.NONE);\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().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
-            @Override\r
-            public void mouseUp(org.eclipse.swt.events.MouseEvent e) {\r
-                if(e.button == MouseEvent.BUTTON3) {\r
-                    Table table = (Table)e.widget;\r
-                    TableItem item = (TableItem)table.getItem(new org.eclipse.swt.graphics.Point(e.x, e.y));\r
-                    chartPanel.removeItemFromSeries(table.indexOf(item));\r
-                }\r
-            }\r
-            @Override\r
-            public void mouseDown(org.eclipse.swt.events.MouseEvent e) { }\r
-            @Override\r
-            public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent e) { }\r
-        });\r
-        for(Point2D location : this.dataPoints) {\r
-            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
-\r
-        Composite xAxis = new Composite(container, SWT.NONE);\r
-        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
-        minX.addKeyListener(enterListener);\r
-        minX.addModifyListener(getAxisBoundModifyListener());\r
-        minX.setText("" + domainAxis.getLowerBound());\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 LookupChartInfo open(Boolean bool) {\r
-        Shell shell = this.getShell();\r
-        if (shell == null || shell.isDisposed()) {\r
-            shell = null;\r
-            create();\r
-            shell = this.getShell();\r
-        }\r
-        constrainShellSize();\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 chartInfo;\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
-        b.append("{");\r
-        XYSeriesCollection collection = (XYSeriesCollection) ((XYPlot)chart.getPlot()).getDataset();\r
-        XYSeries series = collection.getSeries(0);\r
-        if(series.isEmpty())\r
-            return "";\r
-        Iterator iterator = series.getItems().iterator();\r
-        while(iterator.hasNext()){\r
-            XYDataItem item = (XYDataItem)iterator.next();\r
-            b.append("{" + item.getX() + "," + item.getY() + "}");\r
-            if(iterator.hasNext())\r
-                b.append(",");\r
-        }\r
-        b.append("}");\r
-        return b.toString();\r
-    }\r
-\r
-    private JFreeChart createChart() {\r
-        XYDataset dataset = createDataset();\r
-        chart = ChartFactory.createXYLineChart(null, null, null,\r
-                dataset, PlotOrientation.VERTICAL, false, true, false);\r
-        XYPlot plot = (XYPlot) chart.getPlot();\r
-        XYLineAndShapeRenderer renderer\r
-        = (XYLineAndShapeRenderer) plot.getRenderer();\r
-        renderer.setBaseShapesVisible(true);\r
-        renderer.setDrawOutlines(true);\r
-        renderer.setUseFillPaint(true);\r
-        renderer.setBaseFillPaint(Color.white);\r
-        renderer.setSeriesStroke(0, new BasicStroke(3.0f));\r
-        renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));\r
-        renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));\r
-\r
-        ValueAxis rangeAxis = plot.getRangeAxis();\r
-        rangeAxis.setAutoRange(false);\r
-        rangeAxis.setRange(chartInfo.minY, chartInfo.maxY);\r
-        ValueAxis domainAxis = plot.getDomainAxis();\r
-        domainAxis.setAutoRange(false);\r
-        domainAxis.setRange(chartInfo.minX, chartInfo.maxX);\r
-        return chart;\r
-    }\r
-\r
-    public XYDataset createDataset() {\r
-        XYSeries series = new XYSeries("Series");\r
-        XYSeriesCollection dataset = new XYSeriesCollection();\r
-        dataset.addSeries(series);\r
-        return dataset;\r
-    }\r
-\r
-    private ModifyListener getAxisBoundModifyListener() {\r
-        return new ModifyListener() {\r
-\r
-            @Override\r
-            public void modifyText(ModifyEvent e) {\r
-                Widget widget = e.widget;\r
-                if(widget instanceof Text) {\r
-                    Text text = (Text)widget;\r
-                    Double value;\r
-                    try {\r
-                        value = Double.parseDouble(text.getText());\r
-                    } catch (NumberFormatException e1 ) {\r
-                        return;\r
-                    }\r
-                    XYPlot plot = (XYPlot) chart.getPlot();\r
-                    ValueAxis rangeAxis = plot.getRangeAxis();\r
-                    ValueAxis domainAxis = plot.getDomainAxis();\r
-                    if(text == minX) {\r
-                        domainAxis.setLowerBound(value);\r
-                    } else if (text == maxX) {\r
-                        domainAxis.setUpperBound(value);\r
-                    } else if (text == minY) {\r
-                        rangeAxis.setLowerBound(value);\r
-                    } else if (text == maxY) {\r
-                        rangeAxis.setUpperBound(value);\r
-                    }\r
-                }\r
-            }\r
-        };\r
-    }\r
-\r
-    private class InputOutputCellModifier implements ICellModifier {\r
-\r
-        XYSeries series;\r
-\r
-        public InputOutputCellModifier() {\r
-            XYSeriesCollection collection = (XYSeriesCollection) ((XYPlot)chart.getPlot()).getDataset();\r
-            series = collection.getSeries(0); \r
-        }\r
-\r
-        public boolean canModify(Object element, String property) {\r
-            return true;\r
-        }\r
-\r
-        public Object getValue(Object element, String property) {\r
-            InputOutput io = (InputOutput)element;\r
-            if (LookupInputOutputTable.INPUT.equals(property))\r
-                return (String)io.getInput(String.class);\r
-            else if (LookupInputOutputTable.OUTPUT.equals(property))\r
-                return (String)io.getOutput(String.class);\r
-            else\r
-                return null;\r
-        }\r
-\r
-        public void modify(Object element, String property, Object value) {\r
-            if (element instanceof Item) element = ((Item) element).getData();\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
-            if (LookupInputOutputTable.INPUT.equals(property)) {\r
-                Double newX = io.setInput((String)value);\r
-                // if has the same x-value, revert back\r
-                if(newX != null && series.indexOf(newX) >= 0) {\r
-                    io.setInput(x);\r
-                }\r
-            } else if (LookupInputOutputTable.OUTPUT.equals(property)) {\r
-                io.setOutput((String)value);\r
-            }\r
-\r
-            series.add((Double)io.getInput(Double.class), (Double)io.getOutput(Double.class));\r
-\r
-            table.refresh();\r
-        }\r
-    }\r
-\r
-}\r
index 44d69cf224e0e5c9c4380d89314d37146840a537..619aeaf1a6d5c6214ee458ade4b83dfd22ffbca6 100644 (file)
@@ -25,10 +25,7 @@ import org.eclipse.swt.events.FocusListener;
 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.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
 import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Label;\r
 import org.jfree.chart.ChartFactory;\r
@@ -44,8 +41,10 @@ import org.simantics.db.Resource;
 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.db.request.Read;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.representation.Auxiliary;\r
 import org.simantics.sysdyn.tableParser.ParseException;\r
 import org.simantics.sysdyn.tableParser.TableParser;\r
 import org.simantics.sysdyn.tableParser.Token;\r
@@ -55,14 +54,13 @@ public class WithLookupExpression implements IExpression {
 \r
     private ExpressionField expression;\r
     private ExpressionField lookup;\r
-    private Button asGraph;\r
     private ExpressionField lastSelectedText = expression;\r
-    private Resource variable;\r
-    private LookupChartInfo chartInfo;\r
     private Timer updateChartTimer;\r
+\r
+    private ChartPanel smallPanel;\r
+    private Frame smallFrame;\r
     \r
-    ChartPanel smallPanel;\r
-    Frame smallFrame;\r
+    private Resource variable;\r
 \r
     public WithLookupExpression(Resource variable) {\r
         this.variable = variable;\r
@@ -71,9 +69,9 @@ public class WithLookupExpression implements IExpression {
     @Override\r
     public void createExpressionFields(Composite parent, final Map<String, Object> data) {\r
         GridLayoutFactory.fillDefaults().numColumns(3).applyTo(parent);\r
-        \r
+\r
         updateChartTimer = new Timer(1000, new ActionListener() {\r
-            \r
+\r
             @Override\r
             public void actionPerformed(ActionEvent e) {\r
                 updateChart();\r
@@ -101,7 +99,7 @@ public class WithLookupExpression implements IExpression {
 \r
         Composite chartContainer = new Composite(parent, SWT.NONE);\r
         createChart(chartContainer, data);\r
-        \r
+\r
 \r
         l = new Label(parent, SWT.NONE);\r
         l.setText("Lookup\ntable");\r
@@ -117,9 +115,9 @@ public class WithLookupExpression implements IExpression {
                 lastSelectedText = lookup;\r
             }\r
         });\r
-        \r
+\r
         lookup.getSourceViewer().getTextWidget().addModifyListener(new ModifyListener() {\r
-            \r
+\r
             @Override\r
             public void modifyText(ModifyEvent e) {\r
                 if(!updateChartTimer.isRunning())\r
@@ -129,6 +127,48 @@ public class WithLookupExpression implements IExpression {
             }\r
         });\r
         \r
+        \r
+        SimanticsUI.getSession().asyncRequest(new Read<String>() {\r
+\r
+            @Override\r
+            public String perform(ReadGraph graph) throws DatabaseException {\r
+                SysdynResource sr = SysdynResource.getInstance(graph);\r
+                Resource expression = graph.getPossibleObject(variable, sr.HasExpression);\r
+                String result = "";\r
+                if (expression != null && graph.isInstanceOf(expression, sr.WithLookupExpression)) {\r
+                    result = graph.getRelatedValue(expression, sr.HasLookup);\r
+                }\r
+                return result;\r
+            }\r
+        }, 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 result) {\r
+                if(lookup != null)\r
+                    lookup.getDisplay().asyncExec(new Runnable() {\r
+                        \r
+                        @Override\r
+                        public void run() {\r
+                            lookup.setExpression(result);                            \r
+                        }\r
+                    });\r
+                updateChart();\r
+            }\r
+\r
+            @Override\r
+            public boolean isDisposed() {\r
+                if(lookup != null && !lookup.isDisposed()) {\r
+                    return false;\r
+                }\r
+                return true;\r
+            }\r
+        });\r
+\r
         updateChart();\r
     }\r
 \r
@@ -144,32 +184,37 @@ public class WithLookupExpression implements IExpression {
 \r
     @Override\r
     public void readData(final Resource variable, Map<String, Object> data) {\r
-        String[] results = null;\r
+        \r
+        class Auxiliary {\r
+            String equation, lookup;\r
+        }\r
+        \r
+        Auxiliary results = null;\r
+\r
         if (variable != null && data.get("equation") == null) {\r
             try {\r
-                results = SimanticsUI.getSession().syncRequest(new Read<String[]>() {\r
+                results = SimanticsUI.getSession().syncRequest(new Read<Auxiliary>() {\r
 \r
                     @Override\r
-                    public String[] perform(ReadGraph graph) throws DatabaseException {\r
-                        String[] results = new String[2];\r
+                    public Auxiliary perform(ReadGraph graph) throws DatabaseException {\r
+                        Auxiliary results = new Auxiliary();\r
                         SysdynResource sr = SysdynResource.getInstance(graph);\r
                         Resource expression = graph.getPossibleObject(variable, sr.HasExpression);\r
                         if (expression != null && graph.isInstanceOf(expression, sr.WithLookupExpression)) {\r
-                            results[0] = graph.getRelatedValue(expression, sr.HasEquation);\r
-                            results[1] = graph.getRelatedValue(expression, sr.HasLookup);\r
+                            results.equation = graph.getRelatedValue(expression, sr.HasEquation);\r
+                            results.lookup = graph.getRelatedValue(expression, sr.HasLookup);\r
                         } else {\r
-                            results[0] = "";\r
-                            results[1] = "";\r
+                            results.equation = "";\r
+                            results.lookup = "";\r
                         }\r
                         return results;\r
                     }\r
-\r
                 });\r
             } catch (DatabaseException e1) {\r
                 e1.printStackTrace();\r
             }\r
-            data.put("equation", results[0]);\r
-            data.put("lookup", results[1]);\r
+            data.put("equation", results.equation);\r
+            data.put("lookup", results.lookup);\r
         }\r
 \r
     }\r
@@ -212,12 +257,14 @@ public class WithLookupExpression implements IExpression {
                     g.claim(variable, sr.HasExpression, expression);\r
                     g.claimValue(expression, sr.HasEquation, currentExpression);\r
                     g.claimValue(expression, sr.HasLookup, currentLookupTable);\r
-                    if(chartInfo != null) {\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
+                    if(!g.hasStatement(expression, sr.HasMinX))\r
+                        g.claimValue(expression, sr.HasMinX, 0.0);\r
+                    if(!g.hasStatement(expression, sr.HasMaxX))\r
+                        g.claimValue(expression, sr.HasMaxX, 10.0);\r
+                    if(!g.hasStatement(expression, sr.HasMinY))\r
+                        g.claimValue(expression, sr.HasMinY, 0.0);\r
+                    if(!g.hasStatement(expression, sr.HasMaxY))\r
+                        g.claimValue(expression, sr.HasMaxY, 10.0);\r
                 }\r
             });\r
         }\r
@@ -229,13 +276,7 @@ public class WithLookupExpression implements IExpression {
         if(this.expression != null && this.expression.getExpression() != null)\r
             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
+            data.put("lookup", this.lookup.getExpression());   \r
     }\r
 \r
     @Override\r
@@ -255,7 +296,7 @@ public class WithLookupExpression implements IExpression {
         this.expression.getSourceViewer().getTextWidget().addFocusListener(listener);\r
         this.lookup.getSourceViewer().getTextWidget().addFocusListener(listener);\r
     }\r
-    \r
+\r
     private void createChart(Composite composite, final Map<String, Object> data) {\r
         GridLayoutFactory.fillDefaults().applyTo(composite);\r
         GridDataFactory.fillDefaults().span(1, 2).hint(150, SWT.DEFAULT).applyTo(composite);\r
@@ -268,35 +309,19 @@ public class WithLookupExpression implements IExpression {
         JFreeChart chart = createChart(dataset);\r
         smallPanel = new ChartPanel(chart);\r
         smallFrame.add(smallPanel);\r
-        \r
-        asGraph = new Button(composite, SWT.NONE);\r
-        GridDataFactory.fillDefaults().align(SWT.END, SWT.BEGINNING).applyTo(asGraph);\r
-        asGraph.setText("Configure visually");\r
-        asGraph.addSelectionListener(new SelectionAdapter() {\r
-            public void widgetSelected(SelectionEvent e) {\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
-                    updateChart();\r
-                    lookup.focus();\r
-                }\r
-            }\r
-        });\r
+\r
     }\r
-    \r
+\r
     private static JFreeChart createChart(XYDataset dataset) {\r
         JFreeChart chart = ChartFactory.createXYLineChart(\r
-            null,\r
-            null,\r
-            null,\r
-            dataset,\r
-            PlotOrientation.VERTICAL,\r
-            true,\r
-            true,\r
-            false\r
+                null,\r
+                null,\r
+                null,\r
+                dataset,\r
+                PlotOrientation.VERTICAL,\r
+                true,\r
+                true,\r
+                false\r
         );\r
         chart.removeLegend();\r
         chart.getXYPlot().getDomainAxis().setTickLabelsVisible(false);\r
@@ -308,7 +333,7 @@ public class WithLookupExpression implements IExpression {
         chart.getXYPlot().getRenderer().setSeriesStroke(0, new BasicStroke(3.0f));\r
         return chart;\r
     }\r
-    \r
+\r
     private void updateChart() {\r
         ArrayList<Point2D> dataPoints = new ArrayList<Point2D>();\r
         TableParser parser = new TableParser(new StringReader(""));\r
@@ -324,9 +349,9 @@ public class WithLookupExpression implements IExpression {
         } catch (ParseException e1) {\r
             return;\r
         }\r
-        \r
+\r
         if(dataPoints.size() == 0) return;\r
-        \r
+\r
         XYSeries series = new XYSeries("Lookup Table");\r
         for(Point2D point : dataPoints) {\r
             series.add(point.getX(), point.getY());\r
index 045bf1603011e18475cbe231052552dfbcfe63e0..7727d14ee8b29da4d769f13bda3f4828c8045530 100644 (file)
@@ -4,7 +4,6 @@ import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;
 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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyModifier.java
new file mode 100644 (file)
index 0000000..7b80094
--- /dev/null
@@ -0,0 +1,23 @@
+package org.simantics.sysdyn.ui.properties.widgets.factories;\r
+\r
+import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl;\r
+import org.simantics.databoard.binding.java.DoubleJavaBinding;\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
+\r
+public class DoublePropertyModifier extends TextModifyListenerImpl<Resource> {\r
+\r
+    final private String propertyURI;\r
+    \r
+    public DoublePropertyModifier(ISessionContext context, String propertyURI) {\r
+        this.propertyURI = propertyURI;\r
+    }\r
+\r
+    @Override\r
+    public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException {\r
+        graph.claimValue(input, graph.getResource(propertyURI), Double.parseDouble(text), DoubleJavaBinding.INSTANCE);\r
+    }\r
+\r
+}\r