<activeWhen>\r
<with\r
variable="selection">\r
- <and>\r
+ <or>\r
<test\r
args="org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
- <not>\r
- <test\r
- args="org.simantics.sysdyn.ui.browser.nodes.ModuleNode"\r
- property="org.simantics.sysdyn.ui.nodeClass">\r
- </test>\r
- </not>\r
- </and>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModuleNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </or>\r
</with>\r
</activeWhen>\r
</handler>\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
+import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.PasteHandler;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.ui.SimanticsUI;\r
\r
public class ModuleNode extends ConfigurationNode<Resource> {\r
\r
+ Resource configuration;\r
+ \r
public ModuleNode(Resource resource) {\r
super(resource);\r
+ \r
+\r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ Resource type = graph.getPossibleObject(data, Layer0.getInstance(graph).InstanceOf);\r
+ configuration = graph.getPossibleObject(type, StructuralResource2.getInstance(graph).IsDefinedBy); \r
+ }\r
+ });\r
}\r
\r
public ModuleNode(Variable variable, Resource represents) {\r
super(variable, represents);\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ Resource type = graph.getPossibleObject(data, Layer0.getInstance(graph).InstanceOf);\r
+ configuration = graph.getPossibleObject(type, StructuralResource2.getInstance(graph).IsDefinedBy); \r
+ }\r
+ });\r
+ }\r
+ \r
+ @SuppressWarnings("rawtypes")\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if(PasteHandler.class == adapter && configuration != null) \r
+ return new DefaultPasteHandler(configuration);\r
+ return super.getAdapter(adapter);\r
}\r
}\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\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.procedure.Listener;\r
import org.simantics.db.request.Read;\r
import org.simantics.layer0.Layer0;\r
\r
Listener<String> configurationNameSynchronizer;\r
private boolean disposed = false;\r
+ private Resource configuration;\r
\r
public ModuleTypeNode(Resource resource) {\r
super(resource);\r
+\r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+ Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType);\r
+ configuration = graph.getPossibleObject(type, sr2.IsDefinedBy); \r
+ }\r
+ });\r
\r
// Not the best solution for name sync\r
configurationNameSynchronizer = new Listener<String>() {\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
- Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType);\r
- Resource configuration = graph.getPossibleObject(type, sr2.IsDefinedBy);\r
- graph.claimLiteral(configuration, l0.HasLabel, result);\r
+ if(configuration != null)\r
+ graph.claimLiteral(configuration, Layer0.getInstance(graph).HasLabel, result);\r
}\r
});\r
}\r
e.printStackTrace();\r
}\r
}\r
+ \r
+ @SuppressWarnings("rawtypes")\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if(PasteHandler.class == adapter && configuration != null) \r
+ return new DefaultPasteHandler(configuration);\r
+ return super.getAdapter(adapter);\r
+ }\r
}\r
\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ //TODO: deletenodehandler for all resources\r
+\r
Shell shell = HandlerUtil.getActiveShellChecked(event);\r
ISelection sel = HandlerUtil.getCurrentSelection(event);\r
Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
- if (resources.length == 0)\r
+ if (resources.length != 1) {\r
+ // Quick fix to provide some feedback to users. Removing many items should be allowed.\r
+ MessageDialog dialog = new MessageDialog(shell, "Too many items", null, "Please select only one item to remove.", 0,\r
+ new String[] { "OK" }, 0);\r
+ dialog.create();\r
+ dialog.open();\r
return null;\r
+ }\r
\r
MessageDialog dialog = new MessageDialog(shell, "Remove Item", null, "Are you sure?", 0,\r
new String[] { "OK", "Cancel" }, 0);\r
dialog.create();\r
if (dialog.open() == 0) {\r
- //TODO: deletenodehandler for all resources\r
super.execute(event);\r
}\r
return null;\r