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
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
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
OrderedSetUtils.remove(graph, list, data);\r
}\r
\r
+ RemoverUtil.remove(graph, data);\r
+ \r
}\r
});\r
} catch (DatabaseException e) {\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.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
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
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
\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
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
\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
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
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
\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
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
\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
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
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
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
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
\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
\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
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
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
\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