]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
delete chart node
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 23 Nov 2011 09:12:40 +0000 (09:12 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 23 Nov 2011 09:12:40 +0000 (09:12 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23333 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartNode.java

index dc462d7c02a6f51392facd65efe4ba3cabfb0a01..9b027862b78dbf7f325605cee52c5ede67dc08f9 100644 (file)
                         args="org.simantics.sysdyn.ui.browser.nodes.SheetNode"\r
                         property="org.simantics.sysdyn.ui.nodeClass">\r
                   </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ChartNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
                </or>\r
             </with>\r
          </activeWhen>\r
index a51a9e4c2c7f99a2c312196bbad6aec46bcbd16c..8e40c28b1f0e705473ee78d4fd156b881a2f7a0a 100644 (file)
@@ -16,26 +16,32 @@ import java.util.Iterator;
 import org.eclipse.core.runtime.IAdaptable;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
 import org.simantics.browsing.ui.common.node.IDropTargetNode;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
 import org.simantics.db.common.request.SingleObjectWithType;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.CancelTransactionException;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.sysdyn.JFreeChartResource;\r
 import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
 \r
 /**\r
  * Node representing a chart\r
  * @author Teemu Lempinen\r
  *\r
  */\r
-public class ChartNode extends AbstractNode<Resource> implements IDropTargetNode {\r
+public class ChartNode extends AbstractNode<Resource> implements IDropTargetNode, IDeletableNode {\r
 \r
     public ChartNode(Resource data) {\r
         super(data);\r
@@ -75,7 +81,8 @@ public class ChartNode extends AbstractNode<Resource> implements IDropTargetNode
 \r
                 Resource plot = graph.syncRequest(new SingleObjectWithType(data, l0.ConsistsOf, jfree.Plot));\r
 \r
-                Resource dataset = graph.syncRequest(new SingleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); //FIXME: Support multiple datasets\r
+                // FIXME: order of the datasets varies in this way\r
+                Resource dataset = graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.Dataset)).iterator().next();\r
 \r
                 String rvi = Variables.getRVI(graph, variable);\r
                 Resource type = l0.String;\r
@@ -91,4 +98,19 @@ public class ChartNode extends AbstractNode<Resource> implements IDropTargetNode
         });\r
     }\r
 \r
+    @Override\r
+    public void delete() throws DeleteException {\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+                    RemoverUtil.remove(graph, data);\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            ExceptionUtils.logAndShowError(e);\r
+        }    \r
+        \r
+    }\r
+\r
 }\r