Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Gayed2005-02-07 19:15:46 +0000
committerGrant Gayed2005-02-07 19:15:46 +0000
commit4f97b87498d307bd6463384c05cd190bcdfe42c0 (patch)
tree67e4727fdc7d8e7e07b18948245b6034247de8a9
parentca982392e30f7e92b4d9c90a0826b6836388f5e5 (diff)
downloadeclipse.platform.swt-4f97b87498d307bd6463384c05cd190bcdfe42c0.tar.gz
eclipse.platform.swt-4f97b87498d307bd6463384c05cd190bcdfe42c0.tar.xz
eclipse.platform.swt-4f97b87498d307bd6463384c05cd190bcdfe42c0.zip
*** empty log message ***
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java317
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree2.java1704
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem2.java1423
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java163
4 files changed, 0 insertions, 3607 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java
deleted file mode 100644
index 62f584656b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * This class stores and manages child items of a tree item.
- * It provides protocol to query the index of an item relative
- * to the root and to retrieve items by index.
- * The TreeItem class implements this protocol for general
- * tree items.
- * TreeRoots provides a special implementation that allows the
- * Tree class to treat trees with one root and with multiple
- * roots equally.
- */
-abstract class AbstractTreeItem extends SelectableItem {
- private Vector children;
- private boolean isExpanded = false;
- // number of children.
- // includes all expanded items down to the leafs.
- private int visibleItemCount = 0;
-
-/**
- * Create a new instance of the receiver.
- * @param parent - widget the receiver belongs to
- * @param swtStyle - widget style. see Widget class for details
- */
-AbstractTreeItem(Tree2 parent, int swtStyle) {
- super(parent, swtStyle);
-}
-/**
- * Insert 'item' in the list of child items. Notify the
- * parent about the new item.
- * @param 'item' - the item that should be added to the
- * receiver's children.
- * @param index - position that 'item' will be inserted at
- * in the receiver.
- */
-void add(TreeItem2 item, int index) {
- Vector items = getChildren();
- int visibleIndex = getVisibleIndex();
-
- if (index < 0 || index > items.size()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- if (item.isRoot()) {
- visibleIndex = index;
- }
- else
- if (isExpanded == false) {
- visibleIndex = -1;
- }
- if (visibleIndex != -1) {
- if (index > 0) {
- TreeItem2 previousChild = (TreeItem2) getChildren().elementAt(index - 1);
- visibleIndex = previousChild.getVisibleIndex() + previousChild.getVisibleItemCount() + 1;
- }
- else {
- visibleIndex = getVisibleIndex() + 1;
- }
- }
- getSelectableParent().addingItem(item, visibleIndex);
- item.setIndex(index);
- resetChildIndices(index, true);
- items.insertElementAt(item, index);
- if (isExpanded == true) {
- visibleItemCount++;
- calculateVisibleItemCountParent();
- }
- getSelectableParent().addedItem(item, visibleIndex);
-}
-/**
- * Set whether the receiver is expanded or not.
- * If the receiver is expanded its child items are visible.
- * @param expanded -
- * true=the receiver is expanded, making its child items visible.
- * false=the receiver is collapsed, making its child items invisible
- */
-void internalSetExpanded(boolean expanded) {
- isExpanded = expanded;
- calculateVisibleItemCount();
-}
-/**
- * Calculate the number of expanded children.
- * Recurse up in the tree to the root item.
- */
-abstract void calculateVisibleItemCount();
-/**
- * Calculate the number of expanded children for the parent item
- * of this item.
- */
-abstract void calculateVisibleItemCountParent();
-/**
- * Deselect the receiver and all children
- */
-void deselectAll() {
- Enumeration children = getChildren().elements();
- AbstractTreeItem treeItem;
-
- setSelected(false);
- while (children.hasMoreElements() == true) {
- treeItem = (AbstractTreeItem) children.nextElement();
- treeItem.deselectAll();
- }
-}
-public void dispose() {
- if (isDisposed()) return;
- Vector children = getChildren();
- AbstractTreeItem child;
- while (children.size() > 0) { // TreeItem objects are removed from vector during dispose
- child = (AbstractTreeItem) children.firstElement();
- child.dispose();
- }
- super.dispose();
-}
-void doDispose() {
- setChildren(null);
- visibleItemCount = 0;
- super.doDispose();
-}
-/**
- * Answer the Vector containing the child items of the receiver.
- */
-Vector getChildren() {
- if (children == null) {
- children = new Vector(4);
- }
- return children;
-}
-/**
- * Answer whether the receiver is expanded or not.
- * If the receiver is expanded its children are visible.
- * @return
- * true - the receiver is expanded, making its children visible
- * false - the receiver is collapsed, making its children invisible
- */
-public boolean getExpanded() {
- checkWidget();
-
- return isExpanded;
-}
-/**
- * Answer the number of children.
- */
-public int getItemCount() {
- checkWidget();
-
- return getChildren().size();
-}
-/**
- * Answer the index of the receiver relative to the first root
- * item.
- * If 'anIndex' is the global index of the expanded item 'anItem'
- * then the following expressions are true:
- * 'anItem == theRoot.getVisibleItem(anIndex)' and
- * 'anIndex == anItem.getVisibleIndex()'
- * @return
- * The index of the receiver relative to the first root item.
- * Answer -1 if the receiver is not visible (because the parent
- * is collapsed).
- */
-abstract int getVisibleIndex();
-/**
- * Answer the index of the child item identified by 'childIndex'
- * relative to the first root item.
- */
-abstract int getVisibleIndex(int childIndex);
-/**
- * Answer the item at 'searchIndex' relativ to the receiver.
- * When this method is called for the root item, 'searchIndex'
- * represents the global index into all items of the tree.
- * searchIndex=0 returns the receiver.
- * searchIndex=1 returns the first visible child.
- * Note: searchIndex must be >= 0
- *
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. Visible here means that all
- * the parents of the item are expanded. An item is only
- * visible on screen if it is within the receiver's parent's
- * client area.
- */
-abstract TreeItem2 getVisibleItem(int searchIndex);
-/**
- * Answer the number of expanded children, direct and indirect.
- */
-int getVisibleItemCount() {
- return visibleItemCount;
-}
-/**
- * Returns the expanded state. Circumvent widget/thread check
- * for performance. For non-API callers only.
- */
-boolean internalGetExpanded() {
- return isExpanded;
-}
-/**
- * Answer whether the receiver is a leaf item.
- * An item is a leaf when it has no child items.
- * @return
- * true - receiver is a leaf item
- * false - receiver is not a leaf item.
- */
-boolean isLeaf() {
- return (getChildren().size() == 0);
-}
-/**
- * Answer whether the receiver is a root item.
- * The receiver is a root item when it doesn't have a parent item.
- * @return
- * true - the receiver is a root item.
- * false - the receiver is not a root item.
- */
-boolean isRoot() {
- return false;
-}
-/**
- * Remove 'child' from the receiver.
- * Notify the parent widget only if it is not being disposed itself.
- */
-void removeItem(SelectableItem child) {
- Vector children = getChildren();
- SelectableItemWidget parent = getSelectableParent();
- int childIndex = children.indexOf(child);
-
- if (childIndex != -1) {
- if (((Tree2) parent).isRemovingAll() == true) {
- children.removeElementAt(childIndex); // just remove the item from the list if the whole tree is being disposed
- if (isExpanded == true) {
- visibleItemCount--;
- calculateVisibleItemCountParent();
- }
- }
- else {
- parent.removingItem(child);
- children.removeElementAt(childIndex);
- if (isExpanded == true) {
- visibleItemCount--;
- calculateVisibleItemCountParent();
- }
- resetChildIndices(childIndex, false); // mark child index dirty
- parent.removedItem(child);
- }
- }
-}
-/**
- * Allow subclasses to reset any cached data.
- * Called for all children of the receiver.
- */
-void reset() {
- Enumeration children = getChildren().elements();
- AbstractTreeItem treeItem;
-
- while (children.hasMoreElements() == true) {
- treeItem = (AbstractTreeItem) children.nextElement();
- treeItem.reset();
- }
-}
-/**
- * Mark all child indices dirty starting with the child at
- * 'startIndex'. This causes getIndex to recalculate the index.
- * @param startIndex - index in the list of children at which
- * and after which the indices are reset.
- */
-void resetChildIndices(int startIndex, boolean addItem) {
- Vector children = getChildren();
- TreeItem2 child;
- int increment = addItem ? 1 : 0;
-
- for (int i = startIndex; i < children.size(); i++) {
- child = (TreeItem2) children.elementAt(i);
- child.setIndex(i + increment); // mark child index dirty
- }
-}
-/**
- * Select the receiver and all children.
- * Return a Vector containing all the items that have been selected
- * (and that have not been selected before).
- */
-Vector selectAll(Vector selectedItems) {
- Enumeration children = getChildren().elements();
- AbstractTreeItem treeItem;
-
- if (isSelected() == false) {
- selectedItems.addElement(this);
- setSelected(true);
- getSelectableParent().redrawSelection(this);
- }
- while (children.hasMoreElements() == true) {
- treeItem = (AbstractTreeItem) children.nextElement();
- selectedItems = treeItem.selectAll(selectedItems);
- }
- return selectedItems;
-}
-/**
- * Set the Array containing the receiver's child items to 'children'.
- */
-void setChildren(Vector children) {
- this.children = children;
-}
-
-void setVisibleItemCount(int count) {
- visibleItemCount = count;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree2.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree2.java
deleted file mode 100644
index a044a8cc0f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree2.java
+++ /dev/null
@@ -1,1704 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * Instances of this class provide a selectable user interface object
- * that displays a hierarchy of items and issue notificiation when an
- * item in the hierarchy is selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TreeItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, Collapse, Expand</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class Tree2 extends SelectableItemWidget {
- // These constants are used internally for item hit test on mouse click
- private static final int ActionNone = 0; // The mouse event was not handled
- private static final int ActionExpandCollapse = 1; // Do an expand/collapse
- private static final int ActionSelect = 2; // Select the item
- private static final int ActionCheck = 3; // Toggle checked state of the item
- private static ImageData CollapsedImageData; // collapsed sub tree image data. used to create an image at run time
- private static ImageData ExpandedImageData; // expanded sub tree image data. used to create an image at run time
- static {
- initializeImageData();
- }
-
- private TreeRoots root;
- private TreeItem2 expandingItem;
-
- private Image collapsedImage;
- private Image expandedImage;
-
- // The following fields are needed for painting tree items
- final Color CONNECTOR_LINE_COLOR; // Color constant used during painting. Can't keep this in TreeItem
- // because we only need one instance per tree widget/display and can't
- // have it static. Initialized in c'tor and freed in dispose();
- Rectangle hierarchyIndicatorRect = null; // bounding rectangle of the hierarchy indication image (plus/minus)
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tree2(Composite parent, int style) {
- super(parent, checkStyle (style));
- CONNECTOR_LINE_COLOR = new Color(display, 170, 170, 170); // Light gray;
-}
-/**
- * Add 'item' to the list of root items.
- * @param 'item' - the tree item that should be added as a root.
- * @param index - position that 'item' will be inserted at
- * in the receiver.
- */
-void addItem(TreeItem2 item, int index) {
- if (index < 0 || index > getItemCount()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- getRoot().add(item, index);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's selection changes, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the reciever has <code>SWT.CHECK</code> style set and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- TypedListener typedListener;
-
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- typedListener = new TypedListener(listener);
- addListener(SWT.Selection, typedListener);
- addListener(SWT.DefaultSelection, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>TreeListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #removeTreeListener
- */
-public void addTreeListener(TreeListener listener) {
- checkWidget();
- TypedListener typedListener;
-
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- typedListener = new TypedListener(listener);
- addListener(SWT.Expand, typedListener);
- addListener(SWT.Collapse, typedListener);
-}
-/**
- * The SelectableItem 'item' has been added to the tree.
- * Prevent screen updates when 'item' is inserted due to an
- * expand operation.
- * @param item - item that has been added to the receiver.
- */
-void addedItem(SelectableItem item, int index) {
- super.addedItem(item, index);
- redrawAfterModify(item, index); // redraw plus/minus image, hierarchy lines
-}
-/**
- * Answer the y position of both the first child of 'item' and
- * the item following the last child of 'item'.
- * Used to scroll items on expand/collapse.
- * @param item - TreeItem to use for calculating the y boundary
- * of child items.
- * @return Array - first element is the position of the first
- * child of 'item'. Second element is the position of the item
- * following the last child of 'item'.
- * Both elements are -1 if 'item' is not a child of the receiver.
- */
-int[] calculateChildrenYPos(TreeItem2 item) {
- int itemIndex = item.getVisibleIndex();
- int itemCount = item.getVisibleItemCount();
- int itemHeight = getItemHeight();
- int yPos;
- int[] yPosition = new int[] {-1, -1};
-
- if (itemIndex != -1) {
- itemIndex -= getTopIndex();
- yPos = (itemIndex + itemCount + 1) * itemHeight; // y position of the item following
- // the last child of 'item'
- yPosition = new int[] {yPos - (itemCount * itemHeight), yPos};
- }
- return yPosition;
-}
-/**
- * Calculate the widest of the children of 'item'.
- * Items that are off screen and that may be scrolled into view are
- * included in the calculation.
- * @param item - the tree item that was expanded
- */
-void calculateWidestExpandingItem(TreeItem2 item) {
- int itemIndex = item.getVisibleIndex();
- int newMaximumItemWidth = getContentWidth();
- int stopIndex = itemIndex + item.getVisibleItemCount();
-
- for (int i = itemIndex + 1; i <= stopIndex; i++) {
- newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
- }
- setContentWidth(newMaximumItemWidth);
-}
-/**
- * Calculate the width of new items as they are scrolled into view.
- * Precondition:
- * topIndex has already been set to the new index.
- * @param topIndexDifference - difference between old and new top
- * index.
- */
-void calculateWidestScrolledItem(int topIndexDifference) {
- int visibleItemCount = getItemCountTruncated(getClientArea());
- int newMaximumItemWidth = getContentWidth();
- int topIndex = getTopIndex();
- int stopIndex = topIndex;
-
- if (topIndexDifference < 0) { // scrolled up?
- if (Math.abs(topIndexDifference) > visibleItemCount) { // scrolled down more than one page (via quick thumb dragging)?
- topIndexDifference = visibleItemCount * -1;
- }
- for (int i = stopIndex - topIndexDifference; i >= stopIndex; i--) { // check item width from old top index up to new one
- newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
- }
- }
- else
- if (topIndexDifference > 0) { // scrolled down?
- if (topIndexDifference > visibleItemCount) { // scrolled down more than one page (via quick thumb dragging)?
- topIndexDifference = visibleItemCount;
- }
- stopIndex += visibleItemCount;
- for (int i = stopIndex - topIndexDifference; i < stopIndex; i++) {
- newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
- }
- }
- setContentWidth(newMaximumItemWidth);
-}
-/**
- * Calculate the maximum item width of all displayed items.
- */
-void calculateWidestShowingItem() {
- TreeItem2 visibleItem;
- int newMaximumItemWidth = 0;
- int bottomIndex = getBottomIndex();
- int paintStopX;
-
- // add one to the loop end index because otherwise an item covered
- // by the horizontal scroll bar would not be taken into acount and
- // may become visible after this calculation. We're in trouble if
- // that item is wider than the client area.
- if (getHorizontalBar().getVisible() == true) {
- bottomIndex++;
- }
- for (int i = getTopIndex(); i < bottomIndex; i++) {
- visibleItem = getRoot().getVisibleItem(i);
- if (visibleItem != null) {
- paintStopX = visibleItem.getPaintStopX();
- newMaximumItemWidth = Math.max(newMaximumItemWidth, paintStopX);
- }
- }
- setContentWidth(newMaximumItemWidth);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-/**
- * Collapse the tree item identified by 'item' if it is not
- * already collapsed. Move the selection to the parent item
- * if one of the collapsed items is currently selected.
- * @param item - item that should be collapsed.
- * @param notifyListeners -
- * true=a Collapse event is sent
- * false=no event is sent
- */
-void collapse(TreeItem2 item, boolean notifyListeners) {
- Event event;
- int itemIndex;
-
- if (item.getExpanded() == false) {
- return;
- }
- if (notifyListeners == true) {
- event = new Event();
- event.item = item;
- notifyListeners(SWT.Collapse, event);
- if (isDisposed()) return;
- }
- collapseNoRedraw(item);
- itemIndex = item.getVisibleIndex();
- if (itemIndex != -1) { // if the item's parent is not collapsed (and the item is thus visible) do the screen updates
- item.redrawExpanded(itemIndex - getTopIndex());
- showSelectableItem(item);
- calculateVerticalScrollbar();
- calculateWidestShowingItem();
- claimRightFreeSpace();
- claimBottomFreeSpace();
- }
-}
-
-/**
- * Collapse the tree item identified by 'item' if it is not
- * already collapsed. Move the selection to the parent item
- * if one of the collapsed items is currently selected.
- * This method is used to hide the children if an item is deleted.
- * certain redraw and scroll operations are not needed for this
- * case.
- * @param item - item that should be collapsed.
- */
-void collapseNoRedraw(TreeItem2 item) {
-
- if (item.getExpanded() == false) {
- return;
- }
- if (isSelectedItemCollapsing(item) == true) {
- deselectAllExcept(item);
- selectNotify(item);
- update(); // call update to make sure that new selection is
- // drawn before items are collapsed (looks better)
- }
- scrollForCollapse(item);
- item.internalSetExpanded(false);
-}
-
-public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size = super.computeSize(wHint, hHint, changed);
- GC gc;
- final int WidthCalculationCount = 50; // calculate item width for the first couple of items only
- TreeRoots root = getRoot();
- TreeItem2 item;
- Image itemImage;
- String itemText;
- int width;
- int newItemWidth = 0;
-
- if (wHint == SWT.DEFAULT && getContentWidth() == 0 && getItemCount() > 0) {
- gc = new GC(this);
- for (int i = 0; i < WidthCalculationCount; i++) {
- item = root.getVisibleItem(i);
- if (item == null) {
- break; // no more items
- }
- itemImage = item.getImage();
- itemText = item.getText();
- width = 0;
- if (itemImage != null) {
- width += itemImage.getBounds().width;
- }
- if (itemText != null) {
- gc.setFont(item.getFont());
- width += gc.stringExtent(itemText).x;
- }
- newItemWidth = Math.max(newItemWidth, width);
- }
- if (newItemWidth > 0) {
- size.x = newItemWidth;
- }
- gc.dispose();
- }
- return size;
-}
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll() {
- checkWidget();
- getRoot().deselectAll();
- getSelectionVector().removeAllElements();
- redraw();
-}
-/**
- * Modifier Key Action
- * None Collapse the selected item if expanded. Select
- * parent item if selected item is already
- * collapsed and if it's not the root item.
- * Ctrl super.doArrowLeft(int);
- * Shift see None above
- * @param keyMask - the modifier key that was pressed
- */
-void doArrowLeft(int keyMask) {
- TreeItem2 focusItem = (TreeItem2) getLastFocus();
- TreeItem2 parentItem;
-
- if (focusItem == null) {
- return;
- }
- if (keyMask == SWT.MOD1) {
- super.doArrowLeft(keyMask);
- }
- else
- if (focusItem.getExpanded() == true) { // collapse if expanded
- collapse(focusItem, true);
- }
- else
- if (focusItem.isRoot() == false) { // go to the parent if there is one
- parentItem = focusItem.getParentItem();
- deselectAllExcept(parentItem);
- selectNotify(parentItem);
- }
-}
-/**
- * Modifier Key Action
- * None Expand selected item if collapsed. Select
- * first child item if selected item is
- * already expanded and there is a child item.
- * Ctrl super.doArrowRight(keyMask);
- * Shift see None above
- * @param keyMask - the modifier key that was pressed
- */
-void doArrowRight(int keyMask) {
- TreeItem2 focusItem = (TreeItem2) getLastFocus();
- TreeItem2 childItem;
-
- if (focusItem == null) {
- return;
- }
- if (keyMask == SWT.MOD1) {
- super.doArrowRight(keyMask);
- }
- else
- if (focusItem.isLeaf() == false) {
- if (focusItem.getExpanded() == false) { // expand if collapsed
- expand(focusItem, true);
- }
- else { // go to the first child if there is one
- childItem = focusItem.getItems()[0];
- deselectAllExcept(childItem);
- selectNotify(childItem);
- }
- }
-}
-/**
- * Expand the selected item and all of its children.
- */
-void doAsterisk() {
- expandAll((TreeItem2) getLastFocus());
-}
-/**
- * Free resources.
- */
-void doDispose() {
- super.doDispose();
- if (collapsedImage != null) {
- collapsedImage.dispose();
- }
- if (expandedImage != null) {
- expandedImage.dispose();
- }
- getRoot().dispose();
- CONNECTOR_LINE_COLOR.dispose();
- resetHierarchyIndicatorRect();
-}
-/**
- * Collapse the selected item if it is expanded.
- */
-void doMinus() {
- TreeItem2 selectedItem = (TreeItem2) getLastFocus();
-
- if (selectedItem != null) {
- collapse(selectedItem, true);
- }
-}
-/**
- * Expand the selected item if it is collapsed and if it
- * has children.
- */
-void doPlus() {
- TreeItem2 selectedItem = (TreeItem2) getLastFocus();
-
- if (selectedItem != null && selectedItem.isLeaf() == false) {
- expand(selectedItem, true);
- }
-}
-/**
- * Expand the tree item identified by 'item' if it is not already
- * expanded. Scroll the expanded items into view.
- * @param item - item that should be expanded
- * @param notifyListeners -
- * true=an Expand event is sent
- * false=no event is sent
- */
-void expand(TreeItem2 item, boolean notifyListeners) {
- Event event = new Event();
- boolean nestedExpand = expandingItem != null;
-
- if (item.getExpanded() == true || item.getExpanding() == true) {
- return;
- }
- item.setExpanding(true);
- if (nestedExpand == false) {
- setExpandingItem(item);
- }
- if (notifyListeners == true) {
- event.item = item;
- notifyListeners(SWT.Expand, event);
- }
- scrollForExpand(item);
- item.internalSetExpanded(true);
- // redraw hierarchy image
- item.redrawExpanded(item.getVisibleIndex() - getTopIndex());
- calculateVerticalScrollbar();
- if (nestedExpand == false && isVisible() == true) {
- showSelectableItem(item); // make expanded item visible. Could be invisible if the expand was caused by a key press.
- calculateWidestExpandingItem(item);
- scrollExpandedItemsIntoView(item);
- }
- if (nestedExpand == false) {
- setExpandingItem(null);
- }
- item.setExpanding(false);
-}
-/**
- * Expand 'item' and all its children.
- */
-void expandAll(TreeItem2 item) {
- TreeItem2 items[];
-
- if (item != null && item.isLeaf() == false) {
- expand(item, true);
- update();
- items = item.getItems();
- for (int i = 0; i < items.length; i++) {
- expandAll(items[i]);
- }
- }
-}
-/**
- * Answer the image that is used as a hierarchy indicator
- * for a collapsed hierarchy.
- */
-Image getCollapsedImage() {
- if (collapsedImage == null) {
- collapsedImage = new Image(display, CollapsedImageData);
- }
- return collapsedImage;
-}
-/**
- * Answer the width of the item identified by 'itemIndex'.
- */
-int getContentWidth(int itemIndex) {
- TreeItem2 item = getRoot().getVisibleItem(itemIndex);
- int paintStopX = 0;
-
- if (item != null) {
- paintStopX = item.getPaintStopX();
- }
- return paintStopX;
-}
-/**
- * Answer the image that is used as a hierarchy indicator
- * for an expanded hierarchy.
- */
-Image getExpandedImage() {
- if (expandedImage == null) {
- expandedImage = new Image(display, ExpandedImageData);
- }
- return expandedImage;
-}
-/**
- * Answer the rectangle enclosing the hierarchy indicator of a tree item.
- *
- * Note:
- * Assumes that the hierarchy indicators for expanded and
- * collapsed state are the same size.
- * @return
- * The rectangle enclosing the hierarchy indicator.
- */
-Rectangle getHierarchyIndicatorRect() {
- int itemHeight = getItemHeight();
- Image hierarchyImage;
- Rectangle imageBounds;
-
- if (hierarchyIndicatorRect == null && itemHeight != -1) {
- hierarchyImage = getCollapsedImage();
- if (hierarchyImage != null) {
- imageBounds = hierarchyImage.getBounds();
- }
- else {
- imageBounds = new Rectangle(0, 0, 0, 0);
- }
- hierarchyIndicatorRect = new Rectangle(
- 0,
- (itemHeight - imageBounds.height) / 2 + (itemHeight - imageBounds.height) % 2,
- imageBounds.width,
- imageBounds.height);
- }
- return hierarchyIndicatorRect;
-}
-/**
- * Answer the index of 'item' in the receiver.
- */
-int getIndex(SelectableItem item) {
- int index = -1;
-
- if (item != null) {
- index = ((TreeItem2) item).getGlobalIndex();
- }
- return index;
-}
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver. The
- * number that is returned is the number of roots in the
- * tree.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount() {
- checkWidget();
- return getRoot().getItemCount();
-}
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the tree.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight() {
- checkWidget();
- return super.getItemHeight();
-}
-/**
- * Returns the items contained in the receiver
- * that are direct item children of the receiver. These
- * are the roots of the tree.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem2 [] getItems() {
- checkWidget();
- TreeItem2 childrenArray[] = new TreeItem2[getItemCount()];
-
- getRoot().getChildren().copyInto(childrenArray);
- return childrenArray;
-}
-/**
- * Answer the number of sub items of 'item' that do not fit in the
- * tree client area.
- */
-int getOffScreenItemCount(TreeItem2 item) {
- int itemIndexFromTop = item.getVisibleIndex() - getTopIndex();
- int spaceRemaining = getItemCountWhole()-(itemIndexFromTop+1);
- int expandedItemCount = item.getVisibleItemCount();
-
- return expandedItemCount - spaceRemaining;
-}
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem2 getParentItem() {
- checkWidget();
- return null;
-}
-/**
- * Answer the object that holds the root items of the receiver.
- */
-TreeRoots getRoot() {
- return root;
-}
-/**
- * Returns an array of <code>TreeItem</code>s that are currently
- * selected in the receiver. An empty array indicates that no
- * items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem2 [] getSelection() {
- checkWidget();
- Vector selectionVector = getSelectionVector();
- TreeItem2[] selectionArray = new TreeItem2[selectionVector.size()];
-
- selectionVector.copyInto(selectionArray);
- sort(selectionArray, 0, selectionArray.length);
- return selectionArray;
-}
-/**
- * Answer the index of 'item' in the receiver.
- * Answer -1 if the item is not visible.
- * The returned index must refer to a visible item.
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. It only means that the item
- * would be displayed if it is located inside the receiver's
- * client area.
- * Collapsed items are not visible.
- */
-int getVisibleIndex(SelectableItem item) {
- int index = -1;
-
- if (item != null) {
- index = ((AbstractTreeItem) item).getVisibleIndex();
- }
- return index;
-}
-/**
- * Answer the SelectableItem located at 'itemIndex'
- * in the receiver.
- * @param itemIndex - location of the SelectableItem
- * object to return
- */
-SelectableItem getVisibleItem(int itemIndex) {
- return getRoot().getVisibleItem(itemIndex);
-}
-/**
- * Answer the number of visible items of the receiver.
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. It only means that the item
- * would be displayed if it is located inside the receiver's
- * client area.
- * Collapsed items are not visible.
- */
-int getVisibleItemCount() {
- return getRoot().getVisibleItemCount();
-}
-/**
- * Answer the y coordinate at which 'item' is drawn.
- * @param item - SelectableItem for which the paint position
- * should be returned
- * @return the y coordinate at which 'item' is drawn.
- * Return -1 if 'item' is null or outside the client area
- */
-int getVisibleRedrawY(SelectableItem item) {
- int redrawY = getRedrawY(item);
-
- if (redrawY < 0 || redrawY > getClientArea().height) {
- redrawY = -1;
- }
- return redrawY;
-}
-/**
- * Handle the events the receiver is listening to.
- */
-void handleEvents(Event event) {
- switch (event.type) {
- case SWT.Paint:
- paint(event);
- break;
- case SWT.MouseDown:
- mouseDown(event);
- break;
- case SWT.MouseDoubleClick:
- mouseDoubleClick(event);
- break;
- default:
- super.handleEvents(event);
- }
-}
-/**
- * Initialize the receiver.
- */
-void initialize() {
- resetRoot(); // has to be at very top because super class uses
- // functionality that relies on the TreeRoots object
- super.initialize();
-}
-/**
- * Initialize the ImageData used for the expanded/collapsed images.
- */
-static void initializeImageData() {
- PaletteData fourBit = new PaletteData(
- new RGB[] {new RGB(0, 0, 0), new RGB (128, 0, 0), new RGB (0, 128, 0), new RGB (128, 128, 0), new RGB (0, 0, 128), new RGB (128, 0, 128), new RGB (0, 128, 128), new RGB (128, 128, 128), new RGB (192, 192, 192), new RGB (255, 0, 0), new RGB (0, 255, 0), new RGB (255, 255, 0), new RGB (0, 0, 255), new RGB (255, 0, 255), new RGB (0, 255, 255), new RGB (255, 255, 255)});
-
- CollapsedImageData = new ImageData(
- 9, 9, 4, // width, height, depth
- fourBit, 4,
- new byte[] {119, 119, 119, 119, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, 15, -1, 112, 0, 0, 0, 127, -1, 15, -1, 112, 0, 0, 0, 127, 0, 0, 15, 112, 0, 0, 0, 127, -1, 15, -1, 112, 0, 0, 0, 127, -1, 15, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 119, 119, 119, 119, 112, 0, 0, 0});
- CollapsedImageData.transparentPixel = 15; // use white for transparency
- ExpandedImageData = new ImageData(
- 9, 9, 4, // width, height, depth
- fourBit, 4,
- new byte[] {119, 119, 119, 119, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, 0, 0, 15, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 119, 119, 119, 119, 112, 0, 0, 0});
- ExpandedImageData.transparentPixel = 15; // use white for transparency
-}
-/**
- * Set event listeners for the receiver.
- */
-void installListeners() {
- Listener listener = getListener();
-
- super.installListeners();
- addListener(SWT.Paint, listener);
- addListener(SWT.MouseDown, listener);
- addListener(SWT.MouseDoubleClick, listener);
-}
-/**
- * Answer whether the receiver is currently expanding a sub tree
- * with 'item' in it.
- * Used for performance optimizations.
- */
-boolean isExpandingItem(SelectableItem item) {
- TreeItem2 parentItem;
-
- if (expandingItem == null || item == null || (item instanceof TreeItem2) == false) {
- return false;
- }
- parentItem = ((TreeItem2) item).getParentItem();
- return (parentItem == expandingItem || isExpandingItem(parentItem));
-}
-/**
- * Answer whether the children of 'collapsingItem' contain
- * at least one selected item.
- */
-boolean isSelectedItemCollapsing(TreeItem2 collapsingItem) {
- Enumeration selection = getSelectionVector().elements();
- TreeItem2 item;
- int selectedItemIndex;
- int collapsingItemIndex = collapsingItem.getVisibleIndex();
- int lastCollapsedItemIndex = collapsingItemIndex + collapsingItem.getVisibleItemCount();
-
- if (collapsingItemIndex == -1) { // is the collapsing item in a collapsed subtree?
- return false; // then neither it nor its children are selected
- }
- while (selection.hasMoreElements() == true) {
- item = (TreeItem2) selection.nextElement();
- selectedItemIndex = item.getVisibleIndex();
- if ((selectedItemIndex > collapsingItemIndex) &&
- (selectedItemIndex <= lastCollapsedItemIndex)) {
- return true;
- }
- }
- return false;
-}
-/**
- * Test whether the mouse click specified by 'event' was a
- * valid selection or expand/collapse click.
- * @return
- * One of ActionExpandCollapse, ActionSelect, ActionNone, ActionCheck
- * specifying the action to be taken on the click.
- */
-int itemAction(TreeItem2 item, int x, int y) {
- int action = ActionNone;
- int itemHeight = getItemHeight();
- int offsetX;
- int offsetY;
- Point offsetPoint;
-
- if (item != null) {
- offsetX = x - item.getPaintStartX();
- offsetY = y - itemHeight * (y / itemHeight);
- offsetPoint = new Point(offsetX, offsetY);
- if ((item.isLeaf() == false) &&
- (getHierarchyIndicatorRect().contains(offsetPoint) == true)) {
- action |= ActionExpandCollapse;
- }
- else
- if (item.isSelectionHit(offsetPoint) == true) {
- action |= ActionSelect;
- }
- else
- if (item.isCheckHit(new Point(x, y)) == true) {
- action |= ActionCheck;
- }
- }
- return action;
-}
-/**
- * The table item 'changedItem' has changed. Redraw the whole
- * item in that column. Include the text in the redraw because
- * an image set to null requires a redraw of the whole item anyway.
- */
-void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
- int oldItemHeight = getItemHeight();
- Point oldImageExtent = getImageExtent();
-
- if (isExpandingItem(changedItem) == false) {
- super.itemChanged(changedItem, repaintStartX, repaintWidth);
- }
- else {
- calculateItemHeight(changedItem);
- }
- if ((oldItemHeight != getItemHeight()) || // only reset items if the item height or
- (oldImageExtent != getImageExtent())) { // image size has changed. The latter will only change once,
- // from null to a value-so it's safe to test using !=
- getRoot().reset(); // reset cached data of all items in the receiver
- resetHierarchyIndicatorRect();
- redraw(); // redraw all items if the image extent has changed. Fixes 1FRIHPZ
- }
- else {
- ((AbstractTreeItem) changedItem).reset(); // reset the item that has changed when the tree item
- // height has not changed (otherwise the item caches old data)
- // Fixes 1FF6B42
- }
- if (repaintWidth != 0) {
- calculateWidestShowingItem();
- claimRightFreeSpace(); // otherwise scroll bar may be reset, but not horizontal offset
- // Fixes 1G4SBJ3
- }
-}
-/**
- * A key was pressed.
- * Call the appropriate key handler method.
- * @param event - the key event
- */
-void keyDown(Event event) {
- super.keyDown(event);
- switch (event.character) {
- case '+':
- doPlus();
- break;
- case '-':
- doMinus();
- break;
- case '*':
- doAsterisk();
- break;
- }
-}
-
-/**
- * A mouse double clicked occurred over the receiver.
- * Expand/collapse the clicked item. Do nothing if no item was clicked.
- */
-void mouseDoubleClick(Event event) {
- int hitItemIndex = event.y / getItemHeight();
- TreeItem2 hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
- Event newEvent;
-
- if (hitItem == null || getIgnoreDoubleClick() || itemAction(hitItem, event.x, event.y) != ActionSelect) {
- return;
- }
- if (isListening(SWT.DefaultSelection) == true) {
- newEvent = new Event();
- newEvent.item = hitItem;
- postEvent(SWT.DefaultSelection, newEvent);
- }
- else
- if (hitItem.isLeaf() == false) { // item with children was hit. Default behavior is expand/collapse item
- if (hitItem.getExpanded() == true) {
- collapse(hitItem, true);
- }
- else {
- expand(hitItem, true);
- }
- }
-}
-/**
- * The mouse pointer was pressed down on the receiver.
- * Handle the event according to the position of the mouse click.
- */
-void mouseDown(Event event) {
- int hitItemIndex;
- TreeItem2 hitItem;
- SelectableItem selectionItem = getLastSelection();
- int itemAction;
-
- hitItemIndex = event.y / getItemHeight();
- hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
- if (hitItem == null) {
- return;
- }
- if (!isFocusControl()) forceFocus();
- switch (itemAction = itemAction(hitItem, event.x, event.y)) {
- case ActionExpandCollapse:
- if (event.button != 1) return;
- if (hitItem.getExpanded() == true) {
- collapse(hitItem, true);
- }
- else {
- expand(hitItem, true);
- }
- break;
- case ActionSelect:
- doMouseSelect(hitItem, hitItemIndex + getTopIndex(), event.stateMask, event.button);
- break;
- case ActionCheck:
- if (event.button != 1) return;
- doCheckItem(hitItem);
- break;
- }
- if (itemAction != ActionSelect && selectionItem == null) {
- selectionItem = getRoot().getVisibleItem(getTopIndex()); // select the top item if no item was selected before
- selectNotify(selectionItem);
- }
-}
-/**
- * A paint event has occurred. Display the invalidated items.
- * @param event - expose event specifying the invalidated area.
- */
-void paint(Event event) {
- int visibleRange[] = getIndexRange(event.getBounds());
-
- paintItems(event.gc, visibleRange[0], visibleRange[1] + 1); // + 1 to paint the vertical line
- // connection the last item we really
- // want to paint with the item after that.
-}
-/**
- * Paint tree items on 'gc' starting at index 'topPaintIndex' and
- * stopping at 'bottomPaintIndex'.
- * @param gc - GC to draw tree items on.
- * @param topPaintIndex - index of the first item to draw
- * @param bottomPaintIndex - index of the last item to draw
- */
-void paintItems(GC gc, int topPaintIndex, int bottomPaintIndex) {
- TreeItem2 visibleItem;
- int itemHeight = getItemHeight();
-
- for (int i = topPaintIndex; i <= bottomPaintIndex; i++) {
- visibleItem = getRoot().getVisibleItem(i + getTopIndex());
- if (visibleItem != null) {
- visibleItem.paint(gc, i * itemHeight);
- }
- }
-}
-/**
- * 'item' has been added to or removed from the receiver.
- * Repaint part of the tree to update the vertical hierarchy
- * connectors and hierarchy image.
- * @param modifiedItem - the added/removed item
- * @param modifiedIndex - index of the added/removed item
- */
-void redrawAfterModify(SelectableItem modifiedItem, int modifiedIndex) {
- int redrawStartY;
- int redrawStopY;
- int itemChildIndex = ((TreeItem2) modifiedItem).getIndex();
- int topIndex = getTopIndex();
- int itemHeight = getItemHeight();
- int redrawItemIndex;
- int itemCount;
- AbstractTreeItem parentItem = ((TreeItem2) modifiedItem).getParentItem();
- AbstractTreeItem redrawItem = null;
-
- if (redrawParentItem(modifiedItem) == false) {
- return;
- }
- if (parentItem == null) { // a root item is added/removed
- parentItem = getRoot();
- }
- itemCount = parentItem.getItemCount();
- // redraw hierarchy decorations of preceeding item if the last item at a tree
- // level was added/removed
- // otherwise, if the first item was removed, redraw the parent to update hierarchy icon
- if (itemChildIndex > 0) { // more than one item left at this tree level
- // added/removed last item at this tree level? have to test >=.
- // when removing last item, item index is outside itemCount
- if (itemChildIndex >= itemCount - 1) {
- redrawItem = (AbstractTreeItem) parentItem.getChildren().elementAt(itemChildIndex - 1);
- }
- }
- else
- if (getVisibleItemCount() > 0 && itemCount < 2) { // last item at this level removed/first item added?
- redrawItem = parentItem; // redraw parent item to update hierarchy icon
- }
- if (redrawItem != null) {
- redrawItemIndex = redrawItem.getVisibleIndex();
- if (modifiedIndex == -1) {
- modifiedIndex = redrawItemIndex + 1;
- }
- redrawStartY = (redrawItemIndex - topIndex) * itemHeight;
- redrawStopY = (modifiedIndex - topIndex) * itemHeight;
- redraw(
- 0,
- redrawStartY,
- redrawItem.getCheckboxXPosition(), // only redraw up to and including hierarchy icon to avoid flashing
- redrawStopY - redrawStartY, false);
- }
- if (modifiedIndex == 0) { // added/removed first item ?
- redraw(0, 0, getClientArea().width, getItemHeight() * 2, false);// redraw new first two items to
- // fix vertical hierarchy line
- }
-}
-
-/**
- * Determine if part of the tree hierarchy needs to be redrawn.
- * The hierarchy icon of the parent item of 'item' needs to be redrawn if
- * 'item' is added as the first child or removed as the last child.
- * Hierarchy lines need to be redrawn if 'item' is the last in a series of
- * children.
- * @param item - tree item that is added or removed.
- * @return true=tree hierarchy needs to be redrawn. false=no redraw necessary
- */
-boolean redrawParentItem(SelectableItem item) {
- TreeItem2 parentItem = ((TreeItem2) item).getParentItem();
- TreeItem2 parentItem2;
- boolean redraw = false;
-
- // determine if only the hierarchy icon needs to be redrawn
- if (parentItem != null) {
- parentItem2 = parentItem.getParentItem();
- if ((parentItem2 == null || parentItem2.getExpanded() == true) && parentItem.getChildren().size() < 2) {
- redraw = true;
- }
- }
- // redraw is only neccessary when the receiver is not currently
- // expanding 'item' or a parent item or if the parent item is expanded
- // or if the hierarchy icon of the parent item needs to be redrawn
- if (isExpandingItem(item) == false && parentItem == null || parentItem.getExpanded() == true || redraw == true) {
- redraw = true;
- }
- else {
- redraw = false;
- }
- return redraw;
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll() {
- checkWidget();
- setRedraw(false);
- getRoot().dispose();
- resetRoot();
- reset();
- calculateWidestShowingItem();
- calculateVerticalScrollbar();
- setRedraw(true);
-}
-/**
- * Remove 'item' from the receiver.
- * @param item - tree item that should be removed from the
- * receiver-must be a root item.
- */
-void removeItem(TreeItem2 item) {
- getRoot().removeItem(item);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- removeListener (SWT.Selection, listener);
- removeListener (SWT.DefaultSelection, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed..
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #addTreeListener
- */
-public void removeTreeListener(TreeListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- removeListener (SWT.Expand, listener);
- removeListener (SWT.Collapse, listener);
-}
-/**
- * 'item' has been removed from the receiver.
- * Recalculate the content width.
- */
-void removedItem(SelectableItem item) {
- if (isExpandingItem(item) == false) {
- super.removedItem(item);
- }
- calculateWidestShowingItem();
- claimRightFreeSpace();
-}
-/**
- * Notification that 'item' is about to be removed from the tree.
- * Update the item selection if neccessary.
- * @param item - item that is about to be removed from the tree.
- */
-void removingItem(SelectableItem item) {
- Vector selection = getSelectionVector();
- TreeItem2 parentItem = ((TreeItem2) item).getParentItem();
- TreeItem2 newSelectionItem = null;
- boolean isLastSelected = (selection.size() == 1) && (selection.elementAt(0) == item);
- int itemIndex = getVisibleIndex(item);
-
- if (isLastSelected == true) {
- // try selecting the following item
- newSelectionItem = (TreeItem2) getVisibleItem(itemIndex + 1);
- if (newSelectionItem == null || newSelectionItem.getParentItem() != parentItem) {
- // select parent item if there is no item following the removed
- // one on the same tree level
- newSelectionItem = parentItem;
- }
- if (newSelectionItem != null) {
- selectNotify(newSelectionItem, true);
- }
- }
- super.removingItem(item);
- if (isExpandingItem(item) == false) {
- // redraw plus/minus image, hierarchy lines,
- // redrawing here assumes that no update happens between now and
- // after the item has actually been removed. Otherwise this call
- // would need to be in removedItem and we would need to store the
- // "itemIndex" here to redraw correctly.
- redrawAfterModify(item, itemIndex);
- }
-}
-/**
- * Reset the rectangle enclosing the hierarchy indicator to null.
- * Forces a recalculation next time getHierarchyIndicatorRect is called.
- */
-void resetHierarchyIndicatorRect() {
- hierarchyIndicatorRect = null;
-}
-/**
- * Reset state that is dependent on or calculated from the items
- * of the receiver.
- */
-void resetItemData() {
- setContentWidth(0);
- resetHierarchyIndicatorRect();
- super.resetItemData();
-}
-/**
- * Reset the object holding the root items of the receiver.
- */
-void resetRoot() {
- root = new TreeRoots(this);
-}
-/**
- * The receiver has been resized. Recalculate the content width.
- */
-void resize(Event event) {
- int oldItemCount = getVerticalBar().getPageIncrement();
-
- super.resize(event);
- if (getItemCountWhole() > oldItemCount) { // window resized higher?
- calculateWidestShowingItem(); // recalculate widest item since a longer item may be visible now
- }
-}
-/**
- * Display as many expanded tree items as possible.
- * Scroll the last expanded child to the bottom if all expanded
- * children can be displayed.
- * Otherwise scroll the expanded item to the top.
- * @param item - the tree item that was expanded
- */
-void scrollExpandedItemsIntoView(TreeItem2 item) {
- int itemCountOffScreen = getOffScreenItemCount(item);
- int newTopIndex = getTopIndex() + itemCountOffScreen;
-
- if (itemCountOffScreen > 0) {
- newTopIndex = Math.min(item.getVisibleIndex(), newTopIndex); // make sure the expanded item is never scrolled out of view
- setTopIndex(newTopIndex, true);
- }
-}
-/**
- * Scroll the items following the children of 'collapsedItem'
- * below 'collapsedItem' to cover the collapsed children.
- * @param collapsedItem - item that has been collapsed
- */
-void scrollForCollapse(TreeItem2 collapsedItem) {
- Rectangle clientArea = getClientArea();
- int topIndex = getTopIndex();
- int itemCount = collapsedItem.getVisibleItemCount();
- int scrollYPositions[] = calculateChildrenYPos(collapsedItem);
-
- if (scrollYPositions[0] == -1 && scrollYPositions[1] == -1) {
- return;
- }
- if (topIndex + getItemCountWhole() == getVisibleItemCount() && itemCount < topIndex) {
- // scroll from top if last item is at bottom and will stay at
- // bottom after collapse. Avoids flash caused by too much bit
- // blitting (which force update and thus premature redraw)
- int height = scrollYPositions[1] - scrollYPositions[0];
- scroll(
- 0, 0, // destination x, y
- 0, -height, // source x, y
- clientArea.width, scrollYPositions[0]+height, true);
- setTopIndexNoScroll(topIndex - itemCount, true);
- }
- else {
- scroll(
- 0, scrollYPositions[0], // destination x, y
- 0, scrollYPositions[1], // source x, y
- clientArea.width, clientArea.height - scrollYPositions[0], true);
- }
-}
-/**
- * Scroll the items following 'expandedItem' down to make
- * space for the children of 'expandedItem'.
- * @param expandedItem - item that has been expanded.
- */
-void scrollForExpand(TreeItem2 expandedItem) {
- int scrollYPositions[];
- Rectangle clientArea = getClientArea();
-
- expandedItem.internalSetExpanded(true);
- scrollYPositions = calculateChildrenYPos(expandedItem);
- expandedItem.internalSetExpanded(false);
- if (scrollYPositions[0] == -1 && scrollYPositions[1] == -1) {
- return;
- }
- scroll(
- 0, scrollYPositions[1], // destination x, y
- 0, scrollYPositions[0], // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Scroll horizontally by 'numPixel' pixel.
- * @param numPixel - the number of pixel to scroll
- * < 0 = columns are going to be moved left.
- * > 0 = columns are going to be moved right.
- */
-void scrollHorizontal(int numPixel) {
- Rectangle clientArea = getClientArea();
-
- scroll(
- numPixel, 0, // destination x, y
- 0, 0, // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Scroll vertically by 'scrollIndexCount' items.
- * @param scrollIndexCount - the number of items to scroll.
- * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
- */
-void scrollVertical(int scrollIndexCount) {
- Rectangle clientArea = getClientArea();
-
- scroll(
- 0, 0, // destination x, y
- 0, scrollIndexCount * getItemHeight(), // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll() {
- checkWidget();
- Vector selection = getSelectionVector();
-
- if (isMultiSelect() == true) {
- selection = getRoot().selectAll(selection);
- setSelectionVector(selection);
- }
-}
-/**
- * Set the item that is currently being expanded to 'item'.
- * Used for performance optimizations.
- */
-void setExpandingItem(TreeItem2 item) {
- expandingItem = item;
-}
-public void setFont(Font font) {
- checkWidget();
- Vector children = new Vector();
- Enumeration elements;
- AbstractTreeItem item;
-
- if (font != null && font.equals(getFont()) == true) {
- return;
- }
- setRedraw(false); // disable redraw because itemChanged() triggers undesired redraw
- resetItemData();
- super.setFont(font);
-
- // Call itemChanged for all tree items
- elements = getRoot().getChildren().elements();
- while (elements.hasMoreElements() == true) {
- children.addElement(elements.nextElement());
- }
- // traverse the tree depth first
- int size;
- while ((size = children.size()) != 0) {
- item = (AbstractTreeItem)children.elementAt(size - 1);
- children.removeElementAt(size - 1);
- itemChanged(item, 0, getClientArea().width);
- elements = item.getChildren().elements();
- while (elements.hasMoreElements() == true) {
- children.addElement(elements.nextElement());
- }
- }
- setRedraw(true); // re-enable redraw
-}
-/**
- * Display a mark indicating the point at which an item will be inserted.
- * The drop insert item has a visual hint to show where a dragged item
- * will be inserted when dropped on the tree.
- *
- * @param item the insert item. Null will clear the insertion mark.
- * @param before true places the insert mark above 'item'. false places
- * the insert mark below 'item'.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setInsertMark(TreeItem2 item, boolean before){
- checkWidget();
- if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- motif_setInsertMark(item, !before);
-}
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#deselectAll()
- */
-public void setSelection(TreeItem2 items[]) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) {
- deselectAll ();
- return;
- }
- setSelectableSelection(items);
-}
-/**
- * Set the index of the first visible item in the tree client area
- * to 'index'.
- * Scroll the new top item to the top of the tree.
- * @param index - 0-based index of the first visible item in the
- * tree's client area.
- * @param adjustScrollbar -
- * true = the vertical scroll bar is set to reflect the new top index.
- * false = the vertical scroll bar position is not modified.
- */
-void setTopIndex(int index, boolean adjustScrollbar) {
- int indexDiff = index-getTopIndex();
-
- super.setTopIndex(index, adjustScrollbar);
- calculateWidestScrolledItem(indexDiff);
-}
-/**
- * Sets the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getTopItem()
- *
- * @since 2.1
- */
-public void setTopItem(TreeItem2 item) {
- checkWidget();
- if (item == null) error(SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (item.isVisible() == false) {
- item.makeVisible();
- }
- scrollExpandedItemsIntoView(item);
-}
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled
- * and expanded until the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showSelection()
- */
-public void showItem(TreeItem2 item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- showSelectableItem(item);
-}
-/**
- * Make 'item' visible by expanding its parent items and scrolling
- * it into the receiver's client area if necessary.
- * An SWT.Expand event is going to be sent for every parent item
- * that is expanded to make 'item' visible.
- * @param item - the item that should be made visible to the
- * user.
- */
-void showSelectableItem(SelectableItem item) {
- if (item.getSelectableParent() != this) {
- return;
- }
- if (((TreeItem2) item).isVisible() == false) {
- ((TreeItem2) item).makeVisible();
- }
- super.showSelectableItem(item);
-}
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the item at the given point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem2 getItem(Point point) {
- checkWidget();
- if (point == null) error(SWT.ERROR_NULL_ARGUMENT);
- int itemHeight;
- int hitItemIndex;
- TreeItem2 hitItem;
-
- if (getClientArea().contains(point) == false) {
- return null;
- }
- itemHeight = getItemHeight();
- hitItemIndex = point.y / itemHeight;
- hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
- if (hitItem != null) {
- Point pt = new Point(point.x, point.y);
- pt.x -= hitItem.getPaintStartX();
- pt.y -= itemHeight * hitItemIndex;
- if (hitItem.isSelectionHit(pt) == false) {
- hitItem = null;
- }
- }
- return hitItem;
-}
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount() {
- checkWidget();
- return super.getSelectionCount();
-}
-/**
- * Returns the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @return the item at the top of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public TreeItem2 getTopItem() {
- checkWidget();
- return (TreeItem2)getVisibleItem(getTopIndex());
-}
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showItem(TreeItem)
- */
-public void showSelection() {
- checkWidget();
- super.showSelection();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem2.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem2.java
deleted file mode 100644
index 93c9610474..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem2.java
+++ /dev/null
@@ -1,1423 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a hierarchy of tree items in a tree widget.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class TreeItem2 extends AbstractTreeItem {
-/*
- * This class caches geometric data for drawing.
- * A description of the cached data follows:
- *
- * | 1 || 5 |
- * | 2 | | 6 |
- * |3 7|
- * _____ | 4 |f| |8
- * | | ____
- * | - | ===== {image} root 9
- * |_____| |
- * |b|c| |d|
- * | e |
- *
- * Widths are measured between vertical lines.
- *
- * Cached item rendering data:
- * 1 = getDecorationsWidth
- * 2 = getHierarchyIndicatorRect
- * 3 = getPaintStartX
- * 4 = getItemConnectorWidth
- * 5 = getItemWidth
- * 6 = getSelectionWidth
- * 7 = getPaintStopX
- * 8 - getTextXPos
- * 9 = getTextYPosition
- *
- * Rendering constants:
- * 4 = DEFAULT_ITEM_CONNECTOR_WIDTH, used when no image is set in the tree.
- * Otherwise it is the image width.
- * b = IMAGE_PADDING
- * c = TEXT_INDENT
- * d = SELECTION_PADDING
- * e = ITEM_NOIMAGE_OFFSET
- * f = ITEM_CONNECTOR_PADDING;
- */
- private static final int DEFAULT_ITEM_CONNECTOR_WIDTH = 8; // Default width of the horizontal line connecting
- // items with the vertical lines. Only used when
- // no image is set in the tree. Normally connector
- // line width is half the image width.
- private static final int ITEM_CONNECTOR_PADDING = 2; // Added to the calculated item connector width
- private static final int IMAGE_PADDING = 3; // Space behind bitmap
- private static final int ITEM_NOIMAGE_OFFSET = 8; // Offset added to the calculated paint position where
- // an item starts drawing. To be used when no item
- // image has been set. Otherwise children would start
- // drawing at the end of the horizontal item connector
- // of their parent.
- private static final int ROOT_INDENT = 5; // Indent of root items
- private static final int SELECTION_PADDING = 2; // Space behind text
- private static final int TEXT_INDENT = 2; // Identation of the item label
-
- // basic item info
- private TreeItem2 parentItem;
- private int index; // index in the parent item
-
- // geometrical item info
- private int paintStartX = -1; // X coordinate of the upper-left corner of the
- // receivers bounding rectangle
- private Point itemExtent; // Size of the item (image + label)
- private Point imageExtent; // original size of the item image
- private int textYPosition = -1; // Centered y position of the item text
-
-
- //Determine whether the item is being expanded
- private boolean isExpanding = false;
- Color background = null;
- Color foreground = null;
- Font font = null;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem2(Tree2 parent, int style) {
- this(parent, style, checkNull(parent).getItemCount());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem2(Tree2 parent, int style, int index) {
- super(parent, style);
- parent.addItem(this, index);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem2(TreeItem2 parentItem, int style) {
- this(parentItem, style, checkNull(parentItem).getItemCount());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem2(TreeItem2 parentItem, int style, int index) {
- super(checkNull(parentItem).getParent(), style);
- setParentItem(parentItem);
- parentItem.add(this, index);
-}
-
-/**
- * Calculate the number of expanded children.
- * Recurse up in the tree to the root item.
- */
-void calculateVisibleItemCount() {
- Vector children;
- TreeItem2 child;
- int visibleItemCount = 0;
-
- // check isExpanded field directly for performance
- if (internalGetExpanded() == true) {
- children = getChildren();
- visibleItemCount = children.size();
- for (int i = 0; i < children.size(); i++) {
- child = (TreeItem2) children.elementAt(i);
- visibleItemCount += child.getVisibleItemCount();
- }
- }
- setVisibleItemCount(visibleItemCount);
- calculateVisibleItemCountParent();
-}
-/**
- * Calculate the number of expanded children for the parent item
- * of this item.
- */
-void calculateVisibleItemCountParent() {
- TreeItem2 parentItem = getParentItem();
-
- if (parentItem != null) {
- parentItem.calculateVisibleItemCount();
- }
- else {
- getParent().getRoot().calculateVisibleItemCount();
- }
-}
-/**
- * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'tree' is null.
- * Otherwise return 'tree'
- */
-static Tree2 checkNull(Tree2 tree) {
- if (tree == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return tree;
-}
-/**
- * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'item' is null.
- * Otherwise return 'item'
- */
-static TreeItem2 checkNull(TreeItem2 item) {
- if (item == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Draw the hierarchy indicator at 'position'.
- *
- * Note:
- * Assumes that the hierarchy indicators for the expanded and
- * collapsed state are the same size.
- * @param gc - GC to draw on.
- * @param position - position on the GC to draw at.
- * @return position to continue drawing
- */
-Point drawHierarchyIndicator(GC gc, Point position) {
- Tree2 parent = getParent();
- Image hierarchyImage;
- Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
- int x = position.x;
- int y = position.y;
- int yCenter = y + parent.getItemHeight() / 2;
- Point connectorLinePosition;
-
- if (isLeaf() == false) {
- if (getExpanded() == true) {
- hierarchyImage = parent.getExpandedImage();
- }
- else {
- hierarchyImage = parent.getCollapsedImage();
- }
- if (hierarchyImage != null) {
- gc.drawImage(hierarchyImage, x + indicatorRectangle.x, y + indicatorRectangle.y);
- }
- connectorLinePosition = new Point(x + indicatorRectangle.width, yCenter);
- }
- else {
- connectorLinePosition = new Point(
- x + indicatorRectangle.width / 2
- + indicatorRectangle.width % 2, yCenter); // % 2 in order to not start the next hierarchy
- // component at the middle of the icon but after.
- }
- return connectorLinePosition;
-}
-/**
- * Draw a horizontal line connecting the item image (or label
- * if there is no image) to the vertical line connecting to
- * the parent.
- * @param gc - GC to draw on.
- * @param position - position on the GC to draw at.
- * @return position to continue drawing
- */
-Point drawHorizontalItemConnector(GC gc, Point position) {
- int itemConnectorEndPos = position.x + getItemConnectorWidth() - 1; // -1 because the position of the last pixel needs to be calculated
-
- gc.drawLine(position.x, position.y, itemConnectorEndPos, position.y);
- return new Point(itemConnectorEndPos + 1, position.y); // + 1 in order to resume drawing after line not on end of line
-}
-/**
- * Display the item image at 'position' using 'gc'.
- * @param gc - GC to draw on
- * @param position - position on the GC to draw at
- * @return position to continue drawing
- */
-Point drawImage(GC gc, Point destinationPosition) {
- Tree2 parent = getParent();
- Image image = getImage();
- Point sourceImageExtent;
- Point destinationImageExtent = parent.getImageExtent();
- int yCenter;
-
- if (image != null) {
- sourceImageExtent = getImageExtent();
- yCenter = (parent.getItemHeight() - destinationImageExtent.y) / 2;
- gc.drawImage(
- image,
- 0, 0, // source x, y
- sourceImageExtent.x, sourceImageExtent.y, // source width, height
- destinationPosition.x, destinationPosition.y + yCenter, // destination x, y
- destinationImageExtent.x, destinationImageExtent.y); // destination width, height
- }
- if (destinationImageExtent != null) {
- destinationPosition.x += destinationImageExtent.x + IMAGE_PADDING;
- }
- return destinationPosition;
-}
-/**
- * Draw a rectangle enclosing the item label. The rectangle
- * indicates that the receiver was selected last and that it has
- * the input focus.
- * The rectangle will only be drawn if the receiver is selected.
- * @param gc - GC to draw on.
- * @param position - position on the GC to draw at.
- */
-void drawSelectionFocus(GC gc, Point position) {
- Point selectionExtent = getSelectionExtent();
-
- if (selectionExtent == null) {
- return;
- }
- if (getParent().hasFocus(this) == true) {
- gc.drawFocus(
- position.x, position.y,
- selectionExtent.x, selectionExtent.y);
- }
-}
-/**
- * Draw a vertical line connecting the horizontal connector line
- * with that of the previous item.
- * Called recursively to draw the lines on all tree levels.
- * @param gc - GC to draw on.
- * @param yPosition - y position of the upper side of the
- * receiver's bounding box.
- * @param isFirstChild - method is called to draw a vertical
- * line for the first child. Leave room for the hierarchy icon.
- */
-void drawVerticalItemConnector(GC gc, int yPosition, boolean isFirstChild) {
- Tree2 parent = getParent();
- TreeItem2 nextDrawItem = getParentItem();
- AbstractTreeItem parentItem = nextDrawItem;
- Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
- int itemHeight = parent.getItemHeight();
- int itemHeightDiv2 = itemHeight / 2 + itemHeight % 2;
- int indicatorHeightDiv2 = indicatorRectangle.height / 2 + indicatorRectangle.height % 2;
- int lineX = getPaintStartX() + indicatorRectangle.width / 2;
- int lineStartY = yPosition - itemHeightDiv2;
- int lineEndY = yPosition + itemHeightDiv2;
-
- if (parentItem == null) {
- parentItem = parent.getRoot();
- }
- if (getIndex() != parentItem.getItemCount()-1) { // if item is not the last child
- if (isFirstChild == true) {
- lineStartY += indicatorHeightDiv2; // leave space for the hierarchy image
- }
- gc.drawLine(lineX, lineStartY, lineX, lineEndY);
- }
-
- if (nextDrawItem != null) {
- nextDrawItem.drawVerticalItemConnector(gc, yPosition, false);
- }
-}
-/**
- * Draw a vertical line connecting the horizontal connector line
- * with that of the previous item.
- * Do this on all tree levels up to the root level.
- * @param gc - GC to draw on.
- * @param position - position on the GC to draw at.
- * @return position to continue drawing
- */
-Point drawVerticalItemConnector(GC gc, Point position) {
- Tree2 parent = getParent();
- TreeItem2 parentItem = getParentItem();
- Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
- int itemHeight = parent.getItemHeight();
- int itemHeightDiv2 = itemHeight / 2 + itemHeight % 2;
- int indicatorHeightDiv2 = indicatorRectangle.height / 2 + indicatorRectangle.height % 2;
- int lineX = position.x + indicatorRectangle.width / 2;
- int lineStartY = position.y - itemHeightDiv2;
- int lineEndY = position.y + itemHeightDiv2 - itemHeight % 2;
- TreeItem2 predecessor;
- boolean isFirstChild = false;
-
- if (isRoot() == true) {
- if (getIndex() == 0) {
- return position; // first root, don't draw vertical line
- }
- }
- else
- if (getIndex() == 0) { // if item is first child
- lineStartY += itemHeightDiv2;
- isFirstChild = true;
- }
- predecessor = getPredecessor();
- if (predecessor != null && predecessor.isLeaf() == false) {
- lineStartY += indicatorHeightDiv2; // leave space for the hierarchy image
- }
- if (isLeaf() == false) {
- lineEndY -= indicatorHeightDiv2;
- }
- gc.drawLine(lineX, lineStartY, lineX, lineEndY);
- if (parentItem != null) {
- parentItem.drawVerticalItemConnector(gc, position.y, isFirstChild);
- }
- return position;
-}
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- if (background != null) return background;
- Tree2 parent = getParent();
- return parent.getBackground();
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds() {
- checkWidget();
- Tree2 parent = getParent();
- Point extent = getItemExtent();
- int x = getTextXPos() - TEXT_INDENT;
-
- return new Rectangle(x, parent.getRedrawY(this), extent.x - (x - getItemStartX()), extent.y);
-}
-
-/**
- * Answer the x position of the item check box
- */
-int getCheckboxXPosition() {
- return getPaintStartX() + getDecorationsWidth();
-}
-/**
- * Answer the combined width of the hierarchy indicator and
- * the horizontal item connector line.
- */
-int getDecorationsWidth() {
- int indicatorWidth = getParent().getHierarchyIndicatorRect().width;
- int width = indicatorWidth + getItemConnectorWidth();
-
- if (isLeaf() == true) {
- width -= indicatorWidth / 2;
- }
- return width;
-}
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (font != null) return font;
- Tree2 parent = getParent ();
- return parent.getFont ();
-}
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- if (foreground != null) return foreground;
- Tree2 parent = getParent();
- return parent.getForeground();
-}
-/**
- * Answer the index of the receiver relative to the first root
- * item.
- * @return
- * The index of the receiver relative to the first root item.
- */
-int getGlobalIndex() {
- int globalItemIndex = getIndex();
- AbstractTreeItem item = null;
-
- if (isRoot() == false) {
- item = getParentItem();
- globalItemIndex++; // adjust for 0-based non-root items
- }
- else {
- item = getParent().getRoot();
- }
-
- globalItemIndex += item.getVisibleIndex(getIndex());
- return globalItemIndex;
-}
-/**
- * Answer the original size of the image of the receiver.
- */
-Point getImageExtent() {
- Image image = getImage();
- Rectangle imageBounds;
-
- if (imageExtent == null && image != null) {
- imageBounds = image.getBounds();
- imageExtent = new Point(imageBounds.width, imageBounds.height);
- }
- return imageExtent;
-}
-/**
- * Answer the receiver's index into its parent's list of children
- */
-int getIndex() {
- return index;
-}
-/**
- * Answer the width of the horizontal item connector line.
- */
-int getItemConnectorWidth() {
- Tree2 parent = getParent();
- Point imageExtent = parent.getImageExtent();
- int itemConnectorWidth;
- int indicatorWidth = parent.getHierarchyIndicatorRect().width;
-
- if (imageExtent != null) {
- itemConnectorWidth = imageExtent.x / 2 + ITEM_CONNECTOR_PADDING;
- }
- else {
- itemConnectorWidth = DEFAULT_ITEM_CONNECTOR_WIDTH;
- }
- if (isLeaf() == false) { // has children = has hierarchy indicator = shorter connector
- itemConnectorWidth -= indicatorWidth / 2;
- }
- return itemConnectorWidth;
-}
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount() {
- checkWidget();
- return super.getItemCount();
-}
-/**
- * Answer the size of the receiver as displayed on the screen.
- */
-Point getItemExtent() {
- Tree2 parent;
- Point imageExtent;
- String text;
- int itemWidth;
-
- if (itemExtent == null) {
- parent = getParent();
- imageExtent = parent.getImageExtent();
- text = getText();
- itemWidth = SELECTION_PADDING;
- if (text != null) {
- itemWidth += getTextWidth(text) + TEXT_INDENT;
- }
- if (imageExtent != null) {
- itemWidth += imageExtent.x + IMAGE_PADDING;
- }
- itemExtent = new Point(itemWidth, parent.getItemHeight());
- }
- return itemExtent;
-}
-/**
- * Answer the x position at which painting of the receiver's
- * contents (ie. image, text) can begin.
- */
-int getItemStartX() {
- int itemStartX = getPaintStartX() + getDecorationsWidth();
-
- if (isCheckable() == true) {
- itemStartX += getCheckboxBounds().width + CHECKBOX_PADDING;
- }
- return itemStartX;
-}
-/**
- * Returns an array of <code>TreeItem</code>s which are the
- * direct item children of the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem2 [] getItems() {
- checkWidget();
- TreeItem2 childrenArray[] = new TreeItem2[getItemCount()];
-
- getChildren().copyInto(childrenArray);
- return childrenArray;
-}
-/**
- * Answer the x position where the receiver is drawn.
- */
-int getPaintStartX() {
- Tree2 parent = getParent();
- Point imageExtent;
- TreeItem2 parentItem;
-
- if (paintStartX == -1) {
- if (isRoot() == true) {
- paintStartX = ROOT_INDENT;
- }
- else {
- parentItem = getParentItem();
- // subtract parent.getHorizontalOffset() to calculate the cached start
- // position independent of the horizontal scroll offset. Fixes 1G1L7EU.
- paintStartX = parentItem.getPaintStartX()
- - parent.getHorizontalOffset()
- + parentItem.getDecorationsWidth()
- - parent.getHierarchyIndicatorRect().width / 2;
- imageExtent = parent.getImageExtent();
- if (imageExtent != null) {
- paintStartX += imageExtent.x / 2;
- }
- else {
- paintStartX += ITEM_NOIMAGE_OFFSET;
- }
- }
- }
- return paintStartX + parent.getHorizontalOffset();
-}
-/**
- * Answer the pixel at which the receiver stops drawing.
- */
-int getPaintStopX() {
- return (getItemStartX() + getItemExtent().x - getParent().getHorizontalOffset());
-}
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree2 getParent() {
- checkWidget();
- return (Tree2) super.getSelectableParent();
-}
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem2 getParentItem() {
- checkWidget();
- return parentItem;
-}
-/**
- * Answer the item that directly precedes the receiver.
- * Answer null if this is the first item in a hierarchy level
- * or if there are expanded children in the previous item.
- */
-TreeItem2 getPredecessor() {
- AbstractTreeItem parentItem = getParentItem();
- Vector children;
- int previousIndex = getIndex() - 1;
- TreeItem2 previousItem = null;
-
- if (parentItem == null) {
- parentItem = getParent().getRoot();
- }
- if (previousIndex >= 0) {
- children = parentItem.getChildren();
- previousItem = (TreeItem2) children.elementAt(previousIndex);
- if (previousItem.isLeaf() == false && previousItem.getExpanded() == true) {
- previousItem = null; // no immediate predecessor because there are expanded children
- }
- }
- return previousItem;
-}
-/**
- * Answer the size of the rectangle drawn to indicate the
- * selected state of the receiver.
- * This is also used to draw the selection focus rectangle.
- */
-Point getSelectionExtent() {
- Point selectionExtent = getItemExtent();
- Point imageExtent = getParent().getImageExtent();
- int x = selectionExtent.x;
-
- if (imageExtent != null) {
- x -= imageExtent.x + IMAGE_PADDING;
- }
- return new Point(x, selectionExtent.y);
-}
-/**
- * Return the x position of the selection rectangle
- */
-int getSelectionX() {
- return getTextXPos() - TEXT_INDENT;
-}
-/**
- * Answer the x position where the receiver draws the item text.
- * This position is relative to the item start position.
- */
-int getTextXPos() {
- Point imageExtent = getParent().getImageExtent();
- int textXPos = getItemStartX() + TEXT_INDENT;
-
- if (imageExtent != null) {
- textXPos += imageExtent.x + IMAGE_PADDING;
- }
- return textXPos;
-}
-/**
- * Answer the y position of the receiver's text.
- * @param
- * gc - GC to use for calculating the text y position
- */
-int getTextYPosition(GC gc) {
- String text;
-
- if (textYPosition == -1) {
- text = getText();
- if (text != null) {
- textYPosition = (getParent().getItemHeight() - gc.stringExtent(text).y) / 2;
- }
- else {
- textYPosition = 0;
- }
- }
- return textYPosition;
-}
-/**
- * Answer the width of 'text' in pixel.
- * Answer 0 if 'text' is null.
- */
-int getTextWidth(String text) {
- int textWidth = 0;
- if (text != null) {
- GC gc = new GC(getParent());
- gc.setFont(getFont());
- textWidth = gc.stringExtent(text).x;
- gc.dispose();
- }
- return textWidth;
-}
-/**
- * Answer the index of the receiver relative to the first root
- * item.
- * If 'anIndex' is the index of the expanded item 'anItem'
- * then the following expressions are true:
- * 'anItem == theRoot.getVisibleItem(anIndex)' and
- * 'anIndex == anItem.getVisibleIndex()'
- * @return
- * The index of the receiver relative to the first root item.
- * Answer -1 if the receiver is not visible (because the parent
- * is collapsed).
- */
-int getVisibleIndex() {
- int visibleItemIndex = getIndex();
- AbstractTreeItem item = null;
-
- if (isRoot() == false) {
- if (isVisible() == false) {
- return -1;
- }
- item = getParentItem();
- visibleItemIndex++; // adjust for 0-based non-root items
- }
- else {
- item = getParent().getRoot();
- }
-
- visibleItemIndex += item.getVisibleIndex(getIndex());
- return visibleItemIndex;
-}
-/**
- * Answer the index of the child item identified by 'childIndex'
- * relative to the first root item.
- */
-int getVisibleIndex(int childIndex) {
- Enumeration children = getChildren().elements();
- TreeItem2 child;
- int visibleItemIndex = getIndex();
-
- if (isRoot() == false) {
- visibleItemIndex++; // adjust for 0-based non-root items
- }
-
- while (children.hasMoreElements() == true) {
- child = (TreeItem2) children.nextElement();
- if (child.getIndex() == childIndex) {
- if (isRoot() == false) {
- visibleItemIndex += getParentItem().getVisibleIndex(getIndex());
- }
- else {
- visibleItemIndex += getParent().getRoot().getVisibleIndex(getIndex());
- }
- break;
- }
- visibleItemIndex += child.getVisibleItemCount();
- }
- return visibleItemIndex;
-}
-/**
- * Answer the item at 'searchIndex' relativ to the receiver.
- * When this method is called for the root item, 'searchIndex'
- * represents the global index into all items of the tree.
- * searchIndex=0 returns the receiver.
- * searchIndex=1 returns the first visible child.
- * Note: searchIndex must be >= 0
- *
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. Visible here means that all
- * the parents of the item are expanded. An item is only
- * visible on screen if it is within the widget client area.
- */
-TreeItem2 getVisibleItem(int searchIndex) {
- TreeItem2 child;
- TreeItem2 foundItem = null;
- Enumeration children = getChildren().elements();
-
- if (searchIndex == 0) {
- return this;
- }
- else
- if (getExpanded() == false) { // trying to find a child when this item isn't expanded ?
- return null;
- }
-
- // Search for expanded items first. Count all subitems in the process.
- while (children.hasMoreElements() == true && foundItem == null) {
- child = (TreeItem2) children.nextElement();
- searchIndex--;
- if (child.getExpanded() == true) {
- searchIndex -= child.getVisibleItemCount(); // count children of all expanded items
- }
- if (searchIndex <= 0) { // is searched item past child ?
- // add back children of current item (that's what we want to search)
- foundItem = child.getVisibleItem(searchIndex + child.getVisibleItemCount());
- }
- }
-
- return foundItem;
-}
-/**
- * Answer whether 'item' is a child, direct or indirect, of the receiver.
- * It is an indirect child if it is a child of one of the receiver's children.
- */
-boolean isChild(TreeItem2 item) {
- Vector children = getChildren();
- TreeItem2 child;
-
- if (children.contains(item) == true) {
- return true;
- }
- for (int i = 0; i < children.size(); i++) {
- child = (TreeItem2) children.elementAt(i);
- if (child.isChild(item) == true) {
- return true;
- }
- }
- return false;
-}
-/**
- * Answer whether the receiver is a root item.
- * The receiver is a root item when it does not have a parent item.
- * @return
- * true - the receiver is a root item.
- * false - the receiver is not a root item.
- */
-boolean isRoot() {
- return (getParentItem() == null);
-}
-/**
- * Answer whether the click at 'position' on the receiver is a selection
- * click.
- * @param position - location of the mouse click relative to the
- * upper left corner of the receiver.
- * @return true - receiver was clicked.
- * false - receiver was not clicked.
- */
-boolean isSelectionHit(Point position) {
- Point itemExtent = getItemExtent();
-
- if (itemExtent == null) { // neither image nor text have been set
- return false;
- }
- return (new Rectangle(
- getItemStartX() - getPaintStartX(), 0,
- itemExtent.x, itemExtent.y)).contains(position);
-}
-/**
- * Answer whether the receiver is visible
- * An item is visible when its parent item is visible and
- * expanded. Root items are always visible.
- *
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. Visible here means that all
- * the parents of the item are expanded. An item is only
- * visible on screen if it is within the receiver's parent's
- * client area.
- * @return
- * true - the receiver is visible
- * false - the receiver is not visible
- */
-boolean isVisible() {
- boolean isVisible = true;
- TreeItem2 parentItem = getParentItem();
-
- if (isRoot() == false) {
- isVisible = parentItem.getExpanded();
- if (isVisible == true) {
- isVisible = parentItem.isVisible();
- }
- }
- return isVisible;
-}
-/**
- * Make this item visible by expanding its parent item.
- */
-void makeVisible() {
- TreeItem2 parentItem = getParentItem();
-
- if (isVisible() == false && parentItem != null) {
- getParent().expand(parentItem, true); // have to call Tree.expand directly in order to trigger Expand event
- parentItem.makeVisible();
- }
-}
-/**
- * Draw the receiver at 'yPosition' in the client area of the parent.
- * @param gc - GC to draw on.
- * @param yPosition - y coordinate where the receiver should draw at.
- */
-void paint(GC gc, int yPosition) {
- if (isVisible() == false) {
- return;
- }
- Tree2 parent = getParent();
- Font font = getFont();
- gc.setFont(font);
- Point paintPosition = new Point(getPaintStartX(), yPosition);
- Point extent = getSelectionExtent();
- gc.setForeground(parent.CONNECTOR_LINE_COLOR);
- paintPosition = drawVerticalItemConnector(gc, paintPosition);
- paintPosition = drawHierarchyIndicator(gc, paintPosition);
- paintPosition = drawHorizontalItemConnector(gc, paintPosition);
- gc.setForeground(parent.getForeground());
- // paint the rest
- if (isCheckable() == true) {
- paintPosition = drawCheckbox(gc, new Point(paintPosition.x, yPosition));
- }
- paintPosition = drawImage(gc, new Point(paintPosition.x, yPosition));
- if (isSelected() == true) {
- gc.setBackground(getSelectionBackgroundColor());
- gc.setForeground(getSelectionForegroundColor());
- gc.fillRectangle(paintPosition.x, paintPosition.y, extent.x, extent.y);
- } else {
- gc.setBackground(getBackground());
- gc.setForeground(getForeground());
- if(getBackground() != parent.getBackground()){
- gc.fillRectangle(paintPosition.x, paintPosition.y, extent.x, extent.y);
- }
- }
- if (text != null) {
- gc.drawString(text, getTextXPos(), paintPosition.y + getTextYPosition(gc), true);
- }
- if (this == parent.getInsertItem()) {
- drawInsertMark(gc, paintPosition);
- }
- drawSelectionFocus(gc, paintPosition);
-}
-
-void redraw(){
- Rectangle bounds = getBounds();
- getParent().redraw(bounds.x, bounds.y, bounds.width, bounds.height, false);
-}
-
-/**
- * Update the display to reflect the expanded state of the
- * receiver.
- * @param itemIndex - index position in the receiver's client
- * area where should be drawn.
- */
-void redrawExpanded(int itemIndex) {
- Tree2 parent = getParent();
- int indicatorWidth = parent.getHierarchyIndicatorRect().width;
- int itemHeight = parent.getItemHeight();
-
- parent.redraw(
- getPaintStartX(), itemIndex * itemHeight,
- indicatorWidth, itemHeight, false);
-}
-/**
- * Reset cached size and position data.
- */
-void reset() {
- super.reset();
- setImageExtent(null);
- setItemExtent(null);
- setPaintStartX(-1);
- setTextYPosition(-1);
-}
-/**
- * Sets the expanded state of the receiver.
- * <p>
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded(boolean expand) {
- checkWidget();
- if (isLeaf() == false && expand == true) {
- getParent().expand(this, false);
- }
- else {
- getParent().collapse(this, false);
- }
-}
-public void setImage(Image newImage) {
- checkWidget();
- Tree2 parent = getParent();
- Image oldImage = getImage();
- boolean isSameImage;
- int imageWidth = 0;
- int redrawX = 0;
-
- super.setImage(newImage);
- if (newImage != null && oldImage != null) {
- isSameImage = newImage.equals(oldImage) && newImage.type == SWT.ICON;
- }
- else {
- isSameImage = newImage == oldImage;
- }
- if (isSameImage == false) {
- if (parent.getVisibleRedrawY(this) != -1) {
- if (parent.getImageExtent() != null) {
- imageWidth = parent.getImageExtent().x;
- }
- else
- if (newImage != null) {
- imageWidth = newImage.getBounds().width;
- }
- redrawX = getItemStartX();
- }
- parent.itemChanged(this, redrawX, imageWidth);
- }
-}
-/**
- * Set the size of the original image of the receiver to 'imageExtent'.
- */
-void setImageExtent(Point imageExtent) {
- this.imageExtent = imageExtent;
-}
-/**
- * Set the index of the receiver to 'index'.
- * This index is used to reference children in their parent.
- */
-void setIndex(int index) {
- this.index = index;
-}
-/**
- * Set the size of the receiver to 'extent'.
- */
-void setItemExtent(Point extent) {
- itemExtent = extent;
-}
-/**
- * Set the x position where the receiver is drawn to 'startX'.
- * @param startX - the x position where the receiver is drawn
- */
-void setPaintStartX(int startX) {
- paintStartX = startX;
-}
-/**
- * Set the parent item of the receiver to 'parentItem'.
- * @param parentItem - the receiver's parent item.
- * Receiver is a root if this is null.
- */
-void setParentItem(TreeItem2 parentItem) {
- this.parentItem = parentItem;
-}
-
-public void setText(String newText) {
- checkWidget();
- Tree2 parent = getParent();
- String oldText = getText();
- int redrawX = 0;
- int redrawWidth = 0;
-
- if (newText == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- super.setText(newText);
- if (newText.equals(oldText) == false) {
- if (parent.getVisibleRedrawY(this) != -1) {
- redrawX = getTextXPos();
- redrawWidth = parent.getClientArea().width - redrawX;
- }
- parent.itemChanged(this, redrawX, redrawWidth);
- }
-}
-/**
- * Set the y position of the receiver's text to 'yPosition'.
- */
-void setTextYPosition(int yPosition) {
- textYPosition = yPosition;
-}
-
-public void dispose() {
- if (isDisposed()) return;
- // if the tree is being disposed don't bother collapsing the item since all
- // items in the tree will be deleted and redraws will not be processed anyway
- Tree2 parent = getParent();
- if (parent.isRemovingAll() == false) {
- parent.collapseNoRedraw(this);
- }
-
- if (parentItem != null) {
- parentItem.removeItem(this);
- }
- else {
- parent.removeItem(this);
- }
-
- super.dispose();
-}
-
-void doDispose() {
- // Notify the parent that the receiver is being removed.
- // Reset cached data.
- setParentItem(null);
- setImageExtent(null);
- setItemExtent(null);
- setIndex(-1);
- setPaintStartX(-1);
- setTextYPosition(-1);
- background = foreground = null;
- font = null;
- super.doDispose();
-}
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked() {
- checkWidget();
- return super.getChecked();
-}
-boolean getExpanding(){
- return isExpanding;
-}
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed() {
- checkWidget();
- return super.getGrayed();
-}
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (background == color) return;
- if (background != null && background.equals (color)) return;
- background = color;
- redraw();
-}
-/**
- * Sets the checked state of the receiver.
- * <p>
- *
- * @param checked the new checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked(boolean checked) {
- checkWidget();
- super.setChecked(checked);
-}
-void setExpanding(boolean expanding){
- isExpanding = expanding;
-}
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font){
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (this.font == font) return;
- if (this.font != null && this.font.equals (font)) return;
- this.font = font;
- redraw ();
-}
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @since 2.0
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (foreground == color) return;
- if (foreground != null && foreground.equals (color)) return;
- foreground = color;
- redraw();
-}
-/**
- * Sets the grayed state of the receiver.
- * <p>
- *
- * @param grayed the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- super.setGrayed(grayed);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java
deleted file mode 100644
index 01d7bcc576..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * This class is used to store tree root items.
- * Instances of this class are never displayed.
- */
-class TreeRoots extends AbstractTreeItem {
-/**
- * Create a tree item that holds one or more root items
- * @param parent - Tree widget the receiver belongs to
- */
-TreeRoots(Tree2 parent) {
- super(parent, 0);
- initialize();
-}
-/**
- * Calculate the number of expanded children.
- * Recurse up in the tree to the root item.
- */
-void calculateVisibleItemCount() {
- Vector children = getChildren();
- TreeItem2 child;
- int visibleItemCount = children.size();
-
- for (int i = 0; i < children.size(); i++) {
- child = (TreeItem2) children.elementAt(i);
- visibleItemCount += child.getVisibleItemCount();
- }
- setVisibleItemCount(visibleItemCount);
-}
-/**
- * Calculate the number of expanded children for the parent item
- * of this item.
- */
-void calculateVisibleItemCountParent() {}
-
-public void dispose() {
- if (isDisposed()) return;
- Tree2 parent = (Tree2) getSelectableParent();
-
- // all tree items are removed so we don't need to do
- // time consuming screen updates for each removed item
- parent.setRemovingAll(true);
- super.dispose();
- parent.setRemovingAll(false);
-}
-/**
- * Answer the x position of the item check box
- */
-int getCheckboxXPosition() {
- return 0;
-}
-/**
- * Implements SelectableItem#getSelectionExtent
- * Should never be called since objects of this type are never
- * rendered
- */
-Point getSelectionExtent() {
- return new Point(0, 0);
-}
-/**
- * Implements SelectableItem#getSelectionX
- * Should never be called since objects of this type are never
- * rendered
- */
-int getSelectionX() {
- return 0;
-}
-/**
- * Always answer -1 to indicate that the receiver is not visible.
- */
-int getVisibleIndex() {
- return -1;
-}
-/**
- * Answer the index of the child item identified by 'childIndex'
- * relative to the first root item.
- */
-int getVisibleIndex(int childIndex) {
- Enumeration children = getChildren().elements();
- TreeItem2 child;
- int globalItemIndex = 0;
-
- while (children.hasMoreElements() == true) {
- child = (TreeItem2) children.nextElement();
- if (child.getIndex() == childIndex) {
- break;
- }
- globalItemIndex += child.getVisibleItemCount();
- }
- return globalItemIndex;
-}
-/**
- * Answer the item at 'searchIndex' relativ to the receiver.
- * When this method is called for the root item, 'searchIndex'
- * represents the global index into all items of the tree.
- * searchIndex=0 returns the receiver.
- * searchIndex=1 returns the first visible child.
- * Note: searchIndex must be >= 0
- *
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. Visible here means that all
- * the parents of the item are expanded. An item is only
- * visible on screen if it is within the widget client area.
- */
-TreeItem2 getVisibleItem(int searchIndex) {
- TreeItem2 child;
- TreeItem2 foundItem = null;
- Enumeration children = getChildren().elements();
-
- searchIndex++; // skip this fake root item
-
- // Search for expanded items first. Count all subitems in the process.
- while (children.hasMoreElements() == true && foundItem == null) {
- child = (TreeItem2) children.nextElement();
- searchIndex--;
- if (child.internalGetExpanded() == true) {
- searchIndex -= child.getVisibleItemCount(); // count children of all expanded items
- }
- if (searchIndex <= 0) { // is searched item past child ?
- // add back children of current item (that's what we want to search)
- foundItem = child.getVisibleItem(searchIndex + child.getVisibleItemCount());
- }
- }
- return foundItem;
-}
-/**
- * Initialize the receiver
- */
-void initialize() {
- internalSetExpanded(true);
-}
-
-/**
- * Select the receiver and all children
- */
-Vector selectAll(Vector selectedItems) {
- Enumeration children = getChildren().elements();
- AbstractTreeItem treeItem;
-
- while (children.hasMoreElements() == true) {
- treeItem = (AbstractTreeItem) children.nextElement();
- selectedItems = treeItem.selectAll(selectedItems);
- }
- return selectedItems;
-}
-}

Back to the top