From: lempinen Date: Wed, 23 Nov 2011 09:12:40 +0000 (+0000) Subject: delete chart node X-Git-Tag: simantics-1.6~100 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=000102ab0d03811ecead39b104098b0e81cbf1ef;p=simantics%2Fsysdyn.git delete chart node git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23333 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index dc462d7c..9b027862 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -1024,6 +1024,10 @@ args="org.simantics.sysdyn.ui.browser.nodes.SheetNode" property="org.simantics.sysdyn.ui.nodeClass"> + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartNode.java index a51a9e4c..8e40c28b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartNode.java @@ -16,26 +16,32 @@ import java.util.Iterator; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.viewers.IStructuredSelection; import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IDropTargetNode; import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.SingleObjectWithType; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.JFreeChartResource; import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ExceptionUtils; /** * Node representing a chart * @author Teemu Lempinen * */ -public class ChartNode extends AbstractNode implements IDropTargetNode { +public class ChartNode extends AbstractNode implements IDropTargetNode, IDeletableNode { public ChartNode(Resource data) { super(data); @@ -75,7 +81,8 @@ public class ChartNode extends AbstractNode implements IDropTargetNode Resource plot = graph.syncRequest(new SingleObjectWithType(data, l0.ConsistsOf, jfree.Plot)); - Resource dataset = graph.syncRequest(new SingleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); //FIXME: Support multiple datasets + // FIXME: order of the datasets varies in this way + Resource dataset = graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.Dataset)).iterator().next(); String rvi = Variables.getRVI(graph, variable); Resource type = l0.String; @@ -91,4 +98,19 @@ public class ChartNode extends AbstractNode implements IDropTargetNode }); } + @Override + public void delete() throws DeleteException { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + RemoverUtil.remove(graph, data); + } + }); + } catch (DatabaseException e) { + ExceptionUtils.logAndShowError(e); + } + + } + }