/******************************************************************************* * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * 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 org.eclipse.swt.internal.cocoa.*; /** * Instances of this class provide a selectable user interface object * that displays a hierarchy of items and issues notification when an * item in the hierarchy is selected. *

* The item children that may be added to instances of this class * must be of type TreeItem. *

* Style VIRTUAL is used to create a Tree whose * TreeItems are to be populated by the client on an on-demand basis * instead of up-front. This can provide significant performance improvements for * trees that are very large or for which TreeItem population is * expensive (for example, retrieving values from an external source). *

* Here is an example of using a Tree with style VIRTUAL: *

 *  final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
 *  tree.setItemCount(20);
 *  tree.addListener(SWT.SetData, new Listener() {
 *      public void handleEvent(Event event) {
 *          TreeItem item = (TreeItem)event.item;
 *          TreeItem parentItem = item.getParentItem();
 *          String text = null;
 *          if (parentItem == null) {
 *              text = "node " + tree.indexOf(item);
 *          } else {
 *              text = parentItem.getText() + " - " + parentItem.indexOf(item);
 *          }
 *          item.setText(text);
 *          System.out.println(text);
 *          item.setItemCount(10);
 *      }
 *  });
 * 
*

* Note that although this class is a subclass of Composite, * it does not normally make sense to add Control children to * it, or set a layout on it, unless implementing something like a cell * editor. *

*

*
Styles:
*
SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL
*
Events:
*
Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem
*
*

* Note: Only one of the styles SINGLE and MULTI may be specified. *

* IMPORTANT: This class is not intended to be subclassed. *

* * @see Tree, TreeItem, TreeColumn snippets * @see SWT Example: ControlExample * @see Sample code and further information * @noextend This class is not intended to be subclassed by clients. */ public class Tree extends Composite { NSTableColumn firstColumn, checkColumn; NSTextFieldCell dataCell; NSButtonCell buttonCell; NSTableHeaderView headerView; TreeItem [] items; int itemCount; TreeColumn [] columns; TreeColumn sortColumn; int columnCount; int sortDirection; boolean ignoreExpand, ignoreSelect, ignoreRedraw, reloadPending, drawExpansion, didSelect, preventSelect; Rectangle imageBounds; TreeItem insertItem; boolean insertBefore; /* Used to control drop feedback when DND.FEEDBACK_EXPAND and DND.FEEDBACK_SCROLL is set/not set */ boolean shouldExpand = true, shouldScroll = true; static int NEXT_ID; static final int FIRST_COLUMN_MINIMUM_WIDTH = 5; static final int IMAGE_GAP = 3; static final int TEXT_GAP = 2; static final int CELL_GAP = 1; /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. *

* The style value is either one of the style constants defined in * class SWT which is applicable to instances of this * class, or must be built by bitwise OR'ing together * (that is, using the int "|" operator) two or more * of those SWT style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. *

* * @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 * @exception SWTException * * @see SWT#SINGLE * @see SWT#MULTI * @see SWT#CHECK * @see SWT#FULL_SELECTION * @see SWT#VIRTUAL * @see SWT#NO_SCROLL * @see Widget#checkSubclass * @see Widget#getStyle */ public Tree (Composite parent, int style) { super (parent, checkStyle (style)); } void _addListener (int eventType, Listener listener) { super._addListener (eventType, listener); clearCachedWidth (items); } TreeItem _getItem (TreeItem parentItem, int index, boolean create) { int count; TreeItem[] items; if (parentItem != null) { count = parentItem.itemCount; items = parentItem.items; } else { count = this.itemCount; items = this.items; } if (index < 0 || index >= count) return null; TreeItem item = items [index]; if (item != null || (style & SWT.VIRTUAL) == 0 || !create) return item; item = new TreeItem (this, parentItem, SWT.NONE, index, false); items [index] = item; return item; } int /*long*/ accessibilityAttributeValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { int /*long*/ returnValue = 0; NSString attributeName = new NSString(arg0); // If the check column is visible, don't report it back as a column for accessibility purposes. // The check column is meant to appear as a part of the first column. if (attributeName.isEqualToString (OS.NSAccessibilityColumnsAttribute) || attributeName.isEqualToString(OS.NSAccessibilityVisibleColumnsAttribute)) { if ((style & SWT.CHECK) != 0) { int /*long*/ superValue = super.accessibilityAttributeValue(id, sel, arg0); if (superValue != 0) { NSArray columns = new NSArray(superValue); NSMutableArray columnsWithoutCheck = NSMutableArray.arrayWithCapacity(columns.count() - 1); columnsWithoutCheck.addObjectsFromArray(columns); columnsWithoutCheck.removeObjectAtIndex(0); returnValue = columnsWithoutCheck.id; } } } if (returnValue != 0) { return returnValue; } else { return super.accessibilityAttributeValue(id, sel, arg0); } } /** * Adds the listener to the collection of listeners who will * be notified when the user changes the receiver's selection, by sending * it one of the messages defined in the SelectionListener * interface. *

* When widgetSelected is called, the item field of the event object is valid. * If the receiver has the SWT.CHECK style and the check selection changes, * the event object detail field contains the value SWT.CHECK. * widgetDefaultSelected 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. *

* * @param listener the listener which should be notified when the user changes the receiver's selection * * @exception IllegalArgumentException * @exception SWTException * * @see SelectionListener * @see #removeSelectionListener * @see SelectionEvent */ public void addSelectionListener(SelectionListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener 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 TreeListener * interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException * @exception SWTException * * @see TreeListener * @see #removeTreeListener */ public void addTreeListener(TreeListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Expand, typedListener); addListener (SWT.Collapse, typedListener); } int calculateWidth (TreeItem[] items, int index, GC gc, boolean recurse) { if (items == null) return 0; int width = 0; for (int i=0; iSWT.VIRTUAL style, * these attributes are requested again as needed. * * @param index the index of the item to clear * @param all true if all child items of the indexed item should be * cleared recursively, and false otherwise * * @exception IllegalArgumentException * @exception SWTException * * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.2 */ public void clear (int index, boolean all) { checkWidget (); int count = getItemCount (); if (index < 0 || index >= count) error (SWT.ERROR_INVALID_RANGE); clear (null, index, all); } /** * Clears all the items in the receiver. The text, icon and other * attributes of the items are set to their default values. If the * tree was created with the SWT.VIRTUAL style, these * attributes are requested again as needed. * * @param all true if all child items should be cleared * recursively, and false otherwise * * @exception SWTException * * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.2 */ public void clearAll (boolean all) { checkWidget (); clearAll (null, all); } void clearCachedWidth (TreeItem[] items) { if (items == null) return; for (int i = 0; i < items.length; i++) { TreeItem item = items [i]; if (item == null) break; item.width = -1; clearCachedWidth (item.items); } } void collapseItem_collapseChildren (int /*long*/ id, int /*long*/ sel, int /*long*/ itemID, boolean children) { TreeItem item = (TreeItem)display.getWidget(itemID); if (item == null) return; if (!ignoreExpand) item.sendExpand (false, children); ignoreExpand = true; super.collapseItem_collapseChildren (id, sel, itemID, children); ignoreExpand = false; if (isDisposed() || item.isDisposed()) return; setScrollWidth (); } int /*long*/ columnAtPoint(int /*long*/ id, int /*long*/ sel, NSPoint point) { if ((style & SWT.CHECK) != 0) { if (point.x <= getCheckColumnWidth() && point.y < headerView.frame().height) return 1; } return super.columnAtPoint(id, sel, point); } public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget (); int width = 0, height = 0; if (wHint == SWT.DEFAULT) { if (columnCount != 0) { for (int i=0; i 1) { createColumn (item, index); } } } } void createItem (TreeItem item, TreeItem parentItem, int index) { int count; TreeItem [] items; if (parentItem != null) { count = parentItem.itemCount; items = parentItem.items; } else { count = this.itemCount; items = this.items; } if (index == -1) index = count; if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE); if (count == items.length) { TreeItem [] newItems = new TreeItem [items.length + 4]; System.arraycopy (items, 0, newItems, 0, items.length); items = newItems; if (parentItem != null) { parentItem.items = items; } else { this.items = items; } } System.arraycopy (items, index, items, index + 1, count++ - index); items [index] = item; item.items = new TreeItem [4]; SWTTreeItem handle = (SWTTreeItem) new SWTTreeItem ().alloc ().init (); item.handle = handle; item.createJNIRef (); item.register (); if (parentItem != null) { parentItem.itemCount = count; } else { this.itemCount = count; } ignoreExpand = true; NSOutlineView widget = (NSOutlineView)view; if (getDrawing()) { TreeItem[] selectedItems = getSelection (); if (parentItem != null) { widget.reloadItem (parentItem.handle, true); } else { widget.reloadData (); } selectItems (selectedItems, true); } else { reloadPending = true; } if (parentItem != null && parentItem.itemCount == 1 && parentItem.expanded) { widget.expandItem (parentItem.handle); } ignoreExpand = false; } void createWidget () { super.createWidget (); items = new TreeItem [4]; columns = new TreeColumn [4]; } Color defaultBackground () { return display.getWidgetColor (SWT.COLOR_LIST_BACKGROUND); } NSFont defaultNSFont () { return display.outlineViewFont; } Color defaultForeground () { return display.getWidgetColor (SWT.COLOR_LIST_FOREGROUND); } void deselectAll(int /*long*/ id, int /*long*/ sel, int /*long*/ sender) { if (preventSelect && !ignoreSelect) return; if ((style & SWT.SINGLE) != 0 && !ignoreSelect) { if ( ((NSTableView)view).selectedRow() != -1) return; } super.deselectAll (id, sel, sender); } void deselectRow (int /*long*/ id, int /*long*/ sel, int /*long*/ index) { if (preventSelect && !ignoreSelect) return; if ((style & SWT.SINGLE) != 0 && !ignoreSelect) { if ( ((NSTableView)view).selectedRow() == index) return; } super.deselectRow (id, sel, index); } /** * Deselects all selected items in the receiver. * * @exception SWTException */ public void deselectAll () { checkWidget (); NSTableView widget = (NSOutlineView) view; ignoreSelect = true; widget.deselectAll (null); ignoreSelect = false; } void deregister () { super.deregister (); display.removeWidget (headerView); display.removeWidget (dataCell); if (buttonCell != null) display.removeWidget (buttonCell); } /** * Deselects an item in the receiver. If the item was already * deselected, it remains deselected. * * @param item the item to be deselected * * @exception IllegalArgumentException * @exception SWTException * * @since 3.4 */ public void deselect (TreeItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); NSOutlineView widget = (NSOutlineView)view; int /*long*/ row = widget.rowForItem(item.handle); ignoreSelect = true; widget.deselectRow (row); ignoreSelect = false; } void destroyItem (TreeColumn column) { int index = 0; while (index < columnCount) { if (columns [index] == column) break; index++; } for (int i=0; i size.width) newRect.width -= TEXT_GAP; break; } } newRect.height = rect.height; if (newRect.height > size.height) { newRect.y += (newRect.height - size.height) / 2; newRect.height = size.height; } newStr.drawInRect(newRect); newStr.release(); } else { NSColor nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], color[3]); cell.setTextColor(nsColor); callSuper = true; } } else { callSuper = true; } if (callSuper) { NSAttributedString attrStr = cell.attributedStringValue(); NSSize size = attrStr.size(); if (rect.height > size.height) { rect.y += (rect.height - size.height) / 2; rect.height = size.height; } super.drawInteriorWithFrame_inView(id, sel, rect, view); } } if (hooksPaint) { context.saveGraphicsState(); NSAffineTransform transform = NSAffineTransform.transform(); transform.translateXBy(offsetX, offsetY); transform.concat(); GCData data = new GCData (); data.paintRect = cellRect; GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); if (drawSelection) { gc.setForeground (selectionForeground); gc.setBackground (selectionBackground); } else { gc.setForeground (userForeground != null ? userForeground : item.getForeground (columnIndex)); gc.setBackground (item.getBackground (columnIndex)); } if (!drawExpansion) { gc.setClipping ((int)(cellRect.x - offsetX), (int)(cellRect.y - offsetY), (int)cellRect.width, (int)cellRect.height); } Event event = new Event (); event.item = item; event.gc = gc; event.index = columnIndex; if (drawForeground) event.detail |= SWT.FOREGROUND; if (drawBackground) event.detail |= SWT.BACKGROUND; if (isSelected) event.detail |= SWT.SELECTED; event.x = itemX; event.y = itemY; event.width = contentWidth; event.height = itemHeight; sendEvent (SWT.PaintItem, event); gc.dispose (); context.restoreGraphicsState(); } } void drawWithExpansionFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect cellFrame, int /*long*/ view) { drawExpansion = true; super.drawWithExpansionFrame_inView(id, sel, cellFrame, view); drawExpansion = false; } void expandItem_expandChildren (int /*long*/ id, int /*long*/ sel, int /*long*/ itemID, boolean children) { TreeItem item = (TreeItem)display.getWidget(itemID); if (item == null) return; if (!ignoreExpand) item.sendExpand (true, children); ignoreExpand = true; super.expandItem_expandChildren (id, sel, itemID, children); ignoreExpand = false; if (isDisposed() || item.isDisposed()) return; if (!children) { ignoreExpand = true; TreeItem[] items = item.items; for (int i = 0; i < item.itemCount; i++) { if (items[i] != null) items[i].updateExpanded (); } ignoreExpand = false; } setScrollWidth (false, item.items, true); } NSRect expansionFrameWithFrame_inView(int /*long*/ id, int /*long*/ sel, NSRect cellRect, int /*long*/ view) { if (toolTipText == null) { NSRect rect = super.expansionFrameWithFrame_inView(id, sel, cellRect, view); NSCell cell = new NSCell(id); NSAttributedString str = cell.attributedStringValue(); NSSize textSize = str.size(); NSRect expansionRect; if (rect.width != 0 && rect.height != 0) { if (hooks(SWT.MeasureItem)) { expansionRect = cellRect; NSSize cellSize = cell.cellSize(); expansionRect.width = cellSize.width; } else { expansionRect = rect; } if (textSize.height > expansionRect.height) { expansionRect.height = textSize.height; } } else { if (hooks(SWT.MeasureItem)) { expansionRect = cellRect; NSSize cellSize = cell.cellSize(); expansionRect.width = cellSize.width; } else { expansionRect = cell.titleRectForBounds(cellRect); NSSize cellSize = super.cellSize(id, OS.sel_cellSize); expansionRect.width = cellSize.width; } if (textSize.height > expansionRect.height) { expansionRect.height = textSize.height; } else { NSRect contentRect = scrollView.contentView().bounds(); OS.NSIntersectionRect(contentRect, expansionRect, contentRect); if (OS.NSEqualRects(expansionRect, contentRect)) { return new NSRect(); } } } return expansionRect; } return new NSRect(); } Widget findTooltip (NSPoint pt) { NSTableView widget = (NSTableView)view; NSTableHeaderView headerView = widget.headerView(); if (headerView != null) { pt = headerView.convertPoint_fromView_ (pt, null); int /*long*/ index = headerView.columnAtPoint (pt); if (index != -1) { NSArray nsColumns = widget.tableColumns (); id nsColumn = nsColumns.objectAtIndex (index); for (int i = 0; i < columnCount; i++) { TreeColumn column = columns [i]; if (column.nsColumn.id == nsColumn.id) { return column; } } } } return super.findTooltip (pt); } int getCheckColumnWidth () { return (int)checkColumn.dataCell().cellSize().width; } public Rectangle getClientArea () { checkWidget (); Rectangle rect = super.getClientArea (); NSTableHeaderView headerView = ((NSTableView) view).headerView (); if (headerView != null) { // The origin of the tree is the top-left of the rows of the tree, // not the header. Adjust the y value accordingly. int height = (int) headerView.bounds ().height; rect.y -= height; rect.height += height; } return rect; } TreeColumn getColumn (id id) { for (int i = 0; i < columnCount; i++) { if (columns[i].nsColumn.id == id.id) { return columns[i]; } } return null; } /** * Returns the column at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * Columns are returned in the order that they were created. * If no TreeColumns were created by the programmer, * this method will throw ERROR_INVALID_RANGE despite * the fact that a single column of data may be visible in the tree. * This occurs when the programmer uses the tree like a list, adding * items but never creating a column. * * @param index the index of the column to return * @return the column at the given index * * @exception IllegalArgumentException
    *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
  • *
* @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @see Tree#getColumnOrder() * @see Tree#setColumnOrder(int[]) * @see TreeColumn#getMoveable() * @see TreeColumn#setMoveable(boolean) * @see SWT#Move * * @since 3.1 */ public TreeColumn getColumn (int index) { checkWidget (); if (!(0 <=index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE); return columns [index]; } /** * Returns the number of columns contained in the receiver. * If no TreeColumns were created by the programmer, * this value is zero, despite the fact that visually, one column * of items may be visible. This occurs when the programmer uses * the tree like a list, adding items but never creating a column. * * @return the number of columns * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @since 3.1 */ public int getColumnCount () { checkWidget (); return columnCount; } /** * Returns an array of zero-relative integers that map * the creation order of the receiver's items to the * order in which they are currently being displayed. *

* Specifically, the indices of the returned array represent * the current visual order of the items, and the contents * of the array represent the creation order of the items. *

* 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. *

* * @return the current visual order of the receiver's items * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @see Tree#setColumnOrder(int[]) * @see TreeColumn#getMoveable() * @see TreeColumn#setMoveable(boolean) * @see SWT#Move * * @since 3.2 */ public int [] getColumnOrder () { checkWidget (); int [] order = new int [columnCount]; for (int i = 0; i < columnCount; i++) { TreeColumn column = columns [i]; int index = indexOf (column.nsColumn); if ((style & SWT.CHECK) != 0) index -= 1; order [index] = i; } return order; } /** * Returns an array of TreeColumns which are the * columns in the receiver. Columns are returned in the order * that they were created. If no TreeColumns were * created by the programmer, the array is empty, despite the fact * that visually, one column of items may be visible. This occurs * when the programmer uses the tree like a list, adding items but * never creating a column. *

* 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. *

* * @return the items in the receiver * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @see Tree#getColumnOrder() * @see Tree#setColumnOrder(int[]) * @see TreeColumn#getMoveable() * @see TreeColumn#setMoveable(boolean) * @see SWT#Move * * @since 3.1 */ public TreeColumn [] getColumns () { checkWidget (); TreeColumn [] result = new TreeColumn [columnCount]; System.arraycopy (columns, 0, result, 0, columnCount); return result; } /** * Returns the width in pixels of a grid line. * * @return the width of a grid line in pixels * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @since 3.1 */ public int getGridLineWidth () { checkWidget (); return 0; } /** * Returns the height of the receiver's header * * @return the height of the header or zero if the header is not visible * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @since 3.1 */ public int getHeaderHeight () { checkWidget (); NSTableHeaderView headerView = ((NSOutlineView) view).headerView (); if (headerView == null) return 0; return (int) headerView.bounds ().height; } /** * Returns true if the receiver's header is visible, * and false otherwise. *

* If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, this method * may still indicate that it is considered visible even though * it may not actually be showing. *

* * @return the receiver's header's visibility state * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @since 3.1 */ public boolean getHeaderVisible () { checkWidget (); return ((NSOutlineView) view).headerView () != null; } /** * Returns the item at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * * @param index the index of the item to return * @return the item at the given index * * @exception IllegalArgumentException
    *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
  • *
* @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @since 3.1 */ public TreeItem getItem (int index) { checkWidget (); int count = getItemCount (); if (index < 0 || index >= count) error (SWT.ERROR_INVALID_RANGE); return _getItem (null, index, true); } /** * 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. *

* The item that is returned represents an item that could be selected by the user. * For example, if selection only occurs in items in the first column, then null is * returned if the point is outside of the item. * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy, * determines the extent of the selection. *

* * @param point the point used to locate the item * @return the item at the given point, or null if the point is not in a selectable item * * @exception IllegalArgumentException
    *
  • ERROR_NULL_ARGUMENT - if the point is null
  • *
* @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
*/ public TreeItem getItem (Point point) { checkWidget (); if (point == null) error (SWT.ERROR_NULL_ARGUMENT); checkItems (); NSOutlineView widget = (NSOutlineView)view; NSPoint pt = new NSPoint(); pt.x = point.x; pt.y = point.y; int row = (int)/*64*/widget.rowAtPoint(pt); if (row == -1) return null; NSRect rect = widget.frameOfOutlineCellAtRow(row); if (OS.NSPointInRect(pt, rect)) return null; id id = widget.itemAtRow(row); Widget item = display.getWidget (id.id); if (item != null && item instanceof TreeItem) { return (TreeItem)item; } return null; } /** * 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
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
*/ public int getItemCount () { checkWidget (); return itemCount; } int getItemCount (TreeItem item) { return item == null ? itemCount : item.itemCount; } /** * Returns the height of the area which would be used to * display one of the items in the tree. * * @return the height of one item * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
*/ public int getItemHeight () { checkWidget (); return (int)((NSOutlineView) view).rowHeight () + CELL_GAP; } /** * Returns a (possibly empty) array of items contained in the * receiver that are direct item children of the receiver. These * are the roots of the tree. *

* 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. *

* * @return the items * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
*/ public TreeItem [] getItems () { checkWidget (); TreeItem [] result = new TreeItem [itemCount]; for (int i=0; itrue if the receiver's lines are visible, * and false otherwise. Note that some platforms draw * grid lines while others may draw alternating row colors. *

* If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, this method * may still indicate that it is considered visible even though * it may not actually be showing. *

* * @return the visibility state of the lines * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @since 3.1 */ public boolean getLinesVisible () { checkWidget (); return ((NSOutlineView) view).usesAlternatingRowBackgroundColors (); } /** * Returns the receiver's parent item, which must be a * TreeItem or null when the receiver is a * root. * * @return the receiver's parent item * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
*/ public TreeItem getParentItem () { checkWidget (); return null; } /** * Returns an array of TreeItems that are currently * selected in the receiver. The order of the items is unspecified. * An empty array indicates that no items are selected. *

* Note: This is not the actual structure used by the receiver * to maintain its selection, so modifying the array will * not affect the receiver. *

* @return an array representing the selection * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
*/ public TreeItem [] getSelection () { checkWidget (); NSOutlineView widget = (NSOutlineView) view; if (widget.numberOfSelectedRows () == 0) { return new TreeItem [0]; } NSIndexSet selection = widget.selectedRowIndexes (); int count = (int)/*64*/selection.count (); int /*long*/ [] indexBuffer = new int /*long*/ [count]; selection.getIndexes (indexBuffer, count, 0); TreeItem [] result = new TreeItem [count]; for (int i=0; i *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ public int getSelectionCount () { checkWidget (); return (int)/*64*/((NSOutlineView) view).numberOfSelectedRows (); } /** * Returns the column which shows the sort indicator for * the receiver. The value may be null if no column shows * the sort indicator. * * @return the sort indicator * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see #setSortColumn(TreeColumn) * * @since 3.2 */ public TreeColumn getSortColumn () { checkWidget (); return sortColumn; } /** * Returns the direction of the sort indicator for the receiver. * The value will be one of UP, DOWN * or NONE. * * @return the sort direction * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see #setSortDirection(int) * * @since 3.2 */ public int getSortDirection () { checkWidget (); return sortDirection; } /** * 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
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 2.1 */ public TreeItem getTopItem () { checkWidget (); //TODO - partial item at the top NSRect rect = scrollView.documentVisibleRect (); NSPoint point = new NSPoint (); point.x = rect.x; point.y = rect.y; NSOutlineView outlineView = (NSOutlineView)view; int /*long*/ index = outlineView.rowAtPoint (point); if (index == -1) return null; /* empty */ id item = outlineView.itemAtRow (index); return (TreeItem)display.getWidget (item.id); } NSRect headerRectOfColumn (int /*long*/ id, int /*long*/ sel, int /*long*/ column) { if ((style & SWT.CHECK) == 0) return callSuperRect(id, sel, column); if (column == 0) { NSRect returnValue = callSuperRect(id, sel, column); returnValue.width = 0; return returnValue; } if (column == 1) { NSRect returnValue = callSuperRect(id, sel, column); // Save a call to [NSTableView intercellSpacing] by using our constant. returnValue.width += (checkColumn.width() + CELL_GAP); returnValue.x -= (checkColumn.width() + CELL_GAP); return returnValue; } return callSuperRect(id, sel, column); } void highlightSelectionInClipRect(int /*long*/ id, int /*long*/ sel, int /*long*/ rect) { if (hooks (SWT.EraseItem)) return; if ((style & SWT.HIDE_SELECTION) != 0 && !hasFocus()) return; NSRect clipRect = new NSRect (); OS.memmove (clipRect, rect, NSRect.sizeof); callSuper (id, sel, clipRect); } int /*long*/ hitTestForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event, NSRect rect, int /*long*/ controlView) { /* * For some reason, the cell class needs to implement hitTestForEvent:inRect:ofView:, * otherwise the double action selector is not called properly. */ return callSuper(id, sel, event, rect, controlView); } int /*long*/ image (int /*long*/ id, int /*long*/ sel) { int /*long*/ [] image = new int /*long*/ [1]; OS.object_getInstanceVariable(id, Display.SWT_IMAGE, image); return image[0]; } NSRect imageRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) { NSImage image = new NSCell(id).image(); if (image != null) { cellFrame.x += IMAGE_GAP; cellFrame.width = imageBounds.width; cellFrame.height = imageBounds.height; } return cellFrame; } int indexOf (NSTableColumn column) { return (int)/*64*/((NSTableView)view).tableColumns().indexOfObjectIdenticalTo(column); } /** * Searches the receiver's list starting at the first column * (index 0) until a column is found that is equal to the * argument, and returns the index of that column. If no column * is found, returns -1. * * @param column the search column * @return the index of the column * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the column is null
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.1 */ public int indexOf (TreeColumn column) { checkWidget (); if (column == null) error (SWT.ERROR_NULL_ARGUMENT); if (column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); for (int i=0; i *
  • ERROR_NULL_ARGUMENT - if the item is null
  • *
  • ERROR_INVALID_ARGUMENT - if the item has been disposed
  • * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.1 */ public int indexOf (TreeItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); if (item.parentItem != null) return -1; for (int i = 0; i < itemCount; i++) { if (item == items[i]) return i; } return -1; } boolean isTransparent() { return true; } boolean isTrim (NSView view) { if (super.isTrim (view)) return true; return view.id == headerView.id; } void keyDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { ignoreSelect = preventSelect = false; super.keyDown(id, sel, theEvent); } int /*long*/ menuForEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { if (id != headerView.id) { /* * Feature in Cocoa: Table views do not change the selection when the user * right-clicks or control-clicks on an NSTableView or its subclasses. Fix is to select the * clicked-on row ourselves. */ NSEvent event = new NSEvent(theEvent); NSOutlineView tree = (NSOutlineView)view; // get the current selections for the outline view. NSIndexSet selectedRowIndexes = tree.selectedRowIndexes(); // select the row that was clicked before showing the menu for the event NSPoint mousePoint = view.convertPoint_fromView_(event.locationInWindow(), null); int /*long*/ row = tree.rowAtPoint(mousePoint); // figure out if the row that was just clicked on is currently selected if (selectedRowIndexes.containsIndex(row) == false) { NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc(); set = set.initWithIndex(row); tree.selectRowIndexes (set, false); set.release(); } // else that row is currently selected, so don't change anything. } return super.menuForEvent(id, sel, theEvent); } void mouseDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { if (id == view.id) { // Bug/feature in Cocoa: If the tree has a context menu we just set it visible instead of returning // it from menuForEvent:. This has the side effect, however, of sending control-click to the NSTableView, // which is interpreted as a single click that clears the selection. Fix is to ignore control-click, NSEvent event = new NSEvent(theEvent); if ((event.modifierFlags() & OS.NSControlKeyMask) != 0) return; } super.mouseDown(id, sel, theEvent); } void mouseDownSuper(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { ignoreSelect = preventSelect = false; boolean check = false; NSEvent nsEvent = new NSEvent(theEvent); NSOutlineView widget = (NSOutlineView)view; NSPoint pt = view.convertPoint_fromView_(nsEvent.locationInWindow(), null); int row = (int)/*64*/widget.rowAtPoint(pt); NSObject itemID = null; if (row != -1) itemID = new NSObject(widget.itemAtRow(row)); if (row != -1 && (style & SWT.CHECK) != 0) { int column = (int)/*64*/widget.columnAtPoint(pt); NSCell cell = widget.preparedCellAtColumn(column, row); if (cell != null && cell.isKindOfClass(OS.class_NSButtonCell) && cell.isEnabled()) { NSRect checkRect = cell.imageRectForBounds(widget.frameOfCellAtColumn(column, row)); if (OS.NSPointInRect(pt, checkRect)) { check = preventSelect = true; } } } if (!check && row != -1 && (nsEvent.modifierFlags() & OS.NSDeviceIndependentModifierFlagsMask) == 0 && nsEvent.clickCount() == 1) { if (widget.isRowSelected(row)) { NSRect rect = widget.frameOfOutlineCellAtRow(row); if (!OS.NSPointInRect(pt, rect)) { Widget item = itemID != null ? display.getWidget (itemID.id) : null; if (item != null && item instanceof TreeItem) { Event event = new Event (); event.item = item; sendSelectionEvent (SWT.Selection, event, false); // Feature in Cocoa: This code path handles the case of an unmodified click on an already-selected row. // If other rows are selected they will de-select and fire a outlineViewSelectionDidChange message. // To keep the order of events correct, send the selection event here and ignore the next // outlineViewSelectionDidChange message. We'll reset the flag when the message is received. if (widget.selectedRowIndexes().count() > 1) { ignoreSelect = true; } } } } } didSelect = false; if (itemID != null) itemID.retain(); super.mouseDownSuper(id, sel, theEvent); if (itemID != null) itemID.release(); didSelect = false; } /* * Feature in Cocoa. If a checkbox is in multi-state mode, nextState cycles * from off to mixed to on and back to off again. This will cause the on state * to momentarily appear while clicking on the checkbox. To avoid this, * override [NSCell nextState] to go directly to the desired state. */ int /*long*/ nextState (int /*long*/ id, int /*long*/ sel) { NSOutlineView outlineView = (NSOutlineView)view; int index = (int)/*64*/outlineView.clickedRow(); if (index == -1) index = (int)/*64*/outlineView.selectedRow (); TreeItem item = (TreeItem)display.getWidget (outlineView.itemAtRow (index).id); if (item.grayed) { return item.checked ? OS.NSOffState : OS.NSMixedState; } return item.checked ? OS.NSOffState : OS.NSOnState; } int /*long*/ outlineView_child_ofItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ index, int /*long*/ itemID) { TreeItem parent = (TreeItem) display.getWidget (itemID); TreeItem item = _getItem (parent, (int)/*64*/index, true); return item.handle.id; } void outlineView_didClickTableColumn (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn) { TreeColumn column = getColumn (new id (tableColumn)); if (column == null) return; /* either CHECK column or firstColumn in 0-column Tree */ column.sendSelectionEvent (SWT.Selection); } int /*long*/ outlineView_objectValueForTableColumn_byItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn, int /*long*/ itemID) { TreeItem item = (TreeItem) display.getWidget (itemID); checkData (item); if (checkColumn != null && tableColumn == checkColumn.id) { NSNumber value; if (item.checked && item.grayed) { value = NSNumber.numberWithInt (OS.NSMixedState); } else { value = NSNumber.numberWithInt (item.checked ? OS.NSOnState : OS.NSOffState); } return value.id; } for (int i=0; i 0) { int style = columns [index].style; if ((style & SWT.CENTER) != 0) { alignment = OS.NSCenterTextAlignment; } else if ((style & SWT.RIGHT) != 0) { alignment = OS.NSRightTextAlignment; } } Font font = item.cellFont != null ? item.cellFont [index] : null; if (font == null) font = item.font; if (font == null) font = this.font; if (font == null) font = defaultFont (); if (font.extraTraits != 0) { NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5); dict.setObject (color, OS.NSForegroundColorAttributeName); dict.setObject (font.handle, OS.NSFontAttributeName); addTraits(dict, font); NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init (); paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping); paragraphStyle.setAlignment (alignment); paragraphStyle.setBaseWritingDirection(direction); dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName); paragraphStyle.release (); NSAttributedString attribStr = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString (textCell.title(), dict); textCell.setAttributedStringValue(attribStr); attribStr.release(); dict.release(); } else { textCell.setFont(font.handle); textCell.setTextColor(color); textCell.setAlignment (alignment); textCell.setBaseWritingDirection(direction); } } void outlineViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { NSNotification notification = new NSNotification (aNotification); NSDictionary userInfo = notification.userInfo (); NSString nsstring = (NSString) new NSString().alloc(); nsstring = nsstring.initWithString("NSOldColumn"); //$NON-NLS-1$ id nsOldIndex = userInfo.valueForKey (nsstring); nsstring.release(); nsstring = (NSString) new NSString().alloc(); nsstring = nsstring.initWithString("NSNewColumn"); //$NON-NLS-1$ id nsNewIndex = userInfo.valueForKey (nsstring); nsstring.release(); int oldIndex = new NSNumber (nsOldIndex).intValue (); int newIndex = new NSNumber (nsNewIndex).intValue (); NSOutlineView outlineView = (NSOutlineView)view; int startIndex = Math.min (oldIndex, newIndex); int endIndex = Math.max (oldIndex, newIndex); NSArray nsColumns = outlineView.tableColumns (); for (int i = startIndex; i <= endIndex; i++) { id columnId = nsColumns.objectAtIndex (i); TreeColumn column = getColumn (columnId); if (column != null) { column.sendEvent (SWT.Move); if (isDisposed ()) return; } } headerView.setNeedsDisplay(true); } void outlineViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { NSNotification notification = new NSNotification (aNotification); NSDictionary userInfo = notification.userInfo (); NSString nsstring = (NSString) new NSString().alloc(); nsstring = nsstring.initWithString("NSTableColumn"); //$NON-NLS-1$ id columnId = userInfo.valueForKey (nsstring); nsstring.release(); TreeColumn column = getColumn (columnId); if (column == null) return; /* either CHECK column or firstColumn in 0-column Tree */ column.sendEvent (SWT.Resize); if (isDisposed ()) return; NSOutlineView outlineView = (NSOutlineView)view; int index = indexOf (column.nsColumn); if (index == -1) return; /* column was disposed in Resize callback */ NSArray nsColumns = outlineView.tableColumns (); int columnCount = (int)/*64*/outlineView.numberOfColumns (); for (int i = index + 1; i < columnCount; i++) { columnId = nsColumns.objectAtIndex (i); column = getColumn (columnId); if (column != null) { column.sendEvent (SWT.Move); if (isDisposed ()) return; } } } void scrollClipViewToPoint (int /*long*/ id, int /*long*/ sel, int /*long*/ clipView, NSPoint point) { if (shouldScroll) { super.scrollClipViewToPoint(id, sel, clipView, point); if ((style & SWT.CHECK) != 0 && columnCount > 0 && ((NSOutlineView) view).headerView () != null) { if (point.x <= getCheckColumnWidth()) { /* * Header of first column is extended as header of the checkbox column. * So, redraw header of first column when check column is scrolled to be visible. */ headerView.setNeedsDisplayInRect(headerView.headerRectOfColumn(1)); } } } } void sendSelection () { if (ignoreSelect) return; NSOutlineView widget = (NSOutlineView) view; int row = (int)/*64*/widget.selectedRow (); if (row == -1) sendSelectionEvent (SWT.Selection); else { id _id = widget.itemAtRow (row); TreeItem item = (TreeItem) display.getWidget (_id.id); Event event = new Event (); event.item = item; event.index = row; sendSelectionEvent (SWT.Selection, event, false); } } void outlineViewSelectionDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) { if (didSelect) return; sendSelection (); } void outlineViewSelectionIsChanging (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) { didSelect = true; sendSelection (); } void outlineView_setObjectValue_forTableColumn_byItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ object, int /*long*/ tableColumn, int /*long*/ itemID) { if (checkColumn != null && tableColumn == checkColumn.id) { TreeItem item = (TreeItem) display.getWidget (itemID); item.checked = !item.checked; Event event = new Event (); event.detail = SWT.CHECK; event.item = item; sendSelectionEvent (SWT.Selection, event, false); item.redraw (-1); } } boolean outlineView_writeItems_toPasteboard(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) { return sendMouseEvent(NSApplication.sharedApplication().currentEvent(), SWT.DragDetect, true); } void register () { super.register (); display.addWidget (headerView, this); display.addWidget (dataCell, this); if (buttonCell != null) display.addWidget (buttonCell, this); } void releaseChildren (boolean destroy) { itemCount = 0; ignoreSelect = true; ((NSOutlineView) view).reloadData (); ignoreSelect = false; for (int i=0; i *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ public void removeAll () { checkWidget (); itemCount = 0; ignoreSelect = true; ((NSOutlineView) view).reloadData (); ignoreSelect = false; for (int i=0; i *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see SelectionListener * @see #addSelectionListener */ public void removeSelectionListener (SelectionListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); eventTable.unhook (SWT.Selection, listener); eventTable.unhook (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
      *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see TreeListener * @see #addTreeListener */ public void removeTreeListener (TreeListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Expand, listener); eventTable.unhook (SWT.Collapse, listener); } void reskinChildren (int flags) { if (items != null) { for (int i=0; i *
  • ERROR_INVALID_ARGUMENT - if the item has been disposed
  • * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void setInsertMark (TreeItem item, boolean before) { checkWidget (); if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); TreeItem oldMark = insertItem; insertItem = item; insertBefore = before; if (oldMark != null && !oldMark.isDisposed()) oldMark.redraw (-1); if (item != null) item.redraw (-1); } /** * Selects all of the items in the receiver. *

    * If the receiver is single-select, do nothing. *

    * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void selectAll () { checkWidget (); if ((style & SWT.SINGLE) != 0) return; checkItems (); NSOutlineView widget = (NSOutlineView) view; ignoreSelect = true; widget.selectAll (null); ignoreSelect = false; } /** * Selects an item in the receiver. If the item was already * selected, it remains selected. * * @param item the item to be selected * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the item is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.4 */ public void select (TreeItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); checkItems (); showItem (item); NSOutlineView outlineView = (NSOutlineView) view; int /*long*/ row = outlineView.rowForItem (item.handle); NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc(); set = set.initWithIndex(row); ignoreSelect = true; outlineView.selectRowIndexes (set, (style & SWT.MULTI) != 0); ignoreSelect = false; set.release(); } void selectRowIndexes_byExtendingSelection (int /*long*/ id, int /*long*/ sel, int /*long*/ indexes, boolean extend) { if (preventSelect && !ignoreSelect) return; if ((style & SWT.SINGLE) != 0 && !ignoreSelect) { NSIndexSet set = new NSIndexSet(indexes); if (set.count() == 0) return; } super.selectRowIndexes_byExtendingSelection (id, sel, indexes, extend); } void sendDoubleSelection() { NSOutlineView outlineView = (NSOutlineView)view; int rowIndex = (int)/*64*/outlineView.clickedRow (); if (rowIndex == -1) rowIndex = (int)/*64*/outlineView.selectedRow (); if (rowIndex != -1) { if ((style & SWT.CHECK) != 0) { NSArray columns = outlineView.tableColumns (); int columnIndex = (int)/*64*/outlineView.clickedColumn (); if (columnIndex != -1) { id column = columns.objectAtIndex (columnIndex); if (column.id == checkColumn.id) return; } } TreeItem item = (TreeItem) display.getWidget (outlineView.itemAtRow (rowIndex).id); Event event = new Event (); event.item = item; sendSelectionEvent (SWT.DefaultSelection, event, false); } } boolean sendKeyEvent (NSEvent nsEvent, int type) { boolean result = super.sendKeyEvent (nsEvent, type); if (!result) return result; if (type != SWT.KeyDown) return result; short keyCode = nsEvent.keyCode (); switch (keyCode) { case 76: /* KP Enter */ case 36: { /* Return */ sendDoubleSelection(); break; } } return result; } void sendMeasureItem (TreeItem item, boolean selected, int columnIndex, NSSize size) { NSOutlineView widget = (NSOutlineView)this.view; int contentWidth = (int)Math.ceil (size.width); NSSize spacing = widget.intercellSpacing(); int itemHeight = (int)Math.ceil (widget.rowHeight() + spacing.height); GCData data = new GCData (); data.paintRect = widget.frame (); GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); Event event = new Event (); event.item = item; event.gc = gc; event.index = columnIndex; event.width = contentWidth; event.height = itemHeight; if (selected && ((style & SWT.HIDE_SELECTION) == 0 || hasFocus())) event.detail |= SWT.SELECTED; sendEvent (SWT.MeasureItem, event); gc.dispose (); if (!isDisposed () && !item.isDisposed ()) { size.width = event.width; size.height = event.height; if (itemHeight < event.height) { widget.setRowHeight (event.height); } if (contentWidth != event.width) { if (columnCount == 0 && columnIndex == 0) { item.width = event.width; item.width += widget.indentationPerLevel () * (1 + widget.levelForItem (item.handle)); if (setScrollWidth (item)) { widget.setNeedsDisplay(true); } } } } } void selectItems (TreeItem[] items, boolean ignoreDisposed) { NSOutlineView outlineView = (NSOutlineView) view; NSMutableIndexSet set = (NSMutableIndexSet) new NSMutableIndexSet ().alloc ().init (); int length = items.length; for (int i=0; i *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the item order is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items
    • *
    * * @see Tree#getColumnOrder() * @see TreeColumn#getMoveable() * @see TreeColumn#setMoveable(boolean) * @see SWT#Move * * @since 3.2 */ public void setColumnOrder (int [] order) { checkWidget (); if (order == null) error (SWT.ERROR_NULL_ARGUMENT); if (columnCount == 0) { if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT); return; } if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT); int [] oldOrder = getColumnOrder (); boolean reorder = false; boolean [] seen = new boolean [columnCount]; for (int i=0; i= columnCount) error (SWT.ERROR_INVALID_ARGUMENT); if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT); seen [index] = true; if (order [i] != oldOrder [i]) reorder = true; } if (reorder) { NSOutlineView outlineView = (NSOutlineView)view; int [] oldX = new int [oldOrder.length]; int check = (style & SWT.CHECK) != 0 ? 1 : 0; for (int i=0; itrue, * and marks it invisible otherwise. *

    * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, marking * it visible may not actually cause it to be displayed. *

    * * @param show the new visibility state * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.1 */ public void setHeaderVisible (boolean show) { checkWidget (); ((NSOutlineView) view).setHeaderView (show ? headerView : null); scrollView.tile(); } /** * Sets the number of root-level items contained in the receiver. * * @param count the number of items * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ public void setItemCount (int count) { checkWidget (); checkItems (); count = Math.max (0, count); setItemCount (null, count); } void setItemCount (TreeItem parentItem, int count) { int itemCount = getItemCount (parentItem); if (count == itemCount) return; NSOutlineView widget = (NSOutlineView) view; int length = Math.max (4, (count + 3) / 4 * 4); TreeItem [] children = parentItem == null ? items : parentItem.items; boolean expanded = parentItem == null || parentItem.getExpanded(); if (count < itemCount) { /* * Note that the item count has to be updated before the call to reloadItem(), but * the items have to be released after. */ if (parentItem == null) { this.itemCount = count; } else { parentItem.itemCount = count; } TreeItem[] selectedItems = getSelection (); widget.reloadItem (parentItem != null ? parentItem.handle : null, expanded); for (int index = count; index < itemCount; index ++) { TreeItem item = children [index]; if (item != null && !item.isDisposed()) item.release (false); } selectItems (selectedItems, true); TreeItem [] newItems = new TreeItem [length]; if (children != null) { System.arraycopy (children, 0, newItems, 0, count); } children = newItems; if (parentItem == null) { this.items = newItems; } else { parentItem.items = newItems; } } else { if ((style & SWT.VIRTUAL) == 0) { for (int i=itemCount; itrue, * and marks it invisible otherwise. Note that some platforms draw * grid lines while others may draw alternating row colors. *

    * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, marking * it visible may not actually cause it to be displayed. *

    * * @param show the new visibility state * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.1 */ public void setLinesVisible (boolean show) { checkWidget (); ((NSOutlineView) view).setUsesAlternatingRowBackgroundColors (show); ((NSOutlineView) view).setGridStyleMask(show ? OS.NSTableViewSolidVerticalGridLineMask : OS.NSTableViewGridNone); } public void setRedraw (boolean redraw) { checkWidget (); super.setRedraw (redraw); if (redraw && drawCount == 0) { checkItems (); setScrollWidth (); } } boolean setScrollWidth () { return setScrollWidth (true, items, true); } boolean setScrollWidth (boolean set, TreeItem[] items, boolean recurse) { if (items == null) return false; if (ignoreRedraw || !getDrawing()) return false; if (columnCount != 0) return false; GC gc = new GC (this); int newWidth = calculateWidth (items, 0, gc, recurse); gc.dispose (); if (!set) { int oldWidth = (int)firstColumn.width (); if (oldWidth >= newWidth) return false; } firstColumn.setWidth (newWidth); if (horizontalBar != null && horizontalBar.view != null) redrawWidget (horizontalBar.view, false); return true; } boolean setScrollWidth (TreeItem item) { if (ignoreRedraw || !getDrawing()) return false; if (columnCount != 0) return false; TreeItem parentItem = item.parentItem; if (parentItem != null && !parentItem.getExpanded ()) return false; GC gc = new GC (this); int newWidth = item.calculateWidth (0, gc); gc.dispose (); int oldWidth = (int)firstColumn.width (); if (oldWidth < newWidth) { firstColumn.setWidth (newWidth); if (horizontalBar != null && horizontalBar.view != null) redrawWidget (horizontalBar.view, false); return true; } return false; } void setShouldExpandItem (int /*long*/ id, int /*long*/ sel, boolean shouldExpand) { this.shouldExpand = shouldExpand; } void setShouldScrollClipView (int /*long*/ id, int /*long*/ sel, boolean shouldScroll) { this.shouldScroll = shouldScroll; } /** * Sets the receiver's selection to the given item. * The current selection is cleared before the new item is selected, * and if necessary, the receiver is scrolled to make the new selection visible. *

    * If the item is not in the receiver, then it is ignored. *

    * * @param item the item to select * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the item is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ public void setSelection (TreeItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); setSelection (new TreeItem [] {item}); } /** * Sets the receiver's selection to be the given array of items. * The current selection is cleared before the new items are selected, * and if necessary, the receiver is scrolled to make the new selection visible. *

    * 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
      *
    • ERROR_NULL_ARGUMENT - if the array of items is null
    • *
    • ERROR_INVALID_ARGUMENT - if one of the items has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Tree#deselectAll() */ public void setSelection (TreeItem [] items) { checkWidget (); if (items == null) error (SWT.ERROR_NULL_ARGUMENT); checkItems (); deselectAll (); int length = items.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; selectItems (items, false); if (items.length > 0) { for (int i = 0; i < items.length; i++) { TreeItem item = items[i]; if (item != null) { showItem(item, true); break; } } } } /** * Sets the column used by the sort indicator for the receiver. A null * value will clear the sort indicator. The current sort column is cleared * before the new column is set. * * @param column the column used by the sort indicator or null * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the column is disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ public void setSortColumn (TreeColumn column) { checkWidget (); if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); if (column == sortColumn) return; setSort(column, sortDirection); } /** * Sets the direction of the sort indicator for the receiver. The value * can be one of UP, DOWN or NONE. * * @param direction the direction of the sort indicator * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ public void setSortDirection (int direction) { checkWidget (); if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return; if (direction == sortDirection) return; setSort(sortColumn, direction); } void setSort (TreeColumn column, int direction) { NSImage image = null; NSTableColumn nsColumn = null; if (column != null) { nsColumn = column.nsColumn; if (direction == SWT.DOWN) image = NSImage.imageNamed(NSString.stringWith("NSDescendingSortIndicator")); if (direction == SWT.UP) image = NSImage.imageNamed(NSString.stringWith("NSAscendingSortIndicator")); } NSTableView widget = (NSTableView)view; if (sortColumn != null && sortColumn != column) { widget.setIndicatorImage(null, sortColumn.nsColumn); } widget.setHighlightedTableColumn(nsColumn); widget.setIndicatorImage(image, nsColumn); sortDirection = direction; sortColumn = column; } /** * 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
      *
    • ERROR_NULL_ARGUMENT - if the item is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Tree#getTopItem() * * @since 2.1 */ public void setTopItem (TreeItem item) { checkWidget(); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); checkItems (); showItem (item, false); NSOutlineView widget = (NSOutlineView) view; int /*long*/ row = widget.rowForItem (item.handle); if (row == -1) return; NSPoint pt = new NSPoint(); pt.x = scrollView.contentView().bounds().x; pt.y = widget.frameOfCellAtColumn(0, row).y; view.scrollPoint(pt); } /** * Shows the column. If the column is already showing in the receiver, * this method simply returns. Otherwise, the columns are scrolled until * the column is visible. * * @param column the column to be shown * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the item is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.1 */ public void showColumn (TreeColumn column) { checkWidget (); if (column == null) error (SWT.ERROR_NULL_ARGUMENT); if (column.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); if (column.parent != this) return; if (columnCount <= 1) return; int index = indexOf (column.nsColumn); if (!(0 <= index && index < columnCount + ((style & SWT.CHECK) != 0 ? 1 : 0))) return; ((NSOutlineView)view).scrollColumnToVisible (index); } /** * 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
      *
    • ERROR_NULL_ARGUMENT - if the item is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Tree#showSelection() */ public void showItem (TreeItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); checkItems (); showItem (item, true); } void showItem (TreeItem item, boolean scroll) { TreeItem parentItem = item.parentItem; if (parentItem != null) { showItem (parentItem, false); if (!parentItem.getExpanded()) { parentItem.setExpanded (true); Event event = new Event (); event.item = parentItem; sendEvent (SWT.Expand, event); } } if (scroll) { NSOutlineView outlineView = (NSOutlineView) view; outlineView.scrollRowToVisible (outlineView.rowForItem (item.handle)); } } /** * 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
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Tree#showItem(TreeItem) */ public void showSelection () { checkWidget (); checkItems (); //TODO - optimize TreeItem [] selection = getSelection (); if (selection.length > 0) { checkData(selection [0]); showItem (selection [0], true); } } void updateCursorRects (boolean enabled) { super.updateCursorRects (enabled); if (headerView == null) return; updateCursorRects (enabled, headerView); } }