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 org.simantics.db.Resource;
15 import org.simantics.db.WriteGraph;
16 import org.simantics.db.common.utils.OrderedSetUtils;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.adapter.Remover;
19 import org.simantics.db.layer0.adapter.impl.EntityRemover;
20 import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate;
23 * A {@link Remover} implementation for removing DIA.Monitor instances.
25 * TODO: see why we couldn't just use ElementRemover for monitors? Previously
26 * DIA.Monitors were explicitly declared in adapters.xml to adapt to
27 * EntityRemover, not ElementRemover. There had to be some reason for that
30 * @author Tuukka Lehtonen
32 public class MonitorRemover extends EntityRemover {
34 private static final boolean DEBUG = false;
36 public MonitorRemover(Resource element) throws DatabaseException {
41 public void remove(WriteGraph graph) throws DatabaseException {
43 System.out.println(this + " removing monitor");
45 // 1. Disconnect element from diagrams
46 for (Resource diagram : OrderedSetElementsPredicate.INSTANCE.getSubjects(graph, resource)) {
47 OrderedSetUtils.remove(graph, diagram, resource);
50 // 2. Delete element itself
51 EntityRemover.remove(graph, resource);
55 public String toString() {
56 return getClass().getSimpleName() + resource;