Search in sources :

Example 26 with GridItem

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);
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) Color(org.eclipse.swt.graphics.Color) Point(org.eclipse.swt.graphics.Point)

Example 27 with GridItem

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);
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 28 with GridItem

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;
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem)

Example 29 with GridItem

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);
        }
    }
}
Also used : TalendGridItem(org.eclipse.nebula.widgets.grid.TalendGridItem) GridItem(org.eclipse.nebula.widgets.grid.GridItem) TalendGridColumn(org.eclipse.nebula.widgets.grid.TalendGridColumn) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Point(org.eclipse.swt.graphics.Point)

Example 30 with GridItem

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);
        }
    }
}
Also used : TalendGridItem(org.eclipse.nebula.widgets.grid.TalendGridItem) GridItem(org.eclipse.nebula.widgets.grid.GridItem) IndicatorEnum(org.talend.dq.nodes.indicator.type.IndicatorEnum) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IIndicatorNode(org.talend.dq.nodes.indicator.IIndicatorNode) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Aggregations

GridItem (org.eclipse.nebula.widgets.grid.GridItem)69 Point (org.eclipse.swt.graphics.Point)46 Image (org.eclipse.swt.graphics.Image)20 TextLayout (org.eclipse.swt.graphics.TextLayout)17 GridColumn (org.eclipse.nebula.widgets.grid.GridColumn)16 Color (org.eclipse.swt.graphics.Color)12 Grid (org.eclipse.nebula.widgets.grid.Grid)9 TalendGridItem (org.eclipse.nebula.widgets.grid.TalendGridItem)8 Rectangle (org.eclipse.swt.graphics.Rectangle)8 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 DisposeListener (org.eclipse.swt.events.DisposeListener)6 ArrayList (java.util.ArrayList)5 TalendGridColumn (org.eclipse.nebula.widgets.grid.TalendGridColumn)5 Event (org.eclipse.swt.widgets.Event)5 Listener (org.eclipse.swt.widgets.Listener)5 SQLException (java.sql.SQLException)3 List (java.util.List)3 DBOperator (net.heartsome.cat.database.DBOperator)3 GridCellRenderer (org.eclipse.nebula.widgets.grid.GridCellRenderer)3 GC (org.eclipse.swt.graphics.GC)3