Search in sources :

Example 61 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.

the class TdCellRenderer method computeSize.

/**
 * {@inheritDoc}
 */
@Override
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 (isCheck()) {
        x += 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;
    }
    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)

Example 62 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.

the class TdRowHeaderRenderer method paint.

/**
 * {@inheritDoc}
 */
public void paint(GC gc, Object value) {
    GridItem item = (GridItem) value;
    gc.setFont(item.getFont(getColumn()));
    if (item.getParent().isEnabled()) {
        Color back = item.getBackground(getColumn());
        if (back != null) {
            gc.setBackground(back);
        }
    } else {
        gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    }
    gc.setForeground(item.getForeground(getColumn()));
    gc.fillRectangle(getBounds());
    int x = leftMargin;
    if (isTree()) {
        boolean renderBranches = item.getParent().getTreeLinesVisible();
        if (renderBranches) {
            branchRenderer.setBranches(getBranches(item));
            branchRenderer.setIndent(treeIndent);
            // Take
            branchRenderer.setBounds(getBounds().x + x, getBounds().y, getToggleIndent(item), getBounds().height + 1);
        // into
        // account
        // border
        }
        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;
    }
    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;
    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);
    }
    boolean checkable = item.getCheckable(1);
    boolean checked = item.getChecked(1);
    // 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 + getBounds().width - 50;
    gc.fillRectangle(originX, getBounds().y, 50, getBounds().height);
    // show row select cells
    if (checkable) {
        // draw highlight color as background
        Color highlight = item.getBackground(1);
        if (highlight != null) {
            gc.setBackground(highlight);
            gc.fillRectangle(originX, getBounds().y, 50, getBounds().height);
        }
        if (checked) {
            // draw background oval
            int offset = 50 - getBounds().height;
            gc.setBackground(IndicatorSelectGrid.blue);
            gc.fillOval(originX + offset / 2 + 2, getBounds().y + 2, 50 - offset - 4, getBounds().height - 4);
            // draw a white oval for partially selected cells
            if (item.getGrayed(1)) {
                gc.setBackground(systemBackColor);
                gc.setAlpha(160);
                gc.fillOval(originX + offset / 2 + 2, getBounds().y + 2, 50 - 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 + 18, getBounds().y + 10, originX + 23, getBounds().y + 15);
            gc.drawLine(originX + 21, getBounds().y + 15, originX + 30, getBounds().y + 6);
            gc.setLineWidth(1);
        }
    }
    if (item.getParent().getLinesVisible()) {
        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 - 51, getBounds().y, getBounds().x + getBounds().width - 51, getBounds().y + getBounds().height);
        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);
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) GridItem(org.eclipse.nebula.widgets.grid.GridItem) Color(org.eclipse.swt.graphics.Color) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Image(org.eclipse.swt.graphics.Image) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 63 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.

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

Example 64 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.

the class DefaultEmptyCellRenderer method paint.

/**
 * {@inheritDoc}
 */
public void paint(GC gc, Object value) {
    Grid table = null;
    if (value instanceof Grid)
        table = (Grid) value;
    GridItem item;
    if (value instanceof GridItem) {
        item = (GridItem) value;
        table = item.getParent();
    }
    boolean drawBackground = true;
    if (isSelected()) {
        gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
        gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
    } else {
        if (table.isEnabled()) {
            drawBackground = false;
        } else {
            gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        }
        gc.setForeground(table.getForeground());
    }
    if (drawBackground)
        gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width + 1, getBounds().height);
    if (table.getLinesVisible()) {
        gc.setForeground(table.getLineColor());
        gc.drawLine(getBounds().x, getBounds().y + getBounds().height, getBounds().x + getBounds().width, getBounds().y + getBounds().height);
        gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height);
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) Grid(org.eclipse.nebula.widgets.grid.Grid)

Example 65 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project tdq-studio-se by Talend.

the class DefaultFocusRenderer method paint.

/**
 * {@inheritDoc}
 */
public void paint(GC gc, Object value) {
    GridItem item = (GridItem) value;
    if (item.getParent().isSelected(item)) {
        gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
        gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
    } else {
        gc.setBackground(item.getBackground());
        gc.setForeground(item.getForeground());
    }
    gc.drawFocus(getBounds().x, getBounds().y, getBounds().width + 1, getBounds().height + 1);
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem)

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