1 /*******************************************************************************
2 * Copyright (c) 2012 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 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.adapters;
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;
26 * A remover implementation for symbol terminals.
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.
35 * @author Tuukka Lehtonen
36 * @see ConnectionRelationRemover
38 public class TerminalRemover extends ElementRemover {
40 public TerminalRemover(Resource terminal) {
45 public String canRemove(ReadGraph graph, Map<Object, Object> aux) throws DatabaseException {
46 DiagramResource DIA = DiagramResource.getInstance(graph);
47 ModelingResources MOD = ModelingResources.getInstance(graph);
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);
53 return Removers.formatError(graph, result);
61 public void remove(WriteGraph graph) throws DatabaseException {
62 Layer0 L0 = Layer0.getInstance(graph);
63 DiagramResource DIA = DiagramResource.getInstance(graph);
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);