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.jboss.tools.internal.deltacloud.ui.wizards.CloudConnectionPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    DataBindingContext dbc = new DataBindingContext();
    WizardPageSupport.create(this, dbc);

    final Composite container = new Composite(parent, SWT.NULL);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;/*from ww  w  . j  a va 2s . c  o m*/
    layout.marginWidth = 5;
    container.setLayout(layout);

    Label dummyLabel = new Label(container, SWT.NULL);

    // name
    Label nameLabel = new Label(container, SWT.NULL);
    nameLabel.setText(WizardMessages.getString(NAME_LABEL));
    Text nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    UIUtils.createPreferencesProposalAdapter(nameText, IDeltaCloudPreferenceConstants.CLOUD_NAME_PROPOSAL_KEY);
    bindName(dbc, nameText);

    // url
    Label urlLabel = new Label(container, SWT.NULL);
    urlLabel.setText(WizardMessages.getString(URL_LABEL));
    Point p1 = urlLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Text urlText = new Text(container, SWT.BORDER | SWT.SINGLE);
    UIUtils.createPreferencesProposalAdapter(urlText, IDeltaCloudPreferenceConstants.CLOUD_URL_PROPOSAL_KEY);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(urlText),
            BeanProperties.value(CloudConnectionPageModel.class, CloudConnectionPageModel.PROPERTY_URL)
                    .observe(connectionModel),
            new UpdateValueStrategy()
                    .setAfterGetValidator(
                            new MandatoryStringValidator(WizardMessages.getString(MUST_ENTER_A_URL)))
                    .setConverter(new TrimTrailingSlashConverter()),
            null);

    // cloud type
    Label typeLabel = new Label(container, SWT.NULL);
    typeLabel.setText(WizardMessages.getString(CLOUDTYPE_LABEL));
    Label computedTypeLabel = new Label(container, SWT.NULL);
    Binding typeLabelBinding = bindCloudType(dbc, urlText, computedTypeLabel);

    // bind url text decoration to type
    ControlDecoration decoration = JFaceUtils.createDecoration(urlText,
            WizardMessages.getString("IllegalCloudUrl.msg"), FieldDecorationRegistry.DEC_WARNING);
    IObservableValue validationStatusProvider = typeLabelBinding.getValidationStatus();
    DataBindingUtils.addValueChangeListener(
            new ControlDecorationAdapter(decoration, (IStatus) validationStatusProvider.getValue()),
            typeLabelBinding.getValidationStatus(), urlText);

    // set url from preferences
    String url = new StringPreferenceValue(IDeltaCloudPreferenceConstants.LAST_URL, Activator.PLUGIN_ID)
            .get(urlText.getText());
    urlText.setText(url);

    // username
    Label usernameLabel = new Label(container, SWT.NULL);
    usernameLabel.setText(WizardMessages.getString(USERNAME_LABEL));
    Text usernameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    UIUtils.createPreferencesProposalAdapter(usernameText,
            IDeltaCloudPreferenceConstants.CLOUD_USERNAME_PROPOSAL_KEY);
    IObservableValue usernameObservable = WidgetProperties.text(SWT.Modify).observe(usernameText);
    dbc.bindValue(usernameObservable,
            BeanProperties.value(CloudConnectionPageModel.class, CloudConnectionPageModel.PROPERTY_USERNAME)
                    .observe(connectionModel));

    // password
    Label passwordLabel = new Label(container, SWT.NULL);
    passwordLabel.setText(WizardMessages.getString(PASSWORD_LABEL));
    Text passwordText = new Text(container, SWT.BORDER | SWT.PASSWORD | SWT.SINGLE);
    ISWTObservableValue passwordTextObservable = WidgetProperties.text(SWT.Modify).observe(passwordText);
    dbc.bindValue(passwordTextObservable,
            BeanProperties.value(CloudConnectionPageModel.class, CloudConnectionPageModel.PROPERTY_PASSWORD)
                    .observe(connectionModel));
    // test button
    final Button testButton = new Button(container, SWT.NULL);
    testButton.setText(WizardMessages.getString(TESTBUTTON_LABEL));
    bindTestButtonEnablement(testButton, dbc);

    CredentialsTestAdapter credentialsTestAdapter = new CredentialsTestAdapter(usernameText, passwordText);
    testButton.addSelectionListener(credentialsTestAdapter);
    DataBindingUtils.addValueChangeListener(credentialsTestAdapter, usernameObservable, usernameText);
    DataBindingUtils.addValueChangeListener(credentialsTestAdapter, passwordTextObservable, passwordText);

    // ec2 user link
    Link ec2userLink = new Link(container, SWT.NULL);
    ec2userLink.setText(WizardMessages.getString(EC2_USER_INFO));
    ec2userLink.addListener(SWT.Selection, linkListener);

    // ec2 pw link
    Link ec2pwLink = new Link(container, SWT.NULL);
    ec2pwLink.setText(WizardMessages.getString(EC2_PASSWORD_INFO));
    ec2pwLink.addListener(SWT.Selection, linkListener);

    FormData f = new FormData();
    f.left = new FormAttachment(0, 0);
    f.right = new FormAttachment(100, 0);
    dummyLabel.setLayoutData(f);

    Point p2 = urlText.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int centering = (p2.y - p1.y + 1) / 2;

    f = new FormData();
    f.top = new FormAttachment(dummyLabel, 8 + centering);
    nameLabel.setLayoutData(f);

    f = new FormData();
    f.top = new FormAttachment(dummyLabel, 8);
    f.left = new FormAttachment(usernameLabel, 5);
    f.right = new FormAttachment(100, 0);
    nameText.setLayoutData(f);

    f = new FormData();
    f.top = new FormAttachment(nameText, 5 + centering);
    urlLabel.setLayoutData(f);

    f = new FormData();
    f.left = new FormAttachment(nameText, 0, SWT.LEFT);
    f.top = new FormAttachment(nameText, 5);
    f.right = new FormAttachment(100, 0);
    urlText.setLayoutData(f);

    f = new FormData();
    f.top = new FormAttachment(urlText, 5 + centering);
    typeLabel.setLayoutData(f);

    f = new FormData();
    f.left = new FormAttachment(urlText, 0, SWT.LEFT);
    f.top = new FormAttachment(urlText, 5 + centering);
    f.right = new FormAttachment(100, 0);
    computedTypeLabel.setLayoutData(f);

    f = new FormData();
    f.top = new FormAttachment(typeLabel, 10 + centering);
    usernameLabel.setLayoutData(f);

    f = new FormData();
    f.left = new FormAttachment(computedTypeLabel, 0, SWT.LEFT);
    f.top = new FormAttachment(computedTypeLabel, 10);
    f.right = new FormAttachment(100, -70);
    usernameText.setLayoutData(f);

    f = new FormData();
    f.left = new FormAttachment(usernameText, 0, SWT.LEFT);
    f.top = new FormAttachment(usernameText, 5);
    ec2userLink.setLayoutData(f);

    f = new FormData();
    f.top = new FormAttachment(ec2userLink, 5 + centering);
    passwordLabel.setLayoutData(f);

    f = new FormData();
    f.left = new FormAttachment(usernameText, 0, SWT.LEFT);
    f.top = new FormAttachment(ec2userLink, 5);
    f.right = new FormAttachment(100, -70);
    passwordText.setLayoutData(f);

    f = new FormData();
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Point minSize = testButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    f.width = Math.max(widthHint, minSize.x);
    f.left = new FormAttachment(usernameText, 10);
    f.top = new FormAttachment(usernameText, 0);
    f.right = new FormAttachment(100, 0);
    testButton.setLayoutData(f);

    f = new FormData();
    f.left = new FormAttachment(passwordText, 0, SWT.LEFT);
    f.top = new FormAttachment(passwordText, 5);
    ec2pwLink.setLayoutData(f);

    setControl(container);
}

