]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/Children.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / Children.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/Children.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/Children.java
new file mode 100644 (file)
index 0000000..0813475
--- /dev/null
@@ -0,0 +1,68 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in 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.g2d.element.handler;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.ElementClass.Single;\r
+\r
+/**\r
+ * A handler for retrieving the child elements of an element.\r
+ *\r
+ * @author Tuukka Lehtonen\r
+ */\r
+@Single\r
+public interface Children extends ElementHandler {\r
+\r
+    public static class ChildEvent {\r
+        public final IElement             parent;\r
+        public final Collection<IElement> removed;\r
+        public final Collection<IElement> added;\r
+\r
+        public ChildEvent(IElement parent, Collection<IElement> removed, Collection<IElement> added) {\r
+            this.parent = parent;\r
+            this.removed = removed;\r
+            this.added = added;\r
+        }\r
+\r
+        @Override\r
+        public String toString() {\r
+            return getClass().getSimpleName() + "[parent=" + parent + ", removed=" + removed + ", added=" + added + "]";\r
+        }\r
+    }\r
+\r
+    public interface ChildListener {\r
+        void elementChildrenChanged(ChildEvent event);\r
+    }\r
+\r
+    /**\r
+     * @param element the element to check for child elements\r
+     * @param result the collection to populate with the results or\r
+     *        <code>null</code> to allocate a new collection. The results shall\r
+     *        be appended to the provided collection.\r
+     * @return all child elements of the specified IElement or <code>null</code>\r
+     *         if result was <code>null</code> and no children exist\r
+     */\r
+    Collection<IElement> getChildren(IElement element, Collection<IElement> result);\r
+\r
+    /**\r
+     * @param listener\r
+     */\r
+    void addChildListener(IElement element, ChildListener listener);\r
+\r
+    /**\r
+     * @param listener\r
+     */\r
+    void removeChildListener(IElement element, ChildListener listener);\r
+\r
+}\r