Search in sources :

Example 1 with CellSelection

use of org.eclipse.nebula.jface.gridviewer.internal.CellSelection in project translationstudio8 by heartsome.

the class GridTableViewer method createCellSelection.

private CellSelection createCellSelection() {
    Point[] ps = grid.getCellSelection();
    Arrays.sort(ps, new Comparator() {

        public int compare(Object arg0, Object arg1) {
            Point a = (Point) arg0;
            Point b = (Point) arg1;
            int rv = a.y - b.y;
            if (rv == 0) {
                rv = a.x - b.x;
            }
            return rv;
        }
    });
    ArrayList objectList = new ArrayList();
    ArrayList indiceLists = new ArrayList();
    ArrayList indiceList = new ArrayList();
    int curLine = -1;
    for (int i = 0; i < ps.length; i++) {
        if (curLine != ps[i].y) {
            curLine = ps[i].y;
            indiceList = new ArrayList();
            indiceLists.add(indiceList);
            objectList.add(grid.getItem(curLine).getData());
        }
        indiceList.add(new Integer(ps[i].x));
    }
    Object focusElement = null;
    if (grid.getFocusItem() != null) {
        focusElement = grid.getFocusItem().getData();
    }
    return new CellSelection(objectList, indiceLists, focusElement, getComparer());
}
Also used : ArrayList(java.util.ArrayList) CellSelection(org.eclipse.nebula.jface.gridviewer.internal.CellSelection) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Comparator(java.util.Comparator)

Example 2 with CellSelection

use of org.eclipse.nebula.jface.gridviewer.internal.CellSelection 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)

Aggregations

ArrayList (java.util.ArrayList)2 CellSelection (org.eclipse.nebula.jface.gridviewer.internal.CellSelection)2 Point (org.eclipse.swt.graphics.Point)2 Comparator (java.util.Comparator)1 Iterator (java.util.Iterator)1 List (java.util.List)1 SelectionWithFocusRow (org.eclipse.nebula.jface.gridviewer.internal.SelectionWithFocusRow)1 GridItem (org.eclipse.nebula.widgets.grid.GridItem)1