]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/MonitorRemover.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / MonitorRemover.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.modeling.adapters;\r
13 \r
14 import org.simantics.db.Resource;\r
15 import org.simantics.db.WriteGraph;\r
16 import org.simantics.db.common.utils.OrderedSetUtils;\r
17 import org.simantics.db.exception.DatabaseException;\r
18 import org.simantics.db.layer0.adapter.Remover;\r
19 import org.simantics.db.layer0.adapter.impl.EntityRemover;\r
20 import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate;\r
21 \r
22 /**\r
23  * A {@link Remover} implementation for removing DIA.Monitor instances.\r
24  * \r
25  * TODO: see why we couldn't just use ElementRemover for monitors? Previously\r
26  * DIA.Monitors were explicitly declared in adapters.xml to adapt to\r
27  * EntityRemover, not ElementRemover. There had to be some reason for that\r
28  * choice.\r
29  * \r
30  * @author Tuukka Lehtonen\r
31  */\r
32 public class MonitorRemover extends EntityRemover {\r
33 \r
34     private static final boolean DEBUG = false;\r
35 \r
36     public MonitorRemover(Resource element) throws DatabaseException {\r
37         super(element);\r
38     }\r
39 \r
40     @Override\r
41     public void remove(WriteGraph graph) throws DatabaseException {\r
42         if (DEBUG)\r
43             System.out.println(this + " removing monitor");\r
44 \r
45         // 1. Disconnect element from diagrams\r
46         for (Resource diagram : OrderedSetElementsPredicate.INSTANCE.getSubjects(graph, resource)) {\r
47             OrderedSetUtils.remove(graph, diagram, resource);\r
48         }\r
49 \r
50         // 2. Delete element itself\r
51         EntityRemover.remove(graph, resource);\r
52     }\r
53 \r
54     @Override\r
55     public String toString() {\r
56         return getClass().getSimpleName() + resource;\r
57     }\r
58 \r
59 }\r