/******************************************************************************* * Copyright (c) 2000, 2009 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.internal.wpf.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.events.*; /** * 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 { int gvColumns, parentingHandle, headerTemplate; int columnCount, itemCount; TreeItem anchor, lastSelection, unselect, reselect; TreeColumn [] columns; byte headerVisibility = OS.Visibility_Collapsed; boolean ignoreSelection, shiftDown, ctrlDown; static final String HEADER_PART_NAME = "SWT_PART_HEADER"; static final String SCROLLVIEWER_PART_NAME = "SWT_PART_SCROLLVIEWER"; static final String CHECKBOX_PART_NAME = "SWT_PART_CHECKBOX"; static final String IMAGE_PART_NAME = "SWT_PART_IMAGE"; static final String TEXT_PART_NAME = "SWT_PART_TEXT"; static final String CONTENTPANEL_PART_NAME = "SWT_PART_CONTENTPANEL"; static final String RENDER_PANEL_NAME = "SWT_PART_RENDERPANEL"; static String scrollViewerStyle = ""; /** * 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)); } static int checkStyle (int style) { /* * Feature in Windows. Even when WS_HSCROLL or * WS_VSCROLL is not specified, Windows creates * trees and tables with scroll bars. The fix * is to set H_SCROLL and V_SCROLL. * * NOTE: This code appears on all platforms so that * applications have consistent scroll bar behavior. */ if ((style & SWT.NO_SCROLL) == 0) { style |= SWT.H_SCROLL | SWT.V_SCROLL; } /* WPF is always FULL_SELECTION */ style |= SWT.FULL_SELECTION; return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); } /** * 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 backgroundHandle () { return parentingHandle; } boolean checkData (TreeItem item) { if ((style & SWT.VIRTUAL) == 0) return true; if (!item.cached) { item.cached = true; int parentItem = OS.FrameworkElement_Parent (item.handle); int items = OS.ItemsControl_Items (parentItem); int index = OS.ItemCollection_IndexOf (items, item.handle); OS.GCHandle_Free (items); OS.GCHandle_Free (parentItem); Event event = new Event (); event.item = item; event.index = index; sendEvent (SWT.SetData, event); if (isDisposed () || item.isDisposed ()) return false; } return true; } protected void checkSubclass () { if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); } /** * Clears the item at the given zero-relative index in the receiver. * The text, icon and other attributes of the item are set to the default * value. If the tree was created with the SWT.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 (); if (index < 0 || index >= itemCount) SWT.error (SWT.ERROR_INVALID_RANGE); clear (handle, index, all); } void clear (int parentHandle, int index, boolean all) { int items = OS.ItemsControl_Items (parentHandle); TreeItem item = getItem (items, index, false); if (item != null) { item.clear (); if (all) clearAll (item, true); } OS.GCHandle_Free (items); } /** * 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 clearAll (TreeItem parentItem, boolean all) { int count = parentItem != null ? parentItem.itemCount : itemCount; int parentHandle = parentItem != null ? parentItem.handle : handle; int items = OS.ItemsControl_Items (parentHandle); for (int i=0; i *
  • ERROR_NULL_ARGUMENT - if the item is null
  • *
  • ERROR_INVALID_ARGUMENT - if the item has been disposed
  • * * @exception SWTException * * @since 3.4 */ public void deselect (TreeItem item) { if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); if ((style & SWT.SINGLE) != 0) { ignoreSelection = true; OS.TreeViewItem_IsSelected (item.handle, false); ignoreSelection = false; return; } ignoreSelection = true; setIsSelectionActiveProperty(true); OS.TreeViewItem_IsSelected (item.handle, false); setIsSelectionActiveProperty(false); ignoreSelection = false; } /** * Deselects all selected items in the receiver. * * @exception SWTException */ public void deselectAll () { checkWidget (); if ((style & SWT.SINGLE) != 0) { int tvItem = OS.TreeView_SelectedItem (handle); if (tvItem != 0) { ignoreSelection = true; OS.TreeViewItem_IsSelected (tvItem, false); ignoreSelection = false; OS.GCHandle_Free (tvItem); } } else { int items = OS.ItemsControl_Items (handle); int itemCount = OS.ItemCollection_Count (items); boolean[] selecting = new boolean[] {false}; for (int i = 0; i < itemCount; i++) { int item = OS.ItemCollection_GetItemAt (items, i); fixSelection (item, null, null, selecting); OS.GCHandle_Free (item); } OS.GCHandle_Free (items); } } void destroyItem (TreeColumn column) { int index = OS.GridViewColumnCollection_IndexOf (gvColumns, column.handle); boolean removed = OS.GridViewColumnCollection_Remove (gvColumns, column.handle); if (!removed) error (SWT.ERROR_ITEM_NOT_REMOVED); int arrayIndex = -1; for (int i = 0; i < columnCount; i++) { TreeColumn tc = columns [i]; if (tc.equals(column)) { arrayIndex = i; break; } } columnCount--; columns [arrayIndex] = null; if (arrayIndex < columnCount) System.arraycopy (columns, arrayIndex+1, columns, arrayIndex, columnCount - arrayIndex); if (columnCount == 0) { OS.GCHandle_Free (gvColumns); gvColumns = 0; int templateProperty = OS.Control_TemplateProperty (); OS.DependencyObject_ClearValue(handle, templateProperty); OS.GCHandle_Free(templateProperty); } int items = OS.ItemsControl_Items (handle); 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
  • * * * @since 3.1 */ public int getGridLineWidth () { checkWidget (); //TODO 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 * * @since 3.1 */ public int getHeaderHeight () { checkWidget (); if (gvColumns == 0) return 0; int column = OS.GridViewColumnCollection_default (gvColumns, 0); int height = 0; int header = OS.GridViewColumn_Header (column); if (header != 0) { height = (int) OS.FrameworkElement_ActualHeight (header); if (height == 0) { updateLayout (header); height = (int) OS.FrameworkElement_ActualHeight (header); } OS.GCHandle_Free (header); } OS.GCHandle_Free (column); OS.GCHandle_Free (gvColumns); return 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 * * @since 3.1 */ public boolean getHeaderVisible () { checkWidget (); if (gvColumns == 0) return false; int column = OS.GridViewColumnCollection_default (gvColumns, 0); int header = OS.GridViewColumn_Header (column); boolean visible = OS.UIElement_Visibility (header) == OS.Visibility_Visible; OS.GCHandle_Free (header); OS.GCHandle_Free (column); return visible; } /** * 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 * @exception SWTException * * @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]; } //TreeColumn _getColumn (int index) { // if (columnCount == 0) return null; // int gridColumn = OS.GridViewColumnCollection_default (gvColumns, index); // int header = OS.GridViewColumn_Header (gridColumn); // TreeColumn column = (TreeColumn) display.getWidget (header); // OS.GCHandle_Free (gridColumn); // OS.GCHandle_Free (header); // return column; //} /** * 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 * * @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 * * @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; iTreeColumns 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]; for (int i = 0; i < result.length; i++) { result [i] = columns [i]; } return result; } /** * 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 (); if (index < 0 || index >= itemCount) error (SWT.ERROR_INVALID_RANGE); int items = OS.ItemsControl_Items (handle); TreeItem treeItem = getItem (items, index, true); OS.GCHandle_Free (items); return treeItem; } TreeItem getItem (int items, int index, boolean create) { int item = OS.ItemCollection_GetItemAt (items, index); TreeItem result = getItem (item, create); OS.GCHandle_Free (item); return result; } TreeItem getItem (int item, boolean create) { int tag = OS.FrameworkElement_Tag (item); if (tag != 0) { int contentValue = OS.IntPtr_ToInt32 (tag); OS.GCHandle_Free (tag); return (TreeItem) OS.JNIGetObject (contentValue); } if (create) { int itemHandle = OS.GCHandle_Alloc (item); int parentHandle = OS.FrameworkElement_Parent (item); TreeItem parentItem = null; if (!OS.Object_Equals (parentHandle, handle)) parentItem = (TreeItem) display.getWidget (parentHandle); OS.GCHandle_Free (parentHandle); return new TreeItem (this, parentItem, SWT.NONE, 0, itemHandle); } return null; } /** * 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); int pt = OS.gcnew_Point (point.x, point.y); int input = OS.UIElement_InputHitTest (handle, pt); OS.GCHandle_Free (pt); if (input == 0) return null; Widget widget = display.getWidget (input); OS.GCHandle_Free (input); if (widget instanceof TreeItem) { return (TreeItem) widget; } 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; } /** * 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 (); //FIXME if (itemCount == 0) return 16; int items = OS.ItemsControl_Items (handle); int item = OS.ItemCollection_GetItemAt (items, 0); double height = OS.FrameworkElement_ActualHeight (item); OS.GCHandle_Free (item); OS.GCHandle_Free (items); return height != 0 ? (int) height : 16; } /** * 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]; int items = OS.ItemsControl_Items (handle); for (int i = 0; i < itemCount; i++) { result [i] = getItem (items, i, true); } OS.GCHandle_Free (items); return result; } /** * Returns true 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 (); //TODO return false; } /** * 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 (); TreeItem [] result; if ((style & SWT.SINGLE) != 0) { int item = OS.TreeView_SelectedItem (handle); if (item == 0) return new TreeItem [0]; result = new TreeItem [] { (TreeItem) display.getWidget (item) }; OS.GCHandle_Free (item); } else { result = getSelectedItems (handle, new TreeItem [4], new int [1]); } return result; } TreeItem[] getSelectedItems(int itemsControl, TreeItem [] selectedItems, int [] nextIndex) { int items = OS.ItemsControl_Items (itemsControl); int count = OS.ItemCollection_Count (items); for (int i = 0; i < count; i++) { int item = OS.ItemCollection_GetItemAt (items, i); boolean selected = OS.TreeViewItem_IsSelected (item); if (selected) { if (nextIndex [0] == selectedItems.length) { TreeItem [] newArray = new TreeItem [selectedItems.length + 4]; System.arraycopy (selectedItems, 0, newArray, 0, selectedItems.length); selectedItems = newArray; } selectedItems [nextIndex[0]++] = getItem (item, true); } if (OS.TreeViewItem_IsExpanded (item)) { selectedItems = getSelectedItems (item, selectedItems, nextIndex); } OS.GCHandle_Free (item); } OS.GCHandle_Free (items); if (selectedItems.length != nextIndex [0]) { TreeItem[] newArray = new TreeItem [nextIndex[0]]; System.arraycopy (selectedItems, 0, newArray, 0, nextIndex [0]); selectedItems = newArray; } return selectedItems; } /** * Returns the number of selected items contained in the receiver. * * @return the number of selected 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 getSelectionCount () { checkWidget (); int result; if ((style & SWT.SINGLE) != 0) { int item = OS.TreeView_SelectedItem (handle); result = item == 0 ? 0 : 1; OS.GCHandle_Free (item); } else { TreeItem[] selectedItems = getSelectedItems(handle, new TreeItem[4], new int[] {0}); result = selectedItems.length; } return result; } /** * 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 (); //TODO return null; } /** * 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 (); //TODO return SWT.NONE; } /** * 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 return null; } boolean hasItems () { return true; } void HandleChecked (int sender, int e) { if (!checkEvent (e)) return; if (ignoreSelection) return; int origsource = OS.RoutedEventArgs_OriginalSource (e); int typeid = OS.CheckBox_typeid (); boolean isCheckBox = OS.Type_IsInstanceOfType (typeid, origsource); OS.GCHandle_Free (typeid); OS.GCHandle_Free (origsource); if (!isCheckBox) return; int source = OS.RoutedEventArgs_Source (e); TreeItem item = (TreeItem) display.getWidget (source); OS.GCHandle_Free (source); if (item.grayed) { int checkbox = item.findPart (0, CHECKBOX_PART_NAME); if (checkbox != 0) { OS.ToggleButton_IsCheckedNullSetter (checkbox); OS.GCHandle_Free (checkbox); } } item.checked = true; item.updateCheck (); Event event = new Event (); event.item = item; event.detail = SWT.CHECK; sendEvent (SWT.Selection, event); } void HandleCollapsed (int sender, int e) { if (!checkEvent (e)) return; int source = OS.RoutedEventArgs_Source (e); if (OS.ItemsControl_HasItems (source)) { TreeItem item = (TreeItem) display.getWidget (source); int items = OS.ItemsControl_Items (item.handle); int count = OS.ItemCollection_Count (items); boolean[] selecting = new boolean [] {false}; for (int i = 0; i < count; i++) { int child = OS.ItemCollection_GetItemAt (items, i); fixSelection (child, null, null, selecting); OS.GCHandle_Free (child); } OS.GCHandle_Free (items); Event event = new Event (); event.item = item; sendEvent (SWT.Collapse, event); } OS.GCHandle_Free (source); } void HandleExpanded (int sender, int e) { if (!checkEvent (e)) return; int source = OS.RoutedEventArgs_Source (e); if (OS.ItemsControl_HasItems (source)) { Event event = new Event (); event.item = (TreeItem) display.getWidget (source); sendEvent (SWT.Expand, event); } OS.GCHandle_Free (source); } void HandlePreviewKeyDown (int sender, int e) { super.HandlePreviewKeyDown (sender, e); if (!checkEvent (e)) return; int key = OS.KeyEventArgs_Key (e); if (key == OS.Key_Return) { int source = OS.RoutedEventArgs_OriginalSource (e); Widget widget = display.getWidget (source); OS.GCHandle_Free (source); if (widget instanceof TreeItem) { Event event = new Event (); event.item = (TreeItem) widget; postEvent (SWT.DefaultSelection, event); } } if (key == OS.Key_RightShift || key == OS.Key_LeftShift) shiftDown = true; if (key == OS.Key_RightCtrl || key == OS.Key_LeftCtrl) ctrlDown = true; } void HandlePreviewKeyUp (int sender, int e) { super.HandlePreviewKeyUp (sender, e); if (!checkEvent (e)) return; int key = OS.KeyEventArgs_Key (e); if (key == OS.Key_RightShift || key == OS.Key_LeftShift) shiftDown = false; if (key == OS.Key_RightCtrl || key == OS.Key_LeftCtrl) ctrlDown = false; } void HandleLoaded (int sender, int e) { if (!checkEvent (e)) return; updateHeaderVisibility(); } void HandlePreviewMouseDoubleClick (int sender, int e) { if (!checkEvent (e)) return; int source = OS.RoutedEventArgs_OriginalSource (e); Widget widget = display.getWidget (source); OS.GCHandle_Free (source); if (widget instanceof TreeItem) { Event event = new Event (); event.item = (TreeItem) widget; postEvent (SWT.DefaultSelection, event); } if (hooks (SWT.DefaultSelection)) OS.RoutedEventArgs_Handled(e, true); } void HandlePreviewMouseDown (int sender, int e) { super.HandlePreviewMouseDown (sender, e); if (!checkEvent (e)) return; if ((style & SWT.SINGLE) != 0) return; int source = OS.RoutedEventArgs_Source (e); Widget widget = display.getWidget (source); OS.GCHandle_Free (source); if (widget instanceof TreeItem) { TreeItem item = (TreeItem) widget; /* Check that content of item was clicked, not the expander */ int point = OS.MouseEventArgs_GetPosition (e, item.contentHandle); int input = OS.UIElement_InputHitTest (item.contentHandle, point); OS.GCHandle_Free (point); if (input != 0) { OS.GCHandle_Free (input); boolean rightClick = OS.MouseEventArgs_RightButton (e) == OS.MouseButtonState_Pressed; if (rightClick && (ctrlDown || shiftDown)) return; if (ctrlDown) { boolean selected = OS.TreeViewItem_IsSelected (item.handle); if (widget.equals (lastSelection)) { OS.TreeViewItem_IsSelected (item.handle, !selected); } else { if (selected) unselect = item; if (lastSelection != null && OS.TreeViewItem_IsSelected (lastSelection.handle)) reselect = lastSelection; } } if (!shiftDown && !ctrlDown) { boolean selected = OS.TreeViewItem_IsSelected (item.handle); if (selected && rightClick) return; deselectAll (); OS.TreeViewItem_IsSelected (item.handle, true); } } lastSelection = item; } } void HandleSelectedItemChanged (int sender, int e) { if (!checkEvent (e)) return; if (ignoreSelection) return; int selectedItem = OS.TreeView_SelectedItem (handle); if (selectedItem == 0) return; TreeItem item = (TreeItem) display.getWidget (selectedItem); OS.GCHandle_Free (selectedItem); Event event = new Event (); event.item = item; postEvent (SWT.Selection, event); } void HandleUnchecked (int sender, int e) { if (!checkEvent (e)) return; if (ignoreSelection) return; int origsource = OS.RoutedEventArgs_OriginalSource (e); int typeid = OS.CheckBox_typeid (); boolean isCheckBox = OS.Type_IsInstanceOfType (typeid, origsource); OS.GCHandle_Free (typeid); OS.GCHandle_Free (origsource); if (!isCheckBox) return; int source = OS.RoutedEventArgs_Source (e); TreeItem item = (TreeItem) display.getWidget (source); OS.GCHandle_Free (source); item.checked = false; item.updateCheck (); Event event = new Event (); event.item = item; event.detail = SWT.CHECK; sendEvent (SWT.Selection, event); } void hookEvents () { super.hookEvents (); int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleLoaded"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); OS.FrameworkElement_Loaded (handle, handler); OS.GCHandle_Free (handler); handler = OS.gcnew_RoutedPropertyChangedEventHandlerObject (jniRef, "HandleSelectedItemChanged"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); OS.TreeView_SelectedItemChanged (handle, handler); OS.GCHandle_Free (handler); handler = OS.gcnew_MouseButtonEventHandler (jniRef, "HandlePreviewMouseDoubleClick"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); OS.Control_PreviewMouseDoubleClick (handle, handler); OS.GCHandle_Free (handler); /* Item events */ handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleExpanded"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); int event = OS.TreeViewItem_ExpandedEvent (); OS.UIElement_AddHandler (handle, event, handler, false); OS.GCHandle_Free (event); OS.GCHandle_Free (handler); handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleCollapsed"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); event = OS.TreeViewItem_CollapsedEvent (); OS.UIElement_AddHandler (handle, event, handler, false); OS.GCHandle_Free (event); OS.GCHandle_Free (handler); if ((style & SWT.CHECK) != 0) { handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleChecked"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); event = OS.ToggleButton_CheckedEvent (); OS.UIElement_AddHandler (handle, event, handler, false); OS.GCHandle_Free (event); OS.GCHandle_Free (handler); handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleUnchecked"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); event = OS.ToggleButton_UncheckedEvent (); OS.UIElement_AddHandler (handle, event, handler, false); OS.GCHandle_Free (event); OS.GCHandle_Free (handler); } } /** * 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 (gvColumns == 0) return -1; int index = OS.GridViewColumnCollection_IndexOf (gvColumns, column.handle); return index; } /** * Searches the receiver's list starting at the first item * (index 0) until an item is found that is equal to the * argument, and returns the index of that item. If no item * is found, returns -1. * * @param item the search item * @return the index of the item * * @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 int indexOf (TreeItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); int items = OS.ItemsControl_Items (handle); int index = OS.ItemCollection_IndexOf (items, item.handle); OS.GCHandle_Free (items); return index; } void OnRender (int source, int dc) { int type = OS.TreeViewItem_typeid (); int itemHandle = findPartOfType (source, type); OS.GCHandle_Free (type); TreeItem item = getItem (itemHandle, true); OS.GCHandle_Free (itemHandle); if ((item.cached || (style & SWT.VIRTUAL) == 0) && item.contentHandle != 0) return; checkData (item); if (item.contentHandle == 0) { item.contentHandle = item.findContentPresenter(); } int columns = columnCount == 0 ? 1 : columnCount; item.updateCheck (); 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 (); int items = OS.ItemsControl_Items (handle); for (int i = 0; i < itemCount; i++) { TreeItem item = getItem (items, i, false); if (item != null && !item.isDisposed ()) item.release (false); } ignoreSelection = true; OS.ItemCollection_Clear (items); ignoreSelection = false; itemCount = OS.ItemCollection_Count (items); OS.GCHandle_Free (items); } /** * Removes the listener from the collection of listeners who will * be notified when the user changes the receiver's selection. * * @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 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); } int setBounds (int x, int y, int width, int height, int flags) { int result = super.setBounds (x, y, width, height, flags); if ((result & RESIZED) != 0) { OS.FrameworkElement_Width (handle, width); OS.FrameworkElement_Height (handle, height); } return result; } /** * 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
      *
    • 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); //TODO } /** * 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 (); setItemCount (null, count); } void setItemCount (TreeItem parentItem, int count) { int itemCount = parentItem != null ? parentItem.itemCount : this.itemCount; count = Math.max (0, count); if (count == itemCount) return; int parentHandle = parentItem != null ? parentItem.handle : handle; int index = itemCount - 1; int items = OS.ItemsControl_Items (parentHandle); while (index >= count) { TreeItem item = getItem (items, index, false); if (item != null) { if (!item.isDisposed()) item.release (true); } else { OS.ItemCollection_RemoveAt (items, index); } index--; } if (OS.ItemCollection_Count (items) > count) error (SWT.ERROR_ITEM_NOT_REMOVED); if ((style & SWT.VIRTUAL) != 0) { for (int i=itemCount; ione 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
    • *
    * * @since 3.2 */ /*public*/ void setItemHeight (int itemHeight) { checkWidget (); if (itemHeight < -1) error (SWT.ERROR_INVALID_ARGUMENT); //TODO } /** * Marks the receiver's lines as visible if the argument is true, * 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 (); //TODO } /** * 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) { if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); if ((style & SWT.SINGLE) != 0) { ignoreSelection = true; OS.TreeViewItem_IsSelected (item.handle, true); ignoreSelection = false; return; } ignoreSelection = true; setIsSelectionActiveProperty(true); OS.TreeViewItem_IsSelected (item.handle, true); setIsSelectionActiveProperty(false); ignoreSelection = false; } /** * 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; int items = OS.ItemsControl_Items (handle); int itemCount = OS.ItemCollection_Count (items); boolean[] selecting = new boolean[] {true}; setIsSelectionActiveProperty(true); for (int i = 0; i < itemCount; i++) { int item = OS.ItemCollection_GetItemAt(items, i); fixSelection(item, null, null, selecting); OS.GCHandle_Free(item); } setIsSelectionActiveProperty(false); OS.GCHandle_Free(items); } /** * Sets the order that the items in the receiver should * be displayed in to the given argument which is described * in terms of the zero-relative ordering of when the items * were added. * * @param order the new order to display 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
    • *
    * @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 (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) return; for (int i = 0; i < order.length; i++) { TreeColumn column = columns [order [i]]; int index = OS.IList_IndexOf (gvColumns, column.handle); if (index != i) OS.ObservableCollectionGridViewColumn_Move (gvColumns, index, i); } } void setFont (int font, double size) { if (font != 0) { int fontFamily = OS.Typeface_FontFamily( font); int style = OS.Typeface_Style (font); int weight = OS.Typeface_Weight (font); int stretch = OS.Typeface_Stretch (font); OS.Control_FontFamily (handle, fontFamily); OS.Control_FontStyle (handle, style); OS.Control_FontWeight (handle, weight); OS.Control_FontStretch (handle, stretch); OS.Control_FontSize (handle, size); OS.GCHandle_Free (fontFamily); OS.GCHandle_Free (style); OS.GCHandle_Free (weight); OS.GCHandle_Free (stretch); } else { int property = OS.Control_FontFamilyProperty (); OS.DependencyObject_ClearValue (handle, property); OS.GCHandle_Free (property); property = OS.Control_FontStyleProperty (); OS.DependencyObject_ClearValue (handle, property); OS.GCHandle_Free (property); property = OS.Control_FontWeightProperty (); OS.DependencyObject_ClearValue (handle, property); OS.GCHandle_Free (property); property = OS.Control_FontStretchProperty (); OS.DependencyObject_ClearValue (handle, property); OS.GCHandle_Free (property); property = OS.Control_FontSizeProperty (); OS.DependencyObject_ClearValue (handle, property); OS.GCHandle_Free (property); } } void setForegroundBrush (int brush) { if (brush != 0) { OS.Control_Foreground (handle, brush); } else { int property = OS.Control_ForegroundProperty (); OS.DependencyObject_ClearValue (handle, property); OS.GCHandle_Free (property); } } /** * Marks the receiver's header as visible if the argument is true, * 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 (); headerVisibility = show ? OS.Visibility_Visible : OS.Visibility_Collapsed; updateHeaderVisibility (); for (int i=0; i * 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. *

    * 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); int length = items.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) { deselectAll (); return; } for (int i = 0; i < items.length; i++) { TreeItem item = items [i]; if (item != null && item.isDisposed ()) error (SWT.ERROR_WIDGET_DISPOSED); } deselectAll (); ignoreSelection = true; if ((style & SWT.SINGLE) != 0) { TreeItem select = items [0]; if (select != null) { OS.TreeViewItem_IsSelected (items [0].handle, true); } } else { setIsSelectionActiveProperty (true); for (int i = 0; i < length; i++) { TreeItem item = items [i]; if (item != null) OS.TreeViewItem_IsSelected (item.handle, true); } setIsSelectionActiveProperty (false); } ignoreSelection = false; } /** * 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 (); //TODO } /** * 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 (); //TODO } /** * 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) SWT.error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); //TODO } /** * 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; int index = indexOf (column); if (index == -1) return; //TODO } /** * 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); if (item.parent != this) return; int parent = OS.FrameworkElement_Parent (item.handle); while (!OS.Object_Equals (parent, handle)) { OS.TreeViewItem_IsExpanded (parent, true); int newParent = OS.FrameworkElement_Parent (parent); OS.GCHandle_Free (parent); parent = newParent; } OS.GCHandle_Free (parent); OS.FrameworkElement_BringIntoView (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 (); int item = OS.TreeView_SelectedItem (handle); if (item != 0) { OS.FrameworkElement_BringIntoView (item); OS.GCHandle_Free (item); } } int topHandle () { return parentingHandle; } void updateHeaderVisibility() { int template = OS.Control_Template (handle); int scrollViewerName = createDotNetString (SCROLLVIEWER_PART_NAME, false); int scrollViewer = OS.FrameworkTemplate_FindName (template, scrollViewerName, handle); if (scrollViewer != 0) { int scrollViewerTemplate = OS.Control_Template(scrollViewer); int headerName = createDotNetString(HEADER_PART_NAME, false); int header = OS.FrameworkTemplate_FindName (scrollViewerTemplate, headerName, scrollViewer); if (header != 0) { OS.UIElement_Visibility (header, headerVisibility); OS.GCHandle_Free (header); } OS.GCHandle_Free (scrollViewerTemplate); OS.GCHandle_Free (headerName); OS.GCHandle_Free (scrollViewer); } OS.GCHandle_Free (scrollViewerName); OS.GCHandle_Free (template); } }