From: lempinen Date: Thu, 20 Oct 2011 13:18:20 +0000 (+0000) Subject: Making sure issues and other things are removed properly X-Git-Tag: simantics-1.5~3 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=4fecfb1ff3c54e448004290d3a62133415fd2abf;p=simantics%2Fsysdyn.git Making sure issues and other things are removed properly git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@22895 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java index 36c840ff..32654013 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java @@ -25,7 +25,9 @@ public class ModuleTypeLabeler extends LabelerContributor{ public String getLabel(ReadGraph graph, ModuleTypeNode moduleType) throws DatabaseException { ModelingResources mr = ModelingResources.getInstance(graph); Resource typeResource = graph.getPossibleObject(moduleType.data, mr.SymbolToComponentType); - String label = graph.getPossibleRelatedValue(typeResource, Layer0.getInstance(graph).HasName); + String label = null; + if(typeResource != null) + label = graph.getPossibleRelatedValue(typeResource, Layer0.getInstance(graph).HasName); return label == null ? "ModuleType (no name)" : label; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java index b570ff86..77113d48 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java @@ -8,8 +8,8 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.OrderedSetUtils; 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.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; import org.simantics.utils.ui.ExceptionUtils; @@ -30,9 +30,7 @@ public class EnumerationNode extends VariableNode implements IDeletabl SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { - Layer0 l0 = Layer0.getInstance(graph); SysdynResource sr = SysdynResource.getInstance(graph); - graph.deny(data, l0.PartOf); for(Resource redeclaration : graph.getObjects(data, sr.ReplacedEnumeration_Inverse)) { graph.deny(redeclaration, sr.HasRedeclaration_Inverse); } @@ -45,6 +43,8 @@ public class EnumerationNode extends VariableNode implements IDeletabl OrderedSetUtils.remove(graph, list, data); } + RemoverUtil.remove(graph, data); + } }); } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java index 4a79256d..9bc33413 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java @@ -25,7 +25,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.project.IProject; import org.simantics.simulation.project.IExperimentManager; import org.simantics.sysdyn.SysdynResource; @@ -73,12 +73,11 @@ public class ExperimentNode extends AbstractNode implements IDoubleCli SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { - Layer0 l0 = Layer0.getInstance(graph); Collection results = graph.getObjects(data, SysdynResource.getInstance(graph).HasResult); if(results != null) for(Resource result : results) SimulationResultNode.unlinkResult(graph, result); - graph.deny(data, l0.PartOf); + RemoverUtil.remove(graph, data); } }); } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java index eddb126b..becb2cd1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java @@ -22,6 +22,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.manager.FunctionUtils; @@ -58,14 +59,13 @@ public class FunctionLibraryNode extends AbstractNode implements ID @Override public void delete() throws DeleteException { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - graph.deny(data, l0.PartOf); - } - }); + @Override + public void perform(WriteGraph graph) throws DatabaseException { + RemoverUtil.remove(graph, data); + } + }); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java index 2f2baa23..710d221c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java @@ -21,6 +21,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.manager.FunctionUtils; @@ -56,17 +57,13 @@ public class FunctionNode extends VariableNode implements IDeletableNo @Override public void delete() throws DeleteException { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - Resource partOf = graph.getSingleObject(data, l0.PartOf); - if(partOf != null) { - graph.deny(data, l0.PartOf, partOf); - } - } - }); + @Override + public void perform(WriteGraph graph) throws DatabaseException { + RemoverUtil.remove(graph, data); + } + }); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java index 86c672a3..0c77fa90 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java @@ -25,6 +25,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; import org.simantics.db.request.Write; @@ -121,7 +122,7 @@ public class ModelNode extends AbstractNode implements IDoubleClickabl if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).Result)) SimulationResultNode.deleteResultFiles(graph, r); - graph.deny(data, l0.PartOf); + RemoverUtil.remove(graph, data); } }); } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java index b1da3bb2..242f19e8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java @@ -13,6 +13,10 @@ package org.simantics.sysdyn.ui.browser.nodes; import java.util.Collection; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; import org.simantics.browsing.ui.common.node.AbstractNode; import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDeletableNode; @@ -30,8 +34,10 @@ import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.adapter.PasteHandler; import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; +import org.simantics.issues.ontology.IssueResource; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.simulation.ontology.SimulationResource; @@ -64,6 +70,9 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable @Override public void execute(final String result) { + if(result == null) + return; + SimanticsUI.getSession().asyncRequest(new WriteRequest() { @Override @@ -92,7 +101,7 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable Layer0 l0 = Layer0.getInstance(graph); ModelingResources mr = ModelingResources.getInstance(graph); Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType); - return graph.getRelatedValue(type, l0.HasName); + return (String) (type != null ? graph.getRelatedValue(type, l0.HasName) : null); } }, configurationNameSynchronizer); @@ -138,7 +147,7 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override - public void perform(WriteGraph graph) throws DatabaseException { + public void perform(WriteGraph graph) throws DatabaseException{ Layer0 l0 = Layer0.getInstance(graph); StructuralResource2 st = StructuralResource2.getInstance(graph); ModelingResources mr = ModelingResources.getInstance(graph); @@ -147,25 +156,46 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable Resource model = graph.getSingleObject(type, l0.PartOf); Resource modelConfiguration = graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration); if (!graph.syncRequest(new ObjectsWithType(modelConfiguration, l0.ConsistsOf, type)).isEmpty()) { - System.out.println("The module is used at the model configuration"); - return; + throw new ModuleDeleteException("The module is used at the model configuration"); } Collection moduleTypes = graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, st.ComponentType)); for(Resource r : moduleTypes) { Resource configuration = graph.getSingleObject(r, st.IsDefinedBy); if(!graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, type)).isEmpty()) { - System.out.println("The module is used at another module: " + graph.getRelatedValue(r, l0.HasName)); - return; + throw new ModuleDeleteException("The module is used at another module: " + graph.getRelatedValue(r, l0.HasName)); } } - graph.deny(model, l0.ConsistsOf, type); + + IssueResource ISSUE = IssueResource.getInstance(graph); + // Remove issues + for(Resource issueSource : graph.syncRequest(new ObjectsWithType(type, l0.ConsistsOf, ISSUE.DependencyIssueSource))) { + for(Resource issue : graph.syncRequest(new ObjectsWithType(issueSource, ISSUE.Manages, ISSUE.Issue))) { + RemoverUtil.remove(graph, issue); + } + } + RemoverUtil.remove(graph, type); } }); + } catch (ModuleDeleteException e) { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + MessageDialog dialog = new MessageDialog(shell, "Unable to delete", null, e.message, SWT.ERROR, + new String[] { "OK" }, 0); + dialog.create(); + dialog.open(); } catch (DatabaseException e) { e.printStackTrace(); } } + private class ModuleDeleteException extends DatabaseException { + private static final long serialVersionUID = 4076002781765246919L; + String message; + + public ModuleDeleteException(String message) { + this.message = message; + } + } + @SuppressWarnings("rawtypes") @Override public Object getAdapter(Class adapter) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java index 60b505f9..d21f18b1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java @@ -25,7 +25,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.handlers.ToggleResultActivation; import org.simantics.ui.SimanticsUI; @@ -69,11 +69,8 @@ public class SimulationResultNode extends AbstractNode implements IDo public static void unlinkResult(WriteGraph graph, Resource result) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); deleteResultFiles(graph, result); - graph.deny(result, l0.PartOf); - graph.deny(result, graph.getInverse(SysdynResource.getInstance(graph).HasResult)); - + RemoverUtil.remove(graph, result); } public static void deleteResultFiles(WriteGraph graph, Resource result) throws DatabaseException { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java index f87760de..8ad18ac6 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java @@ -133,7 +133,8 @@ public class ConfigurationTab extends LabelPropertyTabContributor { @Override public String perform(ReadGraph graph, final Resource input) throws DatabaseException { - return graph.getRelatedValue(input, SysdynResource.getInstance(graph).HasSolver); + String s = graph.getPossibleRelatedValue(input, SysdynResource.getInstance(graph).HasSolver); + return s != null ? s : ""; } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java index 2f715045..78faa6b3 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java @@ -36,8 +36,12 @@ public class ReplaceableEnumerations extends ViewpointContributorImpl Layer0 l0 = Layer0.getInstance(graph); StructuralResource2 sr2 = StructuralResource2.getInstance(graph); - Resource moduleType = graph.getSingleObject(input, l0.InstanceOf); - Resource configuration = graph.getSingleObject(moduleType, sr2.IsDefinedBy); + Resource moduleType = graph.getPossibleObject(input, l0.InstanceOf); + if(moduleType == null) + return result; + Resource configuration = graph.getPossibleObject(moduleType, sr2.IsDefinedBy); + if(configuration == null) + return result; for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) { if(Boolean.TRUE.equals(graph.getRelatedValue(r, sr.IsReplaceable))) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileNode.java index 409ee860..726ab4ac 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileNode.java @@ -21,6 +21,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.request.Write; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.manager.FunctionUtils; @@ -71,12 +72,8 @@ public class ExternalFileNode extends AbstractNode implements IModifia @Override public void perform(WriteGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - Resource function = graph.getSingleObject(data, l0.PartOf); - if(function != null) { - graph.deny(data, l0.PartOf, function); - } FunctionUtils.removeExternalFunctionFile(graph, data); + RemoverUtil.remove(graph, data); } }); }