Search in sources :

Example 21 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project translationstudio8 by heartsome.

the class QAResultViewPart method createPropMenu.

/**
	 * 创建右键参数
	 */
private void createPropMenu() {
    Menu propMenu = new Menu(table);
    table.setMenu(propMenu);
    MenuItem deletWarnItem = new MenuItem(propMenu, SWT.NONE);
    deletWarnItem.setText(Messages.getString("views.QAResultViewPart.deletWarnItem"));
    deletWarnItem.setImage(deleteImage);
    deletWarnItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            QAResultBean bean;
            for (int i = 0; i < dataList.size(); i++) {
                bean = dataList.get(i);
                // 0为错误,1为警告
                if (1 == bean.getLevel()) {
                    dataList.remove(bean);
                    i--;
                }
            }
            tableModel.textRenderer.clearRowHeiMap();
            table.redraw();
        }
    });
    MenuItem deleteAllItem = new MenuItem(propMenu, SWT.NONE);
    deleteAllItem.setText(Messages.getString("views.QAResultViewPart.deleteAllItem"));
    deleteAllItem.setImage(deleteImage);
    deleteAllItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dataList.clear();
            tableModel.textRenderer.clearRowHeiMap();
            table.redraw();
        }
    });
    // 导出品质检查报告
    exportItem = new MenuItem(propMenu, SWT.NONE);
    exportItem.setText(Messages.getString("qa.views.QAResultViewPart.exportPopMenu"));
    exportItem.setImage(exportImg);
    exportItem.setEnabled(false);
    exportItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ExportQAResultDialog dialog = new ExportQAResultDialog(getSite().getShell());
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                final String exportFilePath = dialog.getExportFilePath();
                if (exportFilePath == null || exportFilePath.isEmpty()) {
                    MessageDialog.openInformation(getSite().getShell(), Messages.getString("qa.all.dialog.info"), Messages.getString("qa.views.QAResultViewPart.msg.nullFilePath"));
                    return;
                }
                IRunnableWithProgress runnable = new IRunnableWithProgress() {

                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        monitor.beginTask("", 1);
                        while (!isQAEnd) {
                            try {
                                Thread.sleep(500);
                            } catch (Exception e2) {
                                logger.error("", e2);
                            }
                            if (monitor.isCanceled()) {
                                return;
                            }
                        }
                        List<QAResultBean> exportDataList = new ArrayList<QAResultBean>();
                        exportDataList.addAll(dataList);
                        ExportQAResult export = new ExportQAResult(isMultiFile, exportFilePath);
                        export.beginExport(dataList, filePathList, monitor);
                        monitor.done();
                    }
                };
                try {
                    new ProgressMonitorDialog(getSite().getShell()).run(true, true, runnable);
                } catch (Exception e1) {
                    logger.error("", e1);
                }
            }
        }
    });
    propMenu.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            if (deleteImage != null && !deleteImage.isDisposed()) {
                deleteImage.dispose();
            }
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) MenuItem(org.eclipse.swt.widgets.MenuItem) DisposeEvent(org.eclipse.swt.events.DisposeEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ExportQAResult(net.heartsome.cat.ts.ui.qa.export.ExportQAResult) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExportQAResultDialog(net.heartsome.cat.ts.ui.qa.export.ExportQAResultDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu)

Example 22 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project translationstudio8 by heartsome.

the class Comparator method Compare.

/**
	 * 用于比较的参照文本(不含内部标记)
	 * @param referenceText
	 * @param text
	 *            ;
	 */
public static void Compare(String referenceText, StyledText text) {
    ColorConfigBean colorCfgBean = ColorConfigBean.getInstance();
    final Color differencefg = colorCfgBean.getSrcDiffFgColor();
    final Color differencebg = colorCfgBean.getSrcDiffBgColor();
    Position[] tagRanges = InnerTagUtil.getStyledTagRanges(text.getText());
    TokenComparator left = new TokenComparator(InnerTagUtil.getDisplayValueWithoutTags(text.getText()));
    TokenComparator right = new TokenComparator(referenceText);
    ArrayList<StyleRange> styleRanges = new ArrayList<StyleRange>();
    RangeDifference[] e = RangeDifferencer.findRanges(left, right);
    for (int i = 0; i < e.length; i++) {
        RangeDifference es = e[i];
        int leftStart = es.leftStart();
        int leftEnd = es.leftEnd();
        int lStart = left.getTokenStart(leftStart);
        int lEnd = left.getTokenStart(leftEnd);
        if (es.kind() == RangeDifference.CHANGE) {
            int start = lStart;
            int end = lEnd;
            if (tagRanges.length > 0) {
                for (Position tagRange : tagRanges) {
                    int tagStart = tagRange.getOffset();
                    int tagEnd = tagRange.getOffset() + tagRange.getLength();
                    if (tagStart <= start) {
                        start += tagRange.getLength();
                        end += tagRange.getLength();
                    } else if (start < tagStart && tagStart < end) {
                        StyleRange range = new StyleRange(start, tagStart - start, differencefg, differencebg);
                        styleRanges.add(range);
                        start = tagEnd;
                        end += tagRange.getLength();
                    } else {
                        break;
                    }
                }
            }
            StyleRange range = new StyleRange(start, end - start, differencefg, differencebg);
            styleRanges.add(range);
        }
    }
    for (int i = 0; i < styleRanges.size(); i++) {
        text.setStyleRange(styleRanges.get(i));
        text.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                differencefg.dispose();
                differencebg.dispose();
            }
        });
    }
}
Also used : ColorConfigBean(net.heartsome.cat.common.bean.ColorConfigBean) DisposeListener(org.eclipse.swt.events.DisposeListener) Position(org.eclipse.jface.text.Position) Color(org.eclipse.swt.graphics.Color) StyleRange(org.eclipse.swt.custom.StyleRange) ArrayList(java.util.ArrayList) DisposeEvent(org.eclipse.swt.events.DisposeEvent) RangeDifference(org.eclipse.compare.rangedifferencer.RangeDifference)