From source file:org.jboss.tools.jst.web.ui.internal.preferences.AbstractImplementationsPreferencesPage.java

License:Open Source License

protected Control createContents(Composite parent) {
    noDefaultAndApplyButton();//from  w  w w  . j  a va  2s .  c  om

    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    heightHint = convertVerticalDLUsToPixels(14 /*IDialogConstants.BUTTON_HEIGHT*/);

    Composite root = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    root.setLayout(layout);

    //Add in a dummy(or errorMessage) label for spacing
    errorMessageLabel = new Label(root, SWT.NONE);
    if (errorMessage != null) {
        errorMessageLabel.setText(errorMessage);
        errorMessageLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
    }

    Composite impl = new Composite(root, SWT.NULL);
    GridLayout layoutImpl = new GridLayout();
    layoutImpl.numColumns = 2;
    impl.setLayout(layoutImpl);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.grabExcessHorizontalSpace = true;
    impl.setLayoutData(data);

    // listImplementations
    listImplementations = new List(impl, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    if (errorMessage == null)
        listImplementations.setItems(implementations);
    GridData gridDataList = new GridData(GridData.FILL_BOTH);
    gridDataList.widthHint = 270;//Minimum width for the column.
    gridDataList.horizontalSpan = 1;
    gridDataList.verticalSpan = 2;
    listImplementations.setLayoutData(gridDataList);

    heightHint = convertVerticalDLUsToPixels(14 /*IDialogConstants.BUTTON_HEIGHT*/);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);

    addButtonImpl = createButton(impl, Messages.ImplementationsPreferencesPage_Add);
    if (errorMessage != null)
        addButtonImpl.setEnabled(false);

    removeButtonImpl = createButton(impl, Messages.ImplementationsPreferencesPage_Remove);
    removeButtonImpl.setEnabled(false);

    // TabFolder
    TabFolder tabbedComposite = new TabFolder(root, SWT.NULL);
    GridData gridDataTab = new GridData(GridData.FILL_BOTH);
    tabbedComposite.setLayoutData(gridDataTab);

    TabItem librariesTab = new TabItem(tabbedComposite, SWT.NULL);
    librariesTab.setText(Messages.ImplementationsPreferencesPage_Library_Sets);

    TabItem projectTab = new TabItem(tabbedComposite, SWT.NULL);
    projectTab.setText(Messages.ImplementationsPreferencesPage_Project_Templates);

    // listLibraries      
    Composite entryLibraries = new Composite(tabbedComposite, SWT.NULL);
    GridLayout layoutEntryLibraries = new GridLayout();
    layoutEntryLibraries.numColumns = 2;
    entryLibraries.setLayout(layoutEntryLibraries);

    final List listLibraries = new List(entryLibraries, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    GridData gridDataListLibraries = new GridData(GridData.FILL_BOTH);
    gridDataListLibraries.verticalSpan = 2;
    listLibraries.setLayoutData(gridDataListLibraries);

    addButtonLibraries = createButton(entryLibraries, Messages.ImplementationsPreferencesPage_Add);
    addButtonLibraries.setEnabled(false);

    removeButtonLibraries = createButton(entryLibraries, Messages.ImplementationsPreferencesPage_Remove);
    removeButtonLibraries.setEnabled(false);

    librariesTab.setControl(entryLibraries);

    // listProject      
    Composite entryProject = new Composite(tabbedComposite, SWT.NULL);
    GridLayout layoutEntryProject = new GridLayout();
    layoutEntryProject.numColumns = 2;
    entryProject.setLayout(layoutEntryProject);

    listProject = new List(entryProject, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    GridData gridDataListProject = new GridData(GridData.FILL_BOTH);
    gridDataListProject.verticalSpan = 5;
    listProject.setLayoutData(gridDataListProject);

    addButtonProject = createButton(entryProject, Messages.ImplementationsPreferencesPage_Add);
    addButtonProject.setEnabled(false);

    editButtonProject = createButton(entryProject, Messages.ImplementationsPreferencesPage_Edit);
    editButtonProject.setEnabled(false);

    upButtonProject = createButton(entryProject, Messages.ImplementationsPreferencesPage_Up);
    upButtonProject.setEnabled(false);
    GridData d = (GridData) upButtonProject.getLayoutData();
    d.verticalIndent = 5;

    downButtonProject = createButton(entryProject, Messages.ImplementationsPreferencesPage_Down);
    downButtonProject.setEnabled(false);

    removeButtonProject = createButton(entryProject, Messages.ImplementationsPreferencesPage_Remove);
    removeButtonProject.setEnabled(false);
    d = (GridData) removeButtonProject.getLayoutData();
    d.verticalIndent = 5;

    projectTab.setControl(entryProject);

    // Listeners for List
    listImplementations.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int index = listImplementations.getSelectionIndex();
            String nameImplementation = listImplementations.getItem(index);

            templates = helper.getTemplateList(nameImplementation);
            listProject.setItems(templates);

            ProjectVersion version = helper.getProjectVersions().getVersion(nameImplementation);
            if (version != null) {
                libraries = version.getLibraryNames();
                listLibraries.setItems(libraries);
            }

            removeButtonImpl.setEnabled(true);
            addButtonLibraries.setEnabled(true);
            removeButtonLibraries.setEnabled(false);
            addButtonProject.setEnabled(true);
            editButtonProject.setEnabled(false);
            upButtonProject.setEnabled(false);
            downButtonProject.setEnabled(false);
            removeButtonProject.setEnabled(false);
        }

    });

    listLibraries.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            removeButtonLibraries.setEnabled(true);
        }

    });

    listProject.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            editButtonProject.setEnabled(true);
            removeButtonProject.setEnabled(true);
            updateUpDownProjectEnablement();
        }

    });

    // Listeners for Buttons
    addButtonImpl.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            String newVersionNameImplementation = helper.getProjectVersions().addVersion();
            implementations = helper.getVersionList();
            listImplementations.setItems(implementations);
            if (newVersionNameImplementation != null) {
                listImplementations.setSelection(new String[] { newVersionNameImplementation });

                templates = helper.getTemplateList(newVersionNameImplementation);
                listProject.setItems(templates);

                ProjectVersion version = helper.getProjectVersions().getVersion(newVersionNameImplementation);
                if (version != null) {
                    libraries = version.getLibraryNames();
                    listLibraries.setItems(libraries);
                }

            } else
                removeButtonImpl.setEnabled(false);
        }
    });

    removeButtonImpl.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int index = listImplementations.getSelectionIndex();
            if (index > -1) {
                String nameImplementation = listImplementations.getItem(index);
                if (nameImplementation != null) {
                    helper.getProjectVersions().removeVersion(nameImplementation);
                    implementations = helper.getVersionList();
                    listImplementations.setItems(implementations);
                    removeButtonImpl.setEnabled(false);
                    addButtonLibraries.setEnabled(false);
                    addButtonProject.setEnabled(false);

                    listLibraries.setItems(new String[0]);
                    listProject.setItems(new String[0]);
                }
            }
        }
    });

    addButtonLibraries.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int index = listImplementations.getSelectionIndex();
            if (index > -1) {
                String nameImplementation = listImplementations.getItem(index);

                ProjectVersion version = helper.getProjectVersions().getVersion(nameImplementation);
                if (version != null) {
                    String nameLib = version.addLibrary();
                    libraries = version.getLibraryNames();
                    listLibraries.setItems(libraries);
                    if (nameLib != null)
                        listLibraries.setSelection(new String[] { nameLib });
                    else
                        removeButtonLibraries.setEnabled(false);
                }

            }
        }
    });

    removeButtonLibraries.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int index = listImplementations.getSelectionIndex();
            if (index > -1) {
                String nameImplementation = listImplementations.getItem(index);

                int indexLib = listLibraries.getSelectionIndex();
                if (indexLib > -1) {

                    String nameLib = listLibraries.getItem(indexLib);
                    ProjectVersion version = helper.getProjectVersions().getVersion(nameImplementation);
                    if (version != null) {
                        version.removeLibrary(nameLib);
                        libraries = version.getLibraryNames();
                        listLibraries.setItems(libraries);
                        removeButtonLibraries.setEnabled(false);
                    }
                }
            }
        }
    });

    addButtonProject.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            addProject();
        }
    });
    upButtonProject.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int from = listProject.getSelectionIndex();
            moveProject(from, from - 1);
        }
    });
    downButtonProject.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int from = listProject.getSelectionIndex();
            moveProject(from, from + 1);
        }
    });
    removeButtonProject.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            removeProject();
        }
    });
    editButtonProject.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            editProject();
        }
    });

    return root;
}

