All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.gef.util.EditPartUtilities Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2010, 2012 IBM Corporation, Gerhardt Informatics Ktf. and others.
 * 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:
 *     Research Group Software Construction,
 *     RWTH Aachen University, Germany - initial API and implementation
 *     Gerhardt Informatics Ktf.
 */
package org.eclipse.gef.util;

import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;

/**
 * Utility class comprising functions related to {@link EditPart}s
 * 
 * @author Alexander Nyssen
 * @author Philip Ritzkopf
 * 
 * @since 3.6
 * 
 */
public final class EditPartUtilities {

	private EditPartUtilities() {
		// provides only static utility functions and should not be accessed in
		// any other way than static.
	}

	/**
	 * Returns the transitive child edit part set of the given parent
	 * GraphicalEditPart.
	 * 
	 * @param parentEditPart
	 *            the parent graphical edit part for which to retrieve the
	 *            transitive child edit part set.
	 * 
	 * @return the transitive child edit part set
	 */
	public static LinkedHashSet getAllChildren(GraphicalEditPart parentEditPart) {
		LinkedHashSet transitiveChildren = new LinkedHashSet();
		List children = parentEditPart.getChildren();
		transitiveChildren.addAll(children);
		for (Iterator iterator = children.iterator(); iterator.hasNext();) {
			GraphicalEditPart child = (GraphicalEditPart) iterator.next();
			transitiveChildren.addAll(getAllChildren(child));
		}
		return transitiveChildren;
	}

	/**
	 * Returns the transitive nested connection edit parts.
	 * 
	 * @param graphicalEditPart
	 *            the graphical edit part
	 * 
	 * @return the transitive nested connection edit parts
	 */
	public static HashSet getAllNestedConnectionEditParts(
			GraphicalEditPart graphicalEditPart) {
		HashSet transitiveConnections = new HashSet();
		HashSet transitiveChildren = getAllChildren(graphicalEditPart);
		for (Iterator iterator = transitiveChildren.iterator(); iterator
				.hasNext();) {
			GraphicalEditPart child = (GraphicalEditPart) iterator.next();
			transitiveConnections.addAll(child.getSourceConnections());
			transitiveConnections.addAll(child.getTargetConnections());
		}
		return transitiveConnections;
	}

	/**
	 * Returns the set of ConnectionEditParts that are linked to
	 * the child edit parts of the given GraphicalEditPart.
	 * 
	 * @param graphicalEditPart
	 *            the graphical edit part
	 * 
	 * @return the set of child ConnectionEditParts for the given
	 *         GraphicalEditPart
	 */
	public static HashSet getNestedConnectionEditParts(
			GraphicalEditPart graphicalEditPart) {
		HashSet edges = new HashSet();
		List children = graphicalEditPart.getChildren();
		for (Iterator iterator = children.iterator(); iterator.hasNext();) {
			Object child = iterator.next();
			if (child instanceof GraphicalEditPart) {
				GraphicalEditPart childEditPart = (GraphicalEditPart) child;
				edges.addAll(childEditPart.getSourceConnections());
				edges.addAll(childEditPart.getTargetConnections());
			}
		}
		return edges;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy