use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class DefaultRowHeaderRenderer method paint.
/**
* {@inheritDoc}
*/
public void paint(GC gc, Object value) {
GridItem item = (GridItem) value;
String text = getHeaderText(item);
gc.setFont(getDisplay().getSystemFont());
Color background = getHeaderBackground(item);
if (background == null) {
background = getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
}
gc.setBackground(background);
if (isSelected() && item.getParent().getCellSelectionEnabled()) {
gc.setBackground(item.getParent().getCellHeaderSelectionBackground());
}
gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height + 1);
if (!item.getParent().getCellSelectionEnabled()) {
if (isSelected()) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
} else {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
}
gc.drawLine(getBounds().x, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y);
gc.drawLine(getBounds().x, getBounds().y, getBounds().x, getBounds().y + getBounds().height - 1);
if (!isSelected()) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
gc.drawLine(getBounds().x + 1, getBounds().y + 1, getBounds().x + getBounds().width - 2, getBounds().y + 1);
gc.drawLine(getBounds().x + 1, getBounds().y + 1, getBounds().x + 1, getBounds().y + getBounds().height - 2);
}
if (isSelected()) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
} else {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
}
gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height - 1);
gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height - 1);
if (!isSelected()) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
gc.drawLine(getBounds().x + getBounds().width - 2, getBounds().y + 1, getBounds().x + getBounds().width - 2, getBounds().y + getBounds().height - 2);
gc.drawLine(getBounds().x + 1, getBounds().y + getBounds().height - 2, getBounds().x + getBounds().width - 2, getBounds().y + getBounds().height - 2);
}
} else {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height - 1);
gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height - 1);
}
int x = leftMargin;
Image image = getHeaderImage(item);
if (image != null) {
if (isSelected() && !item.getParent().getCellSelectionEnabled()) {
gc.drawImage(image, x + 1, getBounds().y + 1 + (getBounds().height - image.getBounds().height) / 2);
x += 1;
} else {
gc.drawImage(image, x, getBounds().y + (getBounds().height - image.getBounds().height) / 2);
}
x += image.getBounds().width + 5;
}
int width = getBounds().width - x;
width -= rightMargin;
Color foreground = getHeaderForeground(item);
if (foreground == null) {
foreground = getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
}
gc.setForeground(foreground);
int y = getBounds().y;
int selectionOffset = 0;
if (isSelected() && !item.getParent().getCellSelectionEnabled()) {
selectionOffset = 1;
}
if (!item.getParent().isWordWrapHeader()) {
y += (getBounds().height - gc.stringExtent(text).y) / 2;
gc.drawString(TextUtils.getShortString(gc, text, width), getBounds().x + x + selectionOffset, y + selectionOffset, true);
} else {
getTextLayout(gc, item);
textLayout.setWidth(width < 1 ? 1 : width);
textLayout.setText(text);
if (item.getParent().isAutoHeight()) {
// Look through all columns to get the max height needed for this item
int columnCount = item.getParent().getColumnCount();
int maxHeight = textLayout.getBounds().height + topMargin + bottomMargin;
for (int i = 0; i < columnCount; i++) {
GridColumn column = item.getParent().getColumn(i);
if (column.getWordWrap()) {
int height = column.getCellRenderer().computeSize(gc, column.getWidth(), SWT.DEFAULT, item).y;
maxHeight = Math.max(maxHeight, height);
}
}
if (maxHeight != item.getHeight()) {
item.setHeight(maxHeight);
}
}
textLayout.draw(gc, getBounds().x + x + selectionOffset, y + selectionOffset);
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class DefaultRowHeaderRenderer method computeSize.
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
String text = getHeaderText(item);
Image image = getHeaderImage(item);
int x = 0;
x += leftMargin;
if (image != null) {
x += image.getBounds().width + 5;
}
x += gc.stringExtent(text).x + rightMargin;
int y = 0;
y += topMargin;
if (image != null) {
y += Math.max(gc.getFontMetrics().getHeight(), image.getBounds().height);
} else {
y += gc.getFontMetrics().getHeight();
}
y += bottomMargin;
return new Point(x, y);
}
use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class DefaultCellRenderer method paint.
/**
* {@inheritDoc}
*/
public void paint(GC gc, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
boolean drawAsSelected = isSelected();
boolean drawBackground = true;
if (isCellSelected()) {
// (!isCellFocus());
drawAsSelected = true;
}
if (drawAsSelected) {
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
} else {
if (item.getParent().isEnabled()) {
Color back = item.getBackground(getColumn());
if (back != null) {
gc.setBackground(back);
} else {
drawBackground = false;
}
} else {
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
}
gc.setForeground(item.getForeground(getColumn()));
}
if (drawBackground)
gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height);
int x = leftMargin;
if (isTree()) {
boolean renderBranches = item.getParent().getTreeLinesVisible();
if (renderBranches) {
branchRenderer.setBranches(getBranches(item));
branchRenderer.setIndent(treeIndent);
branchRenderer.setBounds(getBounds().x + x, getBounds().y, getToggleIndent(item), // Take into account border
getBounds().height + 1);
}
x += getToggleIndent(item);
toggleRenderer.setExpanded(item.isExpanded());
toggleRenderer.setHover(getHoverDetail().equals("toggle"));
toggleRenderer.setLocation(getBounds().x + x, (getBounds().height - toggleRenderer.getBounds().height) / 2 + getBounds().y);
if (item.hasChildren())
toggleRenderer.paint(gc, null);
if (renderBranches) {
branchRenderer.setToggleBounds(toggleRenderer.getBounds());
branchRenderer.paint(gc, null);
}
x += toggleRenderer.getBounds().width + insideMargin;
}
if (isCheck()) {
checkRenderer.setChecked(item.getChecked(getColumn()));
checkRenderer.setGrayed(item.getGrayed(getColumn()));
if (!item.getParent().isEnabled()) {
checkRenderer.setGrayed(true);
}
checkRenderer.setHover(getHoverDetail().equals("check"));
if (isCenteredCheckBoxOnly(item)) {
// Special logic if this column only has a checkbox and is centered
checkRenderer.setBounds(getBounds().x + ((getBounds().width - checkRenderer.getBounds().width) / 2), (getBounds().height - checkRenderer.getBounds().height) / 2 + getBounds().y, checkRenderer.getBounds().width, checkRenderer.getBounds().height);
} else {
checkRenderer.setBounds(getBounds().x + x, (getBounds().height - checkRenderer.getBounds().height) / 2 + getBounds().y, checkRenderer.getBounds().width, checkRenderer.getBounds().height);
x += checkRenderer.getBounds().width + insideMargin;
}
checkRenderer.paint(gc, null);
}
Image image = item.getImage(getColumn());
if (image != null) {
int y = getBounds().y;
y += (getBounds().height - image.getBounds().height) / 2;
gc.drawImage(image, getBounds().x + x, y);
x += image.getBounds().width + insideMargin;
}
int width = getBounds().width - x - rightMargin;
if (drawAsSelected) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
} else {
gc.setForeground(item.getForeground(getColumn()));
}
if (!isWordWrap()) {
String text = TextUtils.getShortString(gc, item.getText(getColumn()), width);
if (getAlignment() == SWT.RIGHT) {
int len = gc.stringExtent(text).x;
if (len < width) {
x += width - len;
}
} else if (getAlignment() == SWT.CENTER) {
int len = gc.stringExtent(text).x;
if (len < width) {
x += (width - len) / 2;
}
}
gc.drawString(text, getBounds().x + x, getBounds().y + textTopMargin + topMargin, true);
} else {
if (textLayout == null) {
textLayout = new TextLayout(gc.getDevice());
item.getParent().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
textLayout.dispose();
}
});
}
textLayout.setFont(gc.getFont());
textLayout.setText(item.getText(getColumn()));
textLayout.setAlignment(getAlignment());
textLayout.setWidth(width < 1 ? 1 : width);
if (item.getParent().isAutoHeight()) {
// Look through all columns (except this one) to get the max height needed for this item
int columnCount = item.getParent().getColumnCount();
int maxHeight = textLayout.getBounds().height + textTopMargin + textBottomMargin;
for (int i = 0; i < columnCount; i++) {
GridColumn column = item.getParent().getColumn(i);
if (i != getColumn() && column.getWordWrap()) {
int height = column.getCellRenderer().computeSize(gc, column.getWidth(), SWT.DEFAULT, item).y;
maxHeight = Math.max(maxHeight, height);
}
}
// Also look at the row header if necessary
if (item.getParent().isWordWrapHeader()) {
int height = item.getParent().getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, item).y;
maxHeight = Math.max(maxHeight, height);
}
if (maxHeight != item.getHeight()) {
item.setHeight(maxHeight);
}
}
textLayout.draw(gc, getBounds().x + x, getBounds().y + textTopMargin + topMargin);
}
if (item.getParent().getLinesVisible()) {
if (isCellSelected()) {
// XXX: should be user definable?
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
} else {
gc.setForeground(item.getParent().getLineColor());
}
gc.drawLine(getBounds().x, getBounds().y + getBounds().height, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height);
gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height);
}
if (isCellFocus()) {
Rectangle focusRect = new Rectangle(getBounds().x, getBounds().y, getBounds().width - 1, getBounds().height);
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
gc.drawRectangle(focusRect);
if (isFocus()) {
focusRect.x++;
focusRect.width -= 2;
focusRect.y++;
focusRect.height -= 2;
gc.drawRectangle(focusRect);
}
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class GridTableViewer method doResetItem.
/**
* {@inheritDoc}
*/
protected void doResetItem(Item item) {
GridItem gridItem = (GridItem) item;
int columnCount = Math.max(1, grid.getColumnCount());
for (int i = 0; i < columnCount; i++) {
// $NON-NLS-1$
gridItem.setText(i, "");
gridItem.setImage(null);
}
}
Aggregations