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.cs3.pdt.connector.internal.preferences.PreferencePage.java

License:Open Source License

private Button createButton(Composite parent, String label) {
    Button button = new Button(parent, SWT.PUSH);
    button.setText(label);//from w w  w.  j a v a  2 s . c o  m

    GridData data = new GridData(SWT.FILL, 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);
    return button;
}

From source file:org.cs3.prolog.ui.util.FileListEditor.java

License:Open Source License

/**
 * Helper method to create a push button.
 * //from  ww  w.j a v a 2s  .  c om
 * @param parent the parent control
 * @param key the resource name used to supply the button's label text
 * @return Button
 */
private Button createPushButton(Composite parent, String key) {
    Button button = new Button(parent, SWT.PUSH);
    if (key.equals("HACK.addFile")) {
        button.setText(addFileButtonLabel);
    } else if (key.equals("HACK.addDir")) {
        button.setText(addDirButtonLabel);
    } else {
        button.setText(JFaceResources.getString(key));
    }
    button.setFont(parent.getFont());
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    int widthHint = convertHorizontalDLUsToPixels(button, IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(data);
    button.addSelectionListener(getSelectionListener());
    return button;
}

From source file:org.csstudio.auth.ui.internal.preferences.SystemPropertiesPreferencePage.java

License:Open Source License

/**
 * {@inheritDoc}//from   ww w .  j  a va2 s  .  c  o m
 */
@Override
protected Control createContents(final Composite parent) {
    // We don't want Reset and Apply buttons on this preference page.
    // Apply does not work anyway (system properties are set during startup)
    // and Reset is not supported currently.
    noDefaultAndApplyButton();

    Composite contents = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    contents.setLayout(layout);
    contents.setFont(parent.getFont());

    Label about = new Label(contents, SWT.WRAP);
    about.setText(Messages.SystemPropertiesPreferencePage_ABOUT_TEXT);
    GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1);
    data.widthHint = 300;
    about.setLayoutData(data);

    final TableViewer viewer = new TableViewer(contents,
            SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    initializeTableViewer(viewer);
    viewer.setContentProvider(new PropertiesContentProvider());
    viewer.setLabelProvider(new PropertiesLabelProvider());

    Button addButton = new Button(contents, SWT.PUSH);
    addButton.setText(Messages.SystemPropertiesPreferencePage_ADD_BUTTON);
    data = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    addButton.setLayoutData(data);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            Shell shell = e.widget.getDisplay().getActiveShell();
            SystemPropertyDialog dlg = new SystemPropertyDialog(shell);
            if (dlg.open() == Window.OK) {
                SystemPropertyPreferenceEntry entry = new SystemPropertyPreferenceEntry(dlg.getKey(),
                        dlg.getValue());
                _properties.add(entry);
            }
        }
    });

    final Button removeButton = new Button(contents, SWT.PUSH);
    removeButton.setText(Messages.SystemPropertiesPreferencePage_REMOVE_BUTTON);
    data = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    removeButton.setLayoutData(data);
    removeButton.setEnabled(false);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                SystemPropertyPreferenceEntry entry = (SystemPropertyPreferenceEntry) i.next();
                _properties.remove(entry);
            }
        }
    });

    // Add a selection listener to the viewer that will enable the
    // "Remove" button when at least one item is selected in the table.
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(final SelectionChangedEvent event) {
            removeButton.setEnabled(!event.getSelection().isEmpty());
        }
    });

    _properties = new PropertiesModel();
    _properties.loadFromPreferences();
    viewer.setInput(_properties);

    return contents;
}

From source file:org.csstudio.domain.common.ui.AbstractTableFieldEditor.java

License:Open Source License

/**
 * Helper method to create a push button.
 *
 * @param parent//  w w w  . jav a  2s .  co  m
 *            the parent control
 * @param key
 *            the resource name used to supply the button's label text
 * @return Button
 */
private Button createPushButton(final Composite parent, final String key,
        final SelectionListener selectionListener) {
    final Button button = new Button(parent, SWT.PUSH);
    button.setText(JFaceResources.getString(key));
    button.setFont(parent.getFont());
    final GridData data = new GridData(GridData.FILL_HORIZONTAL);
    final int widthHint = convertHorizontalDLUsToPixels(button, IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(data);
    button.addSelectionListener(selectionListener);
    return button;
}

From source file:org.csstudio.swt.xygraph.toolbar.XYGraphConfigDialog.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    ((GridLayout) parent.getLayout()).numColumns++;
    Button button = new Button(parent, SWT.PUSH);
    button.setText("Apply");
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    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 ww w . j  a va  2  s. c  o m*/
    button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            applyChanges();
        }
    });
    super.createButtonsForButtonBar(parent);
    Shell shell = parent.getShell();
    if (shell != null) {
        shell.setDefaultButton(button);
    }
}

From source file:org.csstudio.utility.screenshot.preference.AddRemoveListFieldEditor.java

License:Open Source License

/**
 * @see org.eclipse.jface.preference.FieldEditor#doFillIntoGrid
 * (Composite, int)/*  w w  w .j  a  v a 2  s.  c  o  m*/
 */
