]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/action/RemoveAction.java
8fcb93681bd3ea70d06e7997385220122b65b226
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / action / RemoveAction.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g3d.vtk.action;
13
14 import org.eclipse.jface.action.Action;
15 import org.simantics.g3d.scenegraph.IG3DNode;
16 import org.simantics.g3d.scenegraph.structural.IStructuralNode;
17 import org.simantics.g3d.vtk.Activator;
18 import org.simantics.g3d.vtk.common.VTKNodeMap;
19
20 public class RemoveAction extends Action {
21
22         private VTKNodeMap nodeMap;
23         protected IG3DNode node;
24         
25         public RemoveAction(VTKNodeMap nodeMap) {
26                 setText("Remove");
27                 setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/delete.png"));
28                 this.nodeMap = nodeMap;
29         }
30         
31         public void setNode(IG3DNode node) {
32                 this.node = node;
33                 setEnabled(isRemovable(node));
34         }
35         
36         public boolean isRemovable(IG3DNode node) {
37                 if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot())
38                         return false;
39                 return true;
40         }
41         
42         @Override
43         public void run() {
44                 
45                 doRemove(node);
46                 nodeMap.commit("Remove");
47                 node = null;
48         }
49         
50         protected void doRemove(IG3DNode node) {
51                 node.remove();
52         }
53 }