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:com.maccasoft.composer.InstrumentEditor.java

License:Open Source License

protected Button createButton(Composite parent, int id, String label) {
    ((GridLayout) parent.getLayout()).numColumns++;

    Button button = new Button(parent, SWT.PUSH);
    button.setText(label);//  w  w  w  .ja v a  2  s .c  o  m
    button.setFont(JFaceResources.getDialogFont());
    button.setData(new Integer(id));

    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);

    return button;
}

From source file:com.microsoft.tfs.client.common.ui.dialogs.vc.ApplyLabelDialog.java

License:Open Source License

private void createOkButton(final Composite parent) {
    okButton = MenuButtonFactory.getMenuButton(parent, SWT.NONE);
    okButton.setText(Messages.getString("ApplyLabelDialog.OkButtonText")); //$NON-NLS-1$

    final GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    okButton.setLayoutData(data);//from w  w w.ja va2  s  . c om

    /* Set to default size */
    final GC gc = new GC(okButton);
    final FontMetrics fm = gc.getFontMetrics();
    gc.dispose();

    final int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    final Point okSize = okButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    okSize.x = Math.max(widthHint, okSize.x);
    ControlSize.setSizeHints(okButton, okSize);

    /* Create menu */
    okButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            editLabel = false;
            okPressed();
        }
    });

    final IAction createLabelAction = new Action() {
        @Override
        public void run() {
            editLabel = false;
            okPressed();
        }
    };
    createLabelAction.setText(Messages.getString("ApplyLabelDialog.CreateLabelActionText")); //$NON-NLS-1$

    final IAction createAndEditLabelAction = new Action() {
        @Override
        public void run() {
            editLabel = true;
            okPressed();
        }
    };
    createAndEditLabelAction.setText(Messages.getString("ApplyLabelDialog.EditLabelActionText")); //$NON-NLS-1$

    okButton.addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            manager.add(createLabelAction);
            manager.add(createAndEditLabelAction);
        }
    });

    getShell().setDefaultButton(okButton.getButton());

    validate();
}

From source file:com.microsoft.tfs.client.common.ui.framework.helper.ButtonHelper.java

License:Open Source License

public static final void setButtonToButtonBarSize(final Button button) {
    final GC gc = new GC(button);
    final FontMetrics fm = gc.getFontMetrics();
    gc.dispose();//www .  j  a v a 2s  .  c om

    final int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    final Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);

    size.x = Math.max(widthHint, size.x);

    ControlSize.setSizeHints(button, size);
}

From source file:com.microsoft.tfs.client.common.ui.framework.layout.GridDataBuilder.java

License:Open Source License

public GridDataBuilder wButtonHint(final Control control) {
    final int widthHint = Dialog.convertHorizontalDLUsToPixels(ControlSize.getFontMetrics(control),
            IDialogConstants.BUTTON_WIDTH);
    final Point minSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gridData.widthHint = Math.max(widthHint, minSize.x);

    return this;
}

From source file:com.mountainminds.eclemma.internal.ui.wizards.SessionImportPage1.java

License:Open Source License

private void createFileBlock(Composite parent) {
    fileradio = new Button(parent, SWT.RADIO);
    fileradio.setText(ImportSessionPage1ExecutionDataFile_label);
    fileradio.addSelectionListener(new SelectionAdapter() {
        @Override//from w w  w  .  j  av  a  2 s .  c  o m
        public void widgetSelected(SelectionEvent e) {
            updateEnablement();
            updateStatus();
        }
    });
    filecombo = new Combo(parent, SWT.BORDER);
    filecombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            updateStatus();
        }
    });
    GridDataFactory.swtDefaults().span(3, 1).grab(true, false).align(SWT.FILL, SWT.CENTER)
            .hint(convertHorizontalDLUsToPixels(80), SWT.DEFAULT).applyTo(filecombo);
    browsebutton = new Button(parent, SWT.NONE);
    browsebutton.setText(BrowseAction_label);
    GridDataFactory.swtDefaults()
            .hint(convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH), SWT.DEFAULT)
            .applyTo(browsebutton);
    browsebutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            openBrowseDialog();
        }
    });
}

From source file:com.mulgasoft.emacsplus.preferences.ButtonFieldEditor.java

License:Open Source License

/**
 * @see org.eclipse.jface.preference.FieldEditor#doFillIntoGrid(org.eclipse.swt.widgets.Composite, int)
 *//*from www  .j  a v  a 2 s . co  m*/
