Search in sources :

Example 21 with TableItem

use of org.eclipse.swt.widgets.TableItem in project translationstudio8 by heartsome.

the class TableComboViewer method doResetItem.

/**
	 * {@inheritDoc}
	 */
protected void doResetItem(Item item) {
    TableItem tableItem = (TableItem) item;
    int columnCount = Math.max(1, tableCombo.getTable().getColumnCount());
    for (int i = 0; i < columnCount; i++) {
        //$NON-NLS-1$
        tableItem.setText(i, "");
        if (tableItem.getImage(i) != null) {
            tableItem.setImage(i, null);
        }
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point)

Example 22 with TableItem

use of org.eclipse.swt.widgets.TableItem in project translationstudio8 by heartsome.

the class TableCombo method tableEvent.

/**
	 * Handles Table Events.
	 * @param event
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 */
private void tableEvent(Event event) {
    switch(event.type) {
        case SWT.Dispose:
            if (getShell() != popup.getParent()) {
                int selectionIndex = table.getSelectionIndex();
                popup = null;
                table = null;
                createPopup(selectionIndex);
            }
            break;
        case SWT.FocusIn:
            {
                handleFocus(SWT.FocusIn);
                break;
            }
        case SWT.MouseMove:
            {
                TableItem item = table.getItem(new Point(event.x, event.y));
                if (item != null) {
                    table.setSelection(item);
                }
                break;
            }
        case SWT.MouseUp:
            {
                if (event.button != 1)
                    return;
                dropDown(false);
                int index = table.getSelectionIndex();
                if (index == -1)
                    return;
                // refresh the text.
                refreshText(index);
                // set the selection in the table.
                table.setSelection(index);
                Event e = new Event();
                e.time = event.time;
                e.stateMask = event.stateMask;
                e.doit = event.doit;
                notifyListeners(SWT.Selection, e);
                event.doit = e.doit;
                break;
            }
        case SWT.Traverse:
            {
                switch(event.detail) {
                    case SWT.TRAVERSE_RETURN:
                    case SWT.TRAVERSE_ESCAPE:
                    case SWT.TRAVERSE_ARROW_PREVIOUS:
                    case SWT.TRAVERSE_ARROW_NEXT:
                        event.doit = false;
                        break;
                    case SWT.TRAVERSE_TAB_NEXT:
                    case SWT.TRAVERSE_TAB_PREVIOUS:
                        event.doit = text.traverse(event.detail);
                        event.detail = SWT.TRAVERSE_NONE;
                        if (event.doit)
                            dropDown(false);
                        return;
                }
                Event e = new Event();
                e.time = event.time;
                e.detail = event.detail;
                e.doit = event.doit;
                e.character = event.character;
                e.keyCode = event.keyCode;
                notifyListeners(SWT.Traverse, e);
                event.doit = e.doit;
                event.detail = e.detail;
                break;
            }
        case SWT.KeyUp:
            {
                Event e = new Event();
                e.time = event.time;
                e.character = event.character;
                e.keyCode = event.keyCode;
                e.stateMask = event.stateMask;
                notifyListeners(SWT.KeyUp, e);
                break;
            }
        case SWT.KeyDown:
            {
                if (event.character == SWT.ESC) {
                    // Escape key cancels popup list
                    dropDown(false);
                }
                if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN)) {
                    dropDown(false);
                }
                if (event.character == SWT.CR) {
                    // // Enter causes default selection
                    // System.out.println("test");
                    // dropDown(false);
                    // Event e = new Event();
                    // e.time = event.time;
                    // e.stateMask = event.stateMask;
                    // notifyListeners(SWT.MouseDown, e);
                    int index = table.getSelectionIndex();
                    if (index == -1)
                        return;
                    // refresh the text.
                    refreshText(index);
                    // set the selection in the table.
                    table.setSelection(index);
                    Event e = new Event();
                    e.time = event.time;
                    e.stateMask = event.stateMask;
                    e.doit = event.doit;
                    notifyListeners(SWT.Selection, e);
                    event.doit = e.doit;
                }
                // If so, do not continue.
                if (isDisposed())
                    break;
                Event e = new Event();
                e.time = event.time;
                e.character = event.character;
                e.keyCode = event.keyCode;
                e.stateMask = event.stateMask;
                notifyListeners(SWT.KeyDown, e);
                break;
            }
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Event(org.eclipse.swt.widgets.Event) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) AccessibleTextEvent(org.eclipse.swt.accessibility.AccessibleTextEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 23 with TableItem

use of org.eclipse.swt.widgets.TableItem in project translationstudio8 by heartsome.

the class TableCombo method computeSize.

/**
	 * {@inheritDoc}
	 */
public Point computeSize(int wHint, int hHint, boolean changed) {
    checkWidget();
    int overallWidth = 0;
    int overallHeight = 0;
    int borderWidth = getBorderWidth();
    // use user defined values if they are specified.
    if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
        overallWidth = wHint;
        overallHeight = hHint;
    } else {
        TableItem[] tableItems = table.getItems();
        GC gc = new GC(text);
        //$NON-NLS-1$
        int spacer = gc.stringExtent(" ").x;
        int maxTextWidth = gc.stringExtent(text.getText()).x;
        int colIndex = getDisplayColumnIndex();
        int maxImageHeight = 0;
        int currTextWidth = 0;
        // calculate the maximum text width and image height.
        for (int i = 0; i < tableItems.length; i++) {
            currTextWidth = gc.stringExtent(tableItems[i].getText(colIndex)).x;
            // take image into account if there is one for the tableitem.
            if (tableItems[i].getImage() != null) {
                currTextWidth += tableItems[i].getImage().getBounds().width;
                maxImageHeight = Math.max(tableItems[i].getImage().getBounds().height, maxImageHeight);
            }
            maxTextWidth = Math.max(currTextWidth, maxTextWidth);
        }
        gc.dispose();
        Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
        Point arrowSize = arrow.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
        Point tableSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
        overallHeight = Math.max(textSize.y, arrowSize.y);
        overallHeight = Math.max(maxImageHeight, overallHeight);
        overallWidth = Math.max(maxTextWidth + 2 * spacer + arrowSize.x + 2 * borderWidth, tableSize.x);
        // use user specified if they were entered.
        if (wHint != SWT.DEFAULT)
            overallWidth = wHint;
        if (hHint != SWT.DEFAULT)
            overallHeight = hHint;
    }
    return new Point(overallWidth + 2 * borderWidth, overallHeight + 2 * borderWidth);
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 24 with TableItem

use of org.eclipse.swt.widgets.TableItem in project translationstudio8 by heartsome.

the class TableCombo method refreshText.

/**
	 * Refreshes the label control with the selected object's details.
	 */
private void refreshText(int index) {
    // get a reference to the selected TableItem
    TableItem tableItem = table.getItem(index);
    // get the TableItem index to use for displaying the text.
    int colIndexToUse = getDisplayColumnIndex();
    // set image if requested
    if (showImageWithinSelection) {
        // set the selected image
        selectedImage.setImage(tableItem.getImage(colIndexToUse));
        // refresh the layout of the widget
        internalLayout(false);
    }
    // set color if requested
    if (showColorWithinSelection) {
        text.setForeground(tableItem.getForeground(colIndexToUse));
    }
    // set font if requested
    if (showFontWithinSelection) {
        // set the selected font
        text.setFont(tableItem.getFont(colIndexToUse));
    }
    // set the label text.
    String str = tableItem.getText(colIndexToUse);
    text.setText(str);
    text.setData(index + "");
    // text.selectAll();
    text.setSelection(str.length(), str.length());
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point)

Example 25 with TableItem

use of org.eclipse.swt.widgets.TableItem in project translationstudio8 by heartsome.

the class TableCombo method indexOf.

/**
	 * Searches the receiver's list starting at the given, zero-relative index until an item is found that is equal to
	 * the argument, and returns the index of that item. If no item is found or the starting index is out of range,
	 * returns -1.
	 * @param string
	 *            the search item
	 * @param start
	 *            the zero-relative index at which to begin the search
	 * @return the index of the item
	 * @exception IllegalArgumentException
	 *                <ul>
	 *                <li>ERROR_NULL_ARGUMENT - if the string is null</li>
	 *                </ul>
	 * @exception SWTException
	 *                <ul>
	 *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
	 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
	 *                </ul>
	 */
public int indexOf(String string, int start) {
    checkWidget();
    if (string == null)
        SWT.error(SWT.ERROR_NULL_ARGUMENT);
    // get a list of the table items.
    TableItem[] tableItems = table.getItems();
    int totalItems = (tableItems == null ? 0 : tableItems.length);
    if (start < totalItems) {
        int colIndex = getDisplayColumnIndex();
        // now copy the display string from the tableitems.
        for (int index = start; index < totalItems; index++) {
            if (string.equals(tableItems[index].getText(colIndex))) {
                return index;
            }
        }
    }
    return -1;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point)

Aggregations

TableItem (org.eclipse.swt.widgets.TableItem)323 Point (org.eclipse.swt.graphics.Point)76 Table (org.eclipse.swt.widgets.Table)58 SelectionEvent (org.eclipse.swt.events.SelectionEvent)56 ArrayList (java.util.ArrayList)46 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)40 GridData (org.eclipse.swt.layout.GridData)40 Composite (org.eclipse.swt.widgets.Composite)34 HashMap (java.util.HashMap)33 GridLayout (org.eclipse.swt.layout.GridLayout)33 Map (java.util.Map)31 TableColumn (org.eclipse.swt.widgets.TableColumn)31 List (java.util.List)27 HashSet (java.util.HashSet)25 Rectangle (org.eclipse.swt.graphics.Rectangle)23 Button (org.eclipse.swt.widgets.Button)23 Label (org.eclipse.swt.widgets.Label)22 TreeItem (org.eclipse.swt.widgets.TreeItem)17 Constraint (com.cubrid.common.core.common.model.Constraint)16 TableEditor (org.eclipse.swt.custom.TableEditor)16