1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g3d.csg.actions;
14 import org.eclipse.jface.action.Action;
15 import org.simantics.g3d.csg.scenegraph2.CSGnode;
16 import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
17 import org.simantics.utils.ui.ExceptionUtils;
19 public class AddPrimitiveAction2 extends Action {
22 Class<? extends CSGnode> primitiveClass;
23 public AddPrimitiveAction2(CSGrootNode root, Class<? extends CSGnode> primitiveClass) {
25 String name = primitiveClass.getSimpleName();
26 if (name.endsWith("Node"))
27 name = name.substring(0,name.length()-4);
29 this.primitiveClass = primitiveClass;
36 CSGnode node = primitiveClass.newInstance();
37 String name = root.getUniqueName(node.getClass().getSimpleName());
40 root.getNodeMap().commit("Add primitive");
41 } catch (Exception e) {
42 ExceptionUtils.logAndShowError("Cannot create primitive.", e);