]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d.shapeeditor/src/org/simantics/proconf/g3d/shapeeditor/handlers/NewCSGModelHandler.java
git-svn-id: https://www.simantics.org/svn/simantics/3d/trunk@22283 ac1ea38d-2e2b...
[simantics/3d.git] / org.simantics.g3d.shapeeditor / src / org / simantics / proconf / g3d / shapeeditor / handlers / NewCSGModelHandler.java
diff --git a/org.simantics.g3d.shapeeditor/src/org/simantics/proconf/g3d/shapeeditor/handlers/NewCSGModelHandler.java b/org.simantics.g3d.shapeeditor/src/org/simantics/proconf/g3d/shapeeditor/handlers/NewCSGModelHandler.java
new file mode 100644 (file)
index 0000000..f26f857
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007- VTT Technical Research Centre of Finland.\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.proconf.g3d.shapeeditor.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.proconf.g3d.csg.stubs.CSGModel;\r
+\r
+import org.simantics.proconf.ui.ProConfUI;\r
+import org.simantics.proconf.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.db.Graph;\r
+import org.simantics.db.GraphRequestAdapter;\r
+import org.simantics.db.GraphRequestStatus;\r
+import org.simantics.db.Resource;\r
+import org.simantics.layer0.stubs.Library;\r
+\r
+\r
+public class NewCSGModelHandler extends AbstractHandler {\r
+\r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+               ISelection s = HandlerUtil.getCurrentSelectionChecked(event);\r
+        IStructuredSelection ss = (IStructuredSelection) s;\r
+        if (ss.size() != 1)\r
+            return null;\r
+        final Resource lib = ResourceAdaptionUtils.toSingleResource(ss);\r
+               ProConfUI.getSession().asyncWrite(new GraphRequestAdapter() {\r
+                       @Override\r
+                       public GraphRequestStatus perform(Graph g) throws Exception {\r
+                               CSGModel model = CSGModel.createDefault(g);\r
+                               Library l = new Library(g, lib);\r
+                               l.addStatement(g.getBuiltins().ConsistsOf, model);\r
+                               \r
+                               return GraphRequestStatus.transactionComplete();\r
+                       }\r
+               });\r
+               \r
+               \r
+               return null;\r
+       }\r
+\r
+}\r