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