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.oomph.projectconfig.presentation.ProjectConfigPreferencePage.java

License:Open Source License

@Override
protected void contributeButtons(Composite parent) {
    super.contributeButtons(parent);

    GridLayout gridLayout = (GridLayout) parent.getLayout();
    gridLayout.numColumns += 2;/*  w w  w.  j a  v  a2  s.c  om*/

    {
        Button applyButton = new Button(parent, SWT.PUSH);
        applyButton.setText("Apply");

        Dialog.applyDialogFont(applyButton);
        int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
        Point minButtonSize = applyButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
        GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        data.widthHint = Math.max(widthHint, minButtonSize.x);

        applyButton.setLayoutData(data);
        applyButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                performOk();

                WorkspaceConfiguration workspaceConfiguration = ProjectConfigUtil.getWorkspaceConfiguration();
                workspaceConfiguration.updatePreferenceProfileReferences();
                workspaceConfiguration.applyPreferenceProfiles();
            }
        });
    }

    {
        Button editButton = new Button(parent, SWT.PUSH);
        editButton.setText("Edit...");

        Dialog.applyDialogFont(editButton);
        int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
        Point minButtonSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
        GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        data.widthHint = Math.max(widthHint, minButtonSize.x);

        editButton.setLayoutData(data);
        editButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                performOk();

                // Invoke the close method on the preference dialog, but avoid using internal API, so do it reflectively.
                IPreferencePageContainer container = getContainer();

                try {
                    Method method = container.getClass().getMethod("close");
                    method.invoke(container);
                } catch (Throwable ex) {
                    ProjectConfigEditorPlugin.INSTANCE.log(ex);
                }

                openWorkingSetsEditor();
            }
        });
    }
}

From source file:org.eclipse.oomph.setup.ui.recorder.RecorderPreferencePage.java

License:Open Source License

@Override
protected void contributeButtons(Composite parent) {
    initializePreferencesButton = new Button(parent, SWT.PUSH);
    initializePreferencesButton.setText("Initialize...");

    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Dialog.applyDialogFont(initializePreferencesButton);
    Point minButtonSize = initializePreferencesButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.widthHint = Math.max(widthHint, minButtonSize.x);
    initializePreferencesButton.setLayoutData(data);

    final PreferenceManager preferenceManager = PlatformUI.getWorkbench().getPreferenceManager();
    initializePreferencesButton.addSelectionListener(new SelectionAdapter() {
        @Override/*from   w w  w .  j  a va  2  s. co m*/
        public void widgetSelected(SelectionEvent e) {
            new PreferenceInitializationDialog((PreferenceDialog) getContainer(), preferenceManager).open();
        }
    });

    Set<String> preferencePages = RecorderManager.INSTANCE.getInitializedPreferencePages();
    List<IPreferenceNode> preferenceNodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER);
    for (IPreferenceNode element : preferenceNodes) {
        String id = element.getId();
        if (preferencePages.contains(id)) {
            initializePreferencesButton.setEnabled(false);
            break;
        }
    }
}

From source file:org.eclipse.oomph.workingsets.presentation.WorkingSetsPreferencePage.java

License:Open Source License

@Override
protected void contributeButtons(Composite parent) {
    super.contributeButtons(parent);

    GridLayout gridLayout = (GridLayout) parent.getLayout();
    gridLayout.numColumns += 2;// w  w w . jav  a  2  s  .  c om

    Button editButton = new Button(parent, SWT.PUSH);
    editButton.setText("Edit...");

    Dialog.applyDialogFont(editButton);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Point minButtonSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.widthHint = Math.max(widthHint, minButtonSize.x);

    editButton.setLayoutData(data);
    editButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Invoke the close method on the preference dialog, but avoid using internal API, so do it reflectively.
            IPreferencePageContainer container = getContainer();

            try {
                Method method = container.getClass().getMethod("close");
                method.invoke(container);
            } catch (Throwable ex) {
                WorkingSetsEditorPlugin.INSTANCE.log(ex);
            }

            openWorkingSetsEditor();
        }
    });

    Button applyButton = new Button(parent, SWT.PUSH);
    applyButton.setText("Apply");

    Dialog.applyDialogFont(applyButton);
    minButtonSize = applyButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.widthHint = Math.max(widthHint, minButtonSize.x);

    applyButton.setLayoutData(data);
    applyButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            performApply();
        }
    });
}

From source file:org.eclipse.php.internal.ui.wizards.fields.LayoutUtil.java

License:Open Source License

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

From source file:org.eclipse.ptp.rm.mpi.mpich2.ui.launch.BasicMPICH2RMLaunchConfigurationDynamicTab.java

License:Open Source License

/**
 * @since 2.0//from  w  w w . j  a  v  a 2s.  co m
 */
