Example usage for org.eclipse.jface.dialogs IDialogConstants BUTTON_WIDTH

List of usage examples for org.eclipse.jface.dialogs IDialogConstants BUTTON_WIDTH

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IDialogConstants BUTTON_WIDTH.

Prototype

int BUTTON_WIDTH

To view the source code for org.eclipse.jface.dialogs IDialogConstants BUTTON_WIDTH.

Click Source Link

Document

Button width in dialog units (value 61).

Usage

From source file:org.eclipse.ui.internal.activities.ws.ActivityEnabler.java

License:Open Source License

private GridData setButtonLayoutData(Button button, FontMetrics fontMetrics) {
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    data.widthHint = Math.max(widthHint, minSize.x);
    button.setLayoutData(data);//from w ww.  ja  v  a  2s .c  o  m
    return data;
}

From source file:org.eclipse.ui.internal.ide.dialogs.LinkedResourceEditor.java

License:Open Source License

/**
 * @param parent/*from www. java  2 s. c om*/
 * @param text
 * @return the new button
 */
private Button createButton(Composite parent, String text) {
    Button button = new Button(parent, SWT.PUSH);
    button.setText(text);
    button.setFont(parent.getFont());
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(data);
    return button;
}

From source file:org.eclipse.ui.internal.ide.dialogs.ResourceFilterGroup.java

License:Open Source License

