Search in sources :

Example 66 with DisposeListener

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

the class ExportTbxDialog method createHelpControl.

/**
	 * 添加帮助按钮 robert 2012-09-06
	 */
@Override
protected Control createHelpControl(Composite parent) {
    // ROBERTHELP 导出 tbx
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch06s05.html#export-tbx", language);
    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
        }
    });
    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
    helpItem.setImage(helpImage);
    //$NON-NLS-1$
    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
    helpItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
        }
    });
    return toolBar;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 67 with DisposeListener

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

the class ConcordanceSearchDialog method createHelpControl.

/**
	 * 添加帮助按钮 robert 2012-09-06
	 */
@Override
protected Control createHelpControl(Composite parent) {
    // ROBERTHELP 相关搜索
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s04.html#concordance-search", language);
    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
        }
    });
    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
    helpItem.setImage(helpImage);
    //$NON-NLS-1$
    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
    helpItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
        }
    });
    return toolBar;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 68 with DisposeListener

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

the class RowResizeCursorAction method run.

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

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

Example 69 with DisposeListener

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

the class XLIFFEditorImplWithNatTable method changeLayout.

public void changeLayout(boolean isHorizontalLayout) {
    // 同步布局状态
    this.isHorizontalLayout = isHorizontalLayout;
    // 如果当前的 table 已经存在,销毁后再重新创建。
    if (table != null && !table.isDisposed()) {
        table.dispose();
        for (Control control : parent.getChildren()) {
            control.dispose();
        }
    }
    // 构建 NatTable 的数据提供者
    bodyDataProvider = setupBodyDataProvider(isHorizontalLayout);
    // 构建 NatTable 列头的数据提供者
    DefaultColumnHeaderDataProvider colHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabels);
    // 构建 NatTable 的 body layer stack
    bodyLayer = new BodyLayerStack(bodyDataProvider, isHorizontalLayout);
    // 构建 NatTable 的 column header layout stack
    ColumnHeaderLayerStack columnHeaderLayer = new ColumnHeaderLayerStack(colHeaderDataProvider);
    // 构建 NatTable 之下的 composite layer,不使用默认的 configuration(默认的 configuration 是在点击可编辑单元格时,直接进入编辑状态)。
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, bodyLayer, 0, 1);
    // 标识 BodyLayer 在 CompositeLayer 上的位置
    LayerUtil.setBodyLayerPosition(0, 1);
    /* 给 composite layer 添加编辑相关的命令和 handler */
    // 添加行背景色(奇数行和偶数行不同)
    addRowBackgroundColor(compositeLayer);
    // 构建 NatTable
    table = new NatTable(parent, compositeLayer, false);
    Language srcLang = LocaleService.getLanguageConfiger().getLanguageByCode(srcColumnName);
    Language tgtLang = LocaleService.getLanguageConfiger().getLanguageByCode(tgtColumnName);
    if (srcLang.isBidi() || tgtLang.isBidi()) {
        table.setOrientation(SWT.RIGHT_TO_LEFT);
    }
    // 去除默认绘画器
    table.removePaintListener(table);
    // 使用自定义绘画器,此绘画器,具有自动计算行高功能。
    table.addPaintListener(paintListenerWithAutoRowSize);
    Listener[] ls = table.getListeners(SWT.Resize);
    for (Listener l : ls) {
        table.removeListener(SWT.Resize, l);
    }
    table.addListener(SWT.Resize, resizeListenerWithColumnResize);
    table.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            // ActiveCellEditor.commit(); // 关闭编辑时,先提交未提交的单元格,避免造成内容丢失。Bug #2685
            HsMultiActiveCellEditor.commit(true);
            table.removeListener(SWT.Resize, resizeListenerWithColumnResize);
            table.removePaintListener(paintListenerWithAutoRowSize);
        }
    });
    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    // 给 NatTable 添加相应的配置
    DefaultNatTableStyleConfiguration configuration = new DefaultNatTableStyleConfiguration();
    configuration.hAlign = HorizontalAlignmentEnum.LEFT;
    table.addConfiguration(configuration);
    // To be changed 给NatTable添加选择列的功能 Add By Leakey
    /*
		 * ColumnGroupModel columnGroupModel = new ColumnGroupModel(); DisplayColumnChooserCommandHandler
		 * columnChooserCommandHandler = new DisplayColumnChooserCommandHandler( bodyLayer.getSelectionLayer(),
		 * bodyLayer.getColumnHideShowLayer(), columnHeaderLayer.getColumnHeaderLayer(),
		 * columnHeaderLayer.getColumnHeaderDataLayer(), columnHeaderLayer.getColumnGroupHeaderLayer(), columnGroupModel
		 * ); bodyLayer.registerCommandHandler(columnChooserCommandHandler);
		 */
    /*
		 * 不使用默认的表头菜单,使用自定义的菜单,因此自定义菜单在 corner 中添加了相应的菜单项,所以需要指定这些添加的 command 在哪一层进一处理
		 */
    // 表头中添加自定义菜单会引发一些不可预料的问题,故先去掉
    // table.addConfiguration(new HeaderMenuConfiguration(table));
    /*
		 * 增加表格的自定义右键菜单
		 */
    table.addConfiguration(new BodyMenuConfiguration(this));
    // 注册列头点击监听(处理排序)
    table.addConfiguration(new SingleClickSortConfiguration());
    /*
		 * 初始化“撤销/重做”历史
		 */
    initializeOperationHistory();
    table.setData(IUndoContext.class.getName(), undoContext);
    /* Weachy - 注册修改后保存内容并自适应大小的处理 handler(覆盖默认的handler:UpdateDataCommandHandler) */
    bodyLayer.getBodyDataLayer().registerCommandHandler(new UpdateDataAndAutoResizeCommandHandler(table, bodyLayer.getBodyDataLayer()));
    /* Weachy - 注册当前显示行的行高自适应处理 handler */
    compositeLayer.registerCommandHandler(new AutoResizeCurrentRowsCommandHandler(compositeLayer));
    /* Weachy - 移除系统默认的查找 handler,添加自定义的查找替换 handler */
    bodyLayer.getSelectionLayer().unregisterCommandHandler(SearchCommand.class);
    bodyLayer.getSelectionLayer().registerCommandHandler(new FindReplaceCommandHandler(bodyLayer.getSelectionLayer()));
    /*
		 * 下面给 NatTable 添加可编辑单元格的配置
		 */
    table.addConfiguration(editableGridConfiguration());
    // 添加标记的自定义显示样式
    IConfigRegistry configRegistry = new ConfigRegistry();
    /*
		 * 如果是水平布局,则使用 ColumnOverrideLabelAccumulator 实现指定列都使用相同的显示样式;否则使用 CellOverrideLabelAccumulator 实现根据显示的内容来显示样式。
		 */
    if (isHorizontalLayout) {
        // 第一步:创建一个标签累加器,给需要绘制会不同效果的 cells 添加自定义的标签。在这里是第三列的标签列。
        ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyLayer);
        columnLabelAccumulator.registerColumnOverrides(0, "LINENUMBER_CELL_LABEL");
        columnLabelAccumulator.registerColumnOverrides(1, SOURCE_EDIT_CELL_LABEL);
        columnLabelAccumulator.registerColumnOverrides(2, FLAG_CELL_LABEL);
        columnLabelAccumulator.registerColumnOverrides(3, TARGET_EDIT_CELL_LABEL);
        // 第二步:注册这个标签累加器。
        bodyLayer.setConfigLabelAccumulator(columnLabelAccumulator);
        // 第三步:把自定义的 cell painter,cell style 与自定义的标签进行关联。
        addFlagLableToColumn(configRegistry);
        addLineNumberToColumn(configRegistry);
    } else {
        ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyLayer);
        columnLabelAccumulator.registerColumnOverrides(0, "LINENUMBER_CELL_LABEL");
        columnLabelAccumulator.registerColumnOverrides(1, FLAG_CELL_LABEL);
        columnLabelAccumulator.registerColumnOverrides(VerticalNatTableConfig.TARGET_COL_INDEX, SOURCE_EDIT_CELL_LABEL);
        columnLabelAccumulator.registerColumnOverrides(VerticalNatTableConfig.TARGET_COL_INDEX, TARGET_EDIT_CELL_LABEL);
        bodyLayer.setConfigLabelAccumulator(columnLabelAccumulator);
        // CellOverrideLabelAccumulator<TransUnitDummy> cellLabelAccumulator = new
        // CellOverrideLabelAccumulator<TransUnitDummy>(
        // (IRowDataProvider) bodyDataProvider);
        // CellOverrideLabelAccumulator<TransUnitBean> cellLabelAccumulator = new
        // CellOverrideLabelAccumulator<TransUnitBean>(
        // (IRowDataProvider) bodyDataProvider);
        // cellLabelAccumulator.registerOverride("flag", VerticalNatTableConfig.SOURCE_COL_INDEX,
        // FOCUS_CELL_LABEL);
        //
        // bodyLayer.getBodyDataLayer().setConfigLabelAccumulator(cellLabelAccumulator);
        addFlagLableToColumn(configRegistry);
        addLineNumberToColumn(configRegistry);
    }
    table.setConfigRegistry(configRegistry);
    // configure manually
    table.configure();
    /* Weachy - 垂直布局下,注册使键盘方向键以 2 行为一个单位移动选中行的处理 handler(覆盖默认的handler:MoveRowSelectionCommandHandler) */
    if (!isHorizontalLayout) {
    // SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
    // selectionLayer.registerCommandHandler(new VerticalMoveRowSelectionCommandHandler(selectionLayer));
    }
    if (bodyLayer.selectionLayer.getRowCount() > 0) {
        // 默认选中第一行
        HsMultiActiveCellEditor.commit(true);
        bodyLayer.selectionLayer.doCommand(new SelectCellCommand(bodyLayer.getSelectionLayer(), getTgtColumnIndex(), isHorizontalLayout ? 0 : 1, false, false));
        HsMultiCellEditorControl.activeSourceAndTargetCell(this);
    }
    IWorkbenchPage page = getSite().getPage();
    IViewReference[] viewReferences = page.getViewReferences();
    IViewPart view;
    for (int i = 0; i < viewReferences.length; i++) {
        view = viewReferences[i].getView(false);
        if (view == null) {
            continue;
        }
        // 切换到其他视图,再切换回来,解决NatTable改变布局后其他视图无法监听到的问题。
        view.setFocus();
    // break;
    }
    // 改变布局方式后,把焦点给 NatTable
    table.setFocus();
    RowHeightCalculator rowHeightCalculator = new RowHeightCalculator(bodyLayer, table, 32);
    ILayer lay = bodyLayer.getViewportLayer();
    if (lay instanceof HorizontalViewportLayer) {
        ((HorizontalViewportLayer) bodyLayer.getViewportLayer()).setRowHeightCalculator(rowHeightCalculator);
    } else if (lay instanceof VerticalViewportLayer) {
        ((VerticalViewportLayer) bodyLayer.getViewportLayer()).setRowHeightCalculator(rowHeightCalculator);
    }
    parent.layout();
    NoteToolTip toolTip = new NoteToolTip(table);
    toolTip.setPopupDelay(10);
    toolTip.activate();
    toolTip.setShift(new Point(10, 10));
    StateToolTip stateTip = new StateToolTip(table);
    stateTip.setPopupDelay(10);
    stateTip.activate();
    stateTip.setShift(new Point(10, 10));
    NotSendToTmToolTip notSendToTMToolTip = new NotSendToTmToolTip(table);
    notSendToTMToolTip.setPopupDelay(10);
    notSendToTMToolTip.activate();
    notSendToTMToolTip.setShift(new Point(10, 10));
    HasQustionToolTip hasqustionTooltip = new HasQustionToolTip(table);
    hasqustionTooltip.setPopupDelay(10);
    hasqustionTooltip.activate();
    hasqustionTooltip.setShift(new Point(10, 10));
    // 在状态栏上显示当前文本段的信息。
    updateStatusLine();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IViewPart(org.eclipse.ui.IViewPart) PaintListener(org.eclipse.swt.events.PaintListener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) IPropertyListener(org.eclipse.ui.IPropertyListener) VerifyListener(org.eclipse.swt.events.VerifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FindReplaceCommandHandler(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.command.FindReplaceCommandHandler) DisposeEvent(org.eclipse.swt.events.DisposeEvent) BodyMenuConfiguration(net.heartsome.cat.ts.ui.xliffeditor.nattable.menu.BodyMenuConfiguration) IUndoContext(org.eclipse.core.commands.operations.IUndoContext) IConfigRegistry(net.sourceforge.nattable.config.IConfigRegistry) ConfigRegistry(net.sourceforge.nattable.config.ConfigRegistry) Control(org.eclipse.swt.widgets.Control) Language(net.heartsome.cat.common.locale.Language) DefaultNatTableStyleConfiguration(net.sourceforge.nattable.config.DefaultNatTableStyleConfiguration) IViewReference(org.eclipse.ui.IViewReference) NatTable(net.sourceforge.nattable.NatTable) ColumnOverrideLabelAccumulator(net.sourceforge.nattable.layer.cell.ColumnOverrideLabelAccumulator) UpdateDataAndAutoResizeCommandHandler(net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.UpdateDataAndAutoResizeCommandHandler) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) ILayer(net.sourceforge.nattable.layer.ILayer) Point(org.eclipse.swt.graphics.Point) CompositeLayer(net.sourceforge.nattable.layer.CompositeLayer) Point(org.eclipse.swt.graphics.Point) RowHeightCalculator(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.RowHeightCalculator) VerticalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer) HorizontalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer) SingleClickSortConfiguration(net.sourceforge.nattable.sort.config.SingleClickSortConfiguration) IConfigRegistry(net.sourceforge.nattable.config.IConfigRegistry) GridData(org.eclipse.swt.layout.GridData) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DefaultColumnHeaderDataProvider(net.sourceforge.nattable.grid.data.DefaultColumnHeaderDataProvider) AutoResizeCurrentRowsCommandHandler(net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommandHandler)

Example 70 with DisposeListener

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

the class DefaultColumnGroupHeaderRenderer method getTextLayout.

private void getTextLayout(GC gc, GridColumnGroup group) {
    if (textLayout == null) {
        textLayout = new TextLayout(gc.getDevice());
        textLayout.setFont(gc.getFont());
        group.getParent().addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                textLayout.dispose();
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TextLayout(org.eclipse.swt.graphics.TextLayout)

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