]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/Children.java
Sync git svn branch with SVN repository r33324.
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / Children.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in 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.g2d.element.handler;\r
13 \r
14 import java.util.Collection;\r
15 \r
16 import org.simantics.g2d.element.IElement;\r
17 import org.simantics.g2d.element.ElementClass.Single;\r
18 \r
19 /**\r
20  * A handler for retrieving the child elements of an element.\r
21  *\r
22  * @author Tuukka Lehtonen\r
23  */\r
24 @Single\r
25 public interface Children extends ElementHandler {\r
26 \r
27     public static class ChildEvent {\r
28         public final IElement             parent;\r
29         public final Collection<IElement> removed;\r
30         public final Collection<IElement> added;\r
31 \r
32         public ChildEvent(IElement parent, Collection<IElement> removed, Collection<IElement> added) {\r
33             this.parent = parent;\r
34             this.removed = removed;\r
35             this.added = added;\r
36         }\r
37 \r
38         @Override\r
39         public String toString() {\r
40             return getClass().getSimpleName() + "[parent=" + parent + ", removed=" + removed + ", added=" + added + "]";\r
41         }\r
42     }\r
43 \r
44     public interface ChildListener {\r
45         void elementChildrenChanged(ChildEvent event);\r
46     }\r
47 \r
48     /**\r
49      * @param element the element to check for child elements\r
50      * @param result the collection to populate with the results or\r
51      *        <code>null</code> to allocate a new collection. The results shall\r
52      *        be appended to the provided collection.\r
53      * @return all child elements of the specified IElement or <code>null</code>\r
54      *         if result was <code>null</code> and no children exist\r
55      */\r
56     Collection<IElement> getChildren(IElement element, Collection<IElement> result);\r
57 \r
58     /**\r
59      * @param listener\r
60      */\r
61     void addChildListener(IElement element, ChildListener listener);\r
62 \r
63     /**\r
64      * @param listener\r
65      */\r
66     void removeChildListener(IElement element, ChildListener listener);\r
67 \r
68 }\r