private static int getButtonWidthHint(Button button) {
    button.setFont(JFaceResources.getDialogFont());
    FontMetrics fontMetrics;// w w w .  j a v  a2s.  co m
    GC gc = new GC(button);
    try {
        gc.setFont(button.getFont());
        fontMetrics = gc.getFontMetrics();
    } finally {
        gc.dispose();
    }
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:org.eclipse.ui.internal.keys.KeysPreferencePage.java

License:Open Source License

/**
 * Creates the tab that allows the user to change the keyboard shortcuts.
 * /*from   w  w  w  .  ja  v a2 s  .c  om*/
 * @param parent
 *            The tab folder in which the tab should be created; must not be
 *            <code>null</code>.
 * @return The composite which represents the contents of the tab; never
 *         <code>null</code>.
 */
private final Composite createModifyTab(final TabFolder parent) {
    final Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new GridLayout());
    GridData gridData = new GridData(GridData.FILL_BOTH);
    composite.setLayoutData(gridData);
    final Composite compositeKeyConfiguration = new Composite(composite, SWT.NULL);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    compositeKeyConfiguration.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    compositeKeyConfiguration.setLayoutData(gridData);
    final Label labelKeyConfiguration = new Label(compositeKeyConfiguration, SWT.LEFT);
    labelKeyConfiguration.setText(Util.translateString(RESOURCE_BUNDLE, "labelScheme")); //$NON-NLS-1$
    comboScheme = new Combo(compositeKeyConfiguration, SWT.READ_ONLY);
    gridData = new GridData();
    gridData.widthHint = 200;
    comboScheme.setLayoutData(gridData);
    comboScheme.setVisibleItemCount(ITEMS_TO_SHOW);

    comboScheme.addSelectionListener(new SelectionAdapter() {
        public final void widgetSelected(final SelectionEvent e) {
            selectedComboScheme();
        }
    });

    labelSchemeExtends = new Label(compositeKeyConfiguration, SWT.LEFT);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    labelSchemeExtends.setLayoutData(gridData);
    final Control spacer = new Composite(composite, SWT.NULL);
    gridData = new GridData();
    gridData.heightHint = 10;
    gridData.widthHint = 10;
    spacer.setLayoutData(gridData);
    final Group groupCommand = new Group(composite, SWT.SHADOW_NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    groupCommand.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_BOTH);
    groupCommand.setLayoutData(gridData);
    groupCommand.setText(Util.translateString(RESOURCE_BUNDLE, "groupCommand")); //$NON-NLS-1$   
    final Label labelCategory = new Label(groupCommand, SWT.LEFT);
    gridData = new GridData();
    labelCategory.setLayoutData(gridData);
    labelCategory.setText(Util.translateString(RESOURCE_BUNDLE, "labelCategory")); //$NON-NLS-1$
    comboCategory = new Combo(groupCommand, SWT.READ_ONLY);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.widthHint = 200;
    comboCategory.setLayoutData(gridData);
    comboCategory.setVisibleItemCount(ITEMS_TO_SHOW);

    comboCategory.addSelectionListener(new SelectionAdapter() {
        public final void widgetSelected(final SelectionEvent e) {
            update();
        }
    });

    final Label labelCommand = new Label(groupCommand, SWT.LEFT);
    gridData = new GridData();
    labelCommand.setLayoutData(gridData);
    labelCommand.setText(Util.translateString(RESOURCE_BUNDLE, "labelCommand")); //$NON-NLS-1$
    comboCommand = new Combo(groupCommand, SWT.READ_ONLY);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.widthHint = 300;
    comboCommand.setLayoutData(gridData);
    comboCommand.setVisibleItemCount(9);

    comboCommand.addSelectionListener(new SelectionAdapter() {
        public final void widgetSelected(final SelectionEvent e) {
            update();
        }
    });

    labelBindingsForCommand = new Label(groupCommand, SWT.LEFT);
    gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    gridData.verticalAlignment = GridData.FILL_VERTICAL;
    labelBindingsForCommand.setLayoutData(gridData);
    labelBindingsForCommand.setText(Util.translateString(RESOURCE_BUNDLE, "labelAssignmentsForCommand")); //$NON-NLS-1$
    tableBindingsForCommand = new Table(groupCommand,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    tableBindingsForCommand.setHeaderVisible(true);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = 60;
    gridData.horizontalSpan = 2;
    boolean isMac = org.eclipse.jface.util.Util.isMac();
    gridData.widthHint = isMac ? 620 : 520;
    tableBindingsForCommand.setLayoutData(gridData);
    TableColumn tableColumnDelta = new TableColumn(tableBindingsForCommand, SWT.NULL, 0);
    tableColumnDelta.setResizable(false);
    tableColumnDelta.setText(Util.ZERO_LENGTH_STRING);
    tableColumnDelta.setWidth(20);
    TableColumn tableColumnContext = new TableColumn(tableBindingsForCommand, SWT.NULL, 1);
    tableColumnContext.setResizable(true);
    tableColumnContext.setText(Util.translateString(RESOURCE_BUNDLE, "tableColumnContext")); //$NON-NLS-1$
    tableColumnContext.pack();
    tableColumnContext.setWidth(200);
    final TableColumn tableColumnKeySequence = new TableColumn(tableBindingsForCommand, SWT.NULL, 2);
    tableColumnKeySequence.setResizable(true);
    tableColumnKeySequence.setText(Util.translateString(RESOURCE_BUNDLE, "tableColumnKeySequence")); //$NON-NLS-1$
    tableColumnKeySequence.pack();
    tableColumnKeySequence.setWidth(300);

    tableBindingsForCommand.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent mouseEvent) {
            update();
        }
    });

    tableBindingsForCommand.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent selectionEvent) {
            selectedTableBindingsForCommand();
        }
    });

    final Group groupKeySequence = new Group(composite, SWT.SHADOW_NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 4;
    groupKeySequence.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_BOTH);
    groupKeySequence.setLayoutData(gridData);
    groupKeySequence.setText(Util.translateString(RESOURCE_BUNDLE, "groupKeySequence")); //$NON-NLS-1$   
    final Label labelKeySequence = new Label(groupKeySequence, SWT.LEFT);
    gridData = new GridData();
    labelKeySequence.setLayoutData(gridData);
    labelKeySequence.setText(Util.translateString(RESOURCE_BUNDLE, "labelKeySequence")); //$NON-NLS-1$

    // The text widget into which the key strokes will be entered.
    textTriggerSequence = new Text(groupKeySequence, SWT.BORDER);
    // On MacOS X, this font will be changed by KeySequenceText
    textTriggerSequence.setFont(groupKeySequence.getFont());
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.widthHint = 300;
    textTriggerSequence.setLayoutData(gridData);
    textTriggerSequence.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            update();
        }
    });
    textTriggerSequence.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            bindingService.setKeyFilterEnabled(false);
        }

        public void focusLost(FocusEvent e) {
            bindingService.setKeyFilterEnabled(true);
        }
    });
    textTriggerSequence.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            if (!bindingService.isKeyFilterEnabled()) {
                bindingService.setKeyFilterEnabled(true);
            }
        }
    });

    // The manager for the key sequence text widget.
    textTriggerSequenceManager = new KeySequenceText(textTriggerSequence);
    textTriggerSequenceManager.setKeyStrokeLimit(4);

    // Button for adding trapped key strokes
    final Button buttonAddKey = new Button(groupKeySequence, SWT.LEFT | SWT.ARROW);
    buttonAddKey.setToolTipText(Util.translateString(RESOURCE_BUNDLE, "buttonAddKey.ToolTipText")); //$NON-NLS-1$
    gridData = new GridData();
    gridData.heightHint = comboCategory.getTextHeight();
    buttonAddKey.setLayoutData(gridData);

    // Arrow buttons aren't normally added to the tab list. Let's fix that.
    final Control[] tabStops = groupKeySequence.getTabList();
    final ArrayList newTabStops = new ArrayList();
    for (int i = 0; i < tabStops.length; i++) {
        Control tabStop = tabStops[i];
        newTabStops.add(tabStop);
        if (textTriggerSequence.equals(tabStop)) {
            newTabStops.add(buttonAddKey);
        }
    }
    final Control[] newTabStopArray = (Control[]) newTabStops.toArray(new Control[newTabStops.size()]);
    groupKeySequence.setTabList(newTabStopArray);

    // Construct the menu to attach to the above button.
    final Menu menuButtonAddKey = new Menu(buttonAddKey);
    final Iterator trappedKeyItr = KeySequenceText.TRAPPED_KEYS.iterator();
    while (trappedKeyItr.hasNext()) {
        final KeyStroke trappedKey = (KeyStroke) trappedKeyItr.next();
        final MenuItem menuItem = new MenuItem(menuButtonAddKey, SWT.PUSH);
        menuItem.setText(trappedKey.format());
        menuItem.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                textTriggerSequenceManager.insert(trappedKey);
                textTriggerSequence.setFocus();
                textTriggerSequence.setSelection(textTriggerSequence.getTextLimit());
            }
        });
    }
    buttonAddKey.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent selectionEvent) {
            Point buttonLocation = buttonAddKey.getLocation();
            buttonLocation = groupKeySequence.toDisplay(buttonLocation.x, buttonLocation.y);
            Point buttonSize = buttonAddKey.getSize();
            menuButtonAddKey.setLocation(buttonLocation.x, buttonLocation.y + buttonSize.y);
            menuButtonAddKey.setVisible(true);
        }
    });

    labelBindingsForTriggerSequence = new Label(groupKeySequence, SWT.LEFT);
    gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    gridData.verticalAlignment = GridData.FILL_VERTICAL;
    labelBindingsForTriggerSequence.setLayoutData(gridData);
    labelBindingsForTriggerSequence
            .setText(Util.translateString(RESOURCE_BUNDLE, "labelAssignmentsForKeySequence")); //$NON-NLS-1$
    tableBindingsForTriggerSequence = new Table(groupKeySequence,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    tableBindingsForTriggerSequence.setHeaderVisible(true);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = 60;
    gridData.horizontalSpan = 3;
    gridData.widthHint = isMac ? 620 : 520;
    tableBindingsForTriggerSequence.setLayoutData(gridData);
    tableColumnDelta = new TableColumn(tableBindingsForTriggerSequence, SWT.NULL, 0);
    tableColumnDelta.setResizable(false);
    tableColumnDelta.setText(Util.ZERO_LENGTH_STRING);
    tableColumnDelta.setWidth(20);
    tableColumnContext = new TableColumn(tableBindingsForTriggerSequence, SWT.NULL, 1);
    tableColumnContext.setResizable(true);
    tableColumnContext.setText(Util.translateString(RESOURCE_BUNDLE, "tableColumnContext")); //$NON-NLS-1$
    tableColumnContext.pack();
    tableColumnContext.setWidth(200);
    final TableColumn tableColumnCommand = new TableColumn(tableBindingsForTriggerSequence, SWT.NULL, 2);
    tableColumnCommand.setResizable(true);
    tableColumnCommand.setText(Util.translateString(RESOURCE_BUNDLE, "tableColumnCommand")); //$NON-NLS-1$
    tableColumnCommand.pack();
    tableColumnCommand.setWidth(300);

    tableBindingsForTriggerSequence.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent mouseEvent) {
            update();
        }
    });

    tableBindingsForTriggerSequence.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent selectionEvent) {
            selectedTableBindingsForTriggerSequence();
        }
    });

    final Composite compositeContext = new Composite(composite, SWT.NULL);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    compositeContext.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    compositeContext.setLayoutData(gridData);
    final Label labelContext = new Label(compositeContext, SWT.LEFT);
    labelContext.setText(Util.translateString(RESOURCE_BUNDLE, "labelContext")); //$NON-NLS-1$
    comboContext = new Combo(compositeContext, SWT.READ_ONLY);
    gridData = new GridData();
    gridData.widthHint = 250;
    comboContext.setLayoutData(gridData);
    comboContext.setVisibleItemCount(ITEMS_TO_SHOW);

    comboContext.addSelectionListener(new SelectionAdapter() {
        public final void widgetSelected(final SelectionEvent e) {
            update();
        }
    });

    labelContextExtends = new Label(compositeContext, SWT.LEFT);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    labelContextExtends.setLayoutData(gridData);
    final Composite compositeButton = new Composite(composite, SWT.NULL);
    gridLayout = new GridLayout();
    gridLayout.marginHeight = 20;
    gridLayout.marginWidth = 0;
    gridLayout.numColumns = 3;
    compositeButton.setLayout(gridLayout);
    gridData = new GridData();
    compositeButton.setLayoutData(gridData);
    buttonAdd = new Button(compositeButton, SWT.CENTER | SWT.PUSH);
    gridData = new GridData();
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    buttonAdd.setText(Util.translateString(RESOURCE_BUNDLE, "buttonAdd")); //$NON-NLS-1$
    gridData.widthHint = Math.max(widthHint, buttonAdd.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5;
    buttonAdd.setLayoutData(gridData);

    buttonAdd.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent selectionEvent) {
            selectedButtonAdd();
        }
    });

    buttonRemove = new Button(compositeButton, SWT.CENTER | SWT.PUSH);
    gridData = new GridData();
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    buttonRemove.setText(Util.translateString(RESOURCE_BUNDLE, "buttonRemove")); //$NON-NLS-1$
    gridData.widthHint = Math.max(widthHint, buttonRemove.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5;
    buttonRemove.setLayoutData(gridData);

    buttonRemove.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent selectionEvent) {
            selectedButtonRemove();
        }
    });

    buttonRestore = new Button(compositeButton, SWT.CENTER | SWT.PUSH);
    gridData = new GridData();
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    buttonRestore.setText(Util.translateString(RESOURCE_BUNDLE, "buttonRestore")); //$NON-NLS-1$
    gridData.widthHint = Math.max(widthHint, buttonRestore.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5;
    buttonRestore.setLayoutData(gridData);

    buttonRestore.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent selectionEvent) {
            selectedButtonRestore();
        }
    });

    return composite;
}