public void createControl(Composite parent, IResourceManager rm, IPQueue queue) throws CoreException {
    control = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    control.setLayout(layout);

    Label label = new Label(control, SWT.NONE);
    label.setText(Messages.BasicMPICH2RMLaunchConfigurationDynamicTab_Label_NumberProcesses);

    numProcsSpinner = new Spinner(control, SWT.BORDER);
    numProcsSpinner.addModifyListener(getListener());
    numProcsSpinner.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));

    final Group optionsGroup = new Group(control, SWT.NONE);
    optionsGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    optionsGroup.setText(Messages.BasicMPICH2RMLaunchConfigurationDynamicTab_Title_OptionsGroup);
    layout = new GridLayout();
    layout.numColumns = 3;
    optionsGroup.setLayout(layout);

    noLocalButton = new Button(optionsGroup, SWT.CHECK);
    noLocalButton.addSelectionListener(getListener());
    noLocalButton.setText(Messages.BasicMPICH2RMLaunchConfigurationDynamicTab_Label_NoLocal);

    usePrefixButton = new Button(optionsGroup, SWT.CHECK);
    usePrefixButton.addSelectionListener(getListener());
    usePrefixButton.setText(Messages.BasicMPICH2RMLaunchConfigurationDynamicTab_Label_Prefix);

    prefixText = new Text(optionsGroup, SWT.BORDER);
    prefixText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    prefixText.addModifyListener(getListener());

    final Group hostGroup = new Group(control, SWT.NONE);
    hostGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    hostGroup.setText(Messages.BasicMPICH2RMLaunchConfigurationDynamicTab_Title_HostGroup);
    layout = new GridLayout();
    layout.numColumns = 3;
    hostGroup.setLayout(layout);

    hostFileButton = new Button(hostGroup, SWT.CHECK);
    hostFileButton.addSelectionListener(getListener());
    hostFileButton.setText(Messages.BasicMPICH2RMLaunchConfigurationDynamicTab_Label_HostFile);

    hostFileText = new Text(hostGroup, SWT.BORDER);
    hostFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    hostFileText.addModifyListener(getListener());

    browseButton = new Button(hostGroup, SWT.NONE);
    browseButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    browseButton.addSelectionListener(getListener());
    PixelConverter pixelconverter = new PixelConverter(control);
    GridData gd = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
    gd.widthHint = pixelconverter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    browseButton.setLayoutData(gd);
    browseButton.setText(Messages.BasicMPICH2RMLaunchConfigurationDynamicTab_Label_Browse);

    hostListButton = new Button(hostGroup, SWT.CHECK);
    hostListButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    hostListButton.addSelectionListener(getListener());
    hostListButton.setText(Messages.BasicMPICH2RMLaunchConfigurationDynamicTab_Title_HostList);

    hostListText = new Text(hostGroup, SWT.V_SCROLL | SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.heightHint = 20;
    hostListText.setLayoutData(gd);
    hostListText.addModifyListener(getListener());
}

From source file:org.eclipse.ptp.rm.mpi.openmpi.ui.launch.BasicOpenMpiRMLaunchConfigurationDynamicTab.java

License:Open Source License

/**
 * @since 2.0//from   w w  w .  j  a v  a  2 s. c o m
 */
public void createControl(Composite parent, IResourceManager rm, IPQueue queue) throws CoreException {
    control = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    control.setLayout(layout);

    Label label = new Label(control, SWT.NONE);
    label.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Label_NumberProcesses);

    numProcsSpinner = new Spinner(control, SWT.BORDER);
    numProcsSpinner.addModifyListener(getListener());
    numProcsSpinner.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));

    final Group optionsGroup = new Group(control, SWT.NONE);
    optionsGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    optionsGroup.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Title_OptionsGroup);
    layout = new GridLayout();
    layout.numColumns = 4;
    optionsGroup.setLayout(layout);

    byNodeButton = new Button(optionsGroup, SWT.CHECK);
    byNodeButton.addSelectionListener(getListener());
    byNodeButton.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Label_ByNode);

    bySlotButton = new Button(optionsGroup, SWT.CHECK);
    bySlotButton.addSelectionListener(getListener());
    bySlotButton.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Label_BySlot);

    noOversubscribeButton = new Button(optionsGroup, SWT.CHECK);
    noOversubscribeButton.addSelectionListener(getListener());
    noOversubscribeButton.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Label_NoOversubscribe);

    noLocalButton = new Button(optionsGroup, SWT.CHECK);
    noLocalButton.addSelectionListener(getListener());
    noLocalButton.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Label_NoLocal);

    usePrefixButton = new Button(optionsGroup, SWT.CHECK);
    usePrefixButton.addSelectionListener(getListener());
    usePrefixButton.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Label_Prefix);

    prefixText = new Text(optionsGroup, SWT.BORDER);
    prefixText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    prefixText.addModifyListener(getListener());

    final Group hostGroup = new Group(control, SWT.NONE);
    hostGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    hostGroup.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Title_HostGroup);
    layout = new GridLayout();
    layout.numColumns = 3;
    hostGroup.setLayout(layout);

    hostFileButton = new Button(hostGroup, SWT.CHECK);
    hostFileButton.addSelectionListener(getListener());
    hostFileButton.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Label_HostFile);

    hostFileText = new Text(hostGroup, SWT.BORDER);
    hostFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    hostFileText.addModifyListener(getListener());

    browseButton = new Button(hostGroup, SWT.NONE);
    browseButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    browseButton.addSelectionListener(getListener());
    PixelConverter pixelconverter = new PixelConverter(control);
    GridData gd = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
    gd.widthHint = pixelconverter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    browseButton.setLayoutData(gd);
    browseButton.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Label_Browse);

    hostListButton = new Button(hostGroup, SWT.CHECK);
    hostListButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    hostListButton.addSelectionListener(getListener());
    hostListButton.setText(Messages.BasicOpenMpiRMLaunchConfigurationDynamicTab_Title_HostList);

    hostListText = new Text(hostGroup, SWT.V_SCROLL | SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.heightHint = 20;
    hostListText.setLayoutData(gd);
    hostListText.addModifyListener(getListener());

}

