Search in sources :

Example 51 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class CellRenderer 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;
    }
    if (isCheck()) {
        x += checkRenderer.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 = getBounds().width - x - rightMargin;
        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 52 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class CellRenderer method notify.

/**
	 * {@inheritDoc}
	 */
public boolean notify(int event, Point point, Object value) {
    GridItem item = (GridItem) value;
    if (isCheck()) {
        if (event == IInternalWidget.MouseMove) {
            if (overCheck(item, point)) {
                setHoverDetail("check");
                return true;
            }
        }
        if (event == IInternalWidget.LeftMouseButtonDown) {
            if (overCheck(item, point)) {
                if (!item.getCheckable(getColumn())) {
                    return false;
                }
                item.setChecked(getColumn(), !item.getChecked(getColumn()));
                item.getParent().redraw();
                item.fireCheckEvent(getColumn());
                return true;
            }
        }
    }
    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 53 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class CellRenderer 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_BLACK));
        gc.setBackground((Color) item.getParent().getData("selectedBgColor"));
    } 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;
    }
    if (drawAsSelected) {
    // gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
    } else {
        gc.setForeground(item.getForeground(getColumn()));
    }
    if (!isWordWrap()) {
        int width = getBounds().width - x - rightMargin;
        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 {
        TextLayout layout = getTextLayout(gc, item, getColumn(), true, true);
        try {
            int y = getBounds().y + textTopMargin + topMargin;
            y += getVerticalAlignmentAdjustment(layout.getBounds().height, getBounds().height);
            if (item.getParent().isAutoHeight()) {
                int textHeight = topMargin + textTopMargin;
                // fix Bug #3116 库匹配面板--显示的匹配有截断 by Jason
                // for (int cnt = 0; cnt < layout.getLineCount(); cnt++)
                // textHeight += layout.getLineBounds(cnt).height;
                textHeight += layout.getBounds().height;
                Object obj = item.getData("itemHeight");
                if (getColumn() != item.getParent().getColumnCount() - 1) {
                    if (obj != null) {
                        int heigth = (Integer) obj;
                        textHeight = Math.max(textHeight, heigth);
                    }
                    item.setData("itemHeight", textHeight);
                } else {
                    int heigth = (Integer) obj;
                    textHeight = Math.max(textHeight, heigth);
                    if (textHeight != item.getHeight()) {
                        item.setHeight(textHeight);
                    }
                    item.setData("itemHeight", null);
                }
            }
            x = getBounds().x + leftMargin;
            if (copyEnable != null) {
                // Point selection = copyEnable.getSelectionRange(getColumn(), getRow() - 1 );
                Point selection = copyEnable.getSelectionRange(getColumn(), item);
                if (selection == null || selection.x == selection.y) {
                    layout.draw(gc, x, y);
                } else {
                    int start = Math.max(0, selection.x);
                    int end = Math.min(layout.getText().length(), selection.y);
                    layout.draw(gc, x, y, start, end - 1, getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT), getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
                    attachInnertTagStyle(gc, layout, true);
                }
            } else {
                layout.draw(gc, x, y);
            }
        } finally {
            layout.dispose();
        }
    }
    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);
        }
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) 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 54 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class TermViewerBodyMenu method deleteSelectTerm.

void deleteSelectTerm() {
    IProject project = getCurentProject();
    if (null == project) {
        // show some msg here
        return;
    }
    DBOperator dbOperator = getDbOperator(project);
    if (null == dbOperator) {
        // show error msg here
        MessageDialog.openInformation(this.termView.getSite().getShell(), Messages.getString("handler.AddTermToTBHandler.msgTitle"), Messages.getString("handler.AddTermToTBHandler.msg"));
        return;
    }
    GridItem selectItem = getSelectItem();
    if (null == selectItem) {
        // show some msg here
        return;
    }
    try {
        dbOperator.start();
        dbOperator.beginTransaction();
        Object id = selectItem.getData("DBID");
        if (id instanceof String) {
            String termId = (String) id;
            dbOperator.deleteTermEntry(termId, getSrcLang(), getTgtLang());
        }
        dbOperator.commit();
    } catch (SQLException e) {
        MessageDialog.openInformation(this.termView.getSite().getShell(), Messages.getString("view.TerminologyViewPart.action.msg"), Messages.getString("view.TerminologyViewPart.action.deleteFailed"));
        try {
            dbOperator.rollBack();
        } catch (SQLException e1) {
            logger.error("RollBack error", e);
        }
        logger.error("execute sql error", e);
    } catch (ClassNotFoundException e) {
        logger.error("data base driver not found", e);
    } finally {
        if (null != dbOperator) {
            try {
                dbOperator.end();
            } catch (SQLException e) {
                logger.error("", e);
            }
        }
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) IProject(org.eclipse.core.resources.IProject)

Example 55 with GridItem

use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.

the class TargetColunmCellRenderer 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;
    int y = 0;
    Image image = item.getImage(getColumn());
    if (image != null) {
        y = topMargin + image.getBounds().height + bottomMargin;
        x += image.getBounds().width + 3;
    }
    // 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 = getBounds().width - x - rightMargin;
        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)

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