]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@21749 ac1ea38d-2e2b...
authormelander <melander@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 16 Aug 2011 06:22:44 +0000 (06:22 +0000)
committermelander <melander@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 16 Aug 2011 06:22:44 +0000 (06:22 +0000)
27 files changed:
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/ExportWizardFunction.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ExportWizardFunction.java with 93% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeFunctionLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeLibraries.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModelLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModels.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedFolderLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraries.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraryLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSubLibraries.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/ImportWizardFunction.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ImportWizardFunction.java with 86% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/SharedFunctionsFolderNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsExportPage.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardFunctionsExportPage.java with 54% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsImportPage.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardFunctionsImportPage.java with 52% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/ImportWizardMdl.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ImportWizardMdl.java with 92% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardMdlImportPage.java with 94% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ExportWizardModel.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ExportWizardModel.java with 90% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ImportWizardModel.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ImportWizardModel.java with 92% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsExportPage.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardModelsExportPage.java with 57% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardModelsImportPage.java with 90% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ExportWizardModule.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ExportWizardModule.java with 93% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ImportWizardModule.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ImportWizardModule.java with 93% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleComponentTypeNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModels.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModules.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModulesLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesExportPage.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardModulesExportPage.java with 59% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesImportPage.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardModulesImportPage.java with 50% similarity]

diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeFunctionLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeFunctionLabeler.java
new file mode 100644 (file)
index 0000000..37d85e0
--- /dev/null
@@ -0,0 +1,20 @@
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+\r
+public class FunctionTreeFunctionLabeler extends LabelerContributor<FunctionLibraryNode<Resource>>{\r
+\r
+       @Override\r
+       public String getLabel(ReadGraph graph, FunctionLibraryNode<Resource> input)\r
+                       throws DatabaseException {\r
+               String name = NameUtils.getSafeName(graph, input.data);\r
+               return name;\r
+       }\r
+\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeLibraries.java
new file mode 100644 (file)
index 0000000..f234424
--- /dev/null
@@ -0,0 +1,37 @@
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class FunctionTreeLibraries extends ViewpointContributor<ModelNode> {\r
+\r
+    @Override\r
+    public Collection<?> getContribution(ReadGraph graph, ModelNode model)\r
+    throws DatabaseException {\r
+       ArrayList<FunctionLibraryNode<Resource>> result = new ArrayList<FunctionLibraryNode<Resource>>();\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+        \r
+               for (Resource r : graph.syncRequest(new ObjectsWithType(model.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))){\r
+                       result.add(new FunctionLibraryNode<Resource>(r));\r
+               }\r
+\r
+        return result;\r
+    }\r
+\r
+    @Override\r
+    public String getViewpointId() {\r
+        return "Standard";\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModelLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModelLabeler.java
new file mode 100644 (file)
index 0000000..1a2003a
--- /dev/null
@@ -0,0 +1,17 @@
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class FunctionTreeModelLabeler extends LabelerContributorImpl<ModelNode>{\r
+\r
+       @Override\r
+       public String getLabel(ReadGraph graph, ModelNode input)\r
+                       throws DatabaseException {\r
+               return NameUtils.getSafeName(graph, input.data);\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModels.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModels.java
new file mode 100644 (file)
index 0000000..623f1a3
--- /dev/null
@@ -0,0 +1,43 @@
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class FunctionTreeModels extends ViewpointContributorImpl<Resource> {\r
+\r
+       @Override\r
+       public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+                       throws DatabaseException {\r
+               \r
+\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+               for(Resource r : graph.syncRequest(new ObjectsWithType(input, l0.ConsistsOf, sr.SysdynModel))) {\r
+                       result.add(new ModelNode(r));\r
+               }\r
+               Resource sharedlibrary = graph.getPossibleResource("http://SharedOntologies");\r
+               if (sharedlibrary != null)\r
+               result.add(new SharedFunctionsFolderNode(sharedlibrary));\r
+               \r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public String getViewpointId() {\r
+               return "Function Library Import";\r
+       }\r
+       \r
+\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedFolderLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedFolderLabeler.java
new file mode 100644 (file)
index 0000000..17f5368
--- /dev/null
@@ -0,0 +1,15 @@
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class FunctionTreeSharedFolderLabeler extends LabelerContributorImpl<SharedFunctionsFolderNode>{\r
+\r
+       @Override\r
+       public String getLabel(ReadGraph graph, SharedFunctionsFolderNode input)\r
+                       throws DatabaseException {\r
+               return "Shared Functions";\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraries.java
new file mode 100644 (file)
index 0000000..e9003a1
--- /dev/null
@@ -0,0 +1,35 @@
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+\r
+public class FunctionTreeSharedLibraries extends ViewpointContributor<SharedFunctionsFolderNode> {\r
+\r
+    @Override\r
+    public Collection<?> getContribution(ReadGraph graph, SharedFunctionsFolderNode folder)\r
+    throws DatabaseException {\r
+       ArrayList<SharedFunctionLibraryNode> result = new ArrayList<SharedFunctionLibraryNode>();\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Resource sharedlibrary = graph.getPossibleResource("http://SharedOntologies");\r
+               for (Resource r : graph.syncRequest(new ObjectsWithType(sharedlibrary, l0.ConsistsOf, sr.SharedFunctionOntology))){\r
+                       result.add(new SharedFunctionLibraryNode(r));\r
+               }\r
+        return result;\r
+    }\r
+\r
+    @Override\r
+    public String getViewpointId() {\r
+        return "Standard";\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraryLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraryLabeler.java
new file mode 100644 (file)
index 0000000..e054cf6
--- /dev/null
@@ -0,0 +1,17 @@
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+\r
+public class FunctionTreeSharedLibraryLabeler extends LabelerContributorImpl<SharedFunctionLibraryNode>{\r
+\r
+       @Override\r
+       public String getLabel(ReadGraph graph, SharedFunctionLibraryNode input)\r
+                       throws DatabaseException {\r
+               return NameUtils.getSafeName(graph, input.data);\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSubLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSubLibraries.java
new file mode 100644 (file)
index 0000000..c88421a
--- /dev/null
@@ -0,0 +1,36 @@
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+\r
+public class FunctionTreeSubLibraries extends ViewpointContributor<FunctionLibraryNode<Resource>> {\r
+\r
+    @Override\r
+    public Collection<?> getContribution(ReadGraph graph, FunctionLibraryNode<Resource> library)\r
+    throws DatabaseException {\r
+       ArrayList<FunctionLibraryNode<Resource>> result = new ArrayList<FunctionLibraryNode<Resource>>();\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+        \r
+               for (Resource r : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))){\r
+                       result.add(new FunctionLibraryNode<Resource>(r));\r
+               }\r
+\r
+        return result;\r
+    }\r
+\r
+    @Override\r
+    public String getViewpointId() {\r
+        return "Standard";\r
+    }\r
+\r
+}\r
similarity index 86%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ImportWizardFunction.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/ImportWizardFunction.java
index dd394a6706f7c9b4dffa55c00521452aa2cae548..eb8b06f53d5ffd20776ee390f2f38a99bd3d5f27 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.functions;\r
 \r
 \r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
@@ -17,14 +17,14 @@ public class ImportWizardFunction extends Wizard implements IImportWizard {
        public Resource selection;\r
 \r
     /**\r
-     * Constructor for ExternalProjectImportWizard.\r
+     * Constructor for ImportWizardFunction.\r
      */\r
     public ImportWizardFunction() {\r
        this(null);\r
     }\r
     \r
     /**\r
-     * Constructor for ExternalProjectImportWizard.\r
+     * Constructor for ImportWizardFunction.\r
      */\r
     public ImportWizardFunction(String initialPath)\r
     {\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/SharedFunctionsFolderNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/SharedFunctionsFolderNode.java
new file mode 100644 (file)
index 0000000..989c5cd
--- /dev/null
@@ -0,0 +1,65 @@
+package org.simantics.sysdyn.ui.wizards.functions;\r
+\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDropTargetNode;\r
+import org.simantics.db.Resource;\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.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+public class SharedFunctionsFolderNode extends FunctionLibraryNode<Resource> implements IDropTargetNode {\r
+\r
+    public SharedFunctionsFolderNode(Resource resource) {\r
+        super(resource);\r
+    }\r
+\r
+       @Override\r
+       public void delete() throws DeleteException {\r
+               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+                       @Override\r
+                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                               Layer0 l0 = Layer0.getInstance(graph);\r
+                               \r
+                               graph.deny(data, l0.PartOf);\r
+                               graph.deny(data, l0.IsLinkedTo_Inverse);\r
+\r
+                               // TODO: remove file\r
+                       }\r
+               });\r
+       }\r
+       \r
+       @Override\r
+       public void drop(Object data) {\r
+               final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
+               final Resource library = this.data;\r
+               if(resources.length > 0) {\r
+                       SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                       Layer0 l0 = Layer0.getInstance(graph);\r
+                                       for(Resource tobeMoved : resources) {\r
+                                               if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
+                                                               graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
+                                                       Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
+                                                       graph.deny(tobeMoved, l0.PartOf);\r
+                                                       graph.claim(tobeMoved, l0.PartOf, library);\r
+                                                       FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
+                                                       FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
+                                               }\r
+                                       }\r
+                                       \r
+                               }\r
+                       });\r
+               }\r
+       }\r
+\r
+}\r
similarity index 54%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardFunctionsExportPage.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsExportPage.java
index 83096c6448da43019913acd25280c462ed85dd4d..af6c0b215c40340bd481aca2ca5b4396adb3b6ea 100644 (file)
@@ -1,16 +1,22 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.functions;\r
 \r
 import java.io.File;\r
 import java.io.IOException;\r
 import java.util.ArrayList;\r
 \r
 import org.eclipse.core.runtime.Path;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.wizard.WizardPage;\r
 import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.ModifyEvent;\r
+import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.events.SelectionAdapter;\r
 import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
 import org.eclipse.swt.layout.GridData;\r
 import org.eclipse.swt.layout.GridLayout;\r
 import org.eclipse.swt.widgets.Button;\r
@@ -19,6 +25,9 @@ import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.databoard.Files;\r
 import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
@@ -26,13 +35,14 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
 import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.util.TransferableGraphRequest2;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
 import org.simantics.utils.datastructures.Pair;\r
 \r
 public class WizardFunctionsExportPage extends WizardPage {\r
@@ -45,9 +55,13 @@ public class WizardFunctionsExportPage extends WizardPage {
        private static String previouslyBrowsedFile = "";\r
 \r
        private Button browseDirectoriesButton;\r
-\r
-       private IStructuredSelection currentSelection;\r
-\r
+       \r
+       //private IStructuredSelection currentSelection;\r
+       \r
+       GraphExplorerComposite functionLibraryExplorer;\r
+       \r
+       private boolean selectionMade = false;\r
+       \r
        /**\r
         * Creates a new project creation wizard page.\r
         * \r
@@ -76,10 +90,10 @@ public class WizardFunctionsExportPage extends WizardPage {
        public WizardFunctionsExportPage(String pageName,String initialPath,\r
                        IStructuredSelection currentSelection) {\r
                super(pageName);\r
-               this.currentSelection = currentSelection;\r
+               //this.currentSelection = currentSelection;\r
                setPageComplete(false);\r
                setTitle("Export Function Library");\r
-               setDescription("Choose the location where the selected Function Library is exportted. The exportted Function Library is selected from the Model Browser.");\r
+               setDescription("Choose the Function Library and the export location, then press Finish.");\r
        }\r
        \r
        public void createControl(Composite parent) {\r
@@ -94,15 +108,15 @@ public class WizardFunctionsExportPage extends WizardPage {
                                | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));\r
 \r
                createProjectsRoot(workArea);\r
+               createTree(workArea);\r
+               \r
        }\r
        \r
        private void createProjectsRoot(Composite workArea) {\r
                \r
-               \r
-               // project specification group\r
-               \r
+               // set label for field\r
                Label title = new Label(workArea, SWT.NONE);\r
-               title.setText("Select export destination for Function Library:");\r
+               title.setText("Select the export location for Function Library:");\r
                \r
                Composite projectGroup = new Composite(workArea, SWT.NONE);\r
                GridLayout layout = new GridLayout();\r
@@ -113,13 +127,24 @@ public class WizardFunctionsExportPage extends WizardPage {
                projectGroup.setLayout(layout);\r
                projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));\r
                \r
-               // project location entry field\r
+               // function library location entry field\r
                this.filePathField = new Text(projectGroup, SWT.BORDER);\r
 \r
                GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false);\r
                directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25);\r
                filePathField.setLayoutData(directoryPathData);\r
                \r
+               filePathField.addModifyListener(new ModifyListener(){\r
+            @Override\r
+            public void modifyText(ModifyEvent e) {\r
+               previouslyBrowsedFile = filePathField.getText();        \r
+            }\r
+               });\r
+               if (previouslyBrowsedFile != null){\r
+                       filePathField.setText(previouslyBrowsedFile);\r
+                       validatePage();\r
+               }\r
+               \r
                // browse button\r
                browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);\r
                browseDirectoriesButton.setText("Browse");\r
@@ -139,6 +164,60 @@ public class WizardFunctionsExportPage extends WizardPage {
                \r
        }\r
        \r
+       private void createTree(Composite workArea){\r
+               \r
+               //set label for tree\r
+               Label title = new Label(workArea, SWT.NONE);\r
+               title.setText("Select Function Library to export:");\r
+\r
+               try {\r
+                       Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+                               @Override\r
+                               public Resource perform(ReadGraph graph)\r
+                                               throws DatabaseException {\r
+                                       Resource model = SimanticsUI.getProject().get();\r
+                                       return model;\r
+                               }\r
+\r
+                       });\r
+\r
+                       functionLibraryExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+                                       "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+                       functionLibraryExplorer\r
+                       .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/FunctionTree");\r
+\r
+                       functionLibraryExplorer.finish();\r
+\r
+                       functionLibraryExplorer.setInput(null, input);\r
+\r
+                       GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+                                       functionLibraryExplorer);\r
+                       \r
+                       ((Tree)functionLibraryExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
+                               \r
+                               @Override\r
+                               public void widgetSelected(SelectionEvent e) {\r
+                                       setMessage(null);\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                               @Override\r
+                               public void widgetDefaultSelected(SelectionEvent e) {\r
+                                       setMessage(null);\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                       });\r
+\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+\r
+\r
+       }\r
+    \r
        //Set filePathField active\r
        public void setVisible(boolean visible) {\r
                super.setVisible(visible);\r
@@ -149,26 +228,6 @@ public class WizardFunctionsExportPage extends WizardPage {
        //Open dialog for choosing the file\r
        protected void handleLocationDirectoryButtonPressed() {\r
                \r
-               final Resource functionLibrary2 = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
-               String name = null;\r
-               try {\r
-                       name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
-\r
-                               @Override\r
-                               public String perform(ReadGraph graph) throws DatabaseException {\r
-                                       if (!graph.hasStatement(functionLibrary2, Layer0.getInstance(graph).PartOf))\r
-                                               return null;\r
-                                       Layer0 l0 = Layer0.getInstance(graph);\r
-                                       String name = graph.syncRequest(new PossibleRelatedValue<String>(functionLibrary2, l0.HasName, Bindings.STRING ));\r
-                                       return name;\r
-                                       \r
-                               }\r
-                               \r
-                       });\r
-               } catch (DatabaseException e1) {\r
-                       e1.printStackTrace();\r
-               }\r
-               \r
                final Shell shell = filePathField.getShell();\r
                \r
                FileDialog dialog = new FileDialog(shell, SWT.SAVE);\r
@@ -176,8 +235,6 @@ public class WizardFunctionsExportPage extends WizardPage {
                String[] ext = {"*.tg"};\r
                dialog.setFilterExtensions(ext);\r
                \r
-               dialog.setFileName(name);\r
-               \r
                dialog.setText("Export Function Library");\r
 \r
                String dirName = filePathField.getText().trim();\r
@@ -189,22 +246,59 @@ public class WizardFunctionsExportPage extends WizardPage {
                \r
                String selectedFile = dialog.open();\r
                if (selectedFile != null) {\r
-                       previouslyBrowsedFile = selectedFile;\r
-                       filePathField.setText(previouslyBrowsedFile);\r
-                       setPageComplete(true);\r
+                       filePathField.setText(selectedFile);\r
+                       validatePage();\r
                }               \r
 \r
        }\r
        \r
+       //Get selection from the tree\r
+       @SuppressWarnings("unchecked")\r
+       public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+                       Class<T> clazz) {\r
+               if(explorer == null)\r
+                       return null;\r
+               ISelection selection = ((ISelectionProvider) explorer\r
+                               .getAdapter(ISelectionProvider.class)).getSelection();\r
+               if (selection == null)\r
+                       return null;\r
+               IStructuredSelection iss = (IStructuredSelection) selection;\r
+               AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+               if (inc == null)\r
+                       return null;\r
+               final T resource = (T) inc.getAdapter(clazz);\r
+\r
+               return resource;\r
+       }\r
+       \r
        public boolean createProjects(Resource selection) {\r
                \r
                final String selected = previouslyBrowsedFile;\r
                if(selected == null) return false;\r
-        final Resource modulesymbol = selection;\r
-        if(modulesymbol == null) return false;\r
-        \r
-        final Resource functionLibrary = selection;\r
+               \r
+        final Resource functionLibrary = getExplorerResource(functionLibraryExplorer, Resource.class);\r
+        if(functionLibrary == null) return false;\r
         \r
+               String name = null;\r
+               try {\r
+                       name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+                               @Override\r
+                               public String perform(ReadGraph graph) throws DatabaseException {\r
+                                       if (!graph.hasStatement(functionLibrary, Layer0.getInstance(graph).PartOf))\r
+                                               return null;\r
+                                       Layer0 l0 = Layer0.getInstance(graph);\r
+                                       String name = graph.syncRequest(new PossibleRelatedValue<String>(functionLibrary, l0.HasName, Bindings.STRING ));\r
+                                       return name;\r
+                                       \r
+                               }\r
+                               \r
+                       });\r
+               } catch (DatabaseException e1) {\r
+                       e1.printStackTrace();\r
+               }\r
+               if(name == null) return false;\r
+       \r
                SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
                        \r
                        @Override\r
@@ -229,4 +323,43 @@ public class WizardFunctionsExportPage extends WizardPage {
         \r
         return true;\r
        }\r
+       \r
+       void validatePage() {\r
+               \r
+               if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
+                       setPageComplete(false);\r
+                       return;\r
+               }\r
+               \r
+               if (functionLibraryExplorer != null){\r
+                       final Resource selectedResource = getExplorerResource(functionLibraryExplorer, Resource.class);\r
+\r
+                       String root = null;\r
+                       try {\r
+                               root = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+                                       @Override\r
+                                       public String perform(ReadGraph graph) throws DatabaseException {\r
+                                               Layer0 l0 = Layer0.getInstance(graph);\r
+                                               Resource model = graph.getPossibleObject(selectedResource, l0.PartOf);\r
+                                               String rootName = NameUtils.getSafeName(graph, model);\r
+\r
+                                               return rootName;\r
+                                       }\r
+\r
+                               });\r
+                               if (root != null && root.equalsIgnoreCase("Development Project")){\r
+                                       setPageComplete(false);\r
+                                       setMessage("Select Function Library folder under the Model or from the Shared Functions folder.");\r
+                                       return;\r
+                               }\r
+                       } catch (DatabaseException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+               \r
+               setPageComplete(true);\r
+               \r
+       }\r
+       \r
 }
\ No newline at end of file
similarity index 52%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardFunctionsImportPage.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsImportPage.java
index a6adcf964823cbfac98ff9fffeb210569c0281f3..3a5d4e50737583f6576a6b6455fb073b03102adf 100644 (file)
@@ -1,29 +1,32 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.functions;\r
 \r
 import java.io.File;\r
 import java.io.IOException;\r
-import java.util.ArrayList;\r
 \r
 import org.eclipse.core.runtime.Path;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.wizard.WizardPage;\r
 import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.CCombo;\r
 import org.eclipse.swt.events.ModifyEvent;\r
 import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.events.SelectionAdapter;\r
 import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
 import org.eclipse.swt.layout.GridData;\r
 import org.eclipse.swt.layout.GridLayout;\r
 import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.FileDialog;\r
 import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.MessageBox;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.databoard.Files;\r
 import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
@@ -31,8 +34,6 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.WriteOnlyGraph;\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.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
@@ -47,29 +48,30 @@ import org.simantics.layer0.utils.direct.GraphUtils;
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.manager.FunctionUtils;\r
 import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
-import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
 \r
 public class WizardFunctionsImportPage extends WizardPage{\r
-       \r
+\r
        // dialog store id constants\r
        private Text filePathField;\r
-       \r
+\r
        // Keep track of the archive that we browsed to last time\r
        // the wizard was invoked.\r
        private static String previouslyBrowsedFile = "";\r
 \r
        private Button browseDirectoriesButton;\r
-       \r
+\r
        private Shell shell;\r
-       \r
-       private IStructuredSelection currentSelection;\r
-       \r
-       private Resource current;\r
-       \r
+\r
+       //private IStructuredSelection currentSelection;\r
+\r
        private Resource selectedModel;\r
+\r
+       GraphExplorerComposite functionLibraryExplorer;\r
+       \r
+       private String error = "";\r
        \r
-       private String currentModelName;\r
+       private boolean selectionMade = false;\r
        \r
        /**\r
         * Creates a new project creation wizard page.\r
@@ -87,7 +89,7 @@ public class WizardFunctionsImportPage extends WizardPage{
        public WizardFunctionsImportPage(String pageName) {\r
                this(pageName,null, null);\r
        }\r
-                       \r
+\r
        /**\r
         * More (many more) parameters.\r
         * \r
@@ -98,41 +100,43 @@ public class WizardFunctionsImportPage extends WizardPage{
         */\r
        public WizardFunctionsImportPage(String pageName,String initialPath,\r
                        IStructuredSelection currentSelection) {\r
-               super(pageName);\r
+               super(pageName);\r
                setPageComplete(false);\r
-               this.currentSelection = currentSelection;\r
-               setTitle("Import Function Library to Model");\r
-               setDescription("Select Function Library from the local file system to be imported to the selected Model.");\r
+               //this.currentSelection = currentSelection;\r
+               setTitle("Import Function Library");\r
+               setDescription("Choose the Function Library file and the import location, then press Finish.");\r
        }\r
-       \r
+\r
        public void createControl(Composite parent) {\r
-               \r
+\r
                initializeDialogUnits(parent);\r
-               \r
+\r
                Composite workArea = new Composite(parent, SWT.NONE);\r
                setControl(workArea);\r
-               \r
+\r
                workArea.setLayout(new GridLayout());\r
                workArea.setLayoutData(new GridData(GridData.FILL_BOTH\r
                                | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));\r
-               \r
+\r
                createProjectsRoot(workArea);\r
+\r
+               createTree(workArea);\r
+               \r
                \r
-               createDropDown(workArea);\r
        }\r
-       \r
+\r
        private void createProjectsRoot(Composite workArea) {\r
-               \r
+\r
                //set label for field\r
                Label title = new Label(workArea, SWT.NONE);\r
                title.setText("Select Function Library source:");\r
-               \r
+\r
                Composite projectGroup = new Composite(workArea, SWT.NONE);\r
                GridLayout layout = new GridLayout();\r
                layout.numColumns = 2;\r
                layout.makeColumnsEqualWidth = false;\r
                layout.marginWidth = 0;\r
-               \r
+\r
                projectGroup.setLayout(layout);\r
                projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));\r
 \r
@@ -142,24 +146,24 @@ public class WizardFunctionsImportPage extends WizardPage{
                GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false);\r
                directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25);\r
                filePathField.setLayoutData(directoryPathData);\r
+               \r
 \r
                filePathField.addModifyListener(new ModifyListener(){\r
-            @Override\r
-            public void modifyText(ModifyEvent e) {\r
-               previouslyBrowsedFile = filePathField.getText();        \r
-            }\r
+                       @Override\r
+                       public void modifyText(ModifyEvent e) {\r
+                               previouslyBrowsedFile = filePathField.getText();        \r
+                       }\r
                });\r
                if (previouslyBrowsedFile != null){\r
                        filePathField.setText(previouslyBrowsedFile);\r
                        validatePage();\r
                }\r
-               \r
+\r
                // browse button\r
                browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);\r
                browseDirectoriesButton.setText("Browse");\r
                setButtonLayoutData(browseDirectoriesButton);\r
-               \r
-               \r
+\r
                browseDirectoriesButton.addSelectionListener(new SelectionAdapter() {\r
                        /*\r
                         * (non-Javadoc)\r
@@ -171,141 +175,127 @@ public class WizardFunctionsImportPage extends WizardPage{
                                handleLocationDirectoryButtonPressed();\r
                        }\r
                });\r
-               \r
+\r
        }\r
-       \r
-    private void createDropDown(Composite workArea) {\r
-       \r
-       final ArrayList<Pair<Resource, String>> resources = new ArrayList<Pair<Resource, String>>();\r
-       \r
-        new Label(workArea, SWT.NONE).setText("Import target:");      \r
-        \r
-        //Get resources for the DropDown-selection\r
-        try{\r
-               SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+\r
+       private void createTree(Composite workArea){\r
+               \r
+               //set label for tree\r
+               Label title = new Label(workArea, SWT.NONE);\r
+               title.setText("Select import location:");\r
+\r
+               try {\r
+                       Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+                               @Override\r
+                               public Resource perform(ReadGraph graph)\r
+                                               throws DatabaseException {\r
+                                       Resource model = SimanticsUI.getProject().get();\r
+                                       return model;\r
+                               }\r
+\r
+                       });\r
+\r
+                       functionLibraryExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+                                       "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+                       functionLibraryExplorer\r
+                       .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/FunctionTree");\r
+\r
+                       functionLibraryExplorer.finish();\r
+\r
+                       functionLibraryExplorer.setInput(null, input);\r
+\r
+                       GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+                                       functionLibraryExplorer);\r
                        \r
-                       @Override\r
-                       public void run(ReadGraph graph) throws DatabaseException {\r
-                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                       ((Tree)functionLibraryExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
                                \r
-                               Resource model;\r
-                               current = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
-                               //If there is no selection\r
-                               if(current == null){\r
-                                       model = SimanticsUI.getProject().get();\r
-                               }\r
-                               else{\r
-                                       model = graph.getPossibleObject(current, l0.PartOf);\r
-                               }                       \r
-                               currentModelName = NameUtils.getSafeName(graph, current);\r
-                               \r
-                               //Check if selection is not in top-level folder\r
-                               String modelName = NameUtils.getSafeName(graph, model);\r
-                               while (!modelName.equalsIgnoreCase("Development Project")){\r
-                                       Resource previousResource = graph.getPossibleObject(model, l0.PartOf);\r
-                                       String previousName = NameUtils.getSafeName(graph, previousResource);\r
-                                       if (previousName.equalsIgnoreCase("Development Project")){\r
-                                               currentModelName = modelName;\r
-                                       }\r
-                                       //If selection is under Built-in Functions directory\r
-                                       if (modelName.equalsIgnoreCase("Built-in Functions") || currentModelName.equalsIgnoreCase("Built-in Functions")){\r
-                                               model = SimanticsUI.getProject().get();\r
-                                               current = null;\r
-                                               break;\r
-                                       }\r
-                                       current = model;\r
-                                       model = graph.getPossibleObject(model, l0.PartOf);\r
-                                       modelName = NameUtils.getSafeName(graph, model);\r
-                               }                       \r
-                               for (Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.SysdynModel))){\r
-                                       String name = NameUtils.getSafeName(graph, r);\r
-                                       resources.add(Pair.make(r, name));\r
-                               }\r
-                               \r
-                       };\r
-               });\r
-        }\r
-               catch (DatabaseException e) {\r
+                               @Override\r
+                               public void widgetSelected(SelectionEvent e) {\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                               @Override\r
+                               public void widgetDefaultSelected(SelectionEvent e) {\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                       });\r
+\r
+               } catch (DatabaseException e) {\r
                        e.printStackTrace();\r
-                       }\r
-        //Create dropdown-bar\r
-        final CCombo drop = new CCombo(workArea, SWT.BORDER);\r
-        {\r
-            drop.setEditable(false);\r
-            drop.setText("");\r
-            drop.setToolTipText("Selects the Model where to import the Module.");\r
-            GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop);         \r
-        \r
-            //Fill the Dropdown-list\r
-            for(int a=0; a<resources.size(); a++){\r
-               drop.add(resources.get(a).second);\r
-            }\r
-            int selectionNumber = 0;\r
-            for(int a=0; a<resources.size(); a++){\r
-               if (currentModelName.equals(resources.get(a).second)){\r
-                       selectionNumber = a;\r
-                       }\r
-            }\r
-            //Show selected model as default\r
-            drop.select(selectionNumber);\r
-            selectedModel = current;\r
-            if (selectedModel == null){\r
-               selectedModel = resources.get(0).first;\r
-            }\r
-            \r
-            drop.addModifyListener(new ModifyListener(){\r
-                @Override\r
-                public void modifyText(ModifyEvent e) {\r
-                       \r
-                       for(int a=0; a<resources.size(); a++){\r
-                               if (drop.getText().equals(resources.get(a).second))\r
-                                       selectedModel = resources.get(a).first;\r
-                       }               \r
-                       validatePage();                                 \r
-                }\r
-            });\r
-        }\r
-    }\r
-       \r
+               }\r
+\r
+       }\r
+\r
        //Set filePathField active\r
        public void setVisible(boolean visible) {\r
                super.setVisible(visible);\r
                this.filePathField.setFocus();\r
        }\r
-       \r
+\r
        //Open dialog for choosing the file\r
        protected void handleLocationDirectoryButtonPressed() {\r
-               \r
+\r
                shell = filePathField.getShell();\r
-               \r
+\r
                FileDialog dialog = new FileDialog(shell, SWT.OPEN);\r
-               \r
+\r
                String[] ext = {"*.tg"};\r
                dialog.setFilterExtensions(ext);\r
-               \r
+\r
                dialog.setText("Import Function Library");\r
 \r
                String dirName = filePathField.getText().trim();\r
-               \r
+\r
                File path = new File(dirName);\r
                if (path.exists()) {\r
                        dialog.setFilterPath(new Path(dirName).toOSString());   \r
                }\r
-               \r
+\r
                String selectedFile = dialog.open();\r
                if (selectedFile != null) {\r
                        filePathField.setText(selectedFile);\r
                        validatePage();\r
                }       \r
        }\r
-       \r
+\r
+       //Get selection from the tree\r
+       @SuppressWarnings("unchecked")\r
+       public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+                       Class<T> clazz) {\r
+               \r
+               if(explorer == null)\r
+                       return null;\r
+               ISelection selection = ((ISelectionProvider) explorer\r
+                               .getAdapter(ISelectionProvider.class)).getSelection();\r
+               if (selection == null)\r
+                       return null;\r
+               IStructuredSelection iss = (IStructuredSelection) selection;\r
+               AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+               if (inc == null)\r
+                       return null;\r
+               final T resource = (T) inc.getAdapter(clazz);\r
+\r
+               return resource;\r
+       }\r
+\r
        //Create project after finish is pressed.\r
        public boolean createProjects() {\r
                \r
+               selectedModel= getExplorerResource(functionLibraryExplorer, Resource.class);\r
+               if(selectedModel == null){\r
+                       setErrorMessage("Error when retrieving resource");\r
+                       return false;\r
+               }\r
+                       \r
                String selected = previouslyBrowsedFile;\r
-               if(selected == null) return false;\r
-        \r
+               if(selected == null){\r
+                       setErrorMessage("No file selected");\r
+                       return false;\r
+               }\r
+\r
                TransferableGraph1 tg = null;\r
                try {\r
                        tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class));\r
@@ -313,15 +303,15 @@ public class WizardFunctionsImportPage extends WizardPage{
                        e.printStackTrace();\r
                        return false;\r
                } catch (IOException e) {\r
-                       MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
-                       mb.setText("Error");\r
-                       mb.setMessage("The imported file is not of type: Function Library");\r
-                       mb.open();\r
+                       setErrorMessage("The imported file is not of type: Function Library");\r
                        return false;\r
                } \r
-               if(tg == null) return false;\r
+               if(tg == null){\r
+                       setErrorMessage("The imported file is not of type: Function Library");\r
+                       return false;\r
+               }\r
+\r
 \r
-       \r
                try {\r
                        Boolean hasSharedOntologies;\r
                        hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read<Boolean>() {\r
@@ -355,73 +345,71 @@ public class WizardFunctionsImportPage extends WizardPage{
                        return false;\r
                }\r
 \r
-               \r
+\r
                SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(selectedModel);\r
                try {\r
                        DefaultPasteHandler.defaultExecute(tg, selectedModel, ia);\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
                }\r
-               \r
+\r
                final Resource root = ia.getRoot();\r
-               \r
-               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-                       \r
-                       @Override\r
-                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                           Layer0 l0 = Layer0.getInstance(graph);\r
-                           if(graph.isInstanceOf(root, SysdynResource.getInstance(graph).SharedFunctionOntology)) {\r
-                               Resource library = graph.getResource("http://SharedOntologies");\r
-                               if(!graph.hasStatement(library, l0.ConsistsOf, root)) {\r
-                                   graph.claim(library, l0.ConsistsOf, root);\r
-                               }\r
-\r
-                               SysdynResource sr = SysdynResource.getInstance(graph);\r
-                               Resource model = selectedModel;\r
-                               while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology))\r
-                                   model = graph.getSingleObject(model, l0.PartOf);\r
-                               if(graph.isInstanceOf(model, sr.SysdynModel)) {\r
-                                   graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, root);\r
-                               }\r
-\r
-                           } else if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) {\r
-                                       Resource instanceOf = graph.getPossibleObject(root,l0.InstanceOf);\r
-                                       String type = "...";\r
-                                       if(instanceOf != null)\r
-                                               type = NameUtils.getSafeName(graph, instanceOf);\r
-                                       else {\r
-                                               Resource inheritedFrom = graph.getPossibleObject(root, l0.Inherits);\r
-                                               if(inheritedFrom != null)\r
-                                                       type = NameUtils.getSafeName(graph, inheritedFrom);\r
-                                       }\r
-                                       final String ft = type; \r
-                                       graph.deny(root, l0.PartOf);\r
-                                       \r
-                                       shell.getDisplay().asyncExec(new Runnable() {\r
-                                               \r
-                                               @Override\r
-                                               public void run() {\r
-                                                       MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
-                                                       mb.setText("Error");\r
-                                                       mb.setMessage("The imported file is not of type: Function Library (" + ft +")");\r
-                                                       mb.open();                                                              \r
+\r
+               try {\r
+                       SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       Layer0 l0 = Layer0.getInstance(graph);\r
+                                       if(graph.isInstanceOf(root, SysdynResource.getInstance(graph).SharedFunctionOntology)) {\r
+                                               Resource library = graph.getResource("http://SharedOntologies");\r
+                                               if(!graph.hasStatement(library, l0.ConsistsOf, root)) {\r
+                                                       graph.claim(library, l0.ConsistsOf, root);\r
                                                }\r
-                                       });\r
-                               } else {\r
-                                       FunctionUtils.updateFunctionFileForLibrary(graph, selectedModel);\r
-                               }\r
 \r
-                       }\r
-               });\r
+                                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                               Resource model = selectedModel;\r
+                                               while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology))\r
+                                                       model = graph.getSingleObject(model, l0.PartOf);\r
+                                               if(graph.isInstanceOf(model, sr.SysdynModel)) {\r
+                                                       graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, root);\r
+                                               }\r
+\r
+                                       } else if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) {\r
+                                               Resource instanceOf = graph.getPossibleObject(root,l0.InstanceOf);\r
+                                               String type = "...";\r
+                                               if(instanceOf != null)\r
+                                                       type = NameUtils.getSafeName(graph, instanceOf);\r
+                                               else {\r
+                                                       Resource inheritedFrom = graph.getPossibleObject(root, l0.Inherits);\r
+                                                       if(inheritedFrom != null)\r
+                                                               type = NameUtils.getSafeName(graph, inheritedFrom);\r
+                                               } \r
+                                               graph.deny(root, l0.PartOf);\r
+                                               error = type;\r
+                                       } else {\r
+                                               FunctionUtils.updateFunctionFileForLibrary(graph, selectedModel);\r
+                                       }\r
+\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               if (!error.isEmpty()){\r
+                       setErrorMessage("The imported file is not of type: Function Library (" + error +")");\r
+                       error = "";\r
+                       return false;\r
+               }\r
                return true;\r
        }\r
-       \r
+\r
        private class SysdynFunctionLibraryImportAdvisor extends DefaultPasteImportAdvisor {\r
-               \r
+\r
                public SysdynFunctionLibraryImportAdvisor(Resource library) {\r
                        super(library);\r
                }\r
-               \r
+\r
                @Override\r
                public void analyzeType(ReadGraph graph, Root root) throws DatabaseException {\r
                        if(root.type.equals(SysdynResource.URIs.SharedFunctionOntology)) {\r
@@ -432,7 +420,7 @@ public class WizardFunctionsImportPage extends WizardPage{
                                }\r
                        }\r
                }\r
-               \r
+\r
                @Override\r
                public Resource createRoot(WriteOnlyGraph graph, Root root) throws DatabaseException {\r
                        Layer0 l0 = graph.getService(Layer0.class);\r
@@ -444,17 +432,17 @@ public class WizardFunctionsImportPage extends WizardPage{
                        return this.root;\r
 \r
                }\r
-               \r
+\r
        }\r
        void validatePage() {\r
-               \r
-               if (previouslyBrowsedFile.isEmpty()){\r
+\r
+               if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
                        setPageComplete(false);\r
                        return;\r
                }\r
-               \r
+               setErrorMessage(null);\r
                setPageComplete(true);\r
-               \r
+\r
        }\r
-       \r
+\r
 }
\ No newline at end of file
similarity index 92%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ImportWizardMdl.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/ImportWizardMdl.java
index 297c0926c6524f9853b11c1cbae096c6917721d8..91422841462c654858acc1c1c6cb386299da3e9e 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.mdl;\r
 \r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.wizard.Wizard;\r
similarity index 94%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardMdlImportPage.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java
index 7d390dd4b9d82218c51861ad350e2bcc59a7fb1d..bf813ba6ff1ecf0738c52f255c583e5b08fe95cd 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.mdl;\r
 \r
 import java.io.File;\r
 \r
@@ -68,7 +68,7 @@ public class WizardMdlImportPage extends WizardPage{
                super(pageName);\r
                setPageComplete(false);\r
                setTitle("Import Vensim model");\r
-               setDescription("Select Vensim model -file (.mdl) from the local file system.");\r
+               setDescription("Choose the Vensim model file (.mdl), then press Finish.");\r
        }\r
 \r
        public void createControl(Composite parent) {\r
similarity index 90%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ExportWizardModel.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ExportWizardModel.java
index 62310be4551de6828b3ecf81e2038b029f5a7807..d68f341ab0c60851d5f8a78e07d5db2b0de94771 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.models;\r
 \r
 \r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
@@ -46,7 +46,7 @@ public class ExportWizardModel extends Wizard implements IImportWizard {
 \r
        @Override\r
        public boolean performFinish() {\r
-               return mainPage.createProjects(selection);\r
+               return mainPage.createProjects();\r
        }\r
 \r
 }
\ No newline at end of file
similarity index 92%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/ImportWizardModel.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ImportWizardModel.java
index ff3841a204ae6f5718bfad7b5fc84e5ed5b443cc..e743d75055341aa373a72d52a990a2a4cfca8dcb 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.models;\r
 \r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.wizard.Wizard;\r
similarity index 57%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardModelsExportPage.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsExportPage.java
index b7ec70749ea51d57d77b8eb68b7e07def203b86a..36d147f94ef58b60859458bb05cf2a9f88ee1a4d 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.models;\r
 \r
 import java.io.File;\r
 import java.io.IOException;\r
@@ -7,14 +7,16 @@ import java.util.ArrayList;
 import org.eclipse.core.runtime.Path;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.wizard.WizardPage;\r
 import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.CCombo;\r
 import org.eclipse.swt.events.ModifyEvent;\r
 import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.events.SelectionAdapter;\r
 import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
 import org.eclipse.swt.layout.GridData;\r
 import org.eclipse.swt.layout.GridLayout;\r
 import org.eclipse.swt.widgets.Button;\r
@@ -23,23 +25,23 @@ import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.databoard.Files;\r
 import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
 import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.util.TransferableGraphRequest2;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
 import org.simantics.layer0.Layer0;\r
-import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
 import org.simantics.utils.datastructures.Pair;\r
 \r
 public class WizardModelsExportPage extends WizardPage {\r
@@ -54,13 +56,15 @@ public class WizardModelsExportPage extends WizardPage {
 \r
        private Button browseDirectoriesButton;\r
        \r
-       private IStructuredSelection currentSelection;\r
-       \r
-       private Resource current;\r
+       //private IStructuredSelection currentSelection;\r
        \r
        private Resource selectedModel;\r
        \r
-       private String currentModelName;\r
+       GraphExplorerComposite modelExplorer;\r
+       \r
+       private boolean selectionMade = false;\r
+       \r
+       \r
        \r
        /**\r
         * Creates a new project creation wizard page.\r
@@ -90,10 +94,10 @@ public class WizardModelsExportPage extends WizardPage {
        public WizardModelsExportPage(String pageName,String initialPath,\r
                        IStructuredSelection currentSelection) {\r
                super(pageName);\r
-               this.currentSelection = currentSelection;\r
+               //this.currentSelection = currentSelection;\r
                setPageComplete(false);\r
                setTitle("Export Model");\r
-               setDescription("Choose the location where the selected Model is exportted. The exportted Model is selected from the dropdown-menu.");\r
+               setDescription("Choose the Model and the export location, then press Finish.");\r
        }\r
        \r
        public void createControl(Composite parent) {\r
@@ -107,15 +111,15 @@ public class WizardModelsExportPage extends WizardPage {
                workArea.setLayoutData(new GridData(GridData.FILL_BOTH\r
                                | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));\r
                \r
-               createDropDown (workArea);\r
                createProjectsRoot(workArea);\r
+               createTree (workArea);\r
        }\r
        \r
        private void createProjectsRoot(Composite workArea) {\r
                \r
                // set label for field\r
                Label title = new Label(workArea, SWT.NONE);\r
-               title.setText("Select export destination for Model:");\r
+               title.setText("Select the export location for Model:");\r
                \r
                Composite projectGroup = new Composite(workArea, SWT.NONE);\r
                GridLayout layout = new GridLayout();\r
@@ -163,99 +167,57 @@ public class WizardModelsExportPage extends WizardPage {
                \r
        }\r
        \r
-    private void createDropDown(Composite workArea) {\r
-       \r
-       final ArrayList<Pair<Resource, String>> resources = new ArrayList<Pair<Resource, String>>();\r
-       \r
-        new Label(workArea, SWT.NONE).setText("Select Model to export:");      \r
-        \r
-        //Get resources for the DropDown-selection\r
-        try{\r
-               SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+       private void createTree(Composite workArea){\r
+               \r
+               //set label for tree\r
+               Label title = new Label(workArea, SWT.NONE);\r
+               title.setText("Select Model to export:");\r
+\r
+               try {\r
+                       Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+                               @Override\r
+                               public Resource perform(ReadGraph graph)\r
+                                               throws DatabaseException {\r
+                                       Resource model = SimanticsUI.getProject().get();\r
+                                       return model;\r
+                               }\r
+\r
+                       });\r
+\r
+                       modelExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+                                       "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+                       modelExplorer\r
+                       .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/ImportModuleTree");\r
+\r
+                       modelExplorer.finish();\r
+\r
+                       modelExplorer.setInput(null, input);\r
+\r
+                       GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+                                       modelExplorer);\r
                        \r
-                       @Override\r
-                       public void run(ReadGraph graph) throws DatabaseException {\r
-                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               SysdynResource sr = SysdynResource.getInstance(graph);\r
-                               \r
-                               Resource model;\r
-                               current = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
-                               //If there is no selection\r
-                               if(current == null){\r
-                                       model = SimanticsUI.getProject().get();\r
-                               }\r
-                               else{\r
-                                       model = graph.getPossibleObject(current, l0.PartOf);\r
-                               }\r
-                               currentModelName = NameUtils.getSafeName(graph, current);\r
-                               \r
-                               //Check if selection is not in top-level folder\r
-                               String modelName = NameUtils.getSafeName(graph, model);\r
-                               while (!modelName.equalsIgnoreCase("Development Project")){\r
-                                       Resource previousResource = graph.getPossibleObject(model, l0.PartOf);\r
-                                       String previousName = NameUtils.getSafeName(graph, previousResource);\r
-                                       if (previousName.equalsIgnoreCase("Development Project")){\r
-                                               currentModelName = modelName;\r
-                                       }\r
-                                       //If selection is under Built-in Functions directory\r
-                                       if (modelName.equalsIgnoreCase("Built-in Functions") || currentModelName.equalsIgnoreCase("Built-in Functions")){\r
-                                               model = SimanticsUI.getProject().get();\r
-                                               current = null;\r
-                                               break;\r
-                                       }\r
-                                       current = model;\r
-                                       model = graph.getPossibleObject(model, l0.PartOf);\r
-                                       modelName = NameUtils.getSafeName(graph, model);\r
-                               }\r
-                               for (Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.SysdynModel))){\r
-                                       String name = NameUtils.getSafeName(graph, r);\r
-                                       resources.add(Pair.make(r, name));\r
-                               }\r
+                       ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
                                \r
-                       };\r
-               });\r
-        }\r
-               catch (DatabaseException e) {\r
+                               @Override\r
+                               public void widgetSelected(SelectionEvent e) {\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                               @Override\r
+                               public void widgetDefaultSelected(SelectionEvent e) {\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                       });\r
+                       \r
+\r
+               } catch (DatabaseException e) {\r
                        e.printStackTrace();\r
-                       }\r
-        //Create dropdown-bar\r
-        final CCombo drop = new CCombo(workArea, SWT.BORDER);\r
-        {\r
-            drop.setEditable(false);\r
-            drop.setText("");\r
-            drop.setToolTipText("Selects the Model where to import the Module.");\r
-            GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop);         \r
-        \r
-            //Fill the Dropdown-list\r
-            for(int a=0; a<resources.size(); a++){\r
-               drop.add(resources.get(a).second);\r
-            }\r
-            int selectionNumber = 0;\r
-            for(int a=0; a<resources.size(); a++){\r
-               if (currentModelName.equals(resources.get(a).second)){\r
-                       selectionNumber = a;\r
-                       }\r
-            }\r
-            //Show selected model as default\r
-            drop.select(selectionNumber);\r
-            selectedModel = current;\r
-            if (selectedModel == null){\r
-               selectedModel = resources.get(0).first;\r
-            }\r
-            \r
-            drop.addModifyListener(new ModifyListener(){\r
-                @Override\r
-                public void modifyText(ModifyEvent e) {\r
-                       \r
-                       for(int a=0; a<resources.size(); a++){\r
-                               if (drop.getText().equals(resources.get(a).second))\r
-                                       selectedModel = resources.get(a).first;\r
-                       }               \r
-                       validatePage();                                 \r
-                }\r
-            });\r
-        }\r
-    }\r
+               }\r
+\r
+       }\r
        \r
        //Set filePathField active\r
        public void setVisible(boolean visible) {\r
@@ -288,11 +250,34 @@ public class WizardModelsExportPage extends WizardPage {
                }               \r
 \r
        }\r
+       //Get selection from the tree\r
+       @SuppressWarnings("unchecked")\r
+       public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+                       Class<T> clazz) {\r
+               \r
+               if(explorer == null)\r
+                       return null;\r
+               ISelection selection = ((ISelectionProvider) explorer\r
+                               .getAdapter(ISelectionProvider.class)).getSelection();\r
+               if (selection == null)\r
+                       return null;\r
+               IStructuredSelection iss = (IStructuredSelection) selection;\r
+               AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+               if (inc == null)\r
+                       return null;\r
+               final T resource = (T) inc.getAdapter(clazz);\r
+\r
+               return resource;\r
+       }\r
        \r
-       public boolean createProjects(Resource selection) {\r
+       public boolean createProjects() {\r
                \r
                final String selected = previouslyBrowsedFile;\r
                if(selected == null) return false;\r
+               \r
+               selectedModel= getExplorerResource(modelExplorer, Resource.class);\r
+               if(selectedModel == null)\r
+                       return false;\r
         \r
         // FIXME: Model browser doesn't change its selection even if the selected object is removed,\r
         // so you can try to export a removed model \r
@@ -323,7 +308,7 @@ public class WizardModelsExportPage extends WizardPage {
        \r
        void validatePage() {\r
                \r
-               if (previouslyBrowsedFile.isEmpty()){\r
+               if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
                        setPageComplete(false);\r
                        return;\r
                }\r
similarity index 90%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardModelsImportPage.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java
index e7c447f6984ae9f1c0b7eab9770ce091a56e064f..9e2ecc5c655bd39d9e2614f01876877eee068ce7 100644 (file)
@@ -1,11 +1,11 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.models;\r
 \r
 import java.io.File;\r
 import java.io.IOException;\r
 import java.util.HashSet;\r
 import java.util.UUID;\r
 \r
-import org.eclipse.core.runtime.Path;\r
+import org.eclipse.core.runtime.Platform;\r
 import org.eclipse.jface.layout.PixelConverter;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.wizard.WizardPage;\r
@@ -20,7 +20,6 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.FileDialog;\r
 import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.MessageBox;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Text;\r
 import org.simantics.databoard.Bindings;\r
@@ -43,13 +42,13 @@ import org.simantics.simulation.ontology.SimulationResource;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.handlers.ImportModelHandler;\r
 import org.simantics.sysdyn.ui.utils.OldTransferableGraph1;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
 public class WizardModelsImportPage extends WizardPage{\r
        \r
-       // dialog store id constants\r
-       \r
        private Text filePathField;\r
        \r
        // Keep track of the archive that we browsed to last time\r
@@ -60,6 +59,8 @@ public class WizardModelsImportPage extends WizardPage{
 \r
        private Shell shell;\r
        \r
+       private String error = "";\r
+       \r
        /**\r
         * Creates a new project creation wizard page.\r
         * \r
@@ -92,7 +93,7 @@ public class WizardModelsImportPage extends WizardPage{
                //this.currentSelection = currentSelection;\r
                setPageComplete(false);\r
                setTitle("Import Model");\r
-               setDescription("Select Model file from the local file system.");\r
+               setDescription("Choose the Model file, then press Finish.");\r
        }\r
 \r
        \r
@@ -134,7 +135,7 @@ public class WizardModelsImportPage extends WizardPage{
                filePathField.addModifyListener(new ModifyListener(){\r
             @Override\r
             public void modifyText(ModifyEvent e) {\r
-               previouslyBrowsedFile = filePathField.getText();        \r
+               previouslyBrowsedFile = filePathField.getText();\r
             }\r
                });\r
                if (previouslyBrowsedFile != null){\r
@@ -155,10 +156,12 @@ public class WizardModelsImportPage extends WizardPage{
                         * elected(org.eclipse.swt.events.SelectionEvent)\r
                         */\r
                        public void widgetSelected(SelectionEvent e) {\r
+                               setErrorMessage(null);\r
                                handleLocationDirectoryButtonPressed();\r
                        }\r
                });     \r
        }\r
+\r
        \r
        //Set filePathField active\r
        public void setVisible(boolean visible) {\r
@@ -179,28 +182,33 @@ public class WizardModelsImportPage extends WizardPage{
                \r
                dialog.setText("Import Model");\r
 \r
-               String dirName = filePathField.getText().trim();\r
-               \r
-               File path = new File(dirName);\r
-               if (path.exists()) {\r
-                       dialog.setFilterPath(new Path(dirName).toOSString());   \r
-               }\r
+               String path = Activator.getDefault().getPreferenceStore().getString(ImportModelHandler.IMPORTMODELTPATH);\r
+               if(path.isEmpty() || !(new File(path).exists()))\r
+                       path = Platform.getLocation().toOSString();\r
+               dialog.setFilterPath(path);\r
                \r
                String selectedFile = dialog.open();\r
                if (selectedFile != null) {\r
                        filePathField.setText(selectedFile);\r
                        validatePage();\r
                }\r
+               \r
        }\r
 \r
        //Create project after finish is pressed.\r
        public boolean createProjects() {\r
                \r
                Resource project = SimanticsUI.getProject().get();\r
-               if(project == null) return false;\r
+               if(project == null){\r
+                       setErrorMessage("Error when retrieving resource");\r
+                       return false;\r
+               }\r
                \r
                String selected = previouslyBrowsedFile;\r
-               if(selected == null) return false;\r
+               if(selected == null){\r
+                       setErrorMessage("No file selected");\r
+                       return false;\r
+               }\r
                \r
                TransferableGraph1 tg = null;\r
                try {\r
@@ -214,14 +222,14 @@ public class WizardModelsImportPage extends WizardPage{
                        } catch (RuntimeBindingConstructionException e1) {\r
                                e1.printStackTrace();\r
                        } catch (IOException e1) {\r
-                               MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
-                               mb.setText("Error");\r
-                               mb.setMessage("The imported file is not of type: Model");\r
-                               mb.open();\r
+                               setErrorMessage("The imported file is not of type: System Dynamics Model");\r
                                return false;\r
                        }\r
                }\r
-               if(tg == null) return false;\r
+               if(tg == null){ \r
+                       setErrorMessage("The imported file is not of type: System Dynamics Model");\r
+                       return false;\r
+               }\r
                \r
                try {\r
                        \r
@@ -246,20 +254,8 @@ public class WizardModelsImportPage extends WizardPage{
                                                        if(inheritedFrom != null)\r
                                                                type = NameUtils.getSafeName(graph, inheritedFrom);\r
                                                }\r
-                                               final String ft = type; \r
                                                graph.deny(root, Layer0.getInstance(graph).PartOf);\r
-                                               \r
-                                               shell.getDisplay().asyncExec(new Runnable() {\r
-                                                       \r
-                                                       @Override\r
-                                                       public void run() {\r
-                                                               MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
-                                                               mb.setText("Error");\r
-                                                               mb.setMessage("The imported file is not of type: System Dynamics Model (" + ft +")");\r
-                                                               mb.open();                                                              \r
-                                                       }\r
-                                               });\r
-\r
+                                               error = type;\r
                                        } else {\r
                                                updateOldConfigurationToBaseRealization(graph, root);\r
                                                addDefaultOntologyLinks(graph, root);\r
@@ -273,7 +269,12 @@ public class WizardModelsImportPage extends WizardPage{
                } catch (Exception e) {\r
                        e.printStackTrace();\r
                }\r
-               \r
+\r
+               if (!error.isEmpty()){\r
+                       setErrorMessage("The imported file is not of type: System Dynamics Model (" + error +")");\r
+                       error = "";\r
+                       return false;\r
+               }\r
                return true;            \r
        }\r
        \r
@@ -449,7 +450,7 @@ public class WizardModelsImportPage extends WizardPage{
                        setPageComplete(false);\r
                        return;\r
                }\r
-               \r
+               setErrorMessage(null);\r
                setPageComplete(true);\r
     }\r
 }
\ No newline at end of file
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleComponentTypeNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleComponentTypeNode.java
new file mode 100644 (file)
index 0000000..7b50181
--- /dev/null
@@ -0,0 +1,161 @@
+package org.simantics.sysdyn.ui.wizards.modules;\r
+\r
+import java.util.Collection;\r
+\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.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
+import org.simantics.db.ReadGraph;\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
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class ModuleComponentTypeNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
+\r
+       \r
+       Listener<String> configurationNameSynchronizer;\r
+       private boolean disposed = false;\r
+       private Resource configuration;\r
+       \r
+    public ModuleComponentTypeNode(Resource resource) {\r
+        super(resource);\r
+\r
+        SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+                       \r
+                       @Override\r
+                       public void run(ReadGraph graph) throws DatabaseException {\r
+                       StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+                       configuration = graph.getPossibleObject(data, sr2.IsDefinedBy);                         \r
+                       }\r
+               });\r
+        \r
+        // Not the best solution for name sync\r
+        configurationNameSynchronizer = new Listener<String>() {\r
+\r
+               @Override\r
+                       public void execute(final String result) {\r
+                               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+                                       \r
+                                       @Override\r
+                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                               if(configuration != null)\r
+                                                       graph.claimLiteral(configuration, Layer0.getInstance(graph).HasLabel, result);\r
+                                       }\r
+                               });\r
+                       }\r
+\r
+                       @Override\r
+                       public void exception(Throwable t) {\r
+                               t.printStackTrace();\r
+                       }\r
+\r
+                       @Override\r
+                       public boolean isDisposed() {\r
+                               return disposed;\r
+                       }\r
+               };\r
+               \r
+        SimanticsUI.getSession().asyncRequest(new Read<String>() {\r
+\r
+                       @Override\r
+                       public String perform(ReadGraph graph) throws DatabaseException {\r
+                               Layer0 l0 = Layer0.getInstance(graph);\r
+                               return graph.getRelatedValue(data, l0.HasName);\r
+                       }\r
+               \r
+        }, configurationNameSynchronizer);\r
+        \r
+    }\r
+\r
+    @Override\r
+    public Modifier getModifier(String columnId) {\r
+        Modifier modifier = null;\r
+        try {\r
+            modifier = SimanticsUI.getSession().syncRequest(new Read<Modifier>() {\r
+\r
+                @Override\r
+                public Modifier perform(ReadGraph graph) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
+                    ModelingResources mr = ModelingResources.getInstance(graph);\r
+                    Layer0 l0 = Layer0.getInstance(graph);\r
+                    Resource type =  graph.getPossibleObject(data, mr.SymbolToComponentType);\r
+\r
+                    LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), type, l0.HasName) {\r
+                        @Override\r
+                        public String isValid(String label) {\r
+                            if (label.isEmpty())\r
+                                return "Empty name not allowed";\r
+                            return null;\r
+                        }\r
+                    };\r
+\r
+\r
+                    return modifier;\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
+        return modifier;\r
+    }\r
+\r
+    @Override\r
+    public void delete() throws DeleteException {\r
+       disposed = true;\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+                @Override\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
+\r
+                    Resource type =  graph.getPossibleObject(data, mr.SymbolToComponentType);\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
+                    }\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
+                        }\r
+                    }\r
+                    graph.deny(model, l0.ConsistsOf, type);\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\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
+}
\ No newline at end of file
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModels.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModels.java
new file mode 100644 (file)
index 0000000..272a2af
--- /dev/null
@@ -0,0 +1,40 @@
+package org.simantics.sysdyn.ui.wizards.modules;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class ModuleTreeModels extends ViewpointContributorImpl<Resource> {\r
+\r
+       @Override\r
+       public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+                       throws DatabaseException {\r
+               \r
+\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+               for(Resource r : graph.syncRequest(new ObjectsWithType(input, l0.ConsistsOf, sr.SysdynModel))) {\r
+                       result.add(new ModelNode(r));\r
+               }\r
+               \r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public String getViewpointId() {\r
+               return "Module Import";\r
+       }\r
+       \r
+\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModules.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModules.java
new file mode 100644 (file)
index 0000000..76f76f8
--- /dev/null
@@ -0,0 +1,35 @@
+package org.simantics.sysdyn.ui.wizards.modules;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
+\r
+public class ModuleTreeModules extends ViewpointContributor<ModelNode> {\r
+\r
+    @Override\r
+    public Collection<?> getContribution(ReadGraph graph, ModelNode model)\r
+    throws DatabaseException {\r
+       ArrayList<ModuleComponentTypeNode> result = new ArrayList<ModuleComponentTypeNode>();\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+               for (Resource r : graph.syncRequest(new ObjectsWithType(model.data, l0.ConsistsOf, sr2.ComponentType))){\r
+                       result.add(new ModuleComponentTypeNode(r));\r
+               }\r
+\r
+        return result;\r
+    }\r
+\r
+    @Override\r
+    public String getViewpointId() {\r
+        return "Standard";\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModulesLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModulesLabeler.java
new file mode 100644 (file)
index 0000000..0aa030a
--- /dev/null
@@ -0,0 +1,16 @@
+package org.simantics.sysdyn.ui.wizards.modules;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class ModuleTreeModulesLabeler extends LabelerContributorImpl<ModuleComponentTypeNode>{\r
+\r
+       @Override\r
+       public String getLabel(ReadGraph graph, ModuleComponentTypeNode input)\r
+                       throws DatabaseException {\r
+               return NameUtils.getSafeName(graph, input.data);\r
+       }\r
+\r
+}\r
similarity index 59%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardModulesExportPage.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesExportPage.java
index bcc80dc6ac36cc6e9ff3b77efe026c2978b5ce3a..af0a19968b8b732a5827df69a045fdf85bf7df5b 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.modules;\r
 \r
 import java.io.File;\r
 import java.io.IOException;\r
@@ -8,14 +8,16 @@ import java.util.Collection;
 import org.eclipse.core.runtime.Path;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.wizard.WizardPage;\r
 import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.CCombo;\r
 import org.eclipse.swt.events.ModifyEvent;\r
 import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.events.SelectionAdapter;\r
 import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
 import org.eclipse.swt.layout.GridData;\r
 import org.eclipse.swt.layout.GridLayout;\r
 import org.eclipse.swt.widgets.Button;\r
@@ -24,6 +26,9 @@ import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.databoard.Files;\r
 import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
@@ -44,7 +49,7 @@ import org.simantics.modeling.ModelingResources;
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
 import org.simantics.utils.datastructures.Pair;\r
 \r
 public class WizardModulesExportPage extends WizardPage {\r
@@ -58,25 +63,11 @@ public class WizardModulesExportPage extends WizardPage {
 \r
        private Button browseDirectoriesButton;\r
        \r
-       private IStructuredSelection currentSelection;\r
-       \r
-       private Resource current;\r
-       \r
-       private Resource selectedModel;\r
-       \r
        private Resource selectedModule;\r
        \r
-       private String currentModelName;\r
-       \r
-       private CCombo drop;\r
-       \r
-       private CCombo drop2;\r
-       \r
-       private ArrayList<Pair<Resource, String>> resources = new ArrayList<Pair<Resource, String>>();\r
-       \r
-       private ArrayList<Pair<Resource, String>> modules = new ArrayList<Pair<Resource, String>>();\r
+       GraphExplorerComposite modelExplorer;\r
 \r
-       \r
+       private boolean selectionMade = false;\r
        \r
        /**\r
         * Creates a new project creation wizard page.\r
@@ -106,10 +97,10 @@ public class WizardModulesExportPage extends WizardPage {
        public WizardModulesExportPage(String pageName,String initialPath,\r
                        IStructuredSelection currentSelection) {\r
                super(pageName);\r
-               this.currentSelection = currentSelection;\r
+               //this.currentSelection = currentSelection;\r
                setPageComplete(false);\r
                setTitle("Export Module");\r
-               setDescription("Choose the Module and the export location.");\r
+               setDescription("Choose the Module and the export location, then press Finish.");\r
        }\r
        \r
        public void createControl(Composite parent) {\r
@@ -123,16 +114,15 @@ public class WizardModulesExportPage extends WizardPage {
                workArea.setLayoutData(new GridData(GridData.FILL_BOTH\r
                                | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));\r
 \r
-               createDropDownSelections(workArea);\r
                createProjectsRoot(workArea);\r
-               \r
+               createTree(workArea);\r
        }\r
        \r
        private void createProjectsRoot(Composite workArea) {\r
                \r
                // set label for field\r
                Label title = new Label(workArea, SWT.NONE);\r
-               title.setText("Select export destination for Module:");\r
+               title.setText("Select the export location for Module:");\r
                \r
                Composite projectGroup = new Composite(workArea, SWT.NONE);\r
                GridLayout layout = new GridLayout();\r
@@ -179,78 +169,59 @@ public class WizardModulesExportPage extends WizardPage {
                });\r
                \r
        }\r
-       \r
-    private void createDropDownSelections(final Composite workArea) {\r
-       \r
-        new Label(workArea, SWT.NONE).setText("Select the Model which contains the Module:");      \r
-        \r
-        //Find available models\r
-        findModels();\r
-        \r
-        //Create Model dropdown-bar\r
-        drop = new CCombo(workArea, SWT.BORDER);\r
-        \r
-        drop.setEditable(false);\r
-        drop.setText("");\r
-        drop.setToolTipText("Selects the Model where to export the Module.");\r
-        GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop);         \r
-        \r
-        //Fill the Model Dropdown-list\r
-        for(int a=0; a<resources.size(); a++){\r
-            drop.add(resources.get(a).second);\r
-        }\r
-        int selectionNumber = 0;\r
-        for(int a=0; a<resources.size(); a++){\r
-            if (currentModelName.equals(resources.get(a).second)){\r
-               selectionNumber = a;\r
-            }\r
-        }\r
-        //Show selected model as default\r
-        drop.select(selectionNumber);\r
-        selectedModel = current;\r
-        if (selectedModel == null){\r
-            selectedModel = resources.get(0).first;\r
-        }\r
-            \r
-        //Create Module dropdown-bar\r
-        new Label(workArea, SWT.NONE).setText("Select the exportted Module:");      \r
-        drop2 = new CCombo(workArea, SWT.BORDER);\r
-        drop2.setEditable(false);\r
-        drop2.setText("");\r
-        drop2.setToolTipText("Selects the Module to be exportted.");\r
-        GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop2);         \r
-        \r
-        //Update module list according to model list\r
-        updateModules();\r
-            \r
-        //Listeners for drop downs\r
-        drop.addModifyListener(new ModifyListener(){\r
-            @Override\r
-            public void modifyText(ModifyEvent e) {\r
-                       \r
-                for(Pair<Resource, String> resource : resources){\r
-                       if (drop.getText().equals(resource.second))\r
-                               selectedModel = resource.first;\r
-                }      \r
-                       \r
-                updateModules();\r
-                validatePage();\r
-            }\r
-        });\r
-            \r
-        drop2.addModifyListener(new ModifyListener(){\r
-            @Override\r
-            public void modifyText(ModifyEvent e) {\r
-                       \r
-                for(int a=0; a<modules.size(); a++){\r
-                       if (drop2.getText().equals(modules.get(a).second))\r
-                               selectedModule = modules.get(a).first;\r
-                }              \r
-                validatePage();                                \r
-            }\r
-        });\r
-        \r
-    }\r
+\r
+       private void createTree(Composite workArea){\r
+               \r
+               //set label for tree\r
+               Label title = new Label(workArea, SWT.NONE);\r
+               title.setText("Select Module to export:");\r
+\r
+               try {\r
+                       Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+                               @Override\r
+                               public Resource perform(ReadGraph graph)\r
+                                               throws DatabaseException {\r
+                                       Resource model = SimanticsUI.getProject().get();\r
+                                       return model;\r
+                               }\r
+\r
+                       });\r
+\r
+                       modelExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+                                       "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+                       modelExplorer\r
+                       .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/ExportModuleTree");\r
+\r
+                       modelExplorer.finish();\r
+                       \r
+                       modelExplorer.setInput(null, input);\r
+\r
+                       GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+                                       modelExplorer);\r
+                       \r
+                       ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
+                               \r
+                               @Override\r
+                               public void widgetSelected(SelectionEvent e) {\r
+                                       setMessage(null);\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                               @Override\r
+                               public void widgetDefaultSelected(SelectionEvent e) {\r
+                                       setMessage(null);\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                       });\r
+\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+\r
+       }\r
     \r
        //Set filePathField active\r
        public void setVisible(boolean visible) {\r
@@ -258,7 +229,6 @@ public class WizardModulesExportPage extends WizardPage {
                this.filePathField.setFocus();\r
        }\r
        \r
-       \r
        //Open dialog for choosing the file\r
        protected void handleLocationDirectoryButtonPressed() {\r
                \r
@@ -286,137 +256,50 @@ public class WizardModulesExportPage extends WizardPage {
 \r
        }\r
        \r
-       private void findModels(){\r
-               \r
-        //Get resources for the DropDown-selection\r
-        try{\r
-               SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
-                       \r
-                       @Override\r
-                       public void run(ReadGraph graph) throws DatabaseException {\r
-                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               SysdynResource sr = SysdynResource.getInstance(graph);\r
-                               \r
-                               Resource model;\r
-                               current = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
-                               //If there is no selection\r
-                               if(current == null){\r
-                                       model = SimanticsUI.getProject().get();\r
-                               }\r
-                               else{\r
-                                       model = graph.getPossibleObject(current, l0.PartOf);\r
-                               }               \r
-                               currentModelName = NameUtils.getSafeName(graph, current);\r
-                               \r
-                               //Check if selection is not in top-level folder\r
-                               String modelName = NameUtils.getSafeName(graph, model);\r
-                               while (!modelName.equalsIgnoreCase("Development Project")){\r
-                                       Resource previousResource = graph.getPossibleObject(model, l0.PartOf);\r
-                                       String previousName = NameUtils.getSafeName(graph, previousResource);\r
-                                       if (previousName.equalsIgnoreCase("Development Project")){\r
-                                               currentModelName = modelName;\r
-                                       }\r
-                                       //If selection is under Built-in Functions directory\r
-                                       if (modelName.equalsIgnoreCase("Built-in Functions") || currentModelName.equalsIgnoreCase("Built-in Functions")){\r
-                                               model = SimanticsUI.getProject().get();\r
-                                               current = null;\r
-                                               break;\r
-                                       }\r
-                                       current = model;\r
-                                       model = graph.getPossibleObject(model, l0.PartOf);\r
-                                       modelName = NameUtils.getSafeName(graph, model);\r
-                               }\r
-                               for (Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.SysdynModel))){\r
-                                       String name = NameUtils.getSafeName(graph, r);\r
-                                       resources.add(Pair.make(r, name));\r
-                               }\r
-                               \r
-                       };\r
-               });\r
-        }\r
-               catch (DatabaseException e) {\r
-                       e.printStackTrace();\r
-                       }\r
-               \r
-       }\r
-       \r
-       \r
-       private void findModules(){\r
-               \r
-        try{\r
-               SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
-                       \r
-                       @Override\r
-                       public void run(ReadGraph graph) throws DatabaseException {\r
-                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
-                               //modules.removeAll(null);\r
-                               modules = new ArrayList<Pair<Resource, String>>();\r
-                               for (Resource r : graph.syncRequest(new ObjectsWithType(selectedModel, l0.ConsistsOf, sr2.ComponentType))){\r
-                                       String name = NameUtils.getSafeName(graph, r);\r
-                                       modules.add(Pair.make(r, name));\r
-                               }\r
-                               \r
-                       };\r
-               });\r
-        }\r
-               catch (DatabaseException e) {\r
-                       e.printStackTrace();\r
-                       }\r
-       }\r
-       \r
-       private void updateModules(){\r
-               \r
-       //Get resources for the DropDown-selection\r
-       findModules();                  \r
-       \r
-       //Clear the modules dropdown-list\r
-       if (drop2 != null){\r
-               drop2.removeAll();\r
-       \r
-       \r
-               //Fill the Modules dropdown-list\r
-               for(Pair<Resource, String> module : modules){\r
-                       drop2.add(module.second);\r
-               }\r
-               int selectionNumber = 0;\r
-               for(int a=0; a<modules.size(); a++){\r
-                       if (currentModelName.equals(modules.get(a).second)){\r
-                               selectionNumber = a;\r
-                       }\r
-               }\r
-               //Show selected module as default\r
-               drop2.select(selectionNumber);\r
-               selectedModel = current;\r
-               if (selectedModel == null){\r
-                       selectedModel = modules.get(0).first;\r
-               }\r
-       }\r
-               \r
+       //Get selection from the tree\r
+       @SuppressWarnings("unchecked")\r
+       public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+                       Class<T> clazz) {\r
+               \r
+               if(explorer == null)\r
+                       return null;\r
+               ISelection selection = ((ISelectionProvider) explorer\r
+                               .getAdapter(ISelectionProvider.class)).getSelection();\r
+               if (selection == null)\r
+                       return null;\r
+               IStructuredSelection iss = (IStructuredSelection) selection;\r
+               AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+               if (inc == null)\r
+                       return null;\r
+               final T resource = (T) inc.getAdapter(clazz);\r
+\r
+               return resource;\r
        }\r
        \r
+       //Create export file when finish is pressed\r
        public boolean createProjects() {\r
                \r
                final String selected = previouslyBrowsedFile;\r
                if(selected == null) return false;\r
 \r
+               selectedModule= getExplorerResource(modelExplorer, Resource.class);\r
+               if(selectedModule == null)\r
+                       return false;\r
+               \r
                String name = null;\r
                try {\r
                        name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
 \r
                                @Override\r
                                public String perform(ReadGraph graph) throws DatabaseException {\r
-                                       ModelingResources mr = ModelingResources.getInstance(graph);\r
                                        StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
                                        SysdynResource sr = SysdynResource.getInstance(graph);\r
                                        Layer0 l0 = Layer0.getInstance(graph);\r
                                        \r
                                        Resource component = selectedModule;\r
-                               //      Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType);\r
                                        if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf))\r
                                                return null;\r
                                        \r
-                                       \r
                                        Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy);\r
                                        if (configuration == null)\r
                                                return null;\r
@@ -442,17 +325,13 @@ public class WizardModulesExportPage extends WizardPage {
                catch (DatabaseException e1) {\r
                        e1.printStackTrace();\r
                }\r
-//             if(name == null) return false;\r
-               \r
-               \r
-       //      Activator.getDefault().getPreferenceStore().setValue(ImportModuleHandler.IMPORTMODULETPATH, (new File(selected)).getParent());\r
+               if(name == null) return false;\r
                \r
                SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
                        \r
                        @Override\r
                        public void run(ReadGraph graph) throws DatabaseException {\r
                                Layer0 l0 = Layer0.getInstance(graph);\r
-                               ModelingResources mr = ModelingResources.getInstance(graph);\r
                                \r
                                final Resource component = selectedModule;\r
                                //final Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType);\r
@@ -555,11 +434,38 @@ public class WizardModulesExportPage extends WizardPage {
        \r
        void validatePage() {\r
                \r
-               if (previouslyBrowsedFile.isEmpty()){\r
+               if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
                        setPageComplete(false);\r
                        return;\r
                }\r
                \r
+               if (modelExplorer != null){\r
+                       final Resource selectedResource = getExplorerResource(modelExplorer, Resource.class);\r
+\r
+                       String root = null;\r
+                       try {\r
+                               root = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+                                       @Override\r
+                                       public String perform(ReadGraph graph) throws DatabaseException {\r
+                                               Layer0 l0 = Layer0.getInstance(graph);\r
+                                               Resource model = graph.getPossibleObject(selectedResource, l0.PartOf);\r
+                                               String rootName = NameUtils.getSafeName(graph, model);\r
+\r
+                                               return rootName;\r
+                                       }\r
+\r
+                               });\r
+                               if (root != null && root.equalsIgnoreCase("Development Project")){\r
+                                       setPageComplete(false);\r
+                                       setMessage("Select Module under the Model.");\r
+                                       return;\r
+                               }\r
+                       } catch (DatabaseException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+               \r
                setPageComplete(true);\r
                \r
        }\r
similarity index 50%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/WizardModulesImportPage.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesImportPage.java
index 3ad33a18c1b313058b915db786ccbe5e654b7413..0950f7da7310738465c48062ce30048d53e4b8b2 100644 (file)
@@ -1,49 +1,50 @@
-package org.simantics.sysdyn.ui.wizards;\r
+package org.simantics.sysdyn.ui.wizards.modules;\r
 \r
 import java.io.File;\r
 import java.io.IOException;\r
-import java.util.ArrayList;\r
 \r
 import org.eclipse.core.runtime.Path;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.PixelConverter;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.wizard.WizardPage;\r
 import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.CCombo;\r
 import org.eclipse.swt.events.ModifyEvent;\r
 import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.events.SelectionAdapter;\r
 import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
 import org.eclipse.swt.layout.GridData;\r
 import org.eclipse.swt.layout.GridLayout;\r
 import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.FileDialog;\r
 import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.MessageBox;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.databoard.Files;\r
 import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
 import org.simantics.db.ReadGraph;\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.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
+import org.simantics.db.request.Read;\r
 import org.simantics.graph.db.MissingDependencyException;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
-import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
 \r
 \r
 public class WizardModulesImportPage extends WizardPage{\r
@@ -62,13 +63,15 @@ public class WizardModulesImportPage extends WizardPage{
 \r
        private Shell shell;\r
        \r
-       private IStructuredSelection currentSelection;\r
-       \r
-       private Resource current;\r
+       //private IStructuredSelection currentSelection;\r
        \r
        private Resource selectedModel;\r
        \r
-       private String currentModelName;\r
+       GraphExplorerComposite modelExplorer;\r
+       \r
+       private boolean selectionMade = false;\r
+       \r
+       private String error = "";\r
        \r
        /**\r
         * Creates a new project creation wizard page.\r
@@ -99,9 +102,9 @@ public class WizardModulesImportPage extends WizardPage{
                        IStructuredSelection currentSelection) {\r
                super(pageName);\r
                setPageComplete(false);\r
-               this.currentSelection = currentSelection;\r
-               setTitle("Import Module to Model");\r
-               setDescription("Select Module-file from the local file system.");\r
+               //this.currentSelection = currentSelection;\r
+               setTitle("Import Module");\r
+               setDescription("Choose the Module file and the import location, then press Finish.");\r
        }\r
        \r
        public void createControl(Composite parent) {\r
@@ -117,7 +120,7 @@ public class WizardModulesImportPage extends WizardPage{
 \r
                createProjectsRoot(workArea);\r
                \r
-               createDropDown(workArea);\r
+               createTree(workArea);\r
        }\r
        \r
        private void createProjectsRoot(Composite workArea) {\r
@@ -171,100 +174,58 @@ public class WizardModulesImportPage extends WizardPage{
                });\r
                \r
        }\r
-       \r
-    private void createDropDown(Composite workArea) {\r
-       \r
-       final ArrayList<Pair<Resource, String>> resources = new ArrayList<Pair<Resource, String>>();\r
-       \r
-        new Label(workArea, SWT.NONE).setText("Import target:");      \r
-        \r
-        //Get resources for the DropDown-selection\r
-        try{\r
-               SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+\r
+       private void createTree(Composite workArea){\r
+               \r
+               //set label for tree\r
+               Label title = new Label(workArea, SWT.NONE);\r
+               title.setText("Select import location:");\r
+\r
+               try {\r
+                       Resource input = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+                               @Override\r
+                               public Resource perform(ReadGraph graph)\r
+                                               throws DatabaseException {\r
+                                       Resource model = SimanticsUI.getProject().get();\r
+                                       return model;\r
+                               }\r
+\r
+                       });\r
+\r
+                       modelExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+                                       "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE);\r
+\r
+                       modelExplorer\r
+                       .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/ImportModuleTree");\r
+\r
+                       modelExplorer.finish();\r
+\r
+                       modelExplorer.setInput(null, input);\r
                        \r
-                       @Override\r
-                       public void run(ReadGraph graph) throws DatabaseException {\r
-                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               SysdynResource sr = SysdynResource.getInstance(graph);\r
-                               \r
-                               Resource model;\r
-                               current = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class);\r
-                               //If there is no selection\r
-                               if(current == null){\r
-                                       model = SimanticsUI.getProject().get();\r
-                               }\r
-                               else{\r
-                                       model = graph.getPossibleObject(current, l0.PartOf);\r
-                               }               \r
-                               currentModelName = NameUtils.getSafeName(graph, current);\r
-                               \r
-                               //Check if selection is not in top-level folder\r
-                               String modelName = NameUtils.getSafeName(graph, model);\r
-                               while (!modelName.equalsIgnoreCase("Development Project")){\r
-                                       Resource previousResource = graph.getPossibleObject(model, l0.PartOf);\r
-                                       String previousName = NameUtils.getSafeName(graph, previousResource);\r
-                                       if (previousName.equalsIgnoreCase("Development Project")){\r
-                                               currentModelName = modelName;\r
-                                       }\r
-                                       //If selection is under Built-in Functions directory\r
-                                       if (modelName.equalsIgnoreCase("Built-in Functions") || currentModelName.equalsIgnoreCase("Built-in Functions")){\r
-                                               model = SimanticsUI.getProject().get();\r
-                                               current = null;\r
-                                               break;\r
-                                       }\r
-                                       current = model;\r
-                                       model = graph.getPossibleObject(model, l0.PartOf);\r
-                                       modelName = NameUtils.getSafeName(graph, model);\r
-                               }\r
-                               for (Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.SysdynModel))){\r
-                                       String name = NameUtils.getSafeName(graph, r);\r
-                                       resources.add(Pair.make(r, name));\r
-                               }\r
+                       GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+                                       modelExplorer);\r
+                       \r
+                       ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() {\r
                                \r
-                       };\r
-               });\r
-        }\r
-               catch (DatabaseException e) {\r
+                               @Override\r
+                               public void widgetSelected(SelectionEvent e) {\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                               @Override\r
+                               public void widgetDefaultSelected(SelectionEvent e) {\r
+                                       selectionMade = true;\r
+                                       validatePage();\r
+                               }\r
+                       });\r
+                       \r
+\r
+               } catch (DatabaseException e) {\r
                        e.printStackTrace();\r
-                       }\r
-        //Create dropdown-bar\r
-        final CCombo drop = new CCombo(workArea, SWT.BORDER);\r
-        {\r
-            drop.setEditable(false);\r
-            drop.setText("");\r
-            drop.setToolTipText("Selects the Model where to import the Module.");\r
-            GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(drop);         \r
-        \r
-            //Fill the Dropdown-list\r
-            for(int a=0; a<resources.size(); a++){\r
-               drop.add(resources.get(a).second);\r
-            }\r
-            int selectionNumber = 0;\r
-            for(int a=0; a<resources.size(); a++){\r
-               if (currentModelName.equals(resources.get(a).second)){\r
-                       selectionNumber = a;\r
-                       }\r
-            }\r
-            //Show selected model as default\r
-            drop.select(selectionNumber);\r
-            selectedModel = current;\r
-            if (selectedModel == null){\r
-               selectedModel = resources.get(0).first;\r
-            }\r
-            \r
-            drop.addModifyListener(new ModifyListener(){\r
-                @Override\r
-                public void modifyText(ModifyEvent e) {\r
-                       \r
-                       for(int a=0; a<resources.size(); a++){\r
-                               if (drop.getText().equals(resources.get(a).second))\r
-                                       selectedModel = resources.get(a).first;\r
-                       }               \r
-                       validatePage();                                 \r
-                }\r
-            });\r
-        }\r
-    }\r
+               }\r
+\r
+       }\r
        \r
        //Set filePathField active\r
        public void setVisible(boolean visible) {\r
@@ -298,11 +259,40 @@ public class WizardModulesImportPage extends WizardPage{
                }               \r
        }\r
        \r
+       //Get selection from the tree\r
+       @SuppressWarnings("unchecked")\r
+       public static <T> T getExplorerResource(GraphExplorerComposite explorer,\r
+                       Class<T> clazz) {\r
+               \r
+               if(explorer == null)\r
+                       return null;\r
+               ISelection selection = ((ISelectionProvider) explorer\r
+                               .getAdapter(ISelectionProvider.class)).getSelection();\r
+               if (selection == null)\r
+                       return null;\r
+               IStructuredSelection iss = (IStructuredSelection) selection;\r
+               AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement();\r
+               if (inc == null)\r
+                       return null;\r
+               final T resource = (T) inc.getAdapter(clazz);\r
+\r
+               return resource;\r
+       }\r
+       \r
        //Create project after finish is pressed.\r
        public boolean createProjects() {\r
                \r
                String selected = previouslyBrowsedFile;\r
-               if(selected == null) return false;\r
+               if(selected == null){ \r
+                       setErrorMessage("Error when retrieving resource");\r
+                       return false;\r
+               }\r
+               \r
+               selectedModel= getExplorerResource(modelExplorer, Resource.class);\r
+               if(selectedModel == null){\r
+                       setErrorMessage("No file selected");\r
+                       return false;\r
+               }\r
                \r
                TransferableGraph1 tg = null;\r
                try {\r
@@ -310,13 +300,13 @@ public class WizardModulesImportPage extends WizardPage{
                } catch (RuntimeBindingConstructionException e) {\r
                        e.printStackTrace();\r
                } catch (IOException e) {\r
-                       MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
-                       mb.setText("Error");\r
-                       mb.setMessage("The imported file is not of type: Module Type");\r
-                       mb.open();\r
+                       setErrorMessage("The imported file is not of type: Module Type");\r
+                       return false;\r
+               }\r
+               if(tg == null){\r
+                       setErrorMessage("The imported file is not of type: Module Type");\r
                        return false;\r
                }\r
-               if(tg == null) return false;\r
 \r
                \r
                DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(selectedModel);\r
@@ -330,46 +320,46 @@ public class WizardModulesImportPage extends WizardPage{
                \r
                final Resource root = ia.getRoot();\r
                \r
-               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-                       \r
-                       @Override\r
-                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                               if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) {\r
-                                       Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf);\r
-                                       String type = "...";\r
-                                       if(instanceOf != null)\r
-                                               type = NameUtils.getSafeName(graph, instanceOf);\r
-                                       else {\r
-                                               Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits);\r
-                                               if(inheritedFrom != null)\r
-                                                       type = NameUtils.getSafeName(graph, inheritedFrom);\r
-                                       }\r
-                                       final String ft = type; \r
-                                       graph.deny(root, Layer0.getInstance(graph).PartOf);\r
-                                       \r
-                                       shell.getDisplay().asyncExec(new Runnable() {\r
-                                               \r
-                                               @Override\r
-                                               public void run() {\r
-                                                       MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR);\r
-                                                       mb.setText("Error");\r
-                                                       mb.setMessage("The imported file is not of type: System Dynamics Module (" + ft +")");\r
-                                                       mb.open();                                                              \r
+               try {\r
+                       SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) {\r
+                                               Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf);\r
+                                               String type = "...";\r
+                                               if(instanceOf != null)\r
+                                                       type = NameUtils.getSafeName(graph, instanceOf);\r
+                                               else {\r
+                                                       Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits);\r
+                                                       if(inheritedFrom != null)\r
+                                                               type = NameUtils.getSafeName(graph, inheritedFrom);\r
                                                }\r
-                                       });\r
+                                               graph.deny(root, Layer0.getInstance(graph).PartOf);\r
+                                               error = type;\r
+                                       }\r
                                }\r
-                       }\r
-                       });\r
-                       return true;\r
+                               });\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+               if (!error.isEmpty()){\r
+                       setErrorMessage("The imported file is not of type: Module Type (" + error +")");\r
+                       error = "";\r
+                       return false;\r
+               }\r
+               return true;\r
        }\r
        \r
        void validatePage() {\r
                \r
-               if (previouslyBrowsedFile.isEmpty()){\r
+               if (previouslyBrowsedFile.isEmpty() || selectionMade == false){\r
                        setPageComplete(false);\r
                        return;\r
                }\r
                \r
+               setErrorMessage(null);\r
                setPageComplete(true);\r
                \r
        }\r