From source file:org.eclipse.ui.internal.keys.KeysPreferencePage.java

License:Open Source License

/**
 * Creates a tab on the main page for displaying an uneditable list of the
 * current key bindings. This is intended as a discovery tool for new users.
 * It shows all of the key bindings for the current key configuration,
 * platform and locale./*from  w w w. j  av  a  2s. c  om*/
 * 
 * @param parent
 *            The tab folder in which the tab should be created; must not be
 *            <code>null</code>.
 * @return The newly created composite containing all of the controls; never
 *         <code>null</code>.
 * @since 3.1
 */
private final Composite createViewTab(final TabFolder parent) {
    GridData gridData = null;
    int widthHint;

    // Create the composite for the tab.
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new GridLayout());

    // Place a table inside the tab.
    tableBindings = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    tableBindings.setHeaderVisible(true);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = 400;
    gridData.horizontalSpan = 2;
    tableBindings.setLayoutData(gridData);
    final TableColumn tableColumnCategory = new TableColumn(tableBindings, SWT.NONE,
            VIEW_CATEGORY_COLUMN_INDEX);
    tableColumnCategory.setText(SORTED_COLUMN_NAMES[VIEW_CATEGORY_COLUMN_INDEX]);
    tableColumnCategory.addSelectionListener(new SortOrderSelectionListener(VIEW_CATEGORY_COLUMN_INDEX));
    final TableColumn tableColumnCommand = new TableColumn(tableBindings, SWT.NONE, VIEW_COMMAND_COLUMN_INDEX);
    tableColumnCommand.setText(UNSORTED_COLUMN_NAMES[VIEW_COMMAND_COLUMN_INDEX]);
    tableColumnCommand.addSelectionListener(new SortOrderSelectionListener(VIEW_COMMAND_COLUMN_INDEX));
    final TableColumn tableColumnKeySequence = new TableColumn(tableBindings, SWT.NONE,
            VIEW_KEY_SEQUENCE_COLUMN_INDEX);
    tableColumnKeySequence.setText(UNSORTED_COLUMN_NAMES[VIEW_KEY_SEQUENCE_COLUMN_INDEX]);
    tableColumnKeySequence.addSelectionListener(new SortOrderSelectionListener(VIEW_KEY_SEQUENCE_COLUMN_INDEX));
    final TableColumn tableColumnContext = new TableColumn(tableBindings, SWT.NONE, VIEW_CONTEXT_COLUMN_INDEX);
    tableColumnContext.setText(UNSORTED_COLUMN_NAMES[VIEW_CONTEXT_COLUMN_INDEX]);
    tableColumnContext.addSelectionListener(new SortOrderSelectionListener(VIEW_CONTEXT_COLUMN_INDEX));
    tableBindings.addSelectionListener(new SelectionAdapter() {
        public final void widgetDefaultSelected(final SelectionEvent e) {
            selectedTableKeyBindings();
        }
    });

    // A composite for the buttons.
    final Composite buttonBar = new Composite(composite, SWT.NONE);
    buttonBar.setLayout(new GridLayout(2, false));
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    buttonBar.setLayoutData(gridData);

    // A button for editing the current selection.
    final Button editButton = new Button(buttonBar, SWT.PUSH);
    gridData = new GridData();
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    editButton.setText(Util.translateString(RESOURCE_BUNDLE, "buttonEdit")); //$NON-NLS-1$
    gridData.widthHint = Math.max(widthHint, editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5;
    editButton.setLayoutData(gridData);
    editButton.addSelectionListener(new SelectionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public final void widgetDefaultSelected(final SelectionEvent event) {
            selectedTableKeyBindings();
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }
    });

    // A button for exporting the contents to a file.
    final Button buttonExport = new Button(buttonBar, SWT.PUSH);
    gridData = new GridData();
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    buttonExport.setText(Util.translateString(RESOURCE_BUNDLE, "buttonExport")); //$NON-NLS-1$
    gridData.widthHint = Math.max(widthHint, buttonExport.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5;
    buttonExport.setLayoutData(gridData);
    buttonExport.addSelectionListener(new SelectionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public final void widgetDefaultSelected(final SelectionEvent event) {
            selectedButtonExport();
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }
    });

    return composite;
}