From source file:org.jboss.tools.jst.web.ui.internal.preferences.js.JSCSSPreferencePage.java

License:Open Source License

protected Control createContents(Composite parent) {
    model = JSLibFactory.getInstance().getWorkingCopy();

    Composite libs = new Composite(parent, SWT.NULL);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.grabExcessHorizontalSpace = true;
    libs.setLayoutData(data);//from   w  ww  .  ja va 2 s  .co m

    GridLayout layout = new GridLayout();
    libs.setLayout(layout);
    int heightHint = convertVerticalDLUsToPixels(14/*IDialogConstants.BUTTON_HEIGHT*/);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);

    Group gd = new Group(libs, 0);
    gd.setText(WizardMessages.descriptionLabel);
    GridData dl = new GridData(GridData.FILL_HORIZONTAL);
    gd.setLayoutData(dl);
    gd.setLayout(new GridLayout());
    Label label = new Label(gd, 0);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    label.setText(WizardMessages.configureJSCSSDescription);

    Group gt = new Group(libs, 0);
    layout = new GridLayout();
    layout.numColumns = 2;
    gt.setLayout(layout);
    gt.setLayoutData(new GridData(GridData.FILL_BOTH));
    gt.setText(WizardMessages.JSCSSReferencesLabel);
    tree = new TreeViewer(gt);
    tree.setAutoExpandLevel(2);
    tree.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    LibsContentProvider contentProvider = new LibsContentProvider();
    tree.setContentProvider(contentProvider);
    LibsLabelProvider labelProvider = new LibsLabelProvider();
    tree.setLabelProvider(labelProvider);
    tree.setInput(model);
    tree.addSelectionChangedListener(new SL());

    Composite buttons = new Composite(gt, 0);
    GridData db = new GridData(GridData.BEGINNING | GridData.FILL_VERTICAL);
    buttons.setLayoutData(db);
    GridLayout l = new GridLayout();
    l.marginTop = 0;
    l.marginHeight = 0;
    buttons.setLayout(l);

    Button newButton = new Button(buttons, SWT.PUSH);
    newButton.setText(WizardMessages.newButtonLabel);
    GridData d = new GridData(GridData.BEGINNING);
    d.widthHint = widthHint;
    d.heightHint = heightHint;
    newButton.setLayoutData(d);

    editButton = new Button(buttons, SWT.PUSH);
    editButton.setText(WizardMessages.editButtonLabel);
    d = new GridData(GridData.BEGINNING);
    d.widthHint = widthHint;
    d.heightHint = heightHint;
    editButton.setLayoutData(d);

    addJSButton = new Button(buttons, SWT.PUSH);
    addJSButton.setText(WizardMessages.addJSCSSButtonLabel);
    d = new GridData(GridData.BEGINNING);
    d.widthHint = widthHint;
    d.heightHint = heightHint;
    addJSButton.setLayoutData(d);

    removeButton = new Button(buttons, SWT.PUSH);
    removeButton.setText(WizardMessages.removeActionLabel);
    d = new GridData(GridData.BEGINNING);
    d.widthHint = widthHint;
    d.heightHint = heightHint;
    removeButton.setLayoutData(d);

    newButton.addSelectionListener(new DefaultSelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            NewJSLibDialog dialog = new NewJSLibDialog();
            int result = dialog.open();
            if (result == Dialog.OK) {
                JSLib lib = model.getOrCreateLib(dialog.getName());
                lib.getOrCreateVersion(dialog.getVersion());
                refreshTree();
            }
        }
    });

    editButton.addSelectionListener(new DefaultSelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Object s = getSelectedObject();
            if (s instanceof JSLibVersion) {
                JSLibVersion v = (JSLibVersion) s;
                EditJSLibDialog dialog = new EditJSLibDialog(v);
                int result = dialog.open();
                if (result == Dialog.OK) {
                    if (v.getLib().getName().equals(dialog.getName())) {
                        v.getLib().removeVersion(v);
                        v.setVersion(dialog.getVersion());
                        v.getLib().addVersion(v);
                    } else {
                        v.getLib().removeVersion(v);
                        JSLib lib = model.getOrCreateLib(dialog.getName());
                        lib.addVersion(v);
                    }
                    refreshTree();
                }
            } else if (s instanceof URLWrapper) {
                URLWrapper w = (URLWrapper) s;
                EditFileRefDialog dialog = new EditFileRefDialog(w.parent, w);
                int result = dialog.open();
                if (result == Dialog.OK) {
                    w.parent.getURLs().remove(w.url);
                    w.parent.getURLs().add(dialog.getURL());
                    refreshTree();
                }
            }
        }
    });

    addJSButton.addSelectionListener(new DefaultSelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Object s = getSelectedObject();
            JSLibVersion v = null;
            if (s instanceof JSLibVersion) {
                v = (JSLibVersion) s;
            } else if (s instanceof URLWrapper) {
                v = ((URLWrapper) s).parent;
            }
            if (v != null) {
                AddFileRefDialog dialog = new AddFileRefDialog(v);
                int result = dialog.open();
                if (result == Dialog.OK) {
                    v.getURLs().add(dialog.getURL());
                    refreshTree();
                }
            }
        }
    });

    removeButton.addSelectionListener(new DefaultSelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Object s = getSelectedObject();
            if (s instanceof JSLibVersion) {
                JSLibVersion v = (JSLibVersion) s;
                JSLib lib = v.getLib();
                lib.removeVersion(v);
                if (lib.getVersions().isEmpty()) {
                    model.removeLib(lib);
                }
                refreshTree();
            } else if (s instanceof URLWrapper) {
                URLWrapper w = (URLWrapper) s;
                w.parent.getURLs().remove(w.url);
                refreshTree();
            }
        }
    });

    updateButtons();

    return libs;
}

