use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class GridCopyEnable method clearSelection.
void clearSelection() {
int start = selection.x;
int end = selection.y;
selection.x = selection.y = caretOffset;
selectionAnchor = -1;
// redraw old selection, if any
if (end - start > 0 && gridTable.getItems().length != 0) {
if (layout == null && focusItemIndex != -1 && focusItemIndex != -1) {
GridItem item = gridTable.getItem(focusItemIndex);
GridColumn col = gridTable.getColumn(focusColIndex);
GridCellRenderer gcr = col.getCellRenderer();
if (gcr != null && gcr instanceof XGridCellRenderer) {
GC gc = new GC(gcr.getDisplay());
layout = ((XGridCellRenderer) gcr).getTextLayout(gc, item, focusColIndex, true, false);
gc.dispose();
}
if (layout == null) {
return;
}
}
Rectangle rect = layout.getBounds(start, end);
gridTable.redraw(rect.x + coordinateOffsetX, rect.y + coordinateOffsetY, rect.width, rect.height, false);
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class GridCopyEnable method handleVerticalScroll.
void handleVerticalScroll(Event event) {
GridVisibleRange visibleR = gridTable.getVisibleRange();
GridItem[] items = visibleR.getItems();
boolean itemFlg = false;
for (GridItem item : items) {
if (focusItem == item) {
itemFlg = true;
}
}
boolean columnFlg = false;
GridColumn[] columns = visibleR.getColumns();
if (columns.length - 1 >= focusColIndex) {
columnFlg = true;
}
if (!itemFlg || !columnFlg) {
defaultCaret.setVisible(false);
return;
}
defaultCaret.setVisible(true);
GridColumn col = gridTable.getColumn(focusColIndex);
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());
TextLayout layout = null;
try {
layout = cellRender.getTextLayout(gc, focusItem, colIndex, true, false);
if (layout == null) {
gc.dispose();
return;
}
Point point = layout.getLocation(caretOffset, false);
coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
defaultCaret.setLocation(point.x + coordinateOffsetX, point.y + coordinateOffsetY);
} finally {
if (layout != null) {
layout.dispose();
}
if (gc != null) {
gc.dispose();
}
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class DefaultCellRenderer method computeSize.
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
int x = 0;
x += leftMargin;
if (isTree()) {
x += getToggleIndent(item);
x += toggleRenderer.getBounds().width + insideMargin;
}
if (isCheck()) {
x += checkRenderer.getBounds().width + insideMargin;
}
int y = 0;
Image image = item.getImage(getColumn());
if (image != null) {
y = topMargin + image.getBounds().height + bottomMargin;
x += image.getBounds().width + insideMargin;
}
// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
// x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:
int textHeight = 0;
if (!isWordWrap()) {
x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = gc.textExtent(item.getText(getColumn())).x;
else
plainTextWidth = wHint - x - rightMargin;
TextLayout currTextLayout = new TextLayout(gc.getDevice());
currTextLayout.setFont(gc.getFont());
currTextLayout.setText(item.getText(getColumn()));
currTextLayout.setAlignment(getAlignment());
currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
textHeight += topMargin + textTopMargin;
for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++) textHeight += currTextLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
currTextLayout.dispose();
}
y = Math.max(y, textHeight);
return new Point(x, y);
}
use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class DefaultCellRenderer method getBranches.
/**
* Calculates the sequence of branch lines which should be rendered for the provided item
* @param item
* @return an array of integers composed using the constants in {@link BranchRenderer}
*/
private int[] getBranches(GridItem item) {
int[] branches = new int[item.getLevel() + 1];
GridItem[] roots = item.getParent().getRootItems();
// Is this a node or a leaf?
if (item.getParentItem() == null) {
// Add descender if not last item
if (!item.isExpanded() && roots[roots.length - 1].equals(item)) {
if (item.hasChildren())
branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
else
branches[item.getLevel()] = BranchRenderer.SMALL_L;
} else {
if (item.hasChildren())
branches[item.getLevel()] = BranchRenderer.ROOT;
else
branches[item.getLevel()] = BranchRenderer.SMALL_T;
}
} else if (item.hasChildren())
if (item.isExpanded())
branches[item.getLevel()] = BranchRenderer.NODE;
else
branches[item.getLevel()] = BranchRenderer.NONE;
else
branches[item.getLevel()] = BranchRenderer.LEAF;
// Branch for current item
GridItem parent = item.getParentItem();
if (parent == null)
return branches;
// Are there siblings below this item?
if (parent.indexOf(item) < parent.getItemCount() - 1)
branches[item.getLevel() - 1] = BranchRenderer.T;
else // Is the next node a root?
if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
branches[item.getLevel() - 1] = BranchRenderer.T;
else
// This must be the last element at this level
branches[item.getLevel() - 1] = BranchRenderer.L;
Grid grid = item.getParent();
item = parent;
parent = item.getParentItem();
// Branches for parent items
while (item.getLevel() > 0) {
if (parent.indexOf(item) == parent.getItemCount() - 1) {
if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
branches[item.getLevel() - 1] = BranchRenderer.I;
else
branches[item.getLevel() - 1] = BranchRenderer.NONE;
} else
branches[item.getLevel() - 1] = BranchRenderer.I;
item = parent;
parent = item.getParentItem();
}
// item should be null at this point
return branches;
}
use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class DefaultCellRenderer method notify.
/**
* {@inheritDoc}
*/
public boolean notify(int event, Point point, Object value) {
GridItem item = (GridItem) value;
if (isCheck()) {
if (event == IInternalWidget.MouseMove) {
if (overCheck(item, point)) {
setHoverDetail("check");
return true;
}
}
if (event == IInternalWidget.LeftMouseButtonDown) {
if (overCheck(item, point)) {
if (!item.getCheckable(getColumn())) {
return false;
}
item.setChecked(getColumn(), !item.getChecked(getColumn()));
item.getParent().redraw();
item.fireCheckEvent(getColumn());
return true;
}
}
}
if (isTree() && item.hasChildren()) {
if (event == IInternalWidget.MouseMove) {
if (overToggle(item, point)) {
setHoverDetail("toggle");
return true;
}
}
if (event == IInternalWidget.LeftMouseButtonDown) {
if (overToggle(item, point)) {
item.setExpanded(!item.isExpanded());
item.getParent().redraw();
if (item.isExpanded()) {
item.fireEvent(SWT.Expand);
} else {
item.fireEvent(SWT.Collapse);
}
return true;
}
}
}
return false;
}
Aggregations