1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.element.handler;
14 import java.util.Collection;
16 import org.simantics.g2d.element.IElement;
17 import org.simantics.g2d.element.ElementClass.Single;
20 * A handler for retrieving the child elements of an element.
22 * @author Tuukka Lehtonen
25 public interface Children extends ElementHandler {
27 public static class ChildEvent {
28 public final IElement parent;
29 public final Collection<IElement> removed;
30 public final Collection<IElement> added;
32 public ChildEvent(IElement parent, Collection<IElement> removed, Collection<IElement> added) {
34 this.removed = removed;
39 public String toString() {
40 return getClass().getSimpleName() + "[parent=" + parent + ", removed=" + removed + ", added=" + added + "]";
44 public interface ChildListener {
45 void elementChildrenChanged(ChildEvent event);
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
56 Collection<IElement> getChildren(IElement element, Collection<IElement> result);
61 void addChildListener(IElement element, ChildListener listener);
66 void removeChildListener(IElement element, ChildListener listener);