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());
}
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;
}
}
}
}
}
Aggregations