sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/ui/TreeParent.java
author Matti Laitinen <matti.t.laitinen@nokia.com>
Wed, 21 Apr 2010 19:42:48 +0300
changeset 6 f65f740e69f9
parent 1 1050670c6980
permissions -rw-r--r--
AnalyzeTool Carbide Extension v1.9.0

/*
 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
 * Description:  Definitions for the class TreeParent
 *
 */

package com.nokia.s60tools.analyzetool.ui;

import java.util.ArrayList;
import java.util.List;

/**
 * Class to implement TreeParent.
 *
 * @author kihe
 *
 */
public class TreeParent extends TreeObject {

	/** Contains list of childrens. */
	private final List<Object> children;

	/**
	 * Constructor.
	 *
	 * @param name
	 *            Current object name
	 */
	public TreeParent(final String name) {
		if (name != null) {
			super.setName(name);
		}
		children = new ArrayList<Object>();
	}

	/**
	 * Adds child.
	 *
	 * @param index
	 *            Index
	 * @param child
	 *            Current parent child
	 */
	public final void addChild(final int index, final TreeObject child) {
		children.add(index, child);
		child.setParent(this);
	}

	/**
	 * Adds child.
	 *
	 * @param child
	 *            Current parent child
	 */
	public final void addChild(final TreeObject child) {
		children.add(child);
		child.setParent(this);
	}

	/**
	 * Gets current parent child objects.
	 *
	 * @return Array of TreeObject
	 */
	public final Object[] getChildren() {
		return children.toArray(new TreeObject[children.size()]);
	}

	/**
	 * Check that does current parent contains child objects.
	 *
	 * @return True if parent contains childrens otherwise false
	 */
	public final boolean hasChildren() {
		return !children.isEmpty();
	}

	/**
	 * Removes child.
	 *
	 * @param child
	 *            Current parent child
	 */
	public final void removeChild(final TreeObject child) {
		children.remove(child);
		child.setParent(null);
	}
}