/******************************************************************************* * 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.vtk.action; import org.eclipse.jface.action.Action; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.structural.IStructuralNode; import org.simantics.g3d.vtk.Activator; import org.simantics.g3d.vtk.common.VTKNodeMap; public class RemoveAction extends Action { private VTKNodeMap nodeMap; protected INode node; public RemoveAction(VTKNodeMap nodeMap) { setText("Remove"); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/delete.png")); this.nodeMap = nodeMap; } public void setNode(INode node) { this.node = node; setEnabled(isRemovable(node)); } public boolean isRemovable(INode node) { if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()) return false; return true; } @Override public void run() { doRemove(node); nodeMap.commit("Remove"); node = null; } protected void doRemove(INode node) { node.remove(); } }