@Override
protected void doFillIntoGrid(Composite parent, int numColumns) {
    top = parent;

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = numColumns;
    top.setLayoutData(gd);

    Label label = getLabelControl(top);
    GridData labelData = new GridData();
    labelData.horizontalSpan = numColumns;
    label.setLayoutData(labelData);

    list = new List(top, SWT.BORDER | SWT.V_SCROLL);

    // Create a grid data that takes up the extra
    // space in the dialog and spans both columns.
    GridData listData = new GridData(GridData.FILL_HORIZONTAL);
    listData.heightHint = convertVerticalDLUsToPixels(list, LIST_HEIGHT_IN_DLUS);
    listData.horizontalSpan = numColumns;

    list.setLayoutData(listData);
    list.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            selectionChanged();
        }
    });

    // Create a composite for the add and remove
    // buttons and the input text field.
    Composite addRemoveGroup = new Composite(top, SWT.NONE);

    GridData addRemoveData = new GridData(GridData.FILL_HORIZONTAL);
    addRemoveData.horizontalSpan = numColumns;
    addRemoveGroup.setLayoutData(addRemoveData);

    GridLayout addRemoveLayout = new GridLayout();
    addRemoveLayout.numColumns = numColumns;
    addRemoveLayout.marginHeight = 0;
    addRemoveLayout.marginWidth = 0;
    addRemoveGroup.setLayout(addRemoveLayout);

    // Create a composite for the add and remove buttons.
    Composite buttonGroup = new Composite(addRemoveGroup, SWT.NONE);
    buttonGroup.setLayoutData(new GridData());

    GridLayout buttonLayout = new GridLayout();
    buttonLayout.marginHeight = 0;
    buttonLayout.marginWidth = 0;
    buttonGroup.setLayout(buttonLayout);

    // Create the add button.
    add = new Button(buttonGroup, SWT.NONE);
    add.setText(DEFAULT_ADD_LABEL);
    add.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            add();
        }
    });

    GridData addData = new GridData(GridData.FILL_HORIZONTAL);
    //addData.heightHint = convertVerticalDLUsToPixels(add, IDialogConstants.BUTTON_HEIGHT);
    addData.widthHint = convertHorizontalDLUsToPixels(add, IDialogConstants.BUTTON_WIDTH);
    add.setLayoutData(addData);

    // Create the remove button.
    remove = new Button(buttonGroup, SWT.NONE);
    remove.setEnabled(false);
    remove.setText(DEFAULT_REMOVE_LABEL);
    remove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            list.remove(list.getSelectionIndex());
            selectionChanged();
        }
    });
    GridData removeData = new GridData(GridData.FILL_HORIZONTAL);
    // removeData.heightHint = convertVerticalDLUsToPixels(remove, IDialogConstants.BUTTON_HEIGHT);
    removeData.widthHint = convertHorizontalDLUsToPixels(remove, IDialogConstants.BUTTON_WIDTH);
    remove.setLayoutData(removeData);

    // Create the text field.
    textField = new Text(addRemoveGroup, SWT.BORDER);

    GridData textData = new GridData(GridData.FILL_HORIZONTAL);
    textData.horizontalSpan = numColumns - 1;
    textData.verticalAlignment = GridData.BEGINNING;
    textField.setLayoutData(textData);
}

From source file:org.destecs.ide.ui.wizards.DestecsScenarioWizardPageCreation.java

License:Open Source License

private static int getButtonWidthHint(Button button) {
    /*button.setFont(JFaceResources.getDialogFont());*/
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:org.destecs.ide.ui.wizards.DestecsWizardPageCreation.java

License:Open Source License

private static int getButtonWidthHint(Button button) {
    /* button.setFont(JFaceResources.getDialogFont()); */
    PixelConverter converter = new PixelConverter(button);
    int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:org.dita_op.dost.launcher.internal.ui.launchConfiguration.AddArgumentDialog.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 *///from w ww .j  a  v a  2 s .com
@Override
protected Control createDialogArea(Composite parent) {
    Composite comp = (Composite) super.createDialogArea(parent);
    ((GridLayout) comp.getLayout()).numColumns = 2;

    new Label(comp, SWT.NONE).setText(Messages.getString("AddArgumentDialog.nameText.label")); //$NON-NLS-1$

    nameText = new Text(comp, SWT.BORDER | SWT.SINGLE);
    nameText.setText(initialValues[0]);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 300;
    nameText.setLayoutData(gd);
    nameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            updateButtons();
        }
    });

    new Label(comp, SWT.NONE).setText(Messages.getString("AddArgumentDialog.valueText.label")); //$NON-NLS-1$

    valueText = new Text(comp, SWT.BORDER | SWT.SINGLE);
    valueText.setText(initialValues[1]);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 300;
    valueText.setLayoutData(gd);
    valueText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            updateButtons();
        }
    });

    Button variablesButton = new Button(comp, SWT.PUSH);
    variablesButton.setText(Messages.getString("AddArgumentDialog.variableButton.label")); //$NON-NLS-1$
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gd.horizontalSpan = 2;
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    gd.widthHint = Math.max(widthHint, variablesButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    variablesButton.setLayoutData(gd);

    variablesButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent se) {
            getVariable();
        }
    });

    return comp;
}

From source file:org.ebayopensource.turmeric.eclipse.utils.ui.UIUtil.java

License:Open Source License

/**
 * Returns a width hint for a button control.
 * // w  ww.j av  a 2  s.  co  m
 * @param button
 *            the button
 * @return the width hint
 */
public static int getButtonWidthHint(Button button) {
    button.setFont(JFaceResources.getDialogFont());
    Font font = button.getFont();
    GC gc = new GC(font.getDevice());
    gc.setFont(font);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(gc.getFontMetrics(), IDialogConstants.BUTTON_WIDTH);
    gc.dispose();
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}