From bddc868e1a81b6c46eee5628f4013c705727749a Mon Sep 17 00:00:00 2001 From: lempinen Date: Mon, 16 May 2011 13:32:50 +0000 Subject: [PATCH] Copy Enumerations to modules and configurations. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20970 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/plugin.xml | 18 +++++---- .../sysdyn/ui/browser/nodes/ModuleNode.java | 37 +++++++++++++++++++ .../ui/browser/nodes/ModuleTypeNode.java | 31 +++++++++++++--- .../ui/handlers/UnlinkNodeHandler2.java | 11 +++++- 4 files changed, 81 insertions(+), 16 deletions(-) diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 563a7dd3..c8dec6a2 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -903,18 +903,20 @@ - + - - - - - + + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java index cf69782a..0f2dc7c5 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java @@ -11,16 +11,53 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.browser.nodes; +import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.PasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; import org.simantics.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.ui.SimanticsUI; public class ModuleNode extends ConfigurationNode { + Resource configuration; + public ModuleNode(Resource resource) { super(resource); + + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource type = graph.getPossibleObject(data, Layer0.getInstance(graph).InstanceOf); + configuration = graph.getPossibleObject(type, StructuralResource2.getInstance(graph).IsDefinedBy); + } + }); } public ModuleNode(Variable variable, Resource represents) { super(variable, represents); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource type = graph.getPossibleObject(data, Layer0.getInstance(graph).InstanceOf); + configuration = graph.getPossibleObject(type, StructuralResource2.getInstance(graph).IsDefinedBy); + } + }); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(PasteHandler.class == adapter && configuration != null) + return new DefaultPasteHandler(configuration); + return super.getAdapter(adapter); } } 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 95602d5f..b1da3bb2 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 @@ -23,10 +23,13 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; 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.procedure.Listener; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; @@ -40,9 +43,21 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable Listener configurationNameSynchronizer; private boolean disposed = false; + private Resource configuration; public ModuleTypeNode(Resource resource) { super(resource); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + ModelingResources mr = ModelingResources.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType); + configuration = graph.getPossibleObject(type, sr2.IsDefinedBy); + } + }); // Not the best solution for name sync configurationNameSynchronizer = new Listener() { @@ -53,12 +68,8 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable @Override public void perform(WriteGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - StructuralResource2 sr2 = StructuralResource2.getInstance(graph); - Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType); - Resource configuration = graph.getPossibleObject(type, sr2.IsDefinedBy); - graph.claimLiteral(configuration, l0.HasLabel, result); + if(configuration != null) + graph.claimLiteral(configuration, Layer0.getInstance(graph).HasLabel, result); } }); } @@ -154,4 +165,12 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable e.printStackTrace(); } } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(PasteHandler.class == adapter && configuration != null) + return new DefaultPasteHandler(configuration); + return super.getAdapter(adapter); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler2.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler2.java index 15bc5fd6..e616b0a7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler2.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler2.java @@ -25,17 +25,24 @@ public class UnlinkNodeHandler2 extends DeleteNodeHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { + //TODO: deletenodehandler for all resources + Shell shell = HandlerUtil.getActiveShellChecked(event); ISelection sel = HandlerUtil.getCurrentSelection(event); Resource[] resources = ResourceAdaptionUtils.toResources(sel); - if (resources.length == 0) + if (resources.length != 1) { + // Quick fix to provide some feedback to users. Removing many items should be allowed. + MessageDialog dialog = new MessageDialog(shell, "Too many items", null, "Please select only one item to remove.", 0, + new String[] { "OK" }, 0); + dialog.create(); + dialog.open(); return null; + } MessageDialog dialog = new MessageDialog(shell, "Remove Item", null, "Are you sure?", 0, new String[] { "OK", "Cancel" }, 0); dialog.create(); if (dialog.open() == 0) { - //TODO: deletenodehandler for all resources super.execute(event); } return null; -- 2.47.1