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.utils.RemoverUtils;
24 import org.simantics.modeling.utils.RemoverUtils.ValidationResult;
27 * A remover implementation for symbol terminals.
30 * Contrary to ConnectionRelationRemover, this remover will only remove the
31 * diagram side connection relations in addition to removing the terminal
32 * itself. Deleting a terminal from the symbol does not imply that the whole
33 * connection point needs to be removed from the component type configuration,
34 * only that the graphical representation of the connection point is removed.
36 * @author Tuukka Lehtonen
37 * @see ConnectionRelationRemover
39 public class TerminalRemover extends ElementRemover {
41 public TerminalRemover(Resource terminal) {
46 public String canRemove(ReadGraph graph, Map<Object, Object> aux) throws DatabaseException {
47 DiagramResource DIA = DiagramResource.getInstance(graph);
48 ModelingResources MOD = ModelingResources.getInstance(graph);
50 for (Resource diagramConnectionRelation : graph.getObjects(resource, DIA.HasConnectionPoint)) {
51 for (Resource connectionRelation : graph.getObjects(diagramConnectionRelation, MOD.DiagramConnectionRelationToConnectionRelation)) {
52 ValidationResult result = RemoverUtils.validateConnectionRelationRemoval(graph, connectionRelation, diagramConnectionRelation);
54 return RemoverUtils.formatError(graph, result);
62 public void remove(WriteGraph graph) throws DatabaseException {
63 Layer0 L0 = Layer0.getInstance(graph);
64 DiagramResource DIA = DiagramResource.getInstance(graph);
66 for (Resource diagramConnectionPoint : graph.getObjects(resource, DIA.HasConnectionPoint)) {
67 Resource diagramConnectionPointInverse = graph.getPossibleObject(diagramConnectionPoint, L0.InverseOf);
68 graph.deny(diagramConnectionPoint);
69 if (diagramConnectionPointInverse != null)
70 graph.deny(diagramConnectionPointInverse);