use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class TdCellRenderer method paint.
/**
* {@inheritDoc}
*/
@Override
public void paint(GC gc, Object value) {
GridItem item = (GridItem) value;
gc.setAntialias(SWT.ON);
int column = getColumn();
boolean checkable = item.getCheckable(column);
boolean checked = item.getChecked(column);
// fill background rectangle
Color systemBackColor = getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
if (checkable) {
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
} else {
gc.setBackground(IndicatorSelectGrid.gray);
}
int originX = getBounds().x;
gc.fillRectangle(originX, getBounds().y, getBounds().width, getBounds().height);
if (checkable) {
// draw highlight color as background
Color highlight = item.getBackground(column);
if (highlight != null) {
gc.setBackground(highlight);
gc.fillRectangle(originX, getBounds().y, getBounds().width, getBounds().height);
}
if (checked) {
// draw background oval
int offset = (getBounds().width - getBounds().height);
gc.setBackground(IndicatorSelectGrid.blue);
gc.fillOval(originX + offset / 2 + 2, getBounds().y + 2, getBounds().width - offset - 4, getBounds().height - 4);
// draw a white oval for partially selected cells
if (item.getGrayed(column)) {
gc.setBackground(systemBackColor);
gc.setAlpha(160);
gc.fillOval(originX + offset / 2 + 2, getBounds().y + 2, getBounds().width - offset - 4, getBounds().height - 4);
gc.setAlpha(-1);
}
// draw tick image
if (highlight != null) {
gc.setForeground(highlight);
} else {
gc.setForeground(systemBackColor);
}
gc.setLineWidth(3);
gc.drawLine(originX + offset / 2 + 4, getBounds().y + 10, originX + offset / 2 + getBounds().height - 12, getBounds().y + 15);
gc.drawLine(originX + offset / 2 + 7, getBounds().y + 15, originX + offset / 2 + getBounds().height - 5, getBounds().y + 6);
gc.setLineWidth(1);
}
}
if (item.getParent().getLinesVisible()) {
gc.setForeground(item.getParent().getLineColor());
gc.drawLine(originX, getBounds().y + getBounds().height, originX + getBounds().width - 1, getBounds().y + getBounds().height);
gc.drawLine(originX + getBounds().width - 1, getBounds().y, originX + getBounds().width - 1, getBounds().y + getBounds().height);
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class TdRowHeaderRenderer 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;
}
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 TdRowHeaderRenderer method notify.
/**
* {@inheritDoc}
*/
public boolean notify(int event, Point point, Object value) {
GridItem item = (GridItem) value;
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;
}
use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class AbstractIndicatorSelectGrid method handleColumnHighlight.
protected void handleColumnHighlight(int columnIndex) {
GridColumn currentColumn = getColumn(columnIndex);
GridVisibleRange range = this.getVisibleRange();
if (currentColumn != null && !isDraggingColumn()) {
int currentColumnIndex = columnIndex;
for (GridItem item : range.getItems()) {
for (GridColumn column : range.getColumns()) {
int j = indexOf(column);
if (j == currentColumnIndex) {
item.setBackground(j, highlightBlue);
} else {
item.setBackground(j, getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
}
}
item.setBackground(0, gray);
item.setBackground(1, null);
}
for (GridColumn column : range.getColumns()) {
int j = indexOf(column);
column.getHeaderRenderer().setSelected(j == currentColumnIndex);
}
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.
the class AbstractIndicatorSelectGrid method tickCell.
private void tickCell(Point cell, boolean tick) {
if (!getItem(cell.y).getCheckable(cell.x)) {
return;
}
if (cell.x == 1) {
for (int i = 2; i < getColumnCount(); i++) {
tickCell(new Point(i, cell.y), tick);
}
}
getItem(cell.y).setChecked(cell.x, tick);
getItem(cell.y).setGrayed(cell.x, false);
IIndicatorNode indicatorNode = (IIndicatorNode) getItem(cell.y).getData();
IndicatorEnum indicatorEnum = indicatorNode.getIndicatorEnum();
ModelElementIndicator meIndicator = (ModelElementIndicator) getColumn(cell.x).getData();
if (meIndicator != null && indicatorEnum != null) {
if (tick) {
if (IndicatorEnum.isSpecialIndicatorEnum(indicatorEnum)) {
meIndicator.addTempSpecialIndicator(indicatorEnum, indicatorNode.createNewIndicatorInstance());
} else {
meIndicator.addTempIndicatorEnum(indicatorEnum);
}
} else {
if (IndicatorEnum.isSpecialIndicatorEnum(indicatorEnum)) {
meIndicator.removeTempSpecialIndicator(indicatorNode.getIndicatorInstance());
} else {
meIndicator.removeTempIndicatorEnum(indicatorEnum);
}
}
}
// select the entire indicator category
if (getItem(cell.y).hasChildren()) {
for (GridItem child : getItem(cell.y).getItems()) {
tickCell(new Point(cell.x, indexOf(child)), tick);
}
}
}
Aggregations