/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.g2d.element.handler; import java.util.Collection; import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.ElementClass.Single; /** * A handler for retrieving the child elements of an element. * * @author Tuukka Lehtonen */ @Single public interface Children extends ElementHandler { public static class ChildEvent { public final IElement parent; public final Collection removed; public final Collection added; public ChildEvent(IElement parent, Collection removed, Collection added) { this.parent = parent; this.removed = removed; this.added = added; } @Override public String toString() { return getClass().getSimpleName() + "[parent=" + parent + ", removed=" + removed + ", added=" + added + "]"; } } public interface ChildListener { void elementChildrenChanged(ChildEvent event); } /** * @param element the element to check for child elements * @param result the collection to populate with the results or * null to allocate a new collection. The results shall * be appended to the provided collection. * @return all child elements of the specified IElement or null * if result was null and no children exist */ Collection getChildren(IElement element, Collection result); /** * @param listener */ void addChildListener(IElement element, ChildListener listener); /** * @param listener */ void removeChildListener(IElement element, ChildListener listener); }