1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.scenegraph.loader;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.WriteGraph;
\r
16 import org.simantics.db.common.utils.ListUtils;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
18 import org.simantics.db.layer0.adapter.Remover;
\r
19 import org.simantics.db.layer0.adapter.impl.AbstractRemover;
\r
20 import org.simantics.db.layer0.adapter.impl.EntityRemover;
\r
21 import org.simantics.layer0.Layer0;
\r
22 import org.simantics.scenegraph.ontology.ScenegraphResources;
\r
25 * A {@link Remover} implementation for removing SG.Node instances.
\r
28 * In addition to removing the node instance itself, this remover first tries to
\r
29 * remove the node from the <em>children</em> linked list of its possible parent
\r
32 * @author Tuukka Lehtonen
\r
34 public class NodeRemover extends AbstractRemover {
\r
36 private static final boolean DEBUG = false;
\r
38 public NodeRemover(Resource node) throws DatabaseException {
\r
43 public void remove(WriteGraph graph) throws DatabaseException {
\r
45 System.out.println(this + " removing scene graph node");
\r
47 Layer0 L0 = Layer0.getInstance(graph);
\r
48 ScenegraphResources SG = ScenegraphResources.getInstance(graph);
\r
50 // 1. Remove node from possible parent resource linked list.
\r
51 for (Resource parentNode : graph.getObjects(resource, L0.PartOf)) {
\r
52 for (Resource list : graph.getObjects(parentNode, SG.Node_children)) {
\r
53 ListUtils.removeElement(graph, list, resource);
\r
57 // 2. Delete node itself
\r
58 EntityRemover.remove(graph, resource);
\r
62 public String toString() {
\r
63 return getClass().getSimpleName() + resource;
\r