1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.actions;
\r
13 import java.util.List;
\r
15 import org.simantics.db.Graph;
\r
16 import org.simantics.db.GraphRequestStatus;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.layer0.utils.IEntity;
\r
19 import org.simantics.layer0.utils.EntityFactory;
\r
20 import org.simantics.proconf.g3d.Activator;
\r
21 import org.simantics.proconf.g3d.Resources;
\r
22 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;
\r
23 import org.simantics.proconf.g3d.common.StructuredResourceSelection;
\r
25 public class RemoveAction extends WriteAction {
\r
27 public RemoveAction(ThreeDimensionalEditorBase parent) {
\r
28 super(parent,false);
\r
31 public void init() {
\r
33 setToolTipText("Remove the object");
\r
34 this.setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/delete.png"));
\r
36 public GraphRequestStatus doChanges(Graph graph) {
\r
37 StructuredResourceSelection sel = parent.getSelectionAdapter().getCurrentSelection();
\r
38 List<Resource> res = sel.getSelectionList();
\r
39 for (Resource r : res) {
\r
40 IEntity t = EntityFactory.create(graph, r);
\r
41 if (t.isInstanceOf(Resources.g3dResource.G3DNode)) {
\r
42 IEntity parentNode = t.getSingleRelatedObject(Resources.g3dResource.HasParent);
\r
43 parentNode.removeStatement(Resources.g3dResource.HasChild, t);
\r
47 return GraphRequestStatus.transactionComplete();
\r
52 public boolean usable(Graph graph,List<Resource> resources) {
\r
53 return resources.size() > 0;
\r