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.utils.RemoverUtils;
25 import org.simantics.modeling.utils.RemoverUtils.ValidationResult;
28 * @author Tuukka Lehtonen
30 public class FlagRemover extends ElementRemover {
32 public FlagRemover(Resource flag) {
37 public String canRemove(ReadGraph graph, Map<Object, Object> aux) throws DatabaseException {
38 boolean lifted = FlagUtil.isLifted(graph, resource);
40 ValidationResult result = RemoverUtils.validateFlagRemoval(graph, resource);
42 return RemoverUtils.formatError(graph, result);
49 public void remove(WriteGraph graph) throws DatabaseException {
50 FlagUtil.disconnectFlag(graph, resource);
52 DiagramResource DIA = DiagramResource.getInstance(graph);
53 Collection<Resource> connectionRelations = Collections.emptySet();
54 if (FlagUtil.isLifted(graph, resource))
55 connectionRelations = graph.getObjects(resource, DIA.IsLiftedAs);
59 if (!connectionRelations.isEmpty()) {
60 for (Resource connectionRelation : connectionRelations) {
61 new ConnectionRelationRemover(connectionRelation).remove(graph);