@Override
protected void doFillIntoGrid(Composite parent, int numColumns) {
    top = parent;
    GridData gd = new GridData();
    gd.horizontalSpan = numColumns;
    gd.horizontalAlignment = GridData.FILL;
    gd.horizontalAlignment = GridData.END;
    gd.grabExcessHorizontalSpace = true;

    button = getButtonControl(parent);

    int widthHint = convertHorizontalDLUsToPixels(button, IDialogConstants.BUTTON_WIDTH);
    gd.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(gd);
}

From source file:com.mulgasoft.emacsplus.preferences.MListEditor.java

License:Open Source License

/**
 * Helper method to create a push button.
 * /*from   w w  w.j  a v  a  2 s . c  o m*/
 * @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);
    String buttonText = JFaceResources.getString(key);
    button.setText(buttonText);
    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:com.nokia.carbide.remoteconnections.internal.ui.ClientServiceSiteUI2.java

License:Open Source License

public void createComposite(Composite parent) {
    initializeDialogUnits(parent);/*from ww w  .j  a  va  2 s .  c  o  m*/
    Group group = new Group(parent, SWT.NONE);
    group.setText(Messages.getString("ClientServiceSiteUI2.UseConnectionGroupLabel")); //$NON-NLS-1$
    group.setLayout(new GridLayout());
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$

    viewer = new ComboViewer(group, SWT.READ_ONLY);
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Check.checkContract(element instanceof String);
            String id = (String) element;
            return connectionNames.get(id);
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    viewer.getCombo().setLayoutData(gd);
    viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            String connection = (String) selection.getFirstElement();
            if (connection != null && !connection.equals(ClientServiceSiteUI2.this.connection)) {
                ClientServiceSiteUI2.this.connection = connection;
                fireConnectionSelected();
            }
        }
    });

    final Composite composite = new Composite(group, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
    layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
    layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
    layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
    composite.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER);
    composite.setLayoutData(gd);
    composite.setFont(parent.getFont());

    newButton = new Button(composite, SWT.PUSH);
    newButton.setText(Messages.getString("ClientServiceSiteUI2.NewButtonLabel")); //$NON-NLS-1$
    newButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    newButton.setLayoutData(gd);
    newButton.setData(UID, "newButton"); //$NON-NLS-1$
    newButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SettingsWizard wizard = new SettingsWizard(null, service);
            wizard.open(composite.getShell());
            IConnection connection = wizard.getConnectionToEdit();
            // note: refresh ASAP so the selection will be valid; but endure a listener event
            // which will redo this
            refreshUI();
            setViewerInput(connection);
        }
    });

    editButton = new Button(composite, SWT.PUSH);
    editButton.setText(Messages.getString("ClientServiceSiteUI2.EditButtonLabel")); //$NON-NLS-1$
    editButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    editButton.setLayoutData(gd);
    editButton.setData(UID, "editButton"); //$NON-NLS-1$
    editButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object value = selection.getFirstElement();
            if (value instanceof String) {
                IConnection editConnection = getActualConnection((String) value);
                SettingsWizard wizard = new SettingsWizard(editConnection, service);
                wizard.open(composite.getShell());

                // leave the viewer the same, callback will refresh anything needed
            }
        }
    });

    // attach listeners
    RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(this);
    RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(this);

    // remove listeners on dispose
    group.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            RemoteConnectionsActivator.getConnectionsManager()
                    .removeConnectionListener(ClientServiceSiteUI2.this);
            RemoteConnectionsActivator.getConnectionsManager()
                    .removeConnectionStoreChangedListener(ClientServiceSiteUI2.this);
        }
    });

    setViewerInput(null);
}

From source file:com.nokia.carbide.remoteconnections.settings.ui.ConnectionSettingsPage.java

License:Open Source License

