/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * 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.g3d.csg.actions; import org.eclipse.jface.action.Action; import org.simantics.g3d.csg.scenegraph2.CSGnode; import org.simantics.g3d.csg.scenegraph2.CSGrootNode; import org.simantics.utils.ui.ExceptionUtils; public class AddPrimitiveAction2 extends Action { CSGrootNode root; Class primitiveClass; public AddPrimitiveAction2(CSGrootNode root, Class primitiveClass) { super(); String name = primitiveClass.getSimpleName(); if (name.endsWith("Node")) name = name.substring(0,name.length()-4); setText(name); this.primitiveClass = primitiveClass; this.root = root; } @Override public void run() { try { CSGnode node = primitiveClass.newInstance(); String name = root.getUniqueName(node.getClass().getSimpleName()); node.setName(name); root.addChild(node); root.getNodeMap().commit(); } catch (Exception e) { ExceptionUtils.logAndShowError("Cannot create primitive.", e); } } }