use of org.eclipse.nebula.jface.gridviewer.internal.SelectionWithFocusRow in project translationstudio8 by heartsome.
the class GridTableViewer method getSelection.
/**
* {@inheritDoc}
*/
public ISelection getSelection() {
if (!grid.isCellSelectionEnabled()) {
IStructuredSelection selection = (IStructuredSelection) super.getSelection();
Object el = null;
if (grid.getFocusItem() != null) {
el = grid.getFocusItem().getData();
}
return new SelectionWithFocusRow(selection.toList(), el, getComparer());
} else {
return createCellSelection();
}
}
use of org.eclipse.nebula.jface.gridviewer.internal.SelectionWithFocusRow 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