private void createServiceTestComposite(Composite parent) {
    Composite serviceSelectionComposite = new Composite(parent, SWT.NONE);
    serviceSelectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    serviceSelectionComposite.setLayout(new GridLayout());
    Label label = new Label(serviceSelectionComposite, SWT.NONE);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    label.setText(Messages.getString("ConnectionSettingsPage.ServicesListLabel")); //$NON-NLS-1$
    servicesListViewer = new ListViewer(serviceSelectionComposite,
            SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gd_viewer = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
    servicesListViewer.getControl().setLayoutData(gd_viewer);
    servicesListViewer.setContentProvider(new ArrayContentProvider());
    servicesListViewer.setLabelProvider(new LabelProvider() {
        @Override/*www .j a  v  a2 s. co m*/
        public String getText(Object element) {
            if (element instanceof IService)
                return ((IService) element).getDisplayName();
            return null;
        }
    });
    servicesListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) servicesListViewer.getSelection();
            IService curService = (IService) selection.getFirstElement();
            if (!curService.equals(service)) {
                service = curService;
                serviceTestButton.setEnabled(service.isTestable());
                resetServiceTesting(true);
            }
        }
    });
    servicesListViewer.getControl()
            .setToolTipText(Messages.getString("ConnectionSettingsPage.ServicesListToolTip")); //$NON-NLS-1$
    servicesListViewer.getControl().setData(UID, "servicesListViewer"); //$NON-NLS-1$

    Composite testButtonComposite = new Composite(parent, SWT.NONE);
    testButtonComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    testButtonComposite.setLayout(new GridLayout());
    serviceTestInfo = new Text(testButtonComposite, SWT.READ_ONLY | SWT.WRAP);
    serviceTestButton = new Button(testButtonComposite, SWT.PUSH);
    GridData gd_button = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    serviceTestButton.setText(Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel")); //$NON-NLS-1$
    Point minSize = serviceTestButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd_button.widthHint = Math.max(widthHint, minSize.x);
    GridData gd_text = new GridData(SWT.CENTER, SWT.FILL, true, true);
    gd_text.widthHint = gd_button.widthHint;
    serviceTestInfo.setLayoutData(gd_text);
    serviceTestInfo.setData(UID, "serviceTestInfo"); //$NON-NLS-1$
    serviceTestButton.setLayoutData(gd_button);
    serviceTestButton.setToolTipText(Messages.getString("ConnectionSettingsPage.ServiceTestButtonToolTip")); //$NON-NLS-1$
    serviceTestButton.setData(UID, "serviceTestButton"); //$NON-NLS-1$
    serviceTestButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (isTesting) {
                serviceTestButton
                        .setText(Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel")); //$NON-NLS-1$
                resetServiceTesting(true);
            } else {
                serviceTestButton
                        .setText(Messages.getString("ConnectionSettingsPage.StopServiceTestButtonLabel")); //$NON-NLS-1$
                testService();
            }
        }
    });

    Composite statusComposite = new Composite(parent, SWT.NONE);
    statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    statusComposite.setLayout(new GridLayout());
    statusLabel = new Label(statusComposite, SWT.NONE);
    statusLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
    statusLabel.setText(Messages.getString("ConnectionSettingsPage.StatusLabel")); //$NON-NLS-1$
    statusText = new Text(statusComposite, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
    statusText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    statusText.setText(STATUS_NOT_TESTED);
    statusText.setData(UID, "statusText"); //$NON-NLS-1$
}

From source file:com.nokia.carbide.remoteconnections.ui.ClientServiceSiteUI.java

License:Open Source License

public void createComposite(Composite parent) {
    initializeDialogUnits(parent);//from  w w w  .ja v  a  2  s.c  om
    Group group = new Group(parent, SWT.NONE);
    group.setText(Messages.getString("ClientServiceSiteUI.UseConnectionGroupLabel")); //$NON-NLS-1$
    group.setLayout(new GridLayout());
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$

    viewer = new ComboViewer(group, SWT.READ_ONLY);
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Check.checkContract(element instanceof IConnection);
            return ((IConnection) element).getDisplayName();
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    viewer.getCombo().setLayoutData(gd);
    viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            IConnection connection = (IConnection) selection.getFirstElement();
            if (!connection.equals(ClientServiceSiteUI.this.connection)) {
                ClientServiceSiteUI.this.connection = connection;
                fireConnectionSelected();
            }
        }
    });

    final Composite composite = new Composite(group, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
    layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
    layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
    layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
    composite.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER);
    composite.setLayoutData(gd);
    composite.setFont(parent.getFont());

    newButton = new Button(composite, SWT.PUSH);
    newButton.setText(Messages.getString("ClientServiceSiteUI.NewButtonLabel")); //$NON-NLS-1$
    newButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    newButton.setLayoutData(gd);
    newButton.setData(UID, "newButton"); //$NON-NLS-1$
    newButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SettingsWizard wizard = new SettingsWizard(null, service);
            wizard.open(composite.getShell());
            setViewerInput(wizard.getConnectionToEdit());
        }
    });

    editButton = new Button(composite, SWT.PUSH);
    editButton.setText(Messages.getString("ClientServiceSiteUI.EditButtonLabel")); //$NON-NLS-1$
    editButton.setFont(JFaceResources.getDialogFont());
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
    minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    editButton.setLayoutData(gd);
    editButton.setData(UID, "editButton"); //$NON-NLS-1$
    editButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object value = selection.getFirstElement();
            if (value instanceof IConnection) {
                SettingsWizard wizard = new SettingsWizard((IConnection) value, service);
                wizard.open(composite.getShell());
                setViewerInput(wizard.getConnectionToEdit());
            }
        }
    });

    setViewerInput(null);
}