]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Making sure issues and other things are removed properly
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 20 Oct 2011 13:18:20 +0000 (13:18 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 20 Oct 2011 13:18:20 +0000 (13:18 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@22895 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileNode.java

index 36c840ff14c7d57a1cf7f8abb9794b7d2a3aab55..32654013429277dfa5b0863e93052961b81230f0 100644 (file)
@@ -25,7 +25,9 @@ public class ModuleTypeLabeler extends LabelerContributor<ModuleTypeNode>{
     public String getLabel(ReadGraph graph, ModuleTypeNode moduleType) throws DatabaseException {\r
         ModelingResources mr = ModelingResources.getInstance(graph);\r
         Resource typeResource =  graph.getPossibleObject(moduleType.data, mr.SymbolToComponentType);\r
-        String label = graph.getPossibleRelatedValue(typeResource, Layer0.getInstance(graph).HasName);\r
+        String label = null;\r
+        if(typeResource != null)\r
+            label = graph.getPossibleRelatedValue(typeResource, Layer0.getInstance(graph).HasName);\r
         return label == null ? "ModuleType (no name)" : label;\r
     }\r
 \r
index b570ff864091dca78572a9310b8a489a3ce1150b..77113d48402616c26ec56fc69bea665d37f203d5 100644 (file)
@@ -8,8 +8,8 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.OrderedSetUtils;\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.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ExceptionUtils;\r
@@ -30,9 +30,7 @@ public class EnumerationNode extends VariableNode<Resource> implements IDeletabl
             SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
                 @Override\r
                 public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
-                    Layer0 l0 = Layer0.getInstance(graph);\r
                     SysdynResource sr = SysdynResource.getInstance(graph);\r
-                    graph.deny(data, l0.PartOf);       \r
                     for(Resource redeclaration : graph.getObjects(data, sr.ReplacedEnumeration_Inverse)) {\r
                        graph.deny(redeclaration, sr.HasRedeclaration_Inverse);\r
                     }\r
@@ -45,6 +43,8 @@ public class EnumerationNode extends VariableNode<Resource> implements IDeletabl
                        OrderedSetUtils.remove(graph, list, data);\r
                     }\r
                     \r
+                    RemoverUtil.remove(graph, data);\r
+                    \r
                 }\r
             });\r
         } catch (DatabaseException e) {\r
index 4a79256d998b3def46289e7b9fb3e9480b4f3a5e..9bc3341328418949e08e594ec9439621ffe7b74b 100644 (file)
@@ -25,7 +25,7 @@ import org.simantics.db.WriteGraph;
 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.Layer0;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
 import org.simantics.project.IProject;\r
 import org.simantics.simulation.project.IExperimentManager;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -73,12 +73,11 @@ public class ExperimentNode extends AbstractNode<Resource> implements IDoubleCli
             SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
                 @Override\r
                 public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
-                    Layer0 l0 = Layer0.getInstance(graph);\r
                     Collection<Resource> results = graph.getObjects(data, SysdynResource.getInstance(graph).HasResult);\r
                     if(results != null)\r
                         for(Resource result : results) \r
                             SimulationResultNode.unlinkResult(graph, result);\r
-                    graph.deny(data, l0.PartOf);\r
+                    RemoverUtil.remove(graph, data);\r
                 }\r
             });\r
         } catch (DatabaseException e) {\r
index eddb126b10e8f42db29d59b8f4356c93c5ffb0ac..becb2cd18711b9b73a06d1c5c7bb7647987341cd 100644 (file)
@@ -22,6 +22,7 @@ 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.layer0.util.RemoverUtil;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.manager.FunctionUtils;\r
@@ -58,14 +59,13 @@ public class FunctionLibraryNode<T> extends AbstractNode<Resource> implements ID
 \r
        @Override\r
        public void delete() throws DeleteException {\r
-               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+           SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
 \r
-                       @Override\r
-                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               graph.deny(data, l0.PartOf);\r
-                       }\r
-               });\r
+               @Override\r
+               public void perform(WriteGraph graph) throws DatabaseException {\r
+                   RemoverUtil.remove(graph, data);\r
+               }\r
+           });\r
        }\r
 \r
        @Override\r
index 2f2baa239147259da7c759ebb92dc1f29e5fda02..710d221c90ee61c11a2947e0657b513e9c3c8f19 100644 (file)
@@ -21,6 +21,7 @@ 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.layer0.util.RemoverUtil;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.manager.FunctionUtils;\r
@@ -56,17 +57,13 @@ public class FunctionNode extends VariableNode<Resource> implements IDeletableNo
 \r
        @Override\r
        public void delete() throws DeleteException {\r
-               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+           SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
 \r
-                       @Override\r
-                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               Resource partOf = graph.getSingleObject(data, l0.PartOf);\r
-                               if(partOf != null) {\r
-                                       graph.deny(data, l0.PartOf, partOf);\r
-                               }\r
-                       }\r
-               });\r
+               @Override\r
+               public void perform(WriteGraph graph) throws DatabaseException {\r
+                   RemoverUtil.remove(graph, data);\r
+               }\r
+           });\r
        }\r
        \r
        @Override\r
