--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2012 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.modeling.adapters;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.Remover;\r
+import org.simantics.db.layer0.adapter.impl.EntityRemover;\r
+import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate;\r
+\r
+/**\r
+ * A {@link Remover} implementation for removing DIA.Monitor instances.\r
+ * \r
+ * TODO: see why we couldn't just use ElementRemover for monitors? Previously\r
+ * DIA.Monitors were explicitly declared in adapters.xml to adapt to\r
+ * EntityRemover, not ElementRemover. There had to be some reason for that\r
+ * choice.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class MonitorRemover extends EntityRemover {\r
+\r
+ private static final boolean DEBUG = false;\r
+\r
+ public MonitorRemover(Resource element) throws DatabaseException {\r
+ super(element);\r
+ }\r
+\r
+ @Override\r
+ public void remove(WriteGraph graph) throws DatabaseException {\r
+ if (DEBUG)\r
+ System.out.println(this + " removing monitor");\r
+\r
+ // 1. Disconnect element from diagrams\r
+ for (Resource diagram : OrderedSetElementsPredicate.INSTANCE.getSubjects(graph, resource)) {\r
+ OrderedSetUtils.remove(graph, diagram, resource);\r
+ }\r
+\r
+ // 2. Delete element itself\r
+ EntityRemover.remove(graph, resource);\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return getClass().getSimpleName() + resource;\r
+ }\r
+\r
+}\r