From source file:org.eclipse.ui.internal.keys.NewKeysPreferencePage.java

License:Open Source License

/**
 * Creates the button bar across the bottom of the preference page. This
 * button bar contains the "Advanced..." button.
 * //from w w w  .j a  v a2s  . c  o  m
 * @param parent
 *            The composite in which the button bar should be placed; never
 *            <code>null</code>.
 * @return The button bar composite; never <code>null</code>.
 */
private final Control createButtonBar(final Composite parent) {
    GridLayout layout;
    GridData gridData;
    int widthHint;

    // Create the composite to house the button bar.
    final Composite buttonBar = new Composite(parent, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    buttonBar.setLayout(layout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.END;
    buttonBar.setLayoutData(gridData);

    // Advanced button.
    final Button filtersButton = new Button(buttonBar, SWT.PUSH);
    gridData = new GridData();
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    filtersButton.setText(NewKeysPreferenceMessages.FiltersButton_Text);
    gridData.widthHint = Math.max(widthHint, filtersButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5;
    filtersButton.setLayoutData(gridData);
    filtersButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            KeysPreferenceFiltersDialog dialog = new KeysPreferenceFiltersDialog(getShell());
            dialog.setFilterActionSet(fFilterActionSetContexts);
            dialog.setFilterInternal(fFilterInternalContexts);
            dialog.setFilterUncategorized(fFilteredTree.isFilteringCategories());
            if (dialog.open() == Window.OK) {
                fFilterActionSetContexts = dialog.getFilterActionSet();
                fFilterInternalContexts = dialog.getFilterInternal();
                fFilteredTree.filterCategories(dialog.getFilterUncategorized());

                // Apply context filters
                keyController.filterContexts(fFilterActionSetContexts, fFilterInternalContexts);

                ISelection currentContextSelection = fWhenCombo.getSelection();
                fWhenCombo.setInput(keyController.getContextModel());
                fWhenCombo.setSelection(currentContextSelection);
            }
        }
    });

    // Export bindings to CSV
    final Button exportButton = new Button(buttonBar, SWT.PUSH);
    // gridData = new GridData();
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    exportButton.setText(NewKeysPreferenceMessages.ExportButton_Text);
    gridData.widthHint = Math.max(widthHint, exportButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5;
    exportButton.setLayoutData(gridData);
    exportButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            keyController.exportCSV(((Button) e.getSource()).getShell());
        }

    });

    return buttonBar;
}

From source file:org.eclipse.ui.internal.keys.NewKeysPreferencePage.java

License:Open Source License

private final Control createTreeControls(final Composite parent) {
    GridLayout layout;/*from  w  ww. j ava  2  s .c  o  m*/
    GridData gridData;
    int widthHint;

    // Creates controls related to the tree.
    final Composite treeControls = new Composite(parent, SWT.NONE);
    layout = new GridLayout(4, false);
    layout.marginWidth = 0;
    treeControls.setLayout(layout);
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = SWT.FILL;
    treeControls.setLayoutData(gridData);

    final Button addBindingButton = new Button(treeControls, SWT.PUSH);
    gridData = new GridData();
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    addBindingButton.setText(NewKeysPreferenceMessages.AddBindingButton_Text);
    gridData.widthHint = Math.max(widthHint, addBindingButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x)
            + 5;
    addBindingButton.setLayoutData(gridData);
    addBindingButton.addSelectionListener(new SelectionAdapter() {
        public final void widgetSelected(final SelectionEvent event) {
            keyController.getBindingModel().copy();
        }
    });

    final Button removeBindingButton = new Button(treeControls, SWT.PUSH);
    gridData = new GridData();
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    removeBindingButton.setText(NewKeysPreferenceMessages.RemoveBindingButton_Text);
    gridData.widthHint = Math.max(widthHint, removeBindingButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x)
            + 5;
    removeBindingButton.setLayoutData(gridData);
    removeBindingButton.addSelectionListener(new SelectionAdapter() {
        public final void widgetSelected(final SelectionEvent event) {
            keyController.getBindingModel().remove();
        }
    });

    final Button restore = new Button(treeControls, SWT.PUSH);
    gridData = new GridData();
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    restore.setText(NewKeysPreferenceMessages.RestoreBindingButton_Text);
    gridData.widthHint = Math.max(widthHint, restore.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5;
    restore.setLayoutData(gridData);
    restore.addSelectionListener(new SelectionAdapter() {
        public final void widgetSelected(final SelectionEvent event) {
            try {
                fFilteredTree.setRedraw(false);
                BindingModel bindingModel = keyController.getBindingModel();
                bindingModel.restoreBinding(keyController.getContextModel());
            } finally {
                fFilteredTree.setRedraw(true);
            }
        }
    });

    return treeControls;
}

From source file:org.eclipse.ui.internal.statushandlers.InternalDialog.java

License:Open Source License

/**
 * Status dialog button should be aligned SWT.END. 
 *///from ww w  .j  a va 2  s  .co m
protected void setButtonLayoutData(Button button) {
    GridData data = new GridData(SWT.END, SWT.CENTER, false, false);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    data.widthHint = Math.max(widthHint, minSize.x);
    button.setLayoutData(data);
}

From source file:org.eclipse.ui.views.markers.internal.DialogMarkerFilter.java

License:Open Source License

protected void createResetArea(Composite parent) {

    Button reset = new Button(parent, SWT.PUSH);
    reset.setText(MarkerMessages.restoreDefaults_text);
    reset.setData(new Integer(RESET_ID));

    reset.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            buttonPressed(((Integer) event.widget.getData()).intValue());
        }//from   ww w  .j  a  va2  s.  c  o  m
    });

    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Point minSize = reset.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    data.widthHint = Math.max(widthHint, minSize.x);
    data.horizontalSpan = 2;
    reset.setLayoutData(data);
}

From source file:org.eclipse.wb.internal.core.nls.ui.PropertiesComposite.java

License:Open Source License

/**
 * Sets good layout data for {@link Button}.
 *///from  w ww. j a v a  2s . c om
private static void setButtonLayoutData(Button button) {
    GridDataFactory.create(button).hintHU(IDialogConstants.BUTTON_WIDTH);
}