index 86c672a3ac350aaf2b208899bc2b0d14b1903300..0c77fa907018a0832f72e11b2fecbdf31b00a65c 100644 (file)
@@ -25,6 +25,7 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.NameUtils;\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.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.db.request.Write;\r
@@ -121,7 +122,7 @@ public class ModelNode extends AbstractNode<Resource> implements IDoubleClickabl
                         if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).Result))\r
                             SimulationResultNode.deleteResultFiles(graph, r);\r
 \r
-                    graph.deny(data, l0.PartOf);\r
+                    RemoverUtil.remove(graph, data);\r
                 }\r
             });\r
         } catch (DatabaseException e) {\r
index b1da3bb26d3d6e70d983a67eedcae69bb93a447b..242f19e84736e0b29afdecc40153a93e3a8e2d3b 100644 (file)
@@ -13,6 +13,10 @@ package org.simantics.sysdyn.ui.browser.nodes;
 \r
 import java.util.Collection;\r
 \r
+import org.eclipse.jface.dialogs.MessageDialog;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.PlatformUI;\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
@@ -30,8 +34,10 @@ import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
 import org.simantics.db.exception.ServiceException;\r
 import org.simantics.db.layer0.adapter.PasteHandler;\r
 import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
+import org.simantics.issues.ontology.IssueResource;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
@@ -64,6 +70,9 @@ public class ModuleTypeNode extends AbstractNode<Resource> implements IDeletable
 \r
                @Override\r
                        public void execute(final String result) {\r
+                   if(result == null)\r
+                       return; \r
+                   \r
                                SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
                                        \r
                                        @Override\r
@@ -92,7 +101,7 @@ public class ModuleTypeNode extends AbstractNode<Resource> implements IDeletable
                                Layer0 l0 = Layer0.getInstance(graph);\r
                 ModelingResources mr = ModelingResources.getInstance(graph);\r
                 Resource type =  graph.getPossibleObject(data, mr.SymbolToComponentType);\r
-                               return graph.getRelatedValue(type, l0.HasName);\r
+                               return (String) (type != null ? graph.getRelatedValue(type, l0.HasName) : null);\r
                        }\r
                \r
         }, configurationNameSynchronizer);\r
@@ -138,7 +147,7 @@ public class ModuleTypeNode extends AbstractNode<Resource> implements IDeletable
             SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
 \r
                 @Override\r
-                public void perform(WriteGraph graph) throws DatabaseException {\r
+                public void perform(WriteGraph graph) throws DatabaseException{\r
                        Layer0 l0 = Layer0.getInstance(graph);\r
                     StructuralResource2 st = StructuralResource2.getInstance(graph);\r
                     ModelingResources mr = ModelingResources.getInstance(graph);\r
@@ -147,25 +156,46 @@ public class ModuleTypeNode extends AbstractNode<Resource> implements IDeletable
                     Resource model = graph.getSingleObject(type, l0.PartOf);\r
                     Resource modelConfiguration = graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
                     if (!graph.syncRequest(new ObjectsWithType(modelConfiguration, l0.ConsistsOf, type)).isEmpty()) {\r
-                        System.out.println("The module is used at the model configuration");\r
-                        return;\r
+                        throw new ModuleDeleteException("The module is used at the model configuration");\r
                     }\r
                     Collection<Resource> moduleTypes = graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, st.ComponentType));\r
                     for(Resource r : moduleTypes) {\r
                         Resource configuration = graph.getSingleObject(r, st.IsDefinedBy);\r
                         if(!graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, type)).isEmpty()) {\r
-                            System.out.println("The module is used at another module: " + graph.getRelatedValue(r, l0.HasName));\r
-                            return;\r
+                            throw new ModuleDeleteException("The module is used at another module: " + graph.getRelatedValue(r, l0.HasName));\r
                         }\r
                     }\r
-                    graph.deny(model, l0.ConsistsOf, type);\r
+                    \r
+                    IssueResource ISSUE = IssueResource.getInstance(graph);\r
+                    // Remove issues\r
+                    for(Resource issueSource : graph.syncRequest(new ObjectsWithType(type, l0.ConsistsOf, ISSUE.DependencyIssueSource))) {\r
+                        for(Resource issue : graph.syncRequest(new ObjectsWithType(issueSource, ISSUE.Manages, ISSUE.Issue))) {\r
+                            RemoverUtil.remove(graph, issue);\r
+                        }\r
+                    }\r
+                    RemoverUtil.remove(graph, type);\r
                 }\r
             });\r
