]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/TerminalRemover.java
Make it possible to debug SCL compiler in production builds
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / TerminalRemover.java
1 /*******************************************************************************
2  * Copyright (c) 2012 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  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.adapters;
13
14 import java.util.Map;
15
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.diagram.stubs.DiagramResource;
21 import org.simantics.layer0.Layer0;
22 import org.simantics.modeling.ModelingResources;
23 import org.simantics.modeling.adapters.Removers.ValidationResult;
24
25 /**
26  * A remover implementation for symbol terminals.
27  * 
28  * <p>
29  * Contrary to ConnectionRelationRemover, this remover will only remove the
30  * diagram side connection relations in addition to removing the terminal
31  * itself. Deleting a terminal from the symbol does not imply that the whole
32  * connection point needs to be removed from the component type configuration,
33  * only that the graphical representation of the connection point is removed.
34  * 
35  * @author Tuukka Lehtonen
36  * @see ConnectionRelationRemover
37  */
38 public class TerminalRemover extends ElementRemover {
39
40     public TerminalRemover(Resource terminal) {
41         super(terminal);
42     }
43
44     @Override
45     public String canRemove(ReadGraph graph, Map<Object, Object> aux) throws DatabaseException {
46         DiagramResource DIA = DiagramResource.getInstance(graph);
47         ModelingResources MOD = ModelingResources.getInstance(graph);
48
49         for (Resource diagramConnectionRelation : graph.getObjects(resource, DIA.HasConnectionPoint)) {
50             for (Resource connectionRelation : graph.getObjects(diagramConnectionRelation, MOD.DiagramConnectionRelationToConnectionRelation)) {
51                 ValidationResult result = Removers.validateConnectionRelationRemoval(graph, connectionRelation, diagramConnectionRelation);
52                 if (result.inUse())
53                     return Removers.formatError(graph, result);
54             }
55         }
56
57         return null;
58     }
59
60     @Override
61     public void remove(WriteGraph graph) throws DatabaseException {
62         Layer0 L0 = Layer0.getInstance(graph);
63         DiagramResource DIA = DiagramResource.getInstance(graph);
64
65         for (Resource diagramConnectionPoint : graph.getObjects(resource, DIA.HasConnectionPoint)) {
66             Resource diagramConnectionPointInverse = graph.getPossibleObject(diagramConnectionPoint, L0.InverseOf);
67             graph.deny(diagramConnectionPoint);
68             if (diagramConnectionPointInverse != null)
69                 graph.deny(diagramConnectionPointInverse);
70         }
71
72         removeElement(graph);
73     }
74
75 }