From source file:org.jboss.tools.jst.web.ui.internal.preferences.LibrarySetsPreferencePage.java

License:Open Source License

protected Control createContents(Composite parent) {
    noDefaultAndApplyButton();//  www  .ja  v a 2 s.c  o  m

    Composite entryLib = new Composite(parent, SWT.NULL);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.grabExcessHorizontalSpace = true;
    entryLib.setLayoutData(data);

    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    entryLib.setLayout(layout);
    int heightHint = convertVerticalDLUsToPixels(14/*IDialogConstants.BUTTON_HEIGHT*/);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);

    // listLib
    final List listLib = new List(entryLib, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    listLib.setItems(librarySets);
    GridData gridDataList = new GridData(GridData.FILL_BOTH);
    gridDataList.widthHint = 270;//Minimum width for the column.
    gridDataList.horizontalSpan = 1;
    gridDataList.verticalSpan = 2;

    int listHeight = listLib.getItemHeight() * 7;
    Rectangle trim = listLib.computeTrim(0, 0, listHeight * 35, listHeight);
    gridDataList.heightHint = trim.height;
    listLib.setLayoutData(gridDataList);

    Button addButtonLib = new Button(entryLib, SWT.PUSH);
    addButtonLib.setText(Messages.LibrarySetsPreferencePage_0);
    //addButtonLib.setText("Add");
    GridData gridDataAddButton = new GridData(GridData.BEGINNING);
    gridDataAddButton.widthHint = widthHint;
    gridDataAddButton.heightHint = heightHint;
    addButtonLib.setLayoutData(gridDataAddButton);

    removeButtonLib = new Button(entryLib, SWT.PUSH);
    removeButtonLib.setText(Messages.LibrarySetsPreferencePage_1);
    GridData gridDataRemoveButton = new GridData(GridData.BEGINNING);
    gridDataRemoveButton.widthHint = widthHint;
    gridDataRemoveButton.heightHint = heightHint;
    gridDataRemoveButton.verticalAlignment = GridData.BEGINNING;
    removeButtonLib.setLayoutData(gridDataRemoveButton);
    removeButtonLib.setEnabled(false);

    Label jarsIncludedLabel = new Label(entryLib, SWT.NONE);
    jarsIncludedLabel.setText(Messages.LibrarySetsPreferencePage_jarsIncluded);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    jarsIncludedLabel.setLayoutData(data);

    listLibJar = new List(entryLib, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    GridData gridDatalistLibJar = new GridData(GridData.FILL_BOTH);
    gridDatalistLibJar.widthHint = 270;//Minimum width for the column.
    gridDatalistLibJar.horizontalSpan = 1;
    gridDatalistLibJar.verticalSpan = 2;
    listHeight = listLibJar.getItemHeight() * 7;
    trim = listLibJar.computeTrim(0, 0, listHeight * 35, listHeight);
    gridDatalistLibJar.heightHint = trim.height;
    listLibJar.setLayoutData(gridDatalistLibJar);

    addButtonLibJar = new Button(entryLib, SWT.PUSH);
    addButtonLibJar.setText(Messages.LibrarySetsPreferencePage_0);
    GridData gridDataAddButtonLibJar = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridDataAddButtonLibJar.widthHint = widthHint;
    gridDataAddButtonLibJar.heightHint = heightHint;
    addButtonLibJar.setLayoutData(gridDataAddButtonLibJar);
    addButtonLibJar.setEnabled(false);

    removeButtonLibJar = new Button(entryLib, SWT.PUSH);
    removeButtonLibJar.setText(Messages.LibrarySetsPreferencePage_1);
    GridData gridDataRemoveButtonLibJar = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridDataRemoveButtonLibJar.widthHint = widthHint;
    gridDataRemoveButtonLibJar.heightHint = heightHint;
    gridDataRemoveButtonLibJar.verticalAlignment = GridData.BEGINNING;
    removeButtonLibJar.setLayoutData(gridDataRemoveButtonLibJar);
    removeButtonLibJar.setEnabled(false);

    // Listeners
    listLibJar.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            if (!addButtonLibJar.getEnabled())
                addButtonLibJar.setEnabled(true);
            if (!removeButtonLibJar.getEnabled())
                removeButtonLibJar.setEnabled(true);
        }

    });
    addButtonLib.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean cancel = false;
            String nameNewItem = helper.addLibrarySet();
            librarySets = helper.getLibrarySetList();
            listLib.setItems(librarySets);
            if (nameNewItem != null) {
                int ind = listLib.indexOf(nameNewItem);
                listLib.setSelection(ind);
                onLibrarySelect(nameNewItem);
                cancel = false;
            } else {
                cancel = true;
                addButtonLibJar.setEnabled(false);
                removeButtonLib.setEnabled(false);
            }
            listLibJar.setItems(new String[] {});
            if (!cancel && (!addButtonLibJar.getEnabled())) {
                addButtonLibJar.setEnabled(true);
                removeButtonLib.setEnabled(true);
            }
        }
    });

    removeButtonLib.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int indexDel = listLib.getSelectionIndex();
            if (indexDel < 0)
                return;
            String nameLib = listLib.getItem(indexDel);
            boolean b = helper.removeLibrarySet(nameLib);
            if (!b)
                return;
            librarySets = helper.getLibrarySetList();
            listLib.setItems(librarySets);
            while (librarySets.length <= indexDel)
                indexDel--;
            if (indexDel >= 0) {
                listLib.setSelection(indexDel);
                String n = listLib.getItem(indexDel);
                if (n != null)
                    onLibrarySelect(n);
            } else {
                listLibJar.setItems(new String[] {});
                removeButtonLib.setEnabled(false);
                addButtonLibJar.setEnabled(false);
                removeButtonLibJar.setEnabled(false);
            }
        }
    });

    listLib.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int indexDel = listLib.getSelectionIndex();
            String nameLib = listLib.getItem(indexDel);
            onLibrarySelect(nameLib);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

    });

    addButtonLibJar.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            String[] ls = openJarFiles();
            if (ls == null || ls.length == 0)
                return;
            String nameJar = null;
            for (int i = 0; i < ls.length; i++) {
                String n = library.addJar(ls[i]);
                if (nameJar == null & n != null)
                    nameJar = n;
            }
            jars = library.getJarList();
            listLibJar.setItems(jars);
            if (nameJar != null) {
                int ind = listLibJar.indexOf(nameJar);
                listLibJar.setSelection(ind);
                removeButtonLibJar.setEnabled(true);
            } else {
                removeButtonLibJar.setEnabled(false);
            }
        }
    });

    removeButtonLibJar.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int indexDel = listLibJar.getSelectionIndex();
            if (indexDel < 0)
                return;
            String nameLibJar = listLibJar.getItem(indexDel);
            if (nameLibJar == null)
                return;
            boolean b = library.removeJar(nameLibJar);
            if (!b)
                return;
            jars = library.getJarList();
            listLibJar.setItems(jars);
            while (jars.length <= indexDel)
                indexDel--;
            addButtonLibJar.setEnabled(true);
            if (indexDel >= 0) {
                listLibJar.setSelection(indexDel);
                removeButtonLibJar.setEnabled(true);
            } else {
                removeButtonLibJar.setEnabled(false);
            }
        }
    });
    if (librarySets != null && librarySets.length > 0) {
        listLib.setSelection(0);
        onLibrarySelect(librarySets[0]);
    }
    return entryLib;

}

