]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Added Delete handler for model configurations in Sysdyn.
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 16 Mar 2010 13:54:56 +0000 (13:54 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 16 Mar 2010 13:54:56 +0000 (13:54 +0000)
Removed Building library from devs.

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14977 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/META-INF/MANIFEST.MF
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DeleteItemHandler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkItemHandler.java [new file with mode: 0644]

index e234fc6a771c6cb58edb6a71f75304b639e83cd4..f9c466355ca79cf30080a4cd2ba21d1acf1ed9ab 100644 (file)
@@ -5,8 +5,6 @@ Bundle-SymbolicName: org.simantics.sysdyn.ui;singleton:=true
 Bundle-Version: 1.0.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Require-Bundle: org.simantics.h2d;bundle-version="1.0.0",
- org.simantics.db;bundle-version="0.6.2",
- org.simantics.db.management;bundle-version="0.6.2",
  org.simantics.layer0.utils;bundle-version="0.6.2",
  org.simantics.scenegraph;bundle-version="0.9.0",
  org.junit4;bundle-version="4.5.0",
@@ -18,11 +16,9 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0",
  org.simantics.project;bundle-version="1.0.0",
  org.eclipse.jface.text;bundle-version="3.5.0",
  org.eclipse.ui.editors;bundle-version="3.5.0",
- org.jfree.jchart;bundle-version="1.0.13",
  org.jfree.jcommon;bundle-version="1.0.16",
+ org.jfree.jchart;bundle-version="1.0.13",
  org.simantics.modelica;bundle-version="1.0.0",
- org.simantics.browsing.ui;bundle-version="0.9.0",
- org.simantics.browsing.ui.common;bundle-version="0.9.0",
  org.apache.log4j;bundle-version="1.2.15",
  org.eclipse.ui.console;bundle-version="3.4.0",
  org.simantics.browsing.ui.graph;bundle-version="0.9.0",
index fffda765070ef894f9966549bee4cf3672436c9e..35bacfa127258678367c3695d3b162783780d829 100644 (file)
                class="org.simantics.ui.contribution.OpenWithMenuContribution"\r
                id="org.simantics.sysdyn.ui.browser.openWithMenu">\r
          </dynamic>\r
+         <command\r
+               commandId="org.simantics.sysdyn.ui.deleteItem"\r
+               label="Delete"\r
+               style="push"\r
+               tooltip="Remove from database">\r
+            <visibleWhen checkEnabled="true">\r
+            </visibleWhen>\r
+         </command>\r
       </menuContribution>\r
       <menuContribution\r
             locationURI="popup:#SysdynDiagramPopup?after=wbStart">\r
             id="org.simantics.sysdyn.ui.rename"\r
             name="Rename">\r
       </command>\r
+      <command\r
+            id="org.simantics.sysdyn.ui.deleteItem"\r
+            name="Delete Item">\r
+      </command>\r
       <command\r
             defaultHandler="org.simantics.sysdyn.ui.actions.ToggleSimulation"\r
             id="org.simantics.sysdyn.ui.simulate"\r
             class="org.simantics.sysdyn.ui.trend.PinTrend"\r
             commandId="org.simantics.sysdyn.ui.trend.view.pin">\r
       </handler>\r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.UnlinkItemHandler"\r
+            commandId="org.simantics.sysdyn.ui.deleteItem">\r
+         <activeWhen>\r
+            <with\r
+                  variable="selection">\r
+               <test\r
+                     args="http://www.simantics.org/Sysdyn-1.0/Configuration"\r
+                     property="org.simantics.graph.resourceType">\r
+               </test>\r
+            </with>\r
+         </activeWhen>\r
+      </handler>\r
    </extension>
 </plugin>\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DeleteItemHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DeleteItemHandler.java
new file mode 100644 (file)
index 0000000..ae26afc
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\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.CancelTransactionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class DeleteItemHandler extends AbstractHandler {\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+        Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
+        if (resources.length == 0)\r
+            return null;\r
+\r
+        MessageDialog dialog = new MessageDialog(shell, "Delete Item", null, "Are you sure?", 0,\r
+                new String[] { "OK", "Cancel" }, 0);\r
+        dialog.create();\r
+        if (dialog.open() == 0)\r
+            deleteItem(resources);\r
+\r
+        return null;\r
+    }\r
+\r
+    private void deleteItem(final Resource[] resources) {\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+                    for (Resource r : resources)\r
+                        GraphUtils.remove(graph, r);\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            ExceptionUtils.logAndShowError(e);\r
+        }\r
+    }\r
+\r
+}
\ No newline at end of file
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkItemHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkItemHandler.java
new file mode 100644 (file)
index 0000000..3fe12bb
--- /dev/null
@@ -0,0 +1,68 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.db.Builtins;\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.CancelTransactionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class UnlinkItemHandler extends AbstractHandler {\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+        Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
+        if (resources.length == 0)\r
+            return null;\r
+\r
+        MessageDialog dialog = new MessageDialog(shell, "Delete Item", null, "Are you sure?", 0,\r
+                new String[] { "OK", "Cancel" }, 0);\r
+        dialog.create();\r
+        if (dialog.open() == 0)\r
+            deleteItem(resources);\r
+\r
+        return null;\r
+    }\r
+\r
+    private void deleteItem(final Resource[] resources) {\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+                    Builtins b = graph.getBuiltins();\r
+                    for (Resource r : resources)\r
+                        graph.deny(r, b.PartOf);\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            ExceptionUtils.logAndShowError(e);\r
+        }\r
+    }\r
+\r
+}
\ No newline at end of file