1 /*******************************************************************************
\r
2 * Copyright (c) 2013 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 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.adapters;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.WriteGraph;
\r
16 import org.simantics.db.exception.DatabaseException;
\r
17 import org.simantics.modeling.ModelingResources;
\r
20 * @author Tuukka Lehtonen
\r
22 public class ReferenceElementRemover extends ElementRemover {
\r
24 public ReferenceElementRemover(Resource referenceElement) {
\r
25 super(referenceElement);
\r
29 public void remove(WriteGraph graph) throws DatabaseException {
\r
30 ModelingResources MOD = ModelingResources.getInstance(graph);
\r
32 Resource referencedComponent = graph.getPossibleObject(resource, MOD.HasParentComponent);
\r
33 Resource referenceRelation = graph.getPossibleObject(resource, MOD.HasReferenceRelation);
\r
34 //System.out.println("references component : " + NameUtils.getSafeName(graph, referencedComponent));
\r
35 //System.out.println("reference relation: " + NameUtils.getSafeName(graph, referenceRelation));
\r
37 if (referencedComponent != null && referenceRelation != null) {
\r
38 // Make sure that all referenceRelations from parentComponent are
\r
39 // removed since removing this reference element will also remove
\r
40 // the referenceRelation which would break the statements into
\r
41 // unusable form if the relation was still used anywhere.
\r
42 graph.deny(referencedComponent, referenceRelation);
\r
45 // Only after successfully denying all uses of referenceRelation
\r
46 // can we delete the reference element itself.
\r
47 super.remove(graph);
\r