All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.swt.widgets.Table Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2000, 2017 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.widgets;

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.cocoa.*;

/**
 * Instances of this class 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 { TableItem [] items; TableColumn [] columns; TableColumn sortColumn; TableItem currentItem; NSTableHeaderView headerView; NSTableColumn firstColumn, checkColumn; NSTextFieldCell dataCell; NSButtonCell buttonCell; int columnCount, itemCount, lastIndexOf, sortDirection, selectedRowIndex = -1; boolean ignoreSelect, fixScrollWidth, drawExpansion, didSelect, preventSelect, dragDetected; Rectangle imageBounds; double /*float*/ [] headerBackground, headerForeground; /* Used to control drop feedback when FEEDBACK_SCROLL is set/not set */ boolean shouldScroll = true; static int NEXT_ID; static final int FIRST_COLUMN_MINIMUM_WIDTH = 5; static final int IMAGE_GAP = 3; static final int TEXT_GAP = 2; static final int CELL_GAP = 1; /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. *

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

* * @param parent a composite control which will be the parent of the new instance (cannot be null) * @param style the style of control to construct * * @exception IllegalArgumentException
    *
  • ERROR_NULL_ARGUMENT - if the parent is null
  • *
* @exception SWTException
    *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  • *
  • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
  • *
* * @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)); } @Override boolean acceptsFirstResponder (long /*int*/ id, long /*int*/ sel) { return true; } @Override long /*int*/ accessibilityAttributeValue(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0) { long /*int*/ returnValue = 0; NSString attributeName = new NSString(arg0); // If the check column is visible, don't report it back as a column for accessibility purposes. // The check column is meant to appear as a part of the first column. if (attributeName.isEqualToString (OS.NSAccessibilityColumnsAttribute) || attributeName.isEqualToString(OS.NSAccessibilityVisibleColumnsAttribute)) { if ((style & SWT.CHECK) != 0) { long /*int*/ superValue = super.accessibilityAttributeValue(id, sel, arg0); if (superValue != 0) { NSArray columns = new NSArray(superValue); NSMutableArray columnsWithoutCheck = NSMutableArray.arrayWithCapacity(columns.count() - 1); columnsWithoutCheck.addObjectsFromArray(columns); columnsWithoutCheck.removeObjectAtIndex(0); returnValue = columnsWithoutCheck.id; } } } if (returnValue != 0) { return returnValue; } else { return super.accessibilityAttributeValue(id, sel, arg0); } } @Override void _addListener (int eventType, Listener listener) { super._addListener (eventType, listener); clearCachedWidth(items); } /** * 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
    *
  • 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 #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); } TableItem _getItem (int index) { if ((style & SWT.VIRTUAL) == 0) return items [index]; if (items [index] != null) return items [index]; return items [index] = new TableItem (this, SWT.NULL, -1, false); } int calculateWidth (TableItem[] items, int index, GC gc) { int width = 0; for (int i=0; i < itemCount; i++) { TableItem item = items [i]; if (item != null && item.cached) { width = Math.max (width, item.calculateWidth (index, gc, isSelected(index))); } } return width; } @Override NSSize cellSize (long /*int*/ id, long /*int*/ sel) { NSSize size = super.cellSize(id, sel); NSCell cell = new NSCell(id); NSImage image = cell.image(); if (image != null) size.width += imageBounds.width + IMAGE_GAP; if (hooks(SWT.MeasureItem)) { long /*int*/ [] outValue = new long /*int*/ [1]; OS.object_getInstanceVariable(id, Display.SWT_ROW, outValue); long /*int*/ rowIndex = outValue [0]; TableItem item = _getItem((int)/*64*/rowIndex); OS.object_getInstanceVariable(id, Display.SWT_COLUMN, outValue); long /*int*/ tableColumn = outValue[0]; int columnIndex = 0; for (int i=0; iSWT.VIRTUAL
style, * these attributes are requested again as needed. * * @param index the index of the item to clear * * @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 SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clear (int index) { checkWidget (); if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); TableItem item = items [index]; if (item != null) { if (currentItem != item) item.clear (); if (currentItem == null) item.redraw (-1); setScrollWidth (item); } } /** * 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
    *
  • 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
  • *
* * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clear (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) { clearAll (); } else { for (int i=start; i<=end; i++) { clear (i); } } } /** * 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
    *
  • 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
  • *
* * @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
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clearAll () { checkWidget (); for (int i=0; i 1) { createColumn (item, index); } } } } void createItem (TableItem item, int index) { if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); if (itemCount == items.length) { /* Grow the array faster when redraw is off */ int length = getDrawing () ? items.length + 4 : Math.max (4, items.length * 3 / 2); TableItem [] newItems = new TableItem [length]; System.arraycopy (items, 0, newItems, 0, items.length); items = newItems; } System.arraycopy (items, index, items, index + 1, itemCount++ - index); items [index] = item; updateRowCount(); if (index != itemCount) fixSelection (index, true); } @Override void createWidget () { super.createWidget (); items = new TableItem [4]; columns = new TableColumn [4]; } @Override Color defaultBackground () { return display.getWidgetColor (SWT.COLOR_LIST_BACKGROUND); } @Override NSFont defaultNSFont () { return display.tableViewFont; } @Override Color defaultForeground () { return display.getWidgetColor (SWT.COLOR_LIST_FOREGROUND); } @Override void deregister () { super.deregister (); display.removeWidget (headerView); display.removeWidget (dataCell); if (buttonCell != null) display.removeWidget (buttonCell); } @Override void deselectAll(long /*int*/ id, long /*int*/ sel, long /*int*/ sender) { if (preventSelect && !ignoreSelect) return; if ((style & SWT.SINGLE) != 0 && !ignoreSelect) { if ( ((NSTableView)view).selectedRow() != -1) return; } super.deselectAll (id, sel, sender); } @Override void deselectRow (long /*int*/ id, long /*int*/ sel, long /*int*/ index) { if (preventSelect && !ignoreSelect) return; if ((style & SWT.SINGLE) != 0 && !ignoreSelect) { if ( ((NSTableView)view).selectedRow() == index) return; } super.deselectRow (id, sel, index); } /** * Deselects the item at the given zero-relative index in the receiver. * If the item at the index was already deselected, it remains * deselected. Indices that are out of range are ignored. * * @param index the index of the item 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 index) { checkWidget (); if (0 <= index && index < itemCount) { NSTableView widget = (NSTableView)view; ignoreSelect = true; widget.deselectRow (index); ignoreSelect = false; } } /** * 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 > end) return; if (end < 0 || start >= itemCount) return; start = Math.max (0, start); end = Math.min (itemCount - 1, end); if (start == 0 && end == itemCount - 1) { deselectAll (); } else { NSTableView widget = (NSTableView)view; ignoreSelect = true; for (int i=start; i<=end; i++) { widget.deselectRow (i); } ignoreSelect = false; } } /** * 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. Indices that are out * of range and duplicate indices are ignored. * * @param indices the array of indices for the items to deselect * * @exception IllegalArgumentException
    *
  • ERROR_NULL_ARGUMENT - if the set 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
  • *
*/ public void deselect (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); NSTableView widget = (NSTableView)view; ignoreSelect = 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 deselectAll () { checkWidget (); NSTableView widget = (NSTableView)view; ignoreSelect = true; widget.deselectAll(null); ignoreSelect = false; } void destroyItem (TableColumn column) { int index = 0; while (index < columnCount) { if (columns [index] == column) break; index++; } for (int i=0; i size.width) newRect.width -= TEXT_GAP; break; } } newRect.height = rect.height; if (newRect.height > size.height) { newRect.y += (newRect.height - size.height) / 2; newRect.height = size.height; } newStr.drawInRect(newRect); newStr.release(); } else { NSColor nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], color[3]); cell.setTextColor(nsColor); callSuper = true; } } else { callSuper = true; } if (callSuper) { NSAttributedString attrStr = cell.attributedStringValue(); NSSize size = attrStr.size(); if (rect.height > size.height) { rect.y += (rect.height - size.height) / 2; rect.height = size.height; } super.drawInteriorWithFrame_inView(id, sel, rect, view); } } if (hooksPaint) { context.saveGraphicsState(); NSAffineTransform transform = NSAffineTransform.transform(); transform.translateXBy(offsetX, offsetY); transform.concat(); GCData data = new GCData (); data.paintRect = cellRect; GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); if (drawSelection) { gc.setForeground (selectionForeground); gc.setBackground (selectionBackground); } else { gc.setForeground (userForeground != null ? userForeground : item.getForeground (columnIndex)); gc.setBackground (item.getBackground (columnIndex)); } if (!drawExpansion) { gc.setClipping ((int)(cellRect.x - offsetX), (int)(cellRect.y - offsetY), (int)cellRect.width, (int)cellRect.height); } Event event = new Event (); event.item = item; event.gc = gc; event.index = columnIndex; if (drawForeground) event.detail |= SWT.FOREGROUND; if (drawBackground) event.detail |= SWT.BACKGROUND; if (isSelected) event.detail |= SWT.SELECTED; event.x = itemX; event.y = itemY; event.width = contentWidth; event.height = itemHeight; sendEvent (SWT.PaintItem, event); gc.dispose (); context.restoreGraphicsState(); } } @Override void drawWithExpansionFrame_inView (long /*int*/ id, long /*int*/ sel, NSRect cellFrame, long /*int*/ view) { drawExpansion = true; super.drawWithExpansionFrame_inView(id, sel, cellFrame, view); drawExpansion = false; } @Override void drawRect(long /*int*/ id, long /*int*/ sel, NSRect rect) { fixScrollWidth = false; super.drawRect(id, sel, rect); if (isDisposed ()) return; if (fixScrollWidth) { fixScrollWidth = false; if (setScrollWidth (items, true)) view.setNeedsDisplay(true); } } @Override NSRect expansionFrameWithFrame_inView(long /*int*/ id, long /*int*/ sel, NSRect cellRect, long /*int*/ view) { if (toolTipText == null) { NSRect rect = super.expansionFrameWithFrame_inView(id, sel, cellRect, view); NSCell cell = new NSCell(id); NSAttributedString str = cell.attributedStringValue(); NSSize textSize = str.size(); NSRect expansionRect; if (rect.width != 0 && rect.height != 0) { if (hooks(SWT.MeasureItem)) { expansionRect = cellRect; NSSize cellSize = cell.cellSize(); expansionRect.width = cellSize.width; } else { expansionRect = rect; } if (textSize.height > expansionRect.height) { expansionRect.height = textSize.height; } } else { if (hooks(SWT.MeasureItem)) { expansionRect = cellRect; NSSize cellSize = cell.cellSize(); expansionRect.width = cellSize.width; } else { expansionRect = cell.titleRectForBounds(cellRect); NSSize cellSize = super.cellSize(id, OS.sel_cellSize); expansionRect.width = cellSize.width; } if (textSize.height > expansionRect.height) { expansionRect.height = textSize.height; } else { NSRect contentRect = scrollView.contentView().bounds(); OS.NSIntersectionRect(contentRect, expansionRect, contentRect); if (OS.NSEqualRects(expansionRect, contentRect)) { return new NSRect(); } } } return expansionRect; } return new NSRect(); } @Override Widget findTooltip (NSPoint pt) { NSTableView widget = (NSTableView)view; NSTableHeaderView headerView = widget.headerView(); if (headerView != null) { pt = headerView.convertPoint_fromView_ (pt, null); long /*int*/ index = headerView.columnAtPoint (pt); if (index != -1) { NSArray nsColumns = widget.tableColumns (); id nsColumn = nsColumns.objectAtIndex (index); for (int i = 0; i < columnCount; i++) { TableColumn column = columns [i]; if (column.nsColumn.id == nsColumn.id) { return column; } } } } return super.findTooltip (pt); } void fixSelection (int index, boolean add) { int [] selection = getSelectionIndices (); if (selection.length == 0) return; int newCount = 0; boolean fix = false; for (int i = 0; i < selection.length; i++) { if (!add && selection [i] == index) { fix = true; } else { int newIndex = newCount++; selection [newIndex] = selection [i]; if (selection [newIndex] >= index) { selection [newIndex] += add ? 1 : -1; fix = true; } } } if (fix) select (selection, newCount, true); } int getCheckColumnWidth () { return (int)checkColumn.dataCell().cellSize().width; } @Override public Rectangle getClientArea () { checkWidget (); Rectangle rect = super.getClientArea (); /* * OSX version < 10.11 - The origin of the table is the top-left of the rows * of the table, not the header. We adjust the y value and height of the rect * accordingly, to include the header. * * OSX 10.11 - The origin of the table is the header and the header's * height is already included in the rect. Hence, we return the rect as is. */ if (OS.VERSION_MMB < OS.VERSION_MMB (10, 11, 0)) { NSTableHeaderView headerView = ((NSTableView) view).headerView (); if (headerView != null) { int height = (int) headerView.bounds ().height; rect.y -= height; rect.height += height; } } return rect; } TableColumn getColumn (id id) { for (int i = 0; i < columnCount; i++) { if (columns[i].nsColumn.id == id.id) { return columns[i]; } } return null; } /** * Returns the column at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * Columns are returned in the order that they were created. * If no TableColumns 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]; } /** * 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; i < columnCount; i++) { TableColumn column = columns [i]; int index = indexOf (column.nsColumn); if ((style & SWT.CHECK) != 0) index -= 1; order [index] = i; } return order; } /** * Returns an array of TableColumns 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]; System.arraycopy (columns, 0, result, 0, columnCount); return result; } /** * Returns the width in pixels of a grid line. * * @return the width of a grid line in pixels * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int getGridLineWidth () { checkWidget (); return 0; } /** * Returns the header background color. * * @return the receiver's header background color. * * @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.106 */ public Color getHeaderBackground () { checkWidget (); return getHeaderBackgroundColor (); } private Color getHeaderBackgroundColor () { return headerBackground != null ? Color.cocoa_new (display, headerBackground) : getBackgroundColor (); } /** * Returns the header foreground color. * * @return the receiver's header foreground color. * * @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.106 */ public Color getHeaderForeground () { checkWidget (); return getHeaderForegroundColor (); } private Color getHeaderForegroundColor () { return headerForeground != null ? Color.cocoa_new (display, headerForeground) : getForegroundColor (); } /** * 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 (); NSTableHeaderView headerView = ((NSTableView)view).headerView(); if (headerView == null) return 0; return (int)headerView.bounds().height; } /** * Returns true if the receiver's header is visible, * and false otherwise. *

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

    * * @return the receiver's header's visibility state * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public boolean getHeaderVisible () { checkWidget (); return ((NSTableView)view).headerView() != null; } /** * Returns the item at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * * @param index the index of the item to return * @return the item at the given index * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public TableItem getItem (int index) { checkWidget (); if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); return _getItem (index); } /** * 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 (); NSTableView widget = (NSTableView)view; NSPoint pt = new NSPoint(); pt.x = point.x; pt.y = point.y; int row = (int)/*64*/widget.rowAtPoint(pt); if (row == -1) return null; return items[row]; } /** * 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 (); return (int)((NSTableView)view).rowHeight() + CELL_GAP; } /** * 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]; if ((style & SWT.VIRTUAL) != 0) { 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 (); return ((NSTableView)view).usesAlternatingRowBackgroundColors(); } /** * 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 (); NSTableView widget = (NSTableView)view; if (widget.numberOfSelectedRows() == 0) { return new TableItem [0]; } NSIndexSet selection = widget.selectedRowIndexes(); int count = (int)/*64*/selection.count(); long /*int*/ [] indexBuffer = new long /*int*/ [count]; selection.getIndexes(indexBuffer, count, 0); TableItem [] result = new TableItem [count]; for (int i=0; i *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ public int getSelectionCount () { checkWidget (); return (int)/*64*/((NSTableView)view).numberOfSelectedRows(); } /** * 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 (); NSTableView widget = (NSTableView)view; if (widget.numberOfSelectedRows() == 0) { return -1; } NSIndexSet selection = widget.selectedRowIndexes(); int count = (int)/*64*/selection.count(); long /*int*/ [] result = new long /*int*/ [count]; selection.getIndexes(result, count, 0); return (int)/*64*/result [0]; } /** * 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 (); NSTableView widget = (NSTableView)view; if (widget.numberOfSelectedRows() == 0) { return new int [0]; } NSIndexSet selection = widget.selectedRowIndexes(); int count = (int)/*64*/selection.count(); long /*int*/ [] indices = new long /*int*/ [count]; selection.getIndexes(indices, count, 0); int [] result = new int [count]; for (int i = 0; i < indices.length; i++) { result [i] = (int)/*64*/indices [i]; } 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(TableColumn) * * @since 3.2 */ public TableColumn getSortColumn () { checkWidget (); return sortColumn; } /** * Returns the direction of the sort indicator for the receiver. * The value will be one of UP, DOWN * or NONE. * * @return the sort direction * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see #setSortDirection(int) * * @since 3.2 */ public int getSortDirection () { checkWidget (); return sortDirection; } /** * Returns the 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 (); //TODO - partial item at the top NSRect rect = scrollView.documentVisibleRect(); NSPoint point = new NSPoint(); point.x = rect.x; point.y = rect.y; /* * In OSX 10.11, the origin of the table is the header, not the top-left of the rows. * Offset the point's y coordinate accordingly. */ if (OS.VERSION_MMB >= OS.VERSION_MMB (10, 11, 0)) { NSTableHeaderView headerView = ((NSTableView) view).headerView (); if (headerView != null) { int height = (int) headerView.bounds ().height; point.y += height; } } int /*64*/ rowAtPoint = (int)/*64*/((NSTableView)view).rowAtPoint(point); if (rowAtPoint == -1) return 0; /* Empty table */ return rowAtPoint; } @Override NSRect headerRectOfColumn (long /*int*/ id, long /*int*/ sel, long /*int*/ column) { if ((style & SWT.CHECK) == 0) return callSuperRect(id, sel, column); if (column == 0) { NSRect returnValue = callSuperRect(id, sel, column); returnValue.width = 0; return returnValue; } if (column == 1) { NSRect returnValue = callSuperRect(id, sel, column); // Save a call to [NSTableView intercellSpacing] by using our constant. returnValue.width += (checkColumn.width() + CELL_GAP); returnValue.x -= (checkColumn.width() + CELL_GAP); return returnValue; } return callSuperRect(id, sel, column); } @Override void highlightSelectionInClipRect(long /*int*/ id, long /*int*/ sel, long /*int*/ rect) { if (hooks (SWT.EraseItem)) return; if ((style & SWT.HIDE_SELECTION) != 0 && !hasFocus()) return; NSRect clipRect = new NSRect (); OS.memmove (clipRect, rect, NSRect.sizeof); callSuper (id, sel, clipRect); } @Override long /*int*/ hitTestForEvent (long /*int*/ id, long /*int*/ sel, long /*int*/ event, NSRect rect, long /*int*/ controlView) { /* * For some reason, the cell class needs to implement hitTestForEvent:inRect:ofView:, * otherwise the double action selector is not called properly. */ return callSuper(id, sel, event, rect, controlView); } @Override long /*int*/ image (long /*int*/ id, long /*int*/ sel) { long /*int*/ [] image = new long /*int*/ [1]; OS.object_getInstanceVariable(id, Display.SWT_IMAGE, image); return image[0]; } @Override NSRect imageRectForBounds (long /*int*/ id, long /*int*/ sel, NSRect cellFrame) { NSImage image = new NSCell(id).image(); if (image != null) { cellFrame.x += IMAGE_GAP; cellFrame.width = imageBounds.width; cellFrame.height = imageBounds.height; } return cellFrame; } int indexOf (NSTableColumn column) { return (int)/*64*/((NSTableView)view).tableColumns().indexOfObjectIdenticalTo(column); } /** * Searches the receiver's list starting at the first column * (index 0) until a column is found that is equal to the * argument, and returns the index of that column. If no column * is found, returns -1. * * @param column the search column * @return the index of the column * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the column is null
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int indexOf (TableColumn column) { checkWidget (); if (column == null) error (SWT.ERROR_NULL_ARGUMENT); for (int i=0; i *
  • 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); if (1 <= lastIndexOf && lastIndexOf < itemCount - 1) { if (items [lastIndexOf] == item) return lastIndexOf; if (items [lastIndexOf + 1] == item) return ++lastIndexOf; if (items [lastIndexOf - 1] == item) return --lastIndexOf; } if (lastIndexOf < itemCount / 2) { for (int i=0; i=0; --i) { if (items [i] == item) return lastIndexOf = i; } } return -1; } /** * 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 (); if (!(0 <= index && index < itemCount)) return false; return ((NSTableView)view).isRowSelected(index); } @Override boolean isTransparent() { return true; } @Override void keyDown(long /*int*/ id, long /*int*/ sel, long /*int*/ theEvent) { ignoreSelect = preventSelect = false; super.keyDown(id, sel, theEvent); } @Override boolean isTrim (NSView view) { if (super.isTrim (view)) return true; return view.id == headerView.id; } @Override long /*int*/ menuForEvent(long /*int*/ id, long /*int*/ sel, long /*int*/ theEvent) { if (id != headerView.id) { /* * Feature in Cocoa: Table views do not change the selection when the user * right-clicks or control-clicks on an NSTableView or its subclasses. Fix is to select the * clicked-on row ourselves. */ NSEvent event = new NSEvent(theEvent); NSTableView table = (NSTableView)view; // get the current selections for the table view. NSIndexSet selectedRowIndexes = table.selectedRowIndexes(); // select the row that was clicked before showing the menu for the event NSPoint mousePoint = view.convertPoint_fromView_(event.locationInWindow(), null); long /*int*/ row = table.rowAtPoint(mousePoint); // figure out if the row that was just clicked on is currently selected if (selectedRowIndexes.containsIndex(row) == false) { NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc(); set = set.initWithIndex(row); table.selectRowIndexes (set, false); set.release(); } // else that row is currently selected, so don't change anything. } return super.menuForEvent(id, sel, theEvent); } @Override void mouseDown (long /*int*/ id, long /*int*/ sel, long /*int*/ theEvent) { if (id == view.id) { // Bug/feature in Cocoa: If the table has a context menu we just set it visible instead of returning // it from menuForEvent:. This has the side effect, however, of sending control-click to the NSTableView, // which is interpreted as a single click that clears the selection. Fix is to ignore control-click if the // view has a context menu. NSEvent event = new NSEvent(theEvent); if ((event.modifierFlags() & OS.NSControlKeyMask) != 0) return; } super.mouseDown(id, sel, theEvent); } @Override void mouseDownSuper(long /*int*/ id, long /*int*/ sel, long /*int*/ theEvent) { ignoreSelect = preventSelect = false; boolean check = false; NSEvent nsEvent = new NSEvent(theEvent); NSTableView widget = (NSTableView)view; NSPoint pt = view.convertPoint_fromView_(nsEvent.locationInWindow(), null); int row = (int)/*64*/widget.rowAtPoint(pt); if (row != -1 && (style & SWT.CHECK) != 0) { int column = (int)/*64*/widget.columnAtPoint(pt); NSCell cell = widget.preparedCellAtColumn(column, row); if (cell != null && cell.isKindOfClass(OS.class_NSButtonCell) && cell.isEnabled()) { NSRect checkRect = cell.imageRectForBounds(widget.frameOfCellAtColumn(column, row)); if (OS.NSPointInRect(pt, checkRect)) { check = preventSelect = true; } } } if (!check && row != -1 && (nsEvent.modifierFlags() & OS.NSDeviceIndependentModifierFlagsMask) == 0 && nsEvent.clickCount() == 1) { if (widget.isRowSelected(row)) { if (0 <= row && row < itemCount) { selectedRowIndex = row; } } } didSelect = false; super.mouseDownSuper(id, sel, theEvent); didSelect = false; } @Override boolean needsPanelToBecomeKey (long /*int*/ id, long /*int*/ sel) { return false; } /* * Feature in Cocoa. If a checkbox is in multi-state mode, nextState cycles * from off to mixed to on and back to off again. This will cause the on state * to momentarily appear while clicking on the checkbox. To avoid this, * override [NSCell nextState] to go directly to the desired state. */ @Override long /*int*/ nextState (long /*int*/ id, long /*int*/ sel) { NSTableView tableView = (NSTableView)view; int index = (int)/*64*/tableView.clickedRow(); if (index == -1) index = (int)/*64*/tableView.selectedRow (); TableItem item = items[index]; if (item.grayed) { return item.checked ? OS.NSOffState : OS.NSMixedState; } return item.checked ? OS.NSOffState : OS.NSOnState; } @Override long /*int*/ numberOfRowsInTableView(long /*int*/ id, long /*int*/ sel, long /*int*/ aTableView) { return itemCount; } @Override void register () { super.register (); display.addWidget (headerView, this); display.addWidget (dataCell, this); if (buttonCell != null) display.addWidget (buttonCell, this); } @Override void releaseChildren (boolean destroy) { if (items != null) { 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)
  • * * @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); TableItem item = items [index]; if (item != null) item.release (false); if (index != itemCount - 1) fixSelection (index, false); System.arraycopy (items, index + 1, items, index, --itemCount - index); items [itemCount] = null; updateRowCount(); if (itemCount == 0) { setTableEmpty (); } } /** * 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 (); } else { int length = end - start + 1; for (int i=start; i= start && selection[i] <= end) { fix = true; } else { int newIndex = newCount++; selection [newIndex] = selection [i]; if (selection [newIndex] > end) { selection [newIndex] -= length; fix = true; } } } if (fix) select (selection, newCount, true); } //fix items array System.arraycopy (items, start + length, items, start, itemCount - (start + length)); for (int i = itemCount; i < items.length; i++) { items [i] = null; } itemCount -= length; updateRowCount(); } if (itemCount == 0) { setTableEmpty (); } } /** * Removes the items from the receiver's list at the given * zero-relative indices. * * @param indices the array of indices of the items * * @exception IllegalArgumentException
      *
    • 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 last = -1; 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 (); for (int i=0; i *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see SelectionListener * @see #addSelectionListener(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); } @Override void reskinChildren (int flags) { if (items != null) { for (int i=0; i 0 && ((NSTableView)view).headerView() != null) { if (point.x <= getCheckColumnWidth()) { /* * Header of first column is extended as header of the checkbox column. * So, redraw header of first column when check column is scrolled to be visible. */ headerView.setNeedsDisplayInRect(headerView.headerRectOfColumn(1)); } } } } /** * 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) { NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc(); set = set.initWithIndex(index); NSTableView widget = (NSTableView)view; ignoreSelect = true; widget.selectRowIndexes(set, (style & SWT.MULTI) != 0); ignoreSelect = false; set.release(); } } /** * 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 (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return; if (itemCount == 0 || start >= itemCount) return; if (start == 0 && end == itemCount - 1) { selectAll (); } else { start = Math.max (0, start); end = Math.min (end, itemCount - 1); NSRange range = new NSRange(); range.location = start; range.length = end - start + 1; NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc(); set = set.initWithIndexesInRange(range); NSTableView widget = (NSTableView)view; ignoreSelect = true; widget.selectRowIndexes(set, (style & SWT.MULTI) != 0); ignoreSelect = false; set.release(); } } /** * 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; int count = 0; NSMutableIndexSet set = (NSMutableIndexSet)new NSMutableIndexSet().alloc().init(); for (int i=0; i= 0 && index < itemCount) { set.addIndex (indices [i]); count++; } } if (count > 0) { NSTableView widget = (NSTableView)view; ignoreSelect = true; widget.selectRowIndexes(set, (style & SWT.MULTI) != 0); ignoreSelect = false; } set.release(); } void select (int [] indices, int count, boolean clear) { NSMutableIndexSet set = (NSMutableIndexSet)new NSMutableIndexSet().alloc().init(); for (int i=0; i * 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; NSTableView widget = (NSTableView)view; ignoreSelect = true; widget.selectAll(null); ignoreSelect = false; } @Override void setBackgroundColor(NSColor nsColor) { ((NSTableView) view).setBackgroundColor (nsColor); } /** * 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 (columnCount == 0) { if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT); return; } if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT); int [] oldOrder = getColumnOrder (); boolean reorder = false; boolean [] seen = new boolean [columnCount]; for (int i=0; i= columnCount) error (SWT.ERROR_INVALID_ARGUMENT); if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT); seen [index] = true; if (order [i] != oldOrder [i]) reorder = true; } if (reorder) { NSTableView tableView = (NSTableView)view; int [] oldX = new int [oldOrder.length]; int check = (style & SWT.CHECK) != 0 ? 1 : 0; for (int i=0; i * Note: This operation is a HINT and is not supported on all platforms. If * the native header has a 3D look and feel (e.g. Windows 7), this method * will cause the header to look FLAT irrespective of the state of the table style. *

    * @param color the new color (or null) * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the argument 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.106 */ public void setHeaderBackground (Color color) { checkWidget (); if (color != null) { if (color.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); } double /*float*/ [] headerBackground = color != null ? color.handle : null; if (equals (headerBackground, this.headerBackground)) return; this.headerBackground = headerBackground; if (getHeaderVisible()) { redrawWidget (view, false); } } /** * Sets the header foreground color to the color specified * by the argument, or to the default system color if the argument is null. *

    * Note: This operation is a HINT and is not supported on all platforms. If * the native header has a 3D look and feel (e.g. Windows 7), this method * will cause the header to look FLAT irrespective of the state of the table style. *

    * @param color the new color (or null) * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the argument 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.106 */ public void setHeaderForeground (Color color) { checkWidget (); if (color != null) { if (color.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); } double /*float*/ [] headerForeground = color != null ? color.handle : null; if (equals (headerForeground, this.headerForeground)) return; this.headerForeground = headerForeground; if (getHeaderVisible()) { redrawWidget (view, false); } } /** * 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 (); ((NSTableView)view).setHeaderView (show ? headerView : null); scrollView.tile(); } @Override void setImage (long /*int*/ id, long /*int*/ sel, long /*int*/ arg0) { OS.object_setInstanceVariable(id, Display.SWT_IMAGE, arg0); } /** * Sets the number of 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.0 */ public void setItemCount (int count) { checkWidget (); count = Math.max (0, count); if (count == itemCount) return; TableItem [] children = items; if (count < itemCount) { for (int index = count; index < itemCount; index ++) { TableItem item = children [index]; if (item != null && !item.isDisposed()) item.release (false); } } if (count > itemCount) { if ((getStyle() & SWT.VIRTUAL) == 0) { for (int i=itemCount; i 4 && items.length - itemCount > 3) { int length = Math.max (4, (itemCount + 3) / 4 * 4); TableItem [] newItems = new TableItem [length]; System.arraycopy (items, 0, newItems, 0, itemCount); items = newItems; } setScrollWidth (); } } /** * 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 (); ((NSTableView)view).setUsesAlternatingRowBackgroundColors(show); ((NSTableView)view).setGridStyleMask(show ? OS.NSTableViewSolidVerticalGridLineMask : OS.NSTableViewGridNone); } boolean setScrollWidth () { return setScrollWidth (items, true); } boolean setScrollWidth (TableItem item) { if (columnCount != 0) return false; if (!getDrawing()) return false; if (currentItem != null) { if (currentItem != item) fixScrollWidth = true; return false; } GC gc = new GC (this); int newWidth = item.calculateWidth (0, gc, isSelected(indexOf(item))); gc.dispose (); int oldWidth = (int)firstColumn.width (); if (oldWidth < newWidth) { firstColumn.setWidth (newWidth); if (horizontalBar != null && horizontalBar.view != null) redrawWidget (horizontalBar.view, false); return true; } return false; } boolean setScrollWidth (TableItem [] items, boolean set) { if (items == null) return false; if (columnCount != 0) return false; if (!getDrawing()) return false; if (currentItem != null) { fixScrollWidth = true; return false; } GC gc = new GC (this); int newWidth = 0; for (int i = 0; i < items.length; i++) { TableItem item = items [i]; if (item != null) { newWidth = Math.max (newWidth, item.calculateWidth (0, gc, isSelected(indexOf(item)))); } } gc.dispose (); if (!set) { int oldWidth = (int)firstColumn.width (); if (oldWidth >= newWidth) return false; } firstColumn.setWidth (newWidth); if (horizontalBar != null && horizontalBar.view != null) redrawWidget (horizontalBar.view, false); return true; } /** * Selects the item at the given zero-relative index in the receiver. * The current selection is first cleared, then the new item is selected, * and if necessary the receiver is scrolled to make the new selection visible. * * @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
    • *
    * * @see Table#deselectAll() * @see Table#select(int) */ public void setSelection (int index) { checkWidget (); //TODO - optimize to use expand flag deselectAll (); if (0 <= index && index < itemCount) { select (index); showIndex (index); } } /** * 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, * and if necessary the receiver is scrolled to make the new selection visible. *

    * 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 (); //TODO - optimize to use expand flag 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); showIndex (start); } /** * Selects the items at the given zero-relative indices in the receiver. * The current selection is cleared before the new items are selected, * and if necessary the receiver is scrolled to make the new selection visible. *

    * 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); //TODO - optimize to use expand flag deselectAll (); int length = indices.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; select (indices); showIndex (indices [0]); } /** * Sets the receiver's selection to the given item. * The current selection is cleared before the new item is selected, * and if necessary the receiver is scrolled to make the new selection visible. *

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

    * * @param item the item to select * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the item is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ public void setSelection (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, * and if necessary the receiver is scrolled to make the new selection visible. *

    * Items that are not in the receiver are ignored. * If the receiver is single-select and multiple items are specified, * then all items are ignored. *

    * * @param items the array of items * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the array of items is null
    • *
    • ERROR_INVALID_ARGUMENT - if one of the items has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#deselectAll() * @see Table#select(int[]) * @see Table#setSelection(int[]) */ public void setSelection (TableItem [] items) { checkWidget (); if (items == null) error (SWT.ERROR_NULL_ARGUMENT); //TODO - optimize to use expand flag deselectAll (); int length = items.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; int [] indices = new int [length]; int count = 0; for (int i=0; i 0) { select (indices); showIndex (indices [0]); } } @Override void setShouldScrollClipView(long /*int*/ id, long /*int*/ sel, boolean shouldScroll) { this.shouldScroll = shouldScroll; } /** * 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); if (column == sortColumn) return; setSort(column, sortDirection); } /** * Sets the direction of the sort indicator for the receiver. The value * can be one of UP, DOWN or NONE. * * @param direction the direction of the sort indicator * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ public void setSortDirection (int direction) { checkWidget (); if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return; if (direction == sortDirection) return; setSort(sortColumn, direction); } void setSort (TableColumn column, int direction) { NSImage image = null; NSTableColumn nsColumn = null; if (column != null) { nsColumn = column.nsColumn; if (direction == SWT.DOWN) image = NSImage.imageNamed(NSString.stringWith("NSDescendingSortIndicator")); if (direction == SWT.UP) image = NSImage.imageNamed(NSString.stringWith("NSAscendingSortIndicator")); } NSTableView widget = (NSTableView)view; if (sortColumn != null && sortColumn != column) { widget.setIndicatorImage(null, sortColumn.nsColumn); } widget.setHighlightedTableColumn(nsColumn); widget.setIndicatorImage(image, nsColumn); sortDirection = direction; sortColumn = column; } void setTableEmpty () { itemCount = 0; items = new TableItem [4]; imageBounds = null; } /** * 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 (); NSTableView widget = (NSTableView) view; int row = Math.max(0, Math.min(index, itemCount)); NSPoint pt = new NSPoint(); pt.x = scrollView.contentView().bounds().x; pt.y = widget.frameOfCellAtColumn(0, row).y; /* * In OSX 10.11, the origin of the table is the header, not the top-left of the rows. * Offset the point's y coordinate accordingly. */ if (OS.VERSION_MMB >= OS.VERSION_MMB(10, 11, 0)) { if (widget.headerView() != null) { NSRect headerRect = headerView.frame(); pt.y -= headerRect.y + headerRect.height; } } view.scrollPoint(pt); } /** * Shows the column. If the column is already showing in the receiver, * this method simply returns. Otherwise, the columns are scrolled until * the column is visible. * * @param column the column to be shown * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the 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; if (columnCount <= 1) return; int index = indexOf (column.nsColumn); if (!(0 <= index && index < columnCount + ((style & SWT.CHECK) != 0 ? 1 : 0))) return; ((NSTableView)view).scrollColumnToVisible (index); } void showIndex (int index) { if (0 <= index && index < itemCount) { ((NSTableView)view).scrollRowToVisible(index); } } /** * 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); int index = indexOf (item); if (index != -1) showIndex (index); } /** * 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 index = getSelectionIndex (); if (index >= 0) { checkData(_getItem(index)); showIndex (index); } } @Override void selectRowIndexes_byExtendingSelection (long /*int*/ id, long /*int*/ sel, long /*int*/ indexes, boolean extend) { if (preventSelect && !ignoreSelect) return; if ((style & SWT.SINGLE) != 0 && !ignoreSelect) { NSIndexSet set = new NSIndexSet(indexes); if (set.count() == 0) return; } super.selectRowIndexes_byExtendingSelection (id, sel, indexes, extend); } @Override void sendDoubleSelection() { NSTableView tableView = (NSTableView)view; int rowIndex = (int)/*64*/tableView.clickedRow (); if (rowIndex == -1) rowIndex = (int)/*64*/tableView.selectedRow(); if (rowIndex != -1) { if ((style & SWT.CHECK) != 0) { NSArray columns = tableView.tableColumns (); int columnIndex = (int)/*64*/tableView.clickedColumn (); if (columnIndex != -1) { id column = columns.objectAtIndex (columnIndex); if (column.id == checkColumn.id) return; } } Event event = new Event (); event.item = _getItem (rowIndex); sendSelectionEvent (SWT.DefaultSelection, event, false); } } @Override boolean sendKeyEvent (NSEvent nsEvent, int type) { boolean result = super.sendKeyEvent (nsEvent, type); if (!result) return result; if (type != SWT.KeyDown) return result; short keyCode = nsEvent.keyCode (); switch (keyCode) { case 76: /* KP Enter */ case 36: { /* Return */ sendDoubleSelection(); break; } } return result; } void sendMeasureItem (TableItem item, int columnIndex, NSSize size, boolean isSelected) { NSTableView widget = (NSTableView)this.view; int contentWidth = (int)Math.ceil (size.width); NSSize spacing = widget.intercellSpacing(); int itemHeight = (int)Math.ceil (widget.rowHeight() + spacing.height); GCData data = new GCData (); data.paintRect = widget.frame (); GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); Event event = new Event (); event.item = item; event.gc = gc; event.index = columnIndex; event.width = contentWidth; event.height = itemHeight; if (isSelected && ((style & SWT.HIDE_SELECTION) == 0 || hasFocus())) event.detail |= SWT.SELECTED; sendEvent (SWT.MeasureItem, event); gc.dispose (); if (!isDisposed () && !item.isDisposed ()) { size.width = event.width; size.height = event.height; if (itemHeight < event.height) { widget.setRowHeight (event.height); } if (contentWidth != event.width) { if (columnCount == 0 && columnIndex == 0) { item.width = event.width; if (setScrollWidth (item)) { widget.setNeedsDisplay(true); } } } } } @Override void tableViewColumnDidMove (long /*int*/ id, long /*int*/ sel, long /*int*/ aNotification) { NSNotification notification = new NSNotification (aNotification); NSDictionary userInfo = notification.userInfo (); NSString nsstring = (NSString) new NSString().alloc(); nsstring = nsstring.initWithString("NSOldColumn"); //$NON-NLS-1$ id nsOldIndex = userInfo.valueForKey (nsstring); nsstring.release(); nsstring = (NSString) new NSString().alloc(); nsstring = nsstring.initWithString("NSNewColumn"); //$NON-NLS-1$ id nsNewIndex = userInfo.valueForKey (nsstring); nsstring.release(); int oldIndex = new NSNumber (nsOldIndex).intValue (); int newIndex = new NSNumber (nsNewIndex).intValue (); NSTableView tableView = (NSTableView)view; int startIndex = Math.min (oldIndex, newIndex); int endIndex = Math.max (oldIndex, newIndex); NSArray nsColumns = tableView.tableColumns (); for (int i = startIndex; i <= endIndex; i++) { id columnId = nsColumns.objectAtIndex (i); TableColumn column = getColumn (columnId); if (column != null) { column.sendEvent (SWT.Move); if (isDisposed ()) return; } } headerView.setNeedsDisplay(true); } @Override void tableViewColumnDidResize (long /*int*/ id, long /*int*/ sel, long /*int*/ aNotification) { NSNotification notification = new NSNotification (aNotification); NSDictionary userInfo = notification.userInfo (); NSString nsstring = (NSString) new NSString().alloc(); nsstring = nsstring.initWithString("NSTableColumn"); //$NON-NLS-1$ id columnId = userInfo.valueForKey (nsstring); nsstring.release(); TableColumn column = getColumn (columnId); if (column == null) return; /* either CHECK column or firstColumn in 0-column Table */ column.sendEvent (SWT.Resize); if (isDisposed ()) return; NSTableView tableView = (NSTableView)view; int index = indexOf (column.nsColumn); if (index == -1) return; /* column was disposed in Resize callback */ NSArray nsColumns = tableView.tableColumns (); int columnCount = (int)/*64*/tableView.numberOfColumns (); for (int i = index + 1; i < columnCount; i++) { columnId = nsColumns.objectAtIndex (i); column = getColumn (columnId); if (column != null) { column.sendEvent (SWT.Move); if (isDisposed ()) return; } } } @Override void sendSelection () { if (ignoreSelect) return; NSTableView widget = (NSTableView) view; int row = (int)/*64*/widget.selectedRow (); if(row == -1) sendSelectionEvent (SWT.Selection); else { TableItem item = _getItem (row); Event event = new Event (); event.item = item; event.index = row; sendSelectionEvent (SWT.Selection, event, false); } } @Override void tableViewSelectionDidChange (long /*int*/ id, long /*int*/ sel, long /*int*/ aNotification) { if (didSelect) return; sendSelection(); } @Override void tableViewSelectionIsChanging (long /*int*/ id, long /*int*/ sel, long /*int*/ aNotification) { didSelect = true; sendSelection(); } @Override void tableView_didClickTableColumn (long /*int*/ id, long /*int*/ sel, long /*int*/ tableView, long /*int*/ tableColumn) { TableColumn column = getColumn (new id (tableColumn)); if (column == null) return; /* either CHECK column or firstColumn in 0-column Table */ column.sendSelectionEvent (SWT.Selection); } @Override long /*int*/ tableView_objectValueForTableColumn_row (long /*int*/ id, long /*int*/ sel, long /*int*/ aTableView, long /*int*/ aTableColumn, long /*int*/ rowIndex) { int index = (int)/*64*/rowIndex; TableItem item = _getItem (index); checkData (item, index); if (checkColumn != null && aTableColumn == checkColumn.id) { NSNumber value; if (item.checked && item.grayed) { value = NSNumber.numberWithInt (OS.NSMixedState); } else { value = NSNumber.numberWithInt (item.checked ? OS.NSOnState : OS.NSOffState); } return value.id; } for (int i=0; i 0) { int style = columns [index].style; if ((style & SWT.CENTER) != 0) { alignment = OS.NSCenterTextAlignment; } else if ((style & SWT.RIGHT) != 0) { alignment = OS.NSRightTextAlignment; } } Font font = item.cellFont != null ? item.cellFont [index] : null; if (font == null) font = item.font; if (font == null) font = this.font; if (font == null) font = defaultFont (); if (font.extraTraits != 0) { NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5); dict.setObject (color, OS.NSForegroundColorAttributeName); dict.setObject (font.handle, OS.NSFontAttributeName); addTraits(dict, font); NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init (); paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping); paragraphStyle.setAlignment (alignment); paragraphStyle.setBaseWritingDirection(direction); dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName); paragraphStyle.release (); NSAttributedString attribStr = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString (textCell.title(), dict); textCell.setAttributedStringValue(attribStr); attribStr.release(); dict.release(); } else { textCell.setFont(font.handle); textCell.setTextColor(color); textCell.setAlignment (alignment); textCell.setBaseWritingDirection(direction); } } @Override boolean tableView_writeRowsWithIndexes_toPasteboard(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1, long /*int*/ arg2) { return sendMouseEvent(NSApplication.sharedApplication().currentEvent(), SWT.DragDetect, true); } @Override boolean sendMouseEvent(NSEvent nsEvent, int type, boolean send) { if (type == SWT.DragDetect) { dragDetected = true; } else if (type == SWT.MouseUp) { /* * This code path handles the case of an unmodified click on an already-selected row. * To keep the order of events correct, deselect the other selected items and send the * selection event before MouseUp is sent. Ignore the next selection event. */ if (!dragDetected && selectedRowIndex != -1) { NSTableView widget = (NSTableView)view; NSIndexSet selectedRows = widget.selectedRowIndexes (); int count = (int)/*64*/selectedRows.count(); long /*int*/ [] indexBuffer = new long /*int*/ [count]; selectedRows.getIndexes(indexBuffer, count, 0); for (int i = 0; i < count; i++) { if (indexBuffer[i] == selectedRowIndex) continue; ignoreSelect = true; widget.deselectRow (indexBuffer[i]); ignoreSelect = false; } Event event = new Event (); event.item = _getItem ((int)/*64*/selectedRowIndex); selectedRowIndex = -1; sendSelectionEvent (SWT.Selection, event, false); ignoreSelect = true; } dragDetected = false; } return super.sendMouseEvent (nsEvent, type, send); } @Override NSRect titleRectForBounds (long /*int*/ id, long /*int*/ sel, NSRect cellFrame) { NSImage image = new NSCell(id).image(); if (image != null) { int imageWidth = imageBounds.width + IMAGE_GAP; cellFrame.x += imageWidth; cellFrame.width -= imageWidth; } return cellFrame; } @Override void updateCursorRects (boolean enabled) { super.updateCursorRects (enabled); if (headerView == null) return; updateCursorRects (enabled, headerView); } void updateRowCount() { NSTableView widget = (NSTableView)view; setRedraw(false); ignoreSelect = true; widget.noteNumberOfRowsChanged (); ignoreSelect = false; widget.tile(); setRedraw(true); } }




    © 2015 - 2024 Weber Informatics LLC | Privacy Policy