Search in sources :

Example 41 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class GridTableViewer method refreshRowHeaders.

/**
	 * Refresh row headers only
	 * 
	 * @param element
	 *            the element to start or <code>null</code> if all rows should
	 *            be refreshed
	 */
public void refreshRowHeaders(Object element) {
    boolean refresh = element == null;
    GridItem[] items = getGrid().getItems();
    for (int i = 0; i < items.length; i++) {
        if (refresh || element.equals(items[i].getData())) {
            refresh = true;
            updateRowHeader(items[i]);
        }
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) Point(org.eclipse.swt.graphics.Point)

Example 42 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class GridTableViewer method doSetSelection.

/** {@inheritDoc} */
protected void doSetSelection(Item[] items) {
    GridItem[] items2 = new GridItem[items.length];
    for (int i = 0; i < items.length; i++) {
        items2[i] = (GridItem) items[i];
    }
    grid.setSelection(items2);
    grid.showSelection();
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) Point(org.eclipse.swt.graphics.Point)

Example 43 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class GridTableViewer method setSelectionToWidget.

/**
	 * {@inheritDoc}
	 */
protected void setSelectionToWidget(ISelection selection, boolean reveal) {
    if (!grid.isCellSelectionEnabled() || !(selection instanceof CellSelection)) {
        super.setSelectionToWidget(selection, reveal);
        if (selection instanceof SelectionWithFocusRow) {
            Object el = ((SelectionWithFocusRow) selection).getFocusElement();
            if (el != null) {
                GridItem[] items = grid.getItems();
                for (int i = 0; i < items.length; i++) {
                    GridItem item = items[i];
                    if (item.getData() == el || item.getData().equals(el) || (getComparer() != null && getComparer().equals(item.getData(), el))) {
                        grid.setFocusItem(item);
                        break;
                    }
                }
            }
        }
    } else {
        CellSelection cellSelection = (CellSelection) selection;
        List l = cellSelection.toList();
        GridItem[] items = grid.getItems();
        ArrayList pts = new ArrayList();
        for (int i = 0; i < items.length; i++) {
            Iterator it = l.iterator();
            Object itemObject = items[i].getData();
            while (it.hasNext()) {
                Object checkObject = it.next();
                if (itemObject == checkObject || (getComparer() != null && getComparer().equals(itemObject, checkObject))) {
                    Iterator idxIt = cellSelection.getIndices(checkObject).iterator();
                    while (idxIt.hasNext()) {
                        Integer idx = (Integer) idxIt.next();
                        pts.add(new Point(idx.intValue(), i));
                    }
                }
            }
        }
        Point[] tmp = new Point[pts.size()];
        pts.toArray(tmp);
        grid.setCellSelection(tmp);
        if (cellSelection.getFocusElement() != null) {
            Object el = cellSelection.getFocusElement();
            for (int i = 0; i < items.length; i++) {
                GridItem item = items[i];
                if (item.getData() == el || item.getData().equals(el) || (getComparer() != null && getComparer().equals(item.getData(), el))) {
                    grid.setFocusItem(item);
                    break;
                }
            }
        }
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) CellSelection(org.eclipse.nebula.jface.gridviewer.internal.CellSelection) SelectionWithFocusRow(org.eclipse.nebula.jface.gridviewer.internal.SelectionWithFocusRow) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 44 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class GridViewerColumn method setEditingSupport.

/** {@inheritDoc} */
public void setEditingSupport(EditingSupport editingSupport) {
    if (editingSupport instanceof CheckEditingSupport) {
        if (checkEditingSupport == null) {
            final int colIndex = getColumn().getParent().indexOf(getColumn());
            getColumn().getParent().addListener(SWT.Selection, new Listener() {

                public void handleEvent(Event event) {
                    if (event.detail == SWT.CHECK && event.index == colIndex) {
                        GridItem item = (GridItem) event.item;
                        Object element = item.getData();
                        checkEditingSupport.setValue(element, new Boolean(item.getChecked(colIndex)));
                    }
                }
            });
        }
        checkEditingSupport = (CheckEditingSupport) editingSupport;
    } else {
        super.setEditingSupport(editingSupport);
    }
}
Also used : Listener(org.eclipse.swt.widgets.Listener) GridItem(org.eclipse.nebula.widgets.grid.GridItem) Event(org.eclipse.swt.widgets.Event)

Example 45 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class GridCopyEnable method doMouseLocationChange.

void doMouseLocationChange(int x, int y, boolean select) {
    if (gridTable.getItems().length == 0) {
        defaultCaret.setVisible(false);
        return;
    }
    Point eventP = new Point(x, y);
    GridItem _focusItem = gridTable.getItem(eventP);
    GridColumn col = gridTable.getColumn(eventP);
    if (_focusItem == null) {
        return;
    }
    GridCellRenderer gcr = col.getCellRenderer();
    int colIndex = gcr.getColumn();
    if (gcr == null || !(gcr instanceof XGridCellRenderer) || !copyAbleColumnIndexs.contains(colIndex)) {
        return;
    }
    XGridCellRenderer cellRender = (XGridCellRenderer) gcr;
    Rectangle cellBounds = _focusItem.getBounds(colIndex);
    GC gc = new GC(Display.getDefault());
    layout = cellRender.getTextLayout(gc, _focusItem, colIndex, true, false);
    if (layout == null) {
        gc.dispose();
        return;
    }
    focusContent = layout.getText();
    coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
    coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
    if (!select) {
        focusCellRect.x = cellBounds.x;
        focusCellRect.y = cellBounds.y;
        focusCellRect.height = cellBounds.height;
        focusCellRect.width = cellBounds.width;
        focusColIndex = colIndex;
        focusItemIndex = gridTable.getIndexOfItem(_focusItem);
    }
    int[] trailing = new int[1];
    int newCaretOffset = layout.getOffset(x - coordinateOffsetX, y - coordinateOffsetY, trailing);
    int newCaretLine = layout.getLineIndex(newCaretOffset + trailing[0]);
    int lineStart = layout.getLineOffsets()[newCaretLine];
    Point point = null;
    if (newCaretOffset + trailing[0] == lineStart && trailing[0] != 0) {
        newCaretOffset += trailing[0];
        newCaretOffset = layout.getPreviousOffset(newCaretOffset, SWT.MOVEMENT_CLUSTER);
        point = layout.getLocation(newCaretOffset, true);
    } else {
        newCaretOffset += trailing[0];
        point = layout.getLocation(newCaretOffset, false);
    }
    // check area, only in cell area effective
    boolean vchange = focusCellRect.y <= y && y < focusCellRect.y + focusCellRect.height;
    boolean hchange = focusCellRect.x <= x && x < focusCellRect.x + focusCellRect.width;
    if (vchange && hchange && newCaretOffset != caretOffset) {
        focusItem = _focusItem;
        caretOffset = newCaretOffset;
        if (select) {
            doMouseSelection();
        }
        defaultCaret.setVisible(true);
        Rectangle rc = layout.getLineBounds(newCaretLine);
        defaultCaret.setBounds(point.x + coordinateOffsetX, point.y + coordinateOffsetY, 0, rc.height);
    }
    if (!select) {
        caretOffset = newCaretOffset;
        clearSelection();
    }
    layout.dispose();
    layout = null;
    gc.dispose();
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridCellRenderer(org.eclipse.nebula.widgets.grid.GridCellRenderer) Rectangle(org.eclipse.swt.graphics.Rectangle) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Aggregations

GridItem (org.eclipse.nebula.widgets.grid.GridItem)69 Point (org.eclipse.swt.graphics.Point)46 Image (org.eclipse.swt.graphics.Image)20 TextLayout (org.eclipse.swt.graphics.TextLayout)17 GridColumn (org.eclipse.nebula.widgets.grid.GridColumn)16 Color (org.eclipse.swt.graphics.Color)12 Grid (org.eclipse.nebula.widgets.grid.Grid)9 TalendGridItem (org.eclipse.nebula.widgets.grid.TalendGridItem)8 Rectangle (org.eclipse.swt.graphics.Rectangle)8 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 DisposeListener (org.eclipse.swt.events.DisposeListener)6 ArrayList (java.util.ArrayList)5 TalendGridColumn (org.eclipse.nebula.widgets.grid.TalendGridColumn)5 Event (org.eclipse.swt.widgets.Event)5 Listener (org.eclipse.swt.widgets.Listener)5 SQLException (java.sql.SQLException)3 List (java.util.List)3 DBOperator (net.heartsome.cat.database.DBOperator)3 GridCellRenderer (org.eclipse.nebula.widgets.grid.GridCellRenderer)3 GC (org.eclipse.swt.graphics.GC)3