Example 23 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project translationstudio8 by heartsome.

the class AutoResizeColumnAction method run.

public void run(NatTable natTable, MouseEvent event) {
    if (gc == null) {
        gc = new GC(natTable);
        natTable.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                gc.dispose();
            }
        });
    }
    Point clickPoint = new Point(event.x, event.y);
    int column = CellEdgeDetectUtil.getColumnPositionToResize(natTable, clickPoint);
    InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(natTable, column, natTable.getConfigRegistry(), gc);
    natTable.doCommand(command);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) InitializeAutoResizeColumnsCommand(net.sourceforge.nattable.resize.command.InitializeAutoResizeColumnsCommand) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point)

Example 24 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project translationstudio8 by heartsome.

the class AutoResizeRowAction method run.

public void run(NatTable natTable, MouseEvent event) {
    if (gc == null) {
        gc = new GC(natTable);
        natTable.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                gc.dispose();
            }
        });
    }
    Point clickPoint = new Point(event.x, event.y);
    int row = CellEdgeDetectUtil.getRowPositionToResize(natTable, clickPoint);
    InitializeAutoResizeRowsCommand command = new InitializeAutoResizeRowsCommand(natTable, row, natTable.getConfigRegistry(), gc);
    natTable.doCommand(command);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) InitializeAutoResizeRowsCommand(net.sourceforge.nattable.resize.command.InitializeAutoResizeRowsCommand) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point)

Example 25 with DisposeListener

use of org.eclipse.swt.events.DisposeListener in project translationstudio8 by heartsome.

the class ColumnResizeCursorAction method run.

public void run(NatTable natTable, MouseEvent event) {
    if (columnResizeCursor == null) {
        columnResizeCursor = new Cursor(Display.getDefault(), SWT.CURSOR_SIZEWE);
        natTable.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                columnResizeCursor.dispose();
            }
        });
    }
    natTable.setCursor(columnResizeCursor);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Aggregations

DisposeListener (org.eclipse.swt.events.DisposeListener)118 DisposeEvent (org.eclipse.swt.events.DisposeEvent)117 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 GridData (org.eclipse.swt.layout.GridData)38 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)33 Image (org.eclipse.swt.graphics.Image)29 Cursor (org.eclipse.swt.graphics.Cursor)26 ToolBar (org.eclipse.swt.widgets.ToolBar)25 ToolItem (org.eclipse.swt.widgets.ToolItem)23 Composite (org.eclipse.swt.widgets.Composite)19 Color (org.eclipse.swt.graphics.Color)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 Point (org.eclipse.swt.graphics.Point)16 ControlEvent (org.eclipse.swt.events.ControlEvent)11 SelectionListener (org.eclipse.swt.events.SelectionListener)10 Control (org.eclipse.swt.widgets.Control)10 TextLayout (org.eclipse.swt.graphics.TextLayout)9 Listener (org.eclipse.swt.widgets.Listener)9 ControlListener (org.eclipse.swt.events.ControlListener)8 MouseEvent (org.eclipse.swt.events.MouseEvent)8