+        } catch (ModuleDeleteException e) {\r
+            Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();\r
+            MessageDialog dialog = new MessageDialog(shell, "Unable to delete", null, e.message, SWT.ERROR,\r
+                    new String[] { "OK" }, 0);\r
+            dialog.create();\r
+            dialog.open();\r
         } catch (DatabaseException e) {\r
             e.printStackTrace();\r
         }\r
     }\r
     \r
+    private class ModuleDeleteException extends DatabaseException {\r
+        private static final long serialVersionUID = 4076002781765246919L;\r
+        String message;\r
+        \r
+        public ModuleDeleteException(String message) {\r
+            this.message = message;\r
+        }\r
+    }\r
+    \r
     @SuppressWarnings("rawtypes")\r
     @Override\r
     public Object getAdapter(Class adapter) {\r
index 60b505f9a42e60f58f8a042cc3f57cca19197f69..d21f18b12d7caf4f0e2cbe0b852dd6afc468a4e0 100644 (file)
@@ -25,7 +25,7 @@ import org.simantics.db.WriteGraph;
 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.Layer0;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.handlers.ToggleResultActivation;\r
 import org.simantics.ui.SimanticsUI;\r
@@ -69,11 +69,8 @@ public class SimulationResultNode  extends AbstractNode<Resource> implements IDo
     \r
     \r
     public static void unlinkResult(WriteGraph graph, Resource result) throws DatabaseException  {\r
-        Layer0 l0 = Layer0.getInstance(graph);\r
         deleteResultFiles(graph, result);\r
-        graph.deny(result, l0.PartOf);\r
-        graph.deny(result, graph.getInverse(SysdynResource.getInstance(graph).HasResult));\r
-\r
+        RemoverUtil.remove(graph, result);\r
     }\r
     \r
     public static void deleteResultFiles(WriteGraph graph, Resource result) throws DatabaseException  {\r
index f87760de0302425ac762e523cda2682ddd44e611..8ad18ac6c7d8766721f37e2e7d1c22e30d391345 100644 (file)
@@ -133,7 +133,8 @@ public class ConfigurationTab extends LabelPropertyTabContributor {
 \r
             @Override\r
             public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
-                return graph.getRelatedValue(input, SysdynResource.getInstance(graph).HasSolver);\r
+                String s = graph.getPossibleRelatedValue(input, SysdynResource.getInstance(graph).HasSolver);\r
+                return s != null ? s : "";\r
             }\r
         });\r
         \r
index 2f715045628c2f87873c67d4fb987068d145fc4c..78faa6b33fb64dd84098f29cd19fef94c983698c 100644 (file)
@@ -36,8 +36,12 @@ public class ReplaceableEnumerations  extends ViewpointContributorImpl<Resource>
         Layer0 l0 = Layer0.getInstance(graph);\r
         StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
         \r
-        Resource moduleType = graph.getSingleObject(input, l0.InstanceOf);\r
-        Resource configuration = graph.getSingleObject(moduleType, sr2.IsDefinedBy);\r
+        Resource moduleType = graph.getPossibleObject(input, l0.InstanceOf);\r
+        if(moduleType == null)\r
+            return result;\r
+        Resource configuration = graph.getPossibleObject(moduleType, sr2.IsDefinedBy);\r
+        if(configuration == null)\r
+            return result;\r
         \r
                for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
                        if(Boolean.TRUE.equals(graph.getRelatedValue(r, sr.IsReplaceable)))\r
index 409ee860085677e2282e7932a77f4426d743c3d1..726ab4ac594431a4b737f5563d725d59e6db7206 100644 (file)
@@ -21,6 +21,7 @@ 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.layer0.util.RemoverUtil;\r
 import org.simantics.db.request.Write;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.manager.FunctionUtils;\r
@@ -71,12 +72,8 @@ public class ExternalFileNode extends AbstractNode<Resource> implements IModifia
 \r
                        @Override\r
                        public void perform(WriteGraph graph) throws DatabaseException {\r
-                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               Resource function = graph.getSingleObject(data, l0.PartOf);\r
-                               if(function != null) {\r
-                                       graph.deny(data, l0.PartOf, function);\r
-                               }\r
                                FunctionUtils.removeExternalFunctionFile(graph, data);\r
+                               RemoverUtil.remove(graph, data);\r
                        }\r
                });\r
        }\r