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