Search in sources :

Example 56 with GridItem

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

the class AbstractIndicatorSelectGrid method onMouseDown.

private void onMouseDown(MouseEvent e) {
    Point cell = getCell(new Point(e.x, e.y));
    if (cell != null) {
        boolean checked = getItem(cell.y).getChecked(cell.x);
        boolean grayed = getItem(cell.y).getGrayed(cell.x);
        tickCell(cell, !checked || grayed);
        GridItem parent = getItem(cell.y);
        while (parent.getParentItem() != null) {
            parent = parent.getParentItem();
        }
        processNodeSelection(null, parent);
    } else {
        GridItem item = getItem(new Point(e.x, e.y));
        if (e.button == 1 && item != null) {
            if (overRowSelect(item, new Point(e.x, e.y))) {
                boolean rowChecked = item.getChecked(1);
                boolean rowGrayed = item.getGrayed(1);
                tickCell(new Point(1, getIndexOfItem(item)), !rowChecked || rowGrayed);
                GridItem parent = item;
                while (parent.getParentItem() != null) {
                    parent = parent.getParentItem();
                }
                processNodeSelection(null, parent);
                if (item.getParentItem() == null && rowChecked && !rowGrayed) {
                    item.setExpanded(false);
                }
            } else {
                if (item.hasChildren()) {
                    item.setExpanded(!item.isExpanded());
                }
                TdRowHeaderRenderer renderer = ((TdRowHeaderRenderer) getRowHeaderRenderer());
                // Move into row select cell
                e.x = renderer.getSize().x - 1;
                onMouseMove(e);
                _dialog.updateIndicatorInfo(item);
                if (item.getParentItem() == null) {
                    redrawTable();
                }
            }
        }
    }
}
Also used : TalendGridItem(org.eclipse.nebula.widgets.grid.TalendGridItem) GridItem(org.eclipse.nebula.widgets.grid.GridItem) Point(org.eclipse.swt.graphics.Point)

Example 57 with GridItem

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

the class AbstractIndicatorSelectGrid method processNodeSelection.

/**
 * recursively check if a entire row/column is selected/
 *
 * @param grid
 * @param parentItem
 * @param currentItem
 */
void processNodeSelection(GridItem parentItem, GridItem currentItem) {
    if (currentItem.hasChildren()) {
        // declare and initialize variables
        Boolean[] allCheckedInColumn = new Boolean[getColumnCount()];
        Boolean[] hasCheckedInColumn = new Boolean[getColumnCount()];
        for (int j = 1; j < getColumnCount(); j++) {
            allCheckedInColumn[j] = true;
            hasCheckedInColumn[j] = false;
        }
        for (int i = 0; i < currentItem.getItemCount(); i++) {
            GridItem childItem = currentItem.getItem(i);
            // process the children of current item, this must be done before handling the current item
            processNodeSelection(currentItem, childItem);
            boolean allCheckedInRow = true;
            boolean hasCheckedInRow = false;
            boolean expanded = false;
            for (int j = 2; j < getColumnCount(); j++) {
                if (childItem.getChecked(j)) {
                    hasCheckedInRow = true;
                    hasCheckedInColumn[j] = true;
                    expanded = true;
                    if (childItem.getGrayed(j)) {
                        allCheckedInRow = false;
                        allCheckedInColumn[j] = false;
                    }
                } else {
                    if (childItem.getCheckable(j)) {
                        allCheckedInRow = false;
                        allCheckedInColumn[j] = false;
                    }
                }
            }
            childItem.setChecked(1, hasCheckedInRow);
            childItem.setGrayed(1, hasCheckedInRow && !allCheckedInRow);
            if (expanded) {
                currentItem.setExpanded(true);
            }
        }
        // process the selections of indicator category row
        boolean entireCategoryChecked = true;
        for (int j = 2; j < getColumnCount(); j++) {
            if (currentItem.getCheckable(j)) {
                if (hasCheckedInColumn[j]) {
                    hasCheckedInColumn[1] = true;
                    currentItem.setChecked(j, true);
                } else {
                    currentItem.setChecked(j, false);
                }
                if (!allCheckedInColumn[j]) {
                    currentItem.setGrayed(j, hasCheckedInColumn[j]);
                    entireCategoryChecked = false;
                } else {
                    currentItem.setGrayed(j, false);
                }
                // are selected
                if (hasCheckedInColumn[j] && allCheckedInColumn[j]) {
                    IIndicatorNode indicatorNode = (IIndicatorNode) currentItem.getData();
                    IndicatorEnum indicatorEnum = indicatorNode.getIndicatorEnum();
                    ModelElementIndicator meIndicator = (ModelElementIndicator) getColumn(j).getData();
                    if (indicatorEnum != null && meIndicator != null && (indicatorEnum == IndicatorEnum.RangeIndicatorEnum || indicatorEnum == IndicatorEnum.IQRIndicatorEnum)) {
                        meIndicator.addTempIndicatorEnum(indicatorEnum);
                    }
                }
            }
        }
        if (currentItem.getCheckable(1)) {
            currentItem.setChecked(1, hasCheckedInColumn[1]);
            currentItem.setGrayed(1, hasCheckedInColumn[1] && !entireCategoryChecked);
        }
    }
}
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) IIndicatorNode(org.talend.dq.nodes.indicator.IIndicatorNode) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Example 58 with GridItem

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

