/******************************************************************************* * 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.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.wpf.OS; /** * Instances of this class implement a selectable user interface * object that displays a list of images and strings and issues * notification when selected. *

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

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

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

 *  final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
 *  table.setItemCount (1000000);
 *  table.addListener (SWT.SetData, new Listener () {
 *      public void handleEvent (Event event) {
 *          TableItem item = (TableItem) event.item;
 *          int index = table.indexOf (item);
 *          item.setText ("Item " + index);
 *          System.out.println (item.getText ());
 *      }
 *  }); 
 * 
*

* 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, HIDE_SELECTION, VIRTUAL, NO_SCROLL
*
Events:
*
Selection, DefaultSelection, 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 Table, TableItem, TableColumn snippets * @see SWT Example: ControlExample * @see Sample code and further information * @noextend This class is not intended to be subclassed by clients. */ public class Table extends Composite { int gridViewHandle, parentingHandle; int columnCount, itemCount; boolean ignoreSelection; TableColumn [] columns; boolean linesVisible; 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"; /** * 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#HIDE_SELECTION * @see SWT#VIRTUAL * @see SWT#NO_SCROLL * @see Widget#checkSubclass * @see Widget#getStyle */ public Table (Composite parent, int style) { super (parent, checkStyle (style)); } void _addListener (int eventType, Listener listener) { super._addListener (eventType, listener); switch (eventType) { case SWT.MeasureItem: case SWT.EraseItem: case SWT.PaintItem: //TODO break; } } /** * 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); } int backgroundProperty () { return OS.Control_BackgroundProperty (); } boolean checkData (TableItem item) { if ((style & SWT.VIRTUAL) == 0) return true; if (!item.cached) { item.cached = true; Event event = new Event (); event.item = item; event.index = indexOf (item); sendEvent (SWT.SetData, event); //widget could be disposed at this point if (isDisposed () || item.isDisposed ()) return false; } return true; } 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); } 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 table was created with the SWT.VIRTUAL style, * these attributes are requested again as needed. * * @param index the index of the item to clear * * @exception IllegalArgumentException * @exception SWTException * * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clear (int index) { checkWidget (); if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); int items = OS.ItemsControl_Items (handle); TableItem item = getItem (items, index, false); OS.GCHandle_Free (items); if (item != null) item.clear (); } /** * Removes the items from the receiver which are between the given * zero-relative start and end indices (inclusive). The text, icon * and other attributes of the items are set to their default values. * If the table was created with the SWT.VIRTUAL style, * these attributes are requested again as needed. * * @param start the start index of the item to clear * @param end the end index of the item to clear * * @exception IllegalArgumentException * @exception SWTException * * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clear (int start, int end) { checkWidget (); checkWidget (); if (start > end) return; if (!(0 <= start && start <= end && end < itemCount)) { error (SWT.ERROR_INVALID_RANGE); } if (start == 0 && end == itemCount - 1) { clearAll (); } else { int items = OS.ItemsControl_Items (handle); for (int i=start; i<=end; i++) { TableItem item = getItem (items, i, false); if (item != null) item.clear (); } OS.GCHandle_Free (items); } } /** * Clears the items at the given zero-relative indices in the receiver. * The text, icon and other attributes of the items are set to their default * values. If the table was created with the SWT.VIRTUAL style, * these attributes are requested again as needed. * * @param indices the array of indices of the items * * @exception IllegalArgumentException * @exception SWTException * * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clear (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); if (indices.length == 0) return; for (int i=0; iSWT.VIRTUAL style, these * attributes are requested again as needed. * * @exception SWTException * * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clearAll () { checkWidget (); int items = OS.ItemsControl_Items (handle); for (int i=0; i *
  • ERROR_NULL_ARGUMENT - if the set of indices is null
  • * * @exception SWTException */ public void deselect (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); if (indices.length == 0) return; int items = OS.ItemsControl_Items (handle); ignoreSelection = true; 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 deselect (int index) { checkWidget (); if (!(0 <= index && index < itemCount)) return; int items = OS.ItemsControl_Items (handle); int item = OS.ItemCollection_GetItemAt (items, index); ignoreSelection = true; OS.ListBoxItem_IsSelected (item, false); ignoreSelection = false; OS.GCHandle_Free (item); OS.GCHandle_Free (items); } /** * Deselects the items at the given zero-relative indices in the receiver. * If the item at the given zero-relative index in the receiver * is selected, it is deselected. If the item at the index * was not selected, it remains deselected. The range of the * indices is inclusive. Indices that are out of range are ignored. * * @param start the start index of the items to deselect * @param end the end index of the items to deselect * * @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 deselect (int start, int end) { checkWidget (); if (start <= 0 && end >= itemCount - 1) { deselectAll (); } else { start = Math.max (0, start); end = Math.min (end, itemCount - 1); int items = OS.ItemsControl_Items (handle); ignoreSelection = true; for (int i=start; i<=end; i++) { int item = OS.ItemCollection_GetItemAt (items, i); OS.ListBoxItem_IsSelected (item, false); OS.GCHandle_Free (item); } ignoreSelection = false; OS.GCHandle_Free (items); } } /** * Deselects all selected 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
    • *
    */ public void deselectAll () { checkWidget (); ignoreSelection = true; OS.ListBox_UnselectAll(handle); ignoreSelection = false; } void destroyItem (TableColumn column) { int gvColumns = OS.GridView_Columns (gridViewHandle); int index = OS.GridViewColumnCollection_IndexOf (gvColumns, column.handle); boolean removed = OS.GridViewColumnCollection_Remove (gvColumns, column.handle); OS.GCHandle_Free (gvColumns); if (!removed) error (SWT.ERROR_ITEM_NOT_REMOVED); int arrayIndex = -1; for (int i = 0; i < columnCount; i++) { TableColumn 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) { createDefaultColumn (); } int items = OS.ItemsControl_Items (handle); for (int i=0; iTableColumns 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 table. * This occurs when the programmer uses the table 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 Table#getColumnOrder() * @see Table#setColumnOrder(int[]) * @see TableColumn#getMoveable() * @see TableColumn#setMoveable(boolean) * @see SWT#Move */ public TableColumn getColumn (int index) { checkWidget (); if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE); return columns [index]; } TableColumn getColumn (int columns, int index) { int gridColumn = OS.GridViewColumnCollection_default (columns, index); int header = OS.GridViewColumn_Header (gridColumn); TableColumn column = (TableColumn) display.getWidget (header); OS.GCHandle_Free (header); OS.GCHandle_Free (gridColumn); return column; } /** * Returns the number of columns contained in the receiver. * If no TableColumns 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 table 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
    • *
    */ 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 Table#setColumnOrder(int[]) * @see TableColumn#getMoveable() * @see TableColumn#setMoveable(boolean) * @see SWT#Move * * @since 3.1 */ public int[] getColumnOrder () { checkWidget (); int [] order = new int [columnCount]; for (int i=0; iTableColumns which are the * columns in the receiver. Columns are returned in the order * that they were created. If no TableColumns 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 table 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 Table#getColumnOrder() * @see Table#setColumnOrder(int[]) * @see TableColumn#getMoveable() * @see TableColumn#setMoveable(boolean) * @see SWT#Move */ public TableColumn [] getColumns () { checkWidget (); TableColumn [] result = new TableColumn [columnCount]; for (int i = 0; i < result.length; i++) { result [i] = columns [i]; } 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
    • *
    */ public int getGridLineWidth () { checkWidget (); return 0; //FIXME: No grid lines yet } /** * 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 2.0 */ public int getHeaderHeight () { checkWidget (); int columns = OS.GridView_Columns (gridViewHandle); int column = OS.GridViewColumnCollection_default (columns, 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 (columns); 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
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public boolean getHeaderVisible () { checkWidget (); int columns = OS.GridView_Columns (gridViewHandle); int column = OS.GridViewColumnCollection_default (columns, 0); int header = OS.GridViewColumn_Header (column); boolean visible = OS.UIElement_Visibility (header) == OS.Visibility_Visible; OS.GCHandle_Free (header); OS.GCHandle_Free (column); OS.GCHandle_Free (columns); return visible; } /** * 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
    • *
    */ public TableItem getItem (int index) { checkWidget (); if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); int items = OS.ItemsControl_Items (handle); TableItem item = getItem (items, index, true); OS.GCHandle_Free (items); return item; } TableItem getItem (int items, int index, boolean create) { int item = OS.ItemCollection_GetItemAt (items, index); TableItem result = getItem (item, create); OS.GCHandle_Free (item); return result; } TableItem 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 (TableItem) OS.JNIGetObject (contentValue); } if (create) { int itemHandle = OS.GCHandle_Alloc (item); return new TableItem (this, 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 TableItem 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 TableItem) { return (TableItem) widget; } return null; } /** * Returns the number of items contained in the receiver. * * @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 receiver. * * @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 what is the default size? 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 TableItems which * are the items in the receiver. *

    * 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
    • *
    */ public TableItem [] getItems () { checkWidget (); TableItem [] result = new TableItem [itemCount]; int items = OS.ItemsControl_Items (handle); 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
    • *
    */ public boolean getLinesVisible () { checkWidget (); //TODO return linesVisible; } /** * Returns an array of TableItems 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 TableItem [] getSelection () { checkWidget (); int selected = OS.ListBox_SelectedItems (handle); int enumerator = OS.IList_GetEnumerator (selected); int count = OS.ICollection_Count (selected); TableItem [] result = new TableItem [count]; int index = 0; while (OS.IEnumerator_MoveNext (enumerator)) { int item = OS.IEnumerator_Current (enumerator); result [index++] = getItem (item, true); OS.GCHandle_Free (item); } OS.GCHandle_Free (enumerator); OS.GCHandle_Free (selected); return result; } /** * 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 selected = OS.ListBox_SelectedItems (handle); int count = OS.ICollection_Count (selected); OS.GCHandle_Free (selected); return count; } /** * Returns the zero-relative index of the item which is currently * selected in the receiver, or -1 if no item is selected. * * @return the index of the selected 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 getSelectionIndex () { checkWidget (); return OS.Selector_SelectedIndex (handle); } /** * Returns the zero-relative indices of the items which are currently * selected in the receiver. The order of the indices is unspecified. * The array is empty if 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 the array of indices of the 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 [] getSelectionIndices () { checkWidget (); int items = OS.ItemsControl_Items (handle); int list = OS.ListBox_SelectedItems (handle); int enumerator = OS.IList_GetEnumerator (list); int count = OS.ICollection_Count (list); int [] indices = new int [count]; int index = 0; while (OS.IEnumerator_MoveNext (enumerator)) { int item = OS.IEnumerator_Current (enumerator); indices [index++] = OS.ItemCollection_IndexOf (items, item); OS.GCHandle_Free (item); } OS.GCHandle_Free (enumerator); OS.GCHandle_Free (list); OS.GCHandle_Free (items); sortAscending (indices); return indices; } /** * 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(TableColumn) * * @since 3.2 */ public TableColumn 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 -1; } /** * Returns the zero-relative index of the item which is currently * at the top of the receiver. This index can change when items are * scrolled or new items are added or removed. * * @return the index of the top 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 getTopIndex () { checkWidget (); int items = OS.ItemsControl_Items (handle); int item = OS.ItemCollection_GetItemAt (items, 0); OS.GCHandle_Free (items); int virtualizingStackPanel = OS.VisualTreeHelper_GetParent (item); OS.GCHandle_Free (item); int topIndex = 0; if (virtualizingStackPanel != 0) { topIndex = (int) OS.VirtualizingStackPanel_VerticalOffset (virtualizingStackPanel); OS.GCHandle_Free (virtualizingStackPanel); } return topIndex; } boolean hasItems () { return true; } void HandleChecked (int sender, int e) { if (!checkEvent (e)) return; if (ignoreSelection) return; int source = OS.RoutedEventArgs_Source (e); TableItem item = (TableItem) 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; Event event = new Event (); event.item = item; event.detail = SWT.CHECK; sendEvent (SWT.Selection, event); } void HandleIndeterminate (int sender, int e) { if (!checkEvent (e)) return; if (ignoreSelection) return; int source = OS.RoutedEventArgs_Source (e); TableItem item = (TableItem) display.getWidget (source); OS.GCHandle_Free (source); if (!item.grayed) { int checkbox = item.findPart (0, CHECKBOX_PART_NAME); if (checkbox != 0) { OS.ToggleButton_IsChecked (checkbox, false); OS.GCHandle_Free (checkbox); } } } 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 TableItem) { Event event = new Event (); event.item = (TableItem)widget; postEvent (SWT.DefaultSelection, event); } } } void HandleMouseDoubleClick (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 TableItem) { Event event = new Event (); event.item = (TableItem)widget; postEvent (SWT.DefaultSelection, event); } } void HandleSelectionChanged (int sender, int e) { if (!checkEvent (e)) return; if (ignoreSelection) return; int item = 0; int list = OS.SelectionChangedEventArgs_AddedItems (e); if (list != 0) { int count = OS.ICollection_Count (list); if (count > 0) item = OS.IList_default (list, count - 1); } OS.GCHandle_Free (list); if (item == 0) { list = OS.SelectionChangedEventArgs_RemovedItems (e); int count = OS.ICollection_Count (list); if (count > 0) item = OS.IList_default (list, count - 1); OS.GCHandle_Free (list); } if (item != 0) { TableItem result = getItem (item, true); OS.GCHandle_Free (item); if (result != null) { Event event = new Event (); event.item = result; postEvent (SWT.Selection, event); } } } void HandleUnchecked (int sender, int e) { if (!checkEvent (e)) return; if (ignoreSelection) return; int source = OS.RoutedEventArgs_Source (e); TableItem item = (TableItem) display.getWidget (source); OS.GCHandle_Free (source); item.checked = false; Event event = new Event (); event.item = item; event.detail = SWT.CHECK; sendEvent (SWT.Selection, event); } void hookEvents () { super.hookEvents (); int handler = OS.gcnew_SelectionChangedEventHandler (jniRef, "HandleSelectionChanged"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); OS.Selector_SelectionChanged (handle, handler); OS.GCHandle_Free (handler); handler = OS.gcnew_MouseButtonEventHandler (jniRef, "HandleMouseDoubleClick"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); OS.Control_MouseDoubleClick (handle, handler); OS.GCHandle_Free (handler); if ((style & SWT.CHECK) != 0) { /* Item events */ handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleChecked"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); int 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); handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleIndeterminate"); if (handler == 0) error (SWT.ERROR_NO_HANDLES); event = OS.ToggleButton_IndeterminateEvent (); 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
    • *
    */ public int indexOf (TableColumn column) { checkWidget (); if (column == null) error (SWT.ERROR_NULL_ARGUMENT); int columns = OS.GridView_Columns (gridViewHandle); int index = OS.GridViewColumnCollection_IndexOf (columns, column.handle); OS.GCHandle_Free (columns); 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
    • *
    * @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 indexOf (TableItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); int items = OS.ItemsControl_Items(handle); int index = OS.ItemCollection_IndexOf(items, item.handle); OS.GCHandle_Free (items); return index; } /** * Returns true if the item is selected, * and false otherwise. Indices out of * range are ignored. * * @param index the index of the item * @return the selection state of the item at the index * * @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 boolean isSelected (int index) { checkWidget (); int items = OS.ItemsControl_Items (handle); int item = OS.ItemCollection_GetItemAt (items, index); boolean result = OS.ListBoxItem_IsSelected (item); OS.GCHandle_Free (item); OS.GCHandle_Free (items); return result; } void OnRender (int source, int dc) { if (isDisposed ()) return; int type = OS.ListViewItem_typeid(); int itemHandle = findPartByType (source, type); OS.GCHandle_Free (type); TableItem item = getItem (itemHandle, true); OS.GCHandle_Free (itemHandle); if ((item.cached || (style & SWT.VIRTUAL) == 0) && item.rowHandle != 0) return; checkData (item); if (item.rowHandle == 0) { int rowPresenterType = OS.GridViewRowPresenter_typeid (); item.rowHandle = item.findRowPresenter (item.handle, rowPresenterType); OS.GCHandle_Free (rowPresenterType); } int columns = columnCount == 0 ? 1 : columnCount; item.updateCheck (); for (int i=0; i *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
  • *
  • ERROR_NULL_ARGUMENT - if the indices array 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 void remove (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); if (indices.length == 0) return; int [] newIndices = new int [indices.length]; System.arraycopy (indices, 0, newIndices, 0, indices.length); sort (newIndices); int start = newIndices [newIndices.length - 1], end = newIndices [0]; if (!(0 <= start && start <= end && end < itemCount)) { error (SWT.ERROR_INVALID_RANGE); } int items = OS.ItemsControl_Items (handle); ignoreSelection = true; int lastIndex = -1; for (int i = newIndices.length-1; i >= 0; i--) { int index = newIndices [i]; if (index != lastIndex) { TableItem item = getItem (items, index, false); if (item != null && !item.isDisposed ()) item.release (false); OS.ItemCollection_RemoveAt (items, index); lastIndex = index; } } ignoreSelection = false; itemCount = OS.ItemCollection_Count (items); OS.GCHandle_Free (items); } /** * Removes the item from the receiver at the given * zero-relative index. * * @param index the index for the item * * @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
    • *
    */ public void remove (int index) { checkWidget (); if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); int items = OS.ItemsControl_Items (handle); TableItem item = getItem (items, index, false); if (item != null && !item.isDisposed ()) item.release (false); ignoreSelection = true; OS.ItemCollection_RemoveAt (items, index); ignoreSelection = false; itemCount = OS.ItemCollection_Count (items); OS.GCHandle_Free (items); } /** * Removes the items from the receiver which are * between the given zero-relative start and end * indices (inclusive). * * @param start the start of the range * @param end the end of the range * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_RANGE - if either the start or end are 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
    • *
    */ public void remove (int start, int end) { checkWidget (); if (start > end) return; if (!(0 <= start && start <= end && end < itemCount)) error (SWT.ERROR_INVALID_RANGE); if (start == 0 && end == itemCount - 1) { removeAll (); return; } int items = OS.ItemsControl_Items (handle); ignoreSelection = true; for (int i = end; i >= start; i--) { TableItem item = getItem (items, i, false); if (item != null && !item.isDisposed ()) item.release (false); OS.ItemCollection_RemoveAt (items, i); } ignoreSelection = false; itemCount = OS.ItemCollection_Count (items); OS.GCHandle_Free (items); } /** * Removes all of the items from 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
    • *
    */ public void removeAll () { checkWidget (); int items = OS.ItemsControl_Items (handle); for (int i = 0; i < itemCount; i++) { TableItem 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(SelectionListener) */ public void removeSelectionListener(SelectionListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Selection, listener); eventTable.unhook (SWT.DefaultSelection,listener); } /** * Selects the items at the given zero-relative indices in the receiver. * The current selection is not cleared before the new items are selected. *

    * If the item at a given index is not selected, it is selected. * If the item at a given index was already selected, it remains selected. * Indices that are out of range and duplicate indices are ignored. * If the receiver is single-select and multiple indices are specified, * then all indices are ignored. *

    * * @param indices the array of indices for the items to select * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the array of indices 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 Table#setSelection(int[]) */ public void select (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); int length = indices.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; ignoreSelection = true; int items = OS.ItemsControl_Items (handle); for (int i = 0; i < indices.length; i++) { if (!(0 <= indices[i] && indices[i] < itemCount)) continue; int item = OS.ItemCollection_GetItemAt (items, indices[i]); OS.ListBoxItem_IsSelected (item, true); OS.GCHandle_Free (item); } OS.GCHandle_Free (items); ignoreSelection = false; } /** * Selects the item at the given zero-relative index in the receiver. * If the item at the index was already selected, it remains * selected. Indices that are out of range are ignored. * * @param index the index of the item to select * * @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 select (int index) { checkWidget (); if (!(0 <= index && index < itemCount)) return; int items = OS.ItemsControl_Items (handle); int item = OS.ItemCollection_GetItemAt (items, index); ignoreSelection = true; OS.ListBoxItem_IsSelected (item, true); ignoreSelection = false; OS.GCHandle_Free (item); OS.GCHandle_Free (items); } /** * Selects the items in the range specified by the given zero-relative * indices in the receiver. The range of indices is inclusive. * The current selection is not cleared before the new items are selected. *

    * If an item in the given range is not selected, it is selected. * If an item in the given range was already selected, it remains selected. * Indices that are out of range are ignored and no items will be selected * if start is greater than end. * If the receiver is single-select and there is more than one item in the * given range, then all indices are ignored. *

    * * @param start the start of the range * @param end the end of the range * * @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 Table#setSelection(int,int) */ public void select (int start, int end) { checkWidget (); if ((style & SWT.SINGLE) != 0 && start != end) return; if (start <= 0 && end >= itemCount - 1) { selectAll (); } else { start = Math.max (0, start); end = Math.min (end, itemCount - 1); int items = OS.ItemsControl_Items (handle); ignoreSelection = true; for (int i=start; i<=end; i++) { int item = OS.ItemCollection_GetItemAt (items, i); OS.ListBoxItem_IsSelected (item, true); OS.GCHandle_Free (item); } ignoreSelection = false; OS.GCHandle_Free (items); } } /** * 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; ignoreSelection = true; OS.ListBox_SelectAll (handle); ignoreSelection = false; } void setBackgroundBrush(int brush) { if (brush != 0) { OS.Control_Background (handle, brush); } else { int property = OS.Control_BackgroundProperty (); OS.DependencyObject_ClearValue (handle, property); OS.GCHandle_Free (property); } } 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) { if (columnCount == 0) { int columns = OS.GridView_Columns (gridViewHandle); int column = OS.GridViewColumnCollection_default (columns, 0); OS.GridViewColumn_Width (column, width); OS.GCHandle_Free (column); OS.GCHandle_Free (columns); } OS.FrameworkElement_Width (handle, width); OS.FrameworkElement_Height (handle, height); } return result; } /** * 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 Table#getColumnOrder() * @see TableColumn#getMoveable() * @see TableColumn#setMoveable(boolean) * @see SWT#Move * * @since 3.1 */ 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; int gvColumns = OS.GridView_Columns (gridViewHandle); for (int i = 0; i < order.length; i++) { TableColumn column = columns [order [i]]; int index = OS.IList_IndexOf (gvColumns, column.handle); if (index != i) OS.ObservableCollectionGridViewColumn_Move (gvColumns, index, i); } OS.GCHandle_Free (gvColumns); } 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
    • *
    */ public void setHeaderVisible (boolean show) { checkWidget (); int style = 0; if (!show) { style = OS.gcnew_Style (); int dp = OS.UIElement_VisibilityProperty (); int setter = OS.gcnew_SetterVisibility (dp, OS.Visibility_Collapsed); int collection = OS.Style_Setters (style); OS.SetterBaseCollection_Add (collection, setter); OS.GCHandle_Free (collection); OS.GCHandle_Free (setter); OS.GCHandle_Free (dp); } OS.GridView_ColumnHeaderContainerStyle (gridViewHandle, style); if (style != 0) OS.GCHandle_Free (style); 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.0 */ public void setItemCount (int count) { checkWidget (); count = Math.max (0, count); if (count == itemCount) return; int index = itemCount - 1; int items = OS.ItemsControl_Items (handle); while (index >= count) { TableItem 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 table. * * @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 (); } /** * 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
    • *
    */ public void setLinesVisible (boolean show) { checkWidget (); linesVisible = show; } /** * Selects the items at the given zero-relative indices in the receiver. * The current selection is cleared before the new items are selected. *

    * Indices that are out of range and duplicate indices are ignored. * If the receiver is single-select and multiple indices are specified, * then all indices are ignored. *

    * * @param indices the indices of the items to select * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the array of indices 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 Table#deselectAll() * @see Table#select(int[]) */ public void setSelection (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); deselectAll (); int length = indices.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; select (indices); //TODO // int focusIndex = indices [0]; // if (focusIndex != -1) setFocusIndex (focusIndex); showSelection (); } /** * Sets the receiver's selection to the given item. * The current selection is cleared before the new item is selected. *

    * 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 (TableItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); setSelection (new TableItem [] {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 Table#deselectAll() * @see Table#select(int[]) * @see Table#setSelection(int[]) */ public void setSelection (TableItem [] items) { checkWidget (); if (items == null) error (SWT.ERROR_NULL_ARGUMENT); deselectAll (); int length = items.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; 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
  • * * * @see Table#deselectAll() * @see Table#select(int) */ public void setSelection (int index) { checkWidget (); deselectAll (); select (index); //TODO // if (index != -1) setFocusIndex (index); showSelection (); } /** * Selects the items in the range specified by the given zero-relative * indices in the receiver. The range of indices is inclusive. * The current selection is cleared before the new items are selected. *

    * Indices that are out of range are ignored and no items will be selected * if start is greater than end. * If the receiver is single-select and there is more than one item in the * given range, then all indices are ignored. *

    * * @param start the start index of the items to select * @param end the end index of the items to select * * @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 Table#deselectAll() * @see Table#select(int,int) */ public void setSelection (int start, int end) { checkWidget (); deselectAll (); if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return; if (itemCount == 0 || start >= itemCount) return; start = Math.max (0, start); end = Math.min (end, itemCount - 1); select (start, end); //TODO // setFocusIndex (start); showSelection (); } /** * 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 (TableColumn column) { checkWidget (); if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); //TODO // if (sortColumn != null && !sortColumn.isDisposed ()) { // sortColumn.setSortDirection (SWT.NONE); // } // sortColumn = column; // if (sortColumn != null && sortDirection != SWT.NONE) { // sortColumn.setSortDirection (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 | SWT.DOWN)) == 0 && direction != SWT.NONE) return; //TODO // sortDirection = direction; // if (sortColumn != null && !sortColumn.isDisposed ()) { // sortColumn.setSortDirection (direction); // } } /** * Sets the zero-relative index of the item which is currently * at the top of the receiver. This index can change when items * are scrolled or new items are added and removed. * * @param index the index of the top 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 void setTopIndex (int index) { checkWidget (); //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 column is null
    • *
    • ERROR_INVALID_ARGUMENT - if the column 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.0 */ public void showColumn (TableColumn 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 (!(0 <= index && index < columnCount)) return; //TODO } /** * Shows the item. If the item is already showing in the receiver, * this method simply returns. Otherwise, the items are scrolled 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 Table#showSelection() */ public void showItem (TableItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); OS.ListBox_ScrollIntoView (handle, 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 Table#showItem(TableItem) */ public void showSelection () { checkWidget (); int itemCollection = OS.ItemsControl_Items (handle); int list = OS.ListBox_SelectedItems (handle); int enumerator = OS.IList_GetEnumerator (list); if (OS.IEnumerator_MoveNext (enumerator)) { int item = OS.IEnumerator_Current (enumerator); OS.ListBox_ScrollIntoView (handle, item); OS.GCHandle_Free (item); } OS.GCHandle_Free (enumerator); OS.GCHandle_Free (list); OS.GCHandle_Free (itemCollection); } int topHandle () { return parentingHandle; } void updateMoveable () { int columns = OS.GridView_Columns (gridViewHandle); boolean moveable = true; for (int i = 0; moveable && i < columnCount; i++) { TableColumn column = getColumn (columns, i); if (!column.moveable) moveable = false; } OS.GCHandle_Free (columns); OS.GridView_AllowsColumnReorder (gridViewHandle, moveable); } }