/******************************************************************************* * Copyright (c) 2007- VTT Technical Research Centre of Finland. * 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.proconf.g3d.shapeeditor.handlers; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.proconf.g3d.csg.stubs.CSGModel; import org.simantics.proconf.ui.ProConfUI; import org.simantics.proconf.ui.utils.ResourceAdaptionUtils; import org.simantics.db.Graph; import org.simantics.db.GraphRequestAdapter; import org.simantics.db.GraphRequestStatus; import org.simantics.db.Resource; import org.simantics.layer0.stubs.Library; public class NewCSGModelHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection s = HandlerUtil.getCurrentSelectionChecked(event); IStructuredSelection ss = (IStructuredSelection) s; if (ss.size() != 1) return null; final Resource lib = ResourceAdaptionUtils.toSingleResource(ss); ProConfUI.getSession().asyncWrite(new GraphRequestAdapter() { @Override public GraphRequestStatus perform(Graph g) throws Exception { CSGModel model = CSGModel.createDefault(g); Library l = new Library(g, lib); l.addStatement(g.getBuiltins().ConsistsOf, model); return GraphRequestStatus.transactionComplete(); } }); return null; } }