the class AbstractIndicatorSelectGrid method handleCellHighlight.

// private boolean handleMouseScroll(MouseEvent e) {
// if (e.x > getRowHeaderWidth() && e.x < getRowHeaderWidth() + 150) {
// ScrollBar hScrollBar = getHorizontalBar();
// if (hScrollBar.getSelection() == hScrollBar.getMinimum()) {
// return false;
// }
// if (!isScrolling && e.x < getRowHeaderWidth() + 100) {
// isScrolling = true;
// thread = new HoverScrollThread(-1, hScrollBar);
// Display.getDefault().timerExec(200, thread);
// handleCellHighlight(e, getVisibleRange());
// }
// if (isScrolling) {
// thread.setAccelaration(getRowHeaderWidth() + 150 - e.x);
// startColumnIndex = -1;
// endColumnIndex = -1;
// return true;
// }
// } else if (e.x > getBounds().width - 150 && e.x < getBounds().width) {
// ScrollBar hScrollBar = getHorizontalBar();
// if (!isScrolling && e.x > getBounds().width - 100) {
// isScrolling = true;
// thread = new HoverScrollThread(1, hScrollBar);
// Display.getDefault().timerExec(200, thread);
// handleCellHighlight(e, getVisibleRange());
// }
// if (isScrolling) {
// thread.setAccelaration(e.x + 150 - getBounds().width);
// startColumnIndex = -1;
// endColumnIndex = -1;
// return true;
// }
// } else {
// if (isScrolling) {
// isScrolling = false;
// Display.getDefault().timerExec(-1, thread); // interrupt the thread
// }
// }
// return false;
// }
private boolean handleCellHighlight(MouseEvent e, GridVisibleRange range) {
    Point cell = getCell(new Point(e.x, e.y));
    if (cell != null) {
        // any cell except the row select cells
        List<GridColumn> columnList = Arrays.asList(range.getColumns());
        // replace cell.x with the current position in case the column has been moved.
        cell.x = columnList.indexOf(getColumn(cell.x)) + 2;
        for (GridItem item : range.getItems()) {
            int i = indexOf(item);
            // set background for row headers
            if (i == cell.y) {
                item.setBackground(0, highlightBlue);
                item.setBackground(1, highlightBlue);
            } else {
                item.setBackground(0, gray);
                item.setBackground(1, getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
                if (item.getCheckable(1)) {
                    item.setBackground(highlightBlue);
                }
            }
            // set background for cells
            for (GridColumn column : range.getColumns()) {
                // real index in current visible range.
                int realIdx = columnList.indexOf(column) + 2;
                // the original index to be colored.
                int j = indexOf(column);
                if (i == cell.y && realIdx == cell.x) {
                    item.setBackground(j, highlightBlue);
                } else if (i == cell.y && realIdx < cell.x || realIdx == cell.x && i < cell.y) {
                    item.setBackground(j, highlightBlue);
                } else {
                    item.setBackground(j, null);
                }
            }
        }
        // set background for column headers
        for (GridColumn column : range.getColumns()) {
            // real index in current visible range.
            int realIdx = columnList.indexOf(column) + 2;
            column.getHeaderRenderer().setSelected(realIdx == cell.x);
        }
        return true;
    }
    return false;
}
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) Point(org.eclipse.swt.graphics.Point)

Example 59 with GridItem

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

the class AbstractIndicatorSelectGrid method handleRowHeaderHighlight.

private boolean handleRowHeaderHighlight(MouseEvent e, GridVisibleRange range) {
    GridItem currentItem = getItem(new Point(e.x, e.y));
    if (currentItem != null) {
        // row header
        if (overRowSelect(currentItem, new Point(e.x, e.y))) {
            // handle hover event of row select cell
            for (GridItem item : range.getItems()) {
                int i = indexOf(item);
                if (item.getCheckable(0)) {
                    if (i == indexOf(currentItem)) {
                        item.setBackground(0, highlightBlue);
                        item.setBackground(1, highlightBlue);
                    } else {
                        item.setBackground(0, gray);
                        item.setBackground(1, getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
                    }
                }
                for (GridColumn column : range.getColumns()) {
                    int j = indexOf(column);
                    if (i == indexOf(currentItem)) {
                        item.setBackground(j, highlightBlue);
                    } else {
                        item.setBackground(j, getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
                    }
                }
            }
            for (GridColumn column : range.getColumns()) {
                column.getHeaderRenderer().setSelected(false);
            }
        }
        return true;
    }
    return false;
}
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) Point(org.eclipse.swt.graphics.Point)

Example 60 with GridItem

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

the class AbstractTdCellRenderer method paint.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.nebula.widgets.grid.IRenderer#paint(org.eclipse.swt.graphics.GC, java.lang.Object)
     */
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);
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    int originX = getBounds().x;
    gc.fillRectangle(originX, getBounds().y, getBounds().width, getBounds().height);
    // 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);
    }
    // draw text
    int x = 0;
    int width = getBounds().width;
    String text = 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.setForeground(Black);
    gc.drawString(text, getBounds().x + x, getBounds().y + textTopMargin + topMargin, true);
    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)

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