]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.views.swt/src/org/simantics/views/swt/ModelledWizardPageImpl.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.views.swt / src / org / simantics / views / swt / ModelledWizardPageImpl.java
diff --git a/bundles/org.simantics.views.swt/src/org/simantics/views/swt/ModelledWizardPageImpl.java b/bundles/org.simantics.views.swt/src/org/simantics/views/swt/ModelledWizardPageImpl.java
new file mode 100644 (file)
index 0000000..735710e
--- /dev/null
@@ -0,0 +1,86 @@
+package org.simantics.views.swt;\r
+\r
+import org.eclipse.jface.wizard.IWizardPage;\r
+import org.eclipse.jface.wizard.WizardPage;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.Simantics;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.UniqueRead;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.views.ontology.ViewsResources;\r
+import org.simantics.views.swt.client.base.SWTRoot;\r
+\r
+public class ModelledWizardPageImpl implements ModelledWizardPage {\r
+\r
+       final private Resource configuration;\r
+       private SWTRoot root;\r
+       \r
+       public ModelledWizardPageImpl(Resource configuration) {\r
+               this.configuration = configuration;\r
+       }\r
+       \r
+       @Override\r
+       public SWTRoot getRoot() {\r
+               return root;\r
+       }\r
+\r
+       class Page extends WizardPage {\r
+\r
+               final private Resource runtime;\r
+               \r
+               public Page(String title, Resource runtime) {\r
+                       super(title, title, null);\r
+                       this.runtime = runtime;\r
+               }\r
+               \r
+               @Override\r
+               public void createControl(Composite parent) {\r
+\r
+                       try {\r
+\r
+                               Resource control = Simantics.getSession().sync(new UniqueRead<Resource>() {\r
+                                       @Override\r
+                                       public Resource perform(ReadGraph graph) throws DatabaseException {\r
+                                               ViewsResources VIEW = ViewsResources.getInstance(graph);\r
+                                               return graph.getPossibleObject(configuration, VIEW.Wizard_Page_Control);\r
+                                       }\r
+                               });\r
+                               \r
+                               SWTViewLoaderProcess process = new SWTViewLoaderProcess(null, null);\r
+                               root = process.load(control, runtime);\r
+                               root.createControls(parent);\r
+\r
+                               setControl(root.getSingleChild());\r
+\r
+                       } catch (DatabaseException e) {\r
+                               \r
+                               e.printStackTrace();\r
+                               Logger.defaultLogError(e);\r
+                               \r
+                       }\r
+                       \r
+               }\r
+               \r
+       }\r
+       \r
+       public IWizardPage create(ISessionContext context, WidgetSupport support, Resource runtime) throws DatabaseException {\r
+\r
+               String title = Simantics.getSession().syncRequest(new Read<String>() {\r
+                       @Override\r
+                       public String perform(ReadGraph graph) throws DatabaseException {\r
+                               ViewsResources VIEW = ViewsResources.getInstance(graph);\r
+                               return graph.getPossibleRelatedValue(configuration, VIEW.Wizard_Page_Title, Bindings.STRING);\r
+                       }\r
+               });\r
+\r
+               return new Page(title, runtime);\r
+               \r
+       }\r
+       \r
+}\r