From source file:org.eclipse.rcptt.launching.configuration.ui.Q7LaunchConfigurationTab.java

License:Open Source License

private void createSelectConfButton(Composite parent) {
    Composite buttonComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;//from  w w  w . j a v  a2 s .c o  m
    layout.marginWidth = 0;
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    buttonComposite.setLayout(layout);
    buttonComposite.setLayoutData(gridData);
    buttonComposite.setFont(parent.getFont());

    Button button = new Button(buttonComposite, SWT.PUSH);
    button.setFont(buttonComposite.getFont());
    button.setText(SELECT_CONF_BUTTON_LABEL);
    GridData gd = new GridData();
    button.setLayoutData(gd);
    gd.widthHint = IDialogConstants.BUTTON_WIDTH;
    gd.horizontalAlignment = GridData.FILL;

    button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            selectSourceConfig();
        }
    });
}

From source file:org.eclipse.rcptt.ui.history.ListDialogField.java

License:Open Source License

protected Button createButton(Composite parent, String label, SelectionListener listener) {
    Button button = new Button(parent, SWT.PUSH);
    button.setFont(parent.getFont());//from   w ww  . j a v  a 2s  . co  m
    button.setText(label);
    button.addSelectionListener(listener);
    GridData gd = new GridData();
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = GridData.BEGINNING;

    button.setFont(JFaceResources.getDialogFont());
    PixelConverter converter = new PixelConverter(button);
    int wh = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    gd.widthHint = Math.max(wh, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);

    button.setLayoutData(gd);

    return button;
}

From source file:org.eclipse.riena.ui.swt.utils.UIControlsFactory.java

License:Open Source License

/**
 * Inspect the given {@link Button} widget and return the recommended width,
 * in pixels, so that the Button is wide enough to show it's contents
 * (image, text, etc.).//  w w  w  . j  a v  a2s  . c o  m
 * 
 * @param button
 *            a Button instance; never null
 * @return suggested width; in pixels
 */
public static int getWidthHint(final Button button) {
    final GC gc = new GC(button.getDisplay());
    try {
        final FontMetrics fm = gc.getFontMetrics();
        final int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
        final Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
        return Math.max(widthHint, minSize.x);
    } finally {
        gc.dispose();
    }
}

From source file:org.eclipse.sirius.common.ui.tools.api.dialog.AbstractFolderSelectionDialog.java

License:Open Source License

/**
 * {@inheritDoc}// w  w w . ja  va  2  s.  c  o  m
 * 
 * @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 */
@Override
protected Control createDialogArea(final Composite parent) {
    final Composite result = (Composite) super.createDialogArea(parent);

    getTreeViewer().addSelectionChangedListener(this);
    getTreeViewer().expandToLevel(2);
    fNewFolderButton = new Button(result, SWT.PUSH);
    fNewFolderButton.setText("New Folder");
    fNewFolderButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent event) {
            newFolderButtonPressed();
        }
    });
    fNewFolderButton.setFont(parent.getFont());
    fNewFolderButton.setLayoutData(new GridData());

    // Modified by Obeo (copy/paste
    // org.eclipse.pde.internal.ui.util.SWTUtil.setButtonDimensionHint(Button)
    Dialog.applyDialogFont(fNewFolderButton);
    final Object gd = fNewFolderButton.getLayoutData();
    if (gd instanceof GridData) {
        if (fNewFolderButton.getFont().equals(JFaceResources.getDefaultFont())) {
            fNewFolderButton.setFont(JFaceResources.getDialogFont());
        }
        final GC gc = new GC(fNewFolderButton);
        gc.setFont(fNewFolderButton.getFont());
        final FontMetrics fFontMetrics = gc.getFontMetrics();
        gc.dispose();
        final int widthHint = Dialog.convertHorizontalDLUsToPixels(fFontMetrics, IDialogConstants.BUTTON_WIDTH);
        ((GridData) gd).widthHint = Math.max(widthHint,
                fNewFolderButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    }

    Dialog.applyDialogFont(result);
    return result;
}