]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.views.swt/src/org/simantics/views/swt/ModelledEditor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.views.swt / src / org / simantics / views / swt / ModelledEditor.java
index 2eaf6588e4080ad96ba3d5ea4481db45a59ebc3e..f6debc049c1c4a2725aa5c7ac7537e4509bc9188 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.views.swt;\r
-\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.simantics.Simantics;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.VirtualGraph;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.common.request.WriteResultRequest;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.ServiceNotFoundException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.scenegraph.ontology.ScenegraphResources;\r
-import org.simantics.scl.runtime.function.Function3;\r
-import org.simantics.ui.workbench.ResourceEditorPart2;\r
-import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
-import org.simantics.views.swt.client.base.SWTRoot;\r
-\r
-/**\r
- * To use this class, first model your view contents in .pgraph files according\r
- * to the Browsing.pgraph ontology. After that there are two ways to put your\r
- * configuration to use by defining a new view extension:\r
- * <ol>\r
- * <li>Set view extension class to\r
- * <code>org.simantics.browsing.ui.swt.ModelledView:configurationURI=ConfigURI</code>\r
- * , where ConfigURI is the URI of your view configuration.</li>\r
- * <li>Extend this class and override at least {@link #configurationURI()} to\r
- * define the URI from which the configuration for the view is found. Set view\r
- * extension class to the created class.</li>\r
- * </ol>\r
- * \r
- * @author Antti Villberg\r
- */\r
-abstract public class ModelledEditor extends ResourceEditorPart2 {\r
-\r
-       public SWTRoot root;\r
-    private Composite base;\r
-       \r
-    abstract protected String configurationURI();\r
-       \r
-    @Override\r
-    public void createPartControl(Composite parent) {\r
-       \r
-        try {\r
-               \r
-               final Variable variable = getResourceInput2().getVariable();\r
-               \r
-            Resource runtime = Simantics.getSession().sync(new WriteResultRequest<Resource>(Simantics.getSession().getService(VirtualGraph.class)) {\r
-                @Override\r
-                public Resource perform(WriteGraph graph) throws DatabaseException {\r
-                       Layer0 L0 = Layer0.getInstance(graph);\r
-                       ScenegraphResources SG = ScenegraphResources.getInstance(graph);\r
-                       Resource resource = graph.newResource();\r
-                                       graph.claim(resource, L0.InstanceOf, null, SG.Runtime);\r
-                       graph.claimLiteral(resource, SG.Runtime_HasVariable, variable.getURI(graph), Bindings.STRING);\r
-                       return resource;\r
-                }\r
-            });\r
-            \r
-            base = new Composite(parent, SWT.NONE);\r
-            base.setLayout(new FillLayout());\r
-            \r
-                       SWTViewLoaderProcess loader = new SWTViewLoaderProcess(null, null);\r
-            final Variable editorVariable = loader.getVariable(getSession(), configurationURI(), runtime);\r
-\r
-               final Function3<WriteGraph, Variable, Variable, Boolean> onLoaded = getSession().syncRequest(new Read<Function3<WriteGraph, Variable, Variable, Boolean>>() {\r
-\r
-                       @Override\r
-                       public Function3<WriteGraph, Variable, Variable, Boolean> perform(ReadGraph graph) throws DatabaseException {\r
-                               return editorVariable.getPossiblePropertyValue(graph, "onLoaded");\r
-                       }\r
-\r
-               });\r
-\r
-               if(onLoaded != null) {\r
-\r
-                       Simantics.getSession().sync(new WriteRequest() {\r
-                    @Override\r
-                    public void perform(WriteGraph graph) throws DatabaseException {\r
-                       onLoaded.apply(graph, editorVariable, variable);\r
-                    }\r
-                });\r
-\r
-               }\r
-            \r
-                       root = loader.load(getSession(), editorVariable);\r
-                       root.createControls(base);\r
-            \r
-        } catch (ServiceNotFoundException e) {\r
-            Logger.defaultLogError(e);\r
-        } catch (DatabaseException e) {\r
-            Logger.defaultLogError(e);\r
-        }\r
-        \r
-        getSite().setSelectionProvider(new ActiveSelectionProvider() {\r
-               \r
-               @Override\r
-               public void setSelection(ISelection selection) {\r
-                       super.setSelection(selection);\r
-               }\r
-               \r
-        });\r
-        \r
-    }\r
-\r
-    @Override\r
-    public void setFocus() {\r
-       if (root != null && root.getControl() != null && !root.getControl().isDisposed())\r
-               root.getControl().setFocus();\r
-       else if (!base.isDisposed())\r
-           base.setFocus();\r
-    }\r
-    \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.views.swt;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.VirtualGraph;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.request.WriteResultRequest;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ServiceNotFoundException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.request.Read;
+import org.simantics.layer0.Layer0;
+import org.simantics.scenegraph.ontology.ScenegraphResources;
+import org.simantics.scl.runtime.function.Function3;
+import org.simantics.ui.workbench.ResourceEditorPart2;
+import org.simantics.utils.ui.jface.ActiveSelectionProvider;
+import org.simantics.views.swt.client.base.SWTRoot;
+
+/**
+ * To use this class, first model your view contents in .pgraph files according
+ * to the Browsing.pgraph ontology. After that there are two ways to put your
+ * configuration to use by defining a new view extension:
+ * <ol>
+ * <li>Set view extension class to
+ * <code>org.simantics.browsing.ui.swt.ModelledView:configurationURI=ConfigURI</code>
+ * , where ConfigURI is the URI of your view configuration.</li>
+ * <li>Extend this class and override at least {@link #configurationURI()} to
+ * define the URI from which the configuration for the view is found. Set view
+ * extension class to the created class.</li>
+ * </ol>
+ * 
+ * @author Antti Villberg
+ */
+abstract public class ModelledEditor extends ResourceEditorPart2 {
+
+       public SWTRoot root;
+    private Composite base;
+       
+    abstract protected String configurationURI();
+       
+    @Override
+    public void createPartControl(Composite parent) {
+       
+        try {
+               
+               final Variable variable = getResourceInput2().getVariable();
+               
+            Resource runtime = Simantics.getSession().sync(new WriteResultRequest<Resource>(Simantics.getSession().getService(VirtualGraph.class)) {
+                @Override
+                public Resource perform(WriteGraph graph) throws DatabaseException {
+                       Layer0 L0 = Layer0.getInstance(graph);
+                       ScenegraphResources SG = ScenegraphResources.getInstance(graph);
+                       Resource resource = graph.newResource();
+                                       graph.claim(resource, L0.InstanceOf, null, SG.Runtime);
+                       graph.claimLiteral(resource, SG.Runtime_HasVariable, variable.getURI(graph), Bindings.STRING);
+                       return resource;
+                }
+            });
+            
+            base = new Composite(parent, SWT.NONE);
+            base.setLayout(new FillLayout());
+            
+                       SWTViewLoaderProcess loader = new SWTViewLoaderProcess(null, null);
+            final Variable editorVariable = loader.getVariable(getSession(), configurationURI(), runtime);
+
+               final Function3<WriteGraph, Variable, Variable, Boolean> onLoaded = getSession().syncRequest(new Read<Function3<WriteGraph, Variable, Variable, Boolean>>() {
+
+                       @Override
+                       public Function3<WriteGraph, Variable, Variable, Boolean> perform(ReadGraph graph) throws DatabaseException {
+                               return editorVariable.getPossiblePropertyValue(graph, "onLoaded");
+                       }
+
+               });
+
+               if(onLoaded != null) {
+
+                       Simantics.getSession().sync(new WriteRequest() {
+                    @Override
+                    public void perform(WriteGraph graph) throws DatabaseException {
+                       onLoaded.apply(graph, editorVariable, variable);
+                    }
+                });
+
+               }
+            
+                       root = loader.load(getSession(), editorVariable);
+                       root.createControls(base);
+            
+        } catch (ServiceNotFoundException e) {
+            Logger.defaultLogError(e);
+        } catch (DatabaseException e) {
+            Logger.defaultLogError(e);
+        }
+        
+        getSite().setSelectionProvider(new ActiveSelectionProvider() {
+               
+               @Override
+               public void setSelection(ISelection selection) {
+                       super.setSelection(selection);
+               }
+               
+        });
+        
+    }
+
+    @Override
+    public void setFocus() {
+       if (root != null && root.getControl() != null && !root.getControl().isDisposed())
+               root.getControl().setFocus();
+       else if (!base.isDisposed())
+           base.setFocus();
+    }
+    
+}