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
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.shapeeditor.handlers;
\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
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
30 public class NewCSGModelHandler extends AbstractHandler {
\r
33 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
34 ISelection s = HandlerUtil.getCurrentSelectionChecked(event);
\r
35 IStructuredSelection ss = (IStructuredSelection) s;
\r
38 final Resource lib = ResourceAdaptionUtils.toSingleResource(ss);
\r
39 ProConfUI.getSession().asyncWrite(new GraphRequestAdapter() {
\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
46 return GraphRequestStatus.transactionComplete();
\r