]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/ReferenceElementRemover.java
Expose proxied subject in GroupProxySymbolItem
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / ReferenceElementRemover.java
1 /*******************************************************************************
2  * Copyright (c) 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.adapters;
13
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;
18
19 /**
20  * @author Tuukka Lehtonen
21  */
22 public class ReferenceElementRemover extends ElementRemover {
23
24     public ReferenceElementRemover(Resource referenceElement) {
25         super(referenceElement);
26     }
27
28     @Override
29     public void remove(WriteGraph graph) throws DatabaseException {
30         ModelingResources MOD = ModelingResources.getInstance(graph);
31
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));
36
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);
43         }
44
45         // Only after successfully denying all uses of referenceRelation
46         // can we delete the reference element itself.
47         super.remove(graph);
48     }
49
50 }