]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/ReferenceElementRemover.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / ReferenceElementRemover.java
1 /*******************************************************************************\r
2  * Copyright (c) 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.modeling.adapters;\r
13 \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
18 \r
19 /**\r
20  * @author Tuukka Lehtonen\r
21  */\r
22 public class ReferenceElementRemover extends ElementRemover {\r
23 \r
24     public ReferenceElementRemover(Resource referenceElement) {\r
25         super(referenceElement);\r
26     }\r
27 \r
28     @Override\r
29     public void remove(WriteGraph graph) throws DatabaseException {\r
30         ModelingResources MOD = ModelingResources.getInstance(graph);\r
31 \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
36 \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
43         }\r
44 \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
48     }\r
49 \r
50 }\r