Search in sources :

Example 46 with GridItem

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

the class TermBaseSearchDialog method InsertGridTgtToEditor.

private void InsertGridTgtToEditor() {
    GridItem[] selection = grid.getSelection();
    if (null == selection || selection.length == 0) {
        return;
    }
    IXliffEditor tempEditor = null;
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof IXliffEditor) {
        IXliffEditor editor = (IXliffEditor) activeEditor;
        tempEditor = editor;
    }
    if (tempEditor == null) {
        return;
    }
    int[] selectedRows = tempEditor.getSelectedRows();
    if (null == selectedRows || selectedRows.length == 0) {
        return;
    }
    int rowIndex = selectedRows[0];
    if (tempEditor == null || rowIndex < 0) {
        return;
    }
    TransUnitBean transUnit = tempEditor.getRowTransUnitBean(rowIndex);
    Hashtable<String, String> tuProp = transUnit.getTuProps();
    if (tuProp != null) {
        String translate = tuProp.get("translate");
        if (translate != null && translate.equalsIgnoreCase("no")) {
            MessageDialog.openInformation(tempEditor.getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg1"));
            return;
        }
    }
    String tarTerm = selection[0].getText(1);
    if (null == tarTerm || tarTerm.isEmpty()) {
        return;
    }
    try {
        tempEditor.insertCell(rowIndex, tempEditor.getTgtColumnIndex(), tarTerm);
    // tempEditor.setFocus(); // 焦点给回编辑器
    } catch (ExecutionException e) {
        if (Constant.RUNNING_MODE == Constant.MODE_DEBUG) {
            e.printStackTrace();
        }
        MessageDialog.openInformation(tempEditor.getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg2") + e.getMessage());
    }
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) GridItem(org.eclipse.nebula.widgets.grid.GridItem) IEditorPart(org.eclipse.ui.IEditorPart) ExecutionException(org.eclipse.core.commands.ExecutionException) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Point(org.eclipse.swt.graphics.Point)

Example 47 with GridItem

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

the class TermBaseSearchDialog method initLanguageMenu.

/**
	 * 初始化语言菜单 ;
	 */
private void initLanguageMenu() {
    Set<String> set = new HashSet<String>();
    for (DatabaseModelBean model : lstDatabase) {
        MetaData metaData = model.toDbMetaData();
        DBOperator dbop = DatabaseService.getDBOperator(metaData);
        if (null == dbop) {
            continue;
        }
        try {
            dbop.start();
            set.addAll(dbop.getLanguages());
        } catch (SQLException e) {
            LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger1"), e);
        } catch (ClassNotFoundException e) {
            LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger1"), e);
        } finally {
            try {
                if (dbop != null) {
                    dbop.end();
                }
            } catch (SQLException e) {
                LOGGER.error("", e);
            }
        }
    }
    set.remove(strSrcLang);
    set.remove(strTgtLang);
    lstLangs = new ArrayList<String>(set);
    Collections.sort(lstLangs);
    // cmbLang.setItems((String[]) langs.toArray(new String[langs.size()]));
    menu = new Menu(getShell(), SWT.POP_UP);
    // }
    if (strTgtLang != null) {
        MenuItem itemTgt = new MenuItem(menu, SWT.CHECK);
        itemTgt.setText(strTgtLang);
        itemTgt.setSelection(true);
        itemTgt.setEnabled(false);
    }
    for (final String lang : lstLangs) {
        final MenuItem itemLang = new MenuItem(menu, SWT.CHECK);
        itemLang.setText(lang);
        itemLang.addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event event) {
                ArrayList<GridColumn> lstShowColumn = new ArrayList<GridColumn>();
                // 每增加一列,除标记列外的其他列的和加100,然后平均分配给各个语言列,删除一列则做相反的操作
                if (itemLang.getSelection()) {
                    int totalWidth = 0;
                    boolean blnIsResetWidth = false;
                    for (int index = 0; index < grid.getColumnCount(); index++) {
                        GridColumn column = grid.getColumn(index);
                        if (column.getText().equals(lang) && column.getWidth() == 0) {
                            lstShowColumn.add(column);
                            blnIsResetWidth = true;
                        } else if (column.getWidth() > 0) {
                            totalWidth += column.getWidth();
                            lstShowColumn.add(column);
                        }
                    }
                    if (blnIsResetWidth) {
                        int width = (totalWidth + 100) / lstShowColumn.size();
                        for (GridColumn column : lstShowColumn) {
                            column.setWidth(width);
                        }
                    }
                // if (grid.getItemCount() > 0) {
                // search();
                // }
                } else {
                    GridColumn deleteColumn = null;
                    for (int index = 0; index < grid.getColumnCount(); index++) {
                        GridColumn column = grid.getColumn(index);
                        if (column.getWidth() > 0) {
                            lstShowColumn.add(column);
                        }
                        if (column.getText().equals(lang)) {
                            deleteColumn = column;
                            // 将删除列中的数据清空,以保证行高正常调整
                            for (GridItem item : grid.getItems()) {
                                item.setText(index, "");
                            }
                        }
                    }
                    int width = (deleteColumn.getWidth() * lstShowColumn.size() - 100) / (lstShowColumn.size() - 1);
                    deleteColumn.setWidth(0);
                    lstShowColumn.remove(deleteColumn);
                    for (GridColumn column : lstShowColumn) {
                        column.setWidth(width);
                    }
                // search();
                }
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) KeyListener(org.eclipse.swt.events.KeyListener) SQLException(java.sql.SQLException) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ArrayList(java.util.ArrayList) DBOperator(net.heartsome.cat.database.DBOperator) MenuItem(org.eclipse.swt.widgets.MenuItem) GridItem(org.eclipse.nebula.widgets.grid.GridItem) MetaData(net.heartsome.cat.common.bean.MetaData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Menu(org.eclipse.swt.widgets.Menu) HashSet(java.util.HashSet)

Example 48 with GridItem

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

the class DefaultCellRenderer 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 49 with GridItem

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

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)

Example 50 with GridItem

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

the class TypeColunmCellRenderer method paint.

/**
	 * {@inheritDoc}
	 */
public void paint(GC gc, Object value) {
    GridItem item = (GridItem) value;
    gc.setFont(item.getFont(getColumn()));
    boolean drawBackground = true;
    boolean drawAsSelected = isSelected();
    if (isCellSelected()) {
        drawAsSelected = true;
    }
    gc.setForeground(item.getForeground(getColumn()));
    if (drawAsSelected) {
        // if (backColor == null || backColor.isDisposed()) {
        gc.setBackground((Color) item.getParent().getData("selectedBgColor"));
    // } else {
    // gc.setBackground(backColor);
    // }
    } else {
        // if (item.getParent().isEnabled()) {
        // if (backColor == null || backColor.isDisposed()) {
        // drawBackground = false;
        // } else {
        // gc.setBackground(backColor);
        // }
        // } else {
        gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
    // }
    }
    if (drawBackground) {
        gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height);
    }
    int x = leftMargin;
    Image image = (Image) item.getData("typeImage");
    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 + 3;
    }
    int height = getBounds().height - bottomMargin;
    if (textLayout == null) {
        textLayout = new TextLayout(gc.getDevice());
        item.getParent().addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                textLayout.dispose();
            }
        });
    }
    textLayout.setFont(gc.getFont());
    String quality = item.getText(getColumn());
    textLayout.setText(quality);
    textLayout.setAlignment(SWT.LEFT);
    int width = getBounds().width - x - rightMargin;
    textLayout.setWidth(width < 1 ? 1 : width);
    int y = getBounds().y + textTopMargin + topMargin;
    y += getVerticalAlignmentAdjustment(textLayout.getBounds().height, height);
    // textLayout.draw(gc, getBounds().x + x, y);
    String type = (String) item.getData("matchType");
    if (type.equals("TM")) {
        Color backColor = TmUtils.getMatchTypeColor(type, quality);
        if (backColor != null && !backColor.isDisposed()) {
            gc.setBackground(backColor);
        }
        gc.drawText(item.getText(getColumn()), getBounds().x + x, y);
    }
    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);
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) GridItem(org.eclipse.nebula.widgets.grid.GridItem) Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) DisposeEvent(org.eclipse.swt.events.DisposeEvent) 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