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