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