]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/MonitorRemover.java
Expose proxied subject in GroupProxySymbolItem
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / MonitorRemover.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.adapters;
13
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;
21
22 /**
23  * A {@link Remover} implementation for removing DIA.Monitor instances.
24  * 
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
28  * choice.
29  * 
30  * @author Tuukka Lehtonen
31  */
32 public class MonitorRemover extends EntityRemover {
33
34     private static final boolean DEBUG = false;
35
36     public MonitorRemover(Resource element) throws DatabaseException {
37         super(element);
38     }
39
40     @Override
41     public void remove(WriteGraph graph) throws DatabaseException {
42         if (DEBUG)
43             System.out.println(this + " removing monitor");
44
45         // 1. Disconnect element from diagrams
46         for (Resource diagram : OrderedSetElementsPredicate.INSTANCE.getSubjects(graph, resource)) {
47             OrderedSetUtils.remove(graph, diagram, resource);
48         }
49
50         // 2. Delete element itself
51         EntityRemover.remove(graph, resource);
52     }
53
54     @Override
55     public String toString() {
56         return getClass().getSimpleName() + resource;
57     }
58
59 }