Java Code Examples for org.eclipse.swt.widgets.ToolItem#addDisposeListener()

The following examples show how to use org.eclipse.swt.widgets.ToolItem#addDisposeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void createToolbar(final int style, final TabbedPropertySheetWidgetFactory widgetFactory) {
    toolbar = new ToolBar(control, SWT.FLAT | SWT.NO_FOCUS);
    toolbar.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).create());
    toolbar.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    final ToolItem editControl = new ToolItem(toolbar, SWT.FLAT);
    editControl.setImage(Pics.getImage(PicsConstants.edit));
    editControl.setData(SWTBOT_WIDGET_ID_KEY, SWTBOT_ID_EDITBUTTON);
    editControl.addDisposeListener(disposeListener);
    editControl.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            editDialog = CellExpressionViewer.this.createEditDialog();
            openEditDialog(editDialog);
        }
    });
}
 
Example 2
Source File: ExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected ToolItem createEditToolItem(final ToolBar tb) {
    final ToolItem editControl = new ToolItem(tb, SWT.PUSH | SWT.NO_FOCUS);
    editControl.setImage(Pics.getImage(PicsConstants.edit));
    editControl.setToolTipText(Messages.editAndContinue);

    /* For test purpose */
    editControl.setData(SWTBOT_WIDGET_ID_KEY, SWTBOT_ID_EDITBUTTON);
    editControl.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            editControlSelected(tb, event, getEditingDomain());
        }

    });

    editControl.addDisposeListener(disposeListener);
    return editControl;
}
 
Example 3
Source File: ExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected ToolItem createEraseToolItem(final ToolBar tb) {
    eraseControl = new ToolItem(tb, SWT.PUSH | SWT.NO_FOCUS);
    eraseControl.setImage(Pics.getImage(PicsConstants.clear));
    eraseControl.setToolTipText(Messages.eraseExpression);

    /* For test purpose */
    eraseControl.setData(SWTBOT_WIDGET_ID_KEY, SWTBOT_ID_ERASEBUTTON);
    eraseControl.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            erase(getSelectedExpression());
        }

    });

    eraseControl.addDisposeListener(disposeListener);
    return eraseControl;
}
 
Example 4
Source File: SWTUtil.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Registers an image for a tool item. Generates a version of the image
 * that renders well on windows toolbars, when disabled.
 * 
 * @param item
 * @param image
 */
public static void createDisabledImage(ToolItem item) {
    final Image image = new Image(item.getDisplay(), item.getImage(), SWT.IMAGE_GRAY);
    item.setDisabledImage(image);
    item.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent arg0) {
            if (image != null && !image.isDisposed()) {
                image.dispose();
            }
        }
    });
}