From source file:org.jboss.tools.modeshape.rest.preferences.IgnoredResourcesEditor.java

License:Open Source License

/**
 * Creates a push button./*from  w w  w.j  av a2  s. co m*/
 * 
 * @param parent the parent control
 * @param key the resource name used to supply the button's label text
 * @return the button (never <code>null</code>)
 */
private Button createPushButton(Composite parent, String key) {
    Button button = new Button(parent, SWT.PUSH);
    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);
    return button;
}

From source file:org.jboss.tools.modeshape.rest.wizards.ServerPage.java

License:Open Source License

private void constructTestConnectionPanel(Composite parent) {
    Composite pnl = new Composite(parent, SWT.NONE);
    pnl.setLayout(new GridLayout(2, false));
    pnl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    Label lbl = new Label(pnl, SWT.LEFT);
    lbl.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    lbl.setText(RestClientI18n.serverPageTestConnectionLabel);

    this.btnTestConnection = new Button(pnl, SWT.PUSH);
    this.btnTestConnection.setText(RestClientI18n.serverPageTestConnectionButton);
    this.btnTestConnection.setToolTipText(RestClientI18n.serverPageTestConnectionButtonToolTip);

    // add margins to the side of the text
    GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Point minSize = this.btnTestConnection.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x + 10);
    this.btnTestConnection.setLayoutData(gd);

    this.btnTestConnection.addSelectionListener(new SelectionAdapter() {
        /**//from   w ww.j  a v a  2s  .  c o m
         * {@inheritDoc}
         *
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            handleTestConnection();
        }
    });
}

From source file:org.jboss.tools.openshift.internal.common.ui.utils.UIUtils.java

License:Open Source License

/**
 * Sets the standard width to the given button if it's layouted via
 * {@code GridLayout}}./*from  w  w w  .  ja  v  a 2s .co m*/
 * 
 * @param button
 */
public static void setDefaultButtonWidth(Button button) {
    assertCanSetGridData(button);
    ((GridData) button.getLayoutData()).widthHint = convertHorizontalDLUsToPixels(button,
            IDialogConstants.BUTTON_WIDTH);
}

From source file:org.jboss.tools.openshift.internal.common.ui.utils.UIUtils.java

License:Open Source License

/**
 * Sets equal width to all buttons in the array, which is the maximum
 * of the standard default button width and the required (computed) button width
 * for the most wide of the buttons./*w w w. ja  v  a 2  s. co  m*/
 * Throws IllegalArgumentException if a button is disposed or does not have GridData.
 * 
 * @param button
 */
public static void setEqualButtonWidth(Button... buttons) {
    if (buttons == null || buttons.length == 0) {
        return;
    }
    int width = convertHorizontalDLUsToPixels(buttons[0], IDialogConstants.BUTTON_WIDTH);
    for (Button button : buttons) {
        assertCanSetGridData(button);
        int w = button.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
        if (width < w) {
            width = w;
        }
    }
    for (Button button : buttons) {
        ((GridData) button.getLayoutData()).widthHint = width;
    }
}

From source file:org.jboss.tools.struts.ui.wizard.sync.SyncProjectStepView.java

License:Open Source License

protected Control createListControl(Composite parent) {
    GridData gd;/* w  w  w  .j a v a  2s .c om*/
    Control control;

    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 10;
    gridLayout.marginWidth = 10;
    gridLayout.horizontalSpacing = 10;
    gridLayout.verticalSpacing = 10;
    composite.setLayout(gridLayout);

    Composite c = new Composite(composite, SWT.NONE);

    gridLayout = new GridLayout(3, false);
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 0;
    c.setLayout(gridLayout);

    control = list.createControl(c);
    list.getTable().addSelectionListener(new SL());
    gd = new GridData(GridData.FILL_BOTH);
    control.setLayoutData(gd);

    control = new Label(c, SWT.NONE);
    gd = new GridData();
    gd.widthHint = 5;
    control.setLayoutData(gd);

    control = bar.getCommandBar().createControl(c);
    bar.getCommandBar().getLayout().buttonWidth = convertHorizontalDLUsToPixels(control,
            IDialogConstants.BUTTON_WIDTH);
    gd = new GridData(GridData.FILL_VERTICAL);
    gd.widthHint = convertHorizontalDLUsToPixels(control, IDialogConstants.BUTTON_WIDTH);
    control.setLayoutData(gd);

    gd = new GridData(GridData.FILL_BOTH);
    c.setLayoutData(gd);

    gd = new GridData(GridData.FILL_BOTH);
    composite.setLayoutData(gd);
    return composite;
}

From source file:org.jboss.tools.struts.validator.ui.wizard.key.AbstractResourcePathView.java

License:Open Source License

public Control createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    layout.horizontalSpacing = 10;//from w  ww.  j  a v a2s. c  o  m
    layout.marginHeight = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);

    Label label = new Label(composite, SWT.NONE);
    label.setText(MessageFormat.format(Messages.AbstractResourcePathView_Label, getDisplayName()));

    combo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
    GridData d = new GridData(GridData.FILL_HORIZONTAL);
    combo.setLayoutData(d);
    populateCombo();
    if (combo.getItemCount() > 0)
        combo.setText(combo.getItem(0));

    combo.addSelectionListener(this);

    commandBar.setMnemonicEnabled(true);
    commandBar.setCommands(new String[] { Messages.AbstractResourcePathView_Browse });
    commandBar.addCommandBarListener(this);
    commandBar.getLayout().setMargins(0, 0, 0, 0);
    commandBar.getLayout().buttonWidth = convertHorizontalDLUsToPixels(parent, IDialogConstants.BUTTON_WIDTH);
    commandBar.createControl(composite);

    return composite;
}