]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.g3d.shapeeditor/src/org/simantics/proconf/g3d/shapeeditor/handlers/NewCSGModelHandler.java
Set copyright texts for java files in the latest development branches.
[simantics/3d.git] / org.simantics.proconf.g3d.shapeeditor / src / org / simantics / proconf / g3d / shapeeditor / handlers / NewCSGModelHandler.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.shapeeditor.handlers;\r
12 \r
13 import org.eclipse.core.commands.AbstractHandler;\r
14 import org.eclipse.core.commands.ExecutionEvent;\r
15 import org.eclipse.core.commands.ExecutionException;\r
16 import org.eclipse.jface.viewers.ISelection;\r
17 import org.eclipse.jface.viewers.IStructuredSelection;\r
18 import org.eclipse.ui.handlers.HandlerUtil;\r
19 import org.simantics.proconf.g3d.csg.stubs.CSGModel;\r
20 \r
21 import org.simantics.proconf.ui.ProConfUI;\r
22 import org.simantics.proconf.ui.utils.ResourceAdaptionUtils;\r
23 import org.simantics.db.Graph;\r
24 import org.simantics.db.GraphRequestAdapter;\r
25 import org.simantics.db.GraphRequestStatus;\r
26 import org.simantics.db.Resource;\r
27 import org.simantics.layer0.stubs.Library;\r
28 \r
29 \r
30 public class NewCSGModelHandler extends AbstractHandler {\r
31 \r
32         @Override\r
33         public Object execute(ExecutionEvent event) throws ExecutionException {\r
34                 ISelection s = HandlerUtil.getCurrentSelectionChecked(event);\r
35         IStructuredSelection ss = (IStructuredSelection) s;\r
36         if (ss.size() != 1)\r
37             return null;\r
38         final Resource lib = ResourceAdaptionUtils.toSingleResource(ss);\r
39                 ProConfUI.getSession().asyncWrite(new GraphRequestAdapter() {\r
40                         @Override\r
41                         public GraphRequestStatus perform(Graph g) throws Exception {\r
42                                 CSGModel model = CSGModel.createDefault(g);\r
43                                 Library l = new Library(g, lib);\r
44                                 l.addStatement(g.getBuiltins().ConsistsOf, model);\r
45                                 \r
46                                 return GraphRequestStatus.transactionComplete();\r
47                         }\r
48                 });\r
49                 \r
50                 \r
51                 return null;\r
52         }\r
53 \r
54 }\r