--- /dev/null
+/*******************************************************************************\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