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;
14 import java.util.Collection;
15 import java.util.Collections;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.diagram.flag.FlagUtil;
23 import org.simantics.diagram.stubs.DiagramResource;
24 import org.simantics.modeling.adapters.Removers.ValidationResult;
27 * @author Tuukka Lehtonen
29 public class FlagRemover extends ElementRemover {
31 public FlagRemover(Resource flag) {
36 public String canRemove(ReadGraph graph, Map<Object, Object> aux) throws DatabaseException {
37 boolean lifted = FlagUtil.isLifted(graph, resource);
39 ValidationResult result = Removers.validateFlagRemoval(graph, resource);
41 return Removers.formatError(graph, result);
48 public void remove(WriteGraph graph) throws DatabaseException {
49 FlagUtil.disconnectFlag(graph, resource);
51 DiagramResource DIA = DiagramResource.getInstance(graph);
52 Collection<Resource> connectionRelations = Collections.emptySet();
53 if (FlagUtil.isLifted(graph, resource))
54 connectionRelations = graph.getObjects(resource, DIA.IsLiftedAs);
58 if (!connectionRelations.isEmpty()) {
59 for (Resource connectionRelation : connectionRelations) {
60 new ConnectionRelationRemover(connectionRelation).remove(graph);