Example usage for org.eclipse.jface.databinding.swt WidgetProperties text

List of usage examples for org.eclipse.jface.databinding.swt WidgetProperties text

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt WidgetProperties text.

Prototype

public static IWidgetValueProperty text() 

Source Link

Document

Returns a value property for observing the text of a Button , CCombo , CLabel , Combo , Item , Label , Link , Shell , Group , StyledText or Text .

Usage

From source file:org.fusesource.ide.syndesis.extensions.ui.wizards.pages.SyndesisExtensionProjectWizardExtensionDetailsPage.java

License:Open Source License

private Binding createBinding(DataBindingContext dbc, Widget control, String property,
        UpdateValueStrategy updateStrategy) {
    IObservableValue target = null;/*from   w w  w .j  a v a2s  . c om*/
    if (control instanceof Combo) {
        target = WidgetProperties.text().observeDelayed(200, control);
    } else if (control instanceof Text) {
        target = WidgetProperties.text(SWT.Modify).observeDelayed(200, control);
    } else {
        // not supported
    }
    IObservableValue model = BeanProperties.value(SyndesisExtension.class, property)
            .observe(wizard.getSyndesisExtension());
    if (model != null && target != null) {
        Binding b = dbc.bindValue(target, model, updateStrategy, null);
        ControlDecorationSupport.create(b, SWT.TOP | SWT.LEFT);
        return b;
    }
    return null;
}

From source file:org.goko.base.dro.controller.DisplayReadOutController.java

License:Open Source License

public void enableTextBindingOnValue(Text widget, String valueId) {
    IObservableValue modelObservable = Observables.observeMapEntry(getDataModel().getWritableObservedValues(),
            valueId);/*from  w  w w  .  j  a va2 s  .c om*/
    IObservableValue controlObservable = WidgetProperties.text().observe(widget);

    UpdateValueStrategy policy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    policy.setConverter(new IConverter() {
        @Override
        public Object getToType() {
            return String.class;
        }

        @Override
        public Object getFromType() {
            return Object.class;
        }

        @Override
        public Object convert(Object fromObject) {
            return ((MachineValue) fromObject).getStringValue();
        }
    });
    getBindingContext().bindValue(controlObservable, modelObservable, null, policy);

}

From source file:org.goko.common.bindings.AbstractController.java

License:Open Source License

/**
 * Binding between an source and a property to change the text of the source
 * @param source the widget use to display the text
 * @param property the property name//from   w  w  w .  j  a v  a  2 s  .co m
 * @throws GkException GkException
 */
public void addTextDisplayBinding(Object source, String property) throws GkException {
    verifyGetter(dataModel, property);
    verifySetter(dataModel, property);

    IObservableValue widgetObserver = WidgetProperties.text().observe(source);
    IObservableValue modelObserver = BeanProperties.value(property).observe(dataModel);

    Binding binding = bindingContext.bindValue(widgetObserver, modelObserver, null,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
    bindings.add(binding);
}

From source file:org.jboss.tools.common.launcher.ui.wizard.NewLauncherProjectWizardPage.java

License:Open Source License

@Override
protected void doCreateControls(final Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(2).applyTo(parent);

    //  explanation
    Label explanation = new Label(parent, SWT.WRAP);
    explanation.setText("Launcher will generate an application for you."
            + " By picking a mission you determine what this application will do."
            + " The runtime then picks the software stack that's used to implement this aim.");
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(explanation);

    // missions//from  ww  w .  j av a  2s .c o  m
    Label lblMissions = new Label(parent, SWT.NONE);
    lblMissions.setText("Mission:");
    lblMissions.setToolTipText("A specification that describes what your application will do.");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblMissions);
    Combo comboMissions = new Combo(parent, SWT.SINGLE | SWT.DROP_DOWN | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().indent(0, 10).align(SWT.LEFT, SWT.CENTER).hint(300, SWT.DEFAULT)
            .applyTo(comboMissions);
    ComboViewer comboMissionsViewer = new ComboViewer(comboMissions);
    comboMissionsViewer.setContentProvider(new ObservableListContentProvider());
    comboMissionsViewer.setInput(BeanProperties.list(NewLauncherProjectModel.MISSIONS_PROPERTY).observe(model));
    comboMissionsViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Mission mission = (Mission) element;
            return mission.getId();
        }
    });
    IObservableValue selectedMissionObservable = BeanProperties
            .value(NewLauncherProjectModel.SELECTED_MISSION_PROPERTY).observe(model);
    ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(comboMissionsViewer))
            .to(selectedMissionObservable).in(dbc);

    new Label(parent, SWT.None); // filler
    StyledText missionDescription = createStyledText(parent);
    IObservableValue missionDescriptionObservable = PojoProperties
            .value(NewLauncherProjectModel.DESCRIPTION_PROPERTY).observeDetail(selectedMissionObservable);
    ValueBindingBuilder.bind(WidgetProperties.text().observe(missionDescription)).notUpdatingParticipant()
            .to(missionDescriptionObservable).in(dbc);
    missionDescriptionObservable.addValueChangeListener(event -> setToPreferredVerticalSize(getShell()));

    // boosters
    Label lblBoosters = new Label(parent, SWT.NONE);
    lblBoosters.setText("Runtime:");
    lblBoosters.setToolTipText("The framework software used in the application's process.");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblBoosters);
    Combo comboBoosters = new Combo(parent, SWT.SINGLE | SWT.DROP_DOWN | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(300, SWT.DEFAULT).applyTo(comboBoosters);
    ComboViewer comboBoostersViewer = new ComboViewer(comboBoosters);
    comboBoostersViewer.setContentProvider(new ObservableListContentProvider());
    comboBoostersViewer.setInput(BeanProperties.list(NewLauncherProjectModel.BOOSTERS_PROPERTY).observe(model));
    comboBoostersViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Booster booster = (Booster) element;
            return booster.getRuntime() + " " + booster.getVersion();
        }
    });
    IObservableValue<Booster> selectedBoosterObservable = BeanProperties
            .value(NewLauncherProjectModel.SELECTED_BOOSTER_PROPERTY).observe(model);
    ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(comboBoostersViewer))
            .to(selectedBoosterObservable).in(dbc);

    new Label(parent, SWT.None); // filler
    StyledText boosterDescription = createStyledText(parent);
    IObservableValue boosterDescriptionObservable = PojoProperties
            .value(NewLauncherProjectModel.DESCRIPTION_PROPERTY).observeDetail(selectedBoosterObservable);
    ValueBindingBuilder.bind(WidgetProperties.text().observe(boosterDescription)).notUpdatingParticipant()
            .to(boosterDescriptionObservable).in(dbc);
    boosterDescriptionObservable.addValueChangeListener(event -> setToPreferredVerticalSize(getShell()));

    // separator
    Label mavenSeparator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).applyTo(mavenSeparator);

    // project name
    createTextWidget(parent, dbc, "Project name:", NewLauncherProjectModel.PROJECT_NAME_PROPERTY,
            new EclipseProjectValidator("Please specify an Eclipse project", "Project already exists"));
    //use default location
    Button buttonUseDefaultLocation = new Button(parent, SWT.CHECK);
    buttonUseDefaultLocation.setText("Use default location");
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.LEFT, SWT.CENTER).applyTo(buttonUseDefaultLocation);
    IObservableValue<Boolean> useDefaultLocationButtonObservable = WidgetProperties.selection()
            .observe(buttonUseDefaultLocation);
    ValueBindingBuilder.bind(useDefaultLocationButtonObservable)
            .to(BeanProperties.value(NewLauncherProjectModel.USE_DEFAULT_LOCATION_PROPERTY).observe(model))
            .in(dbc);

    // location
    Label lblLocation = new Label(parent, SWT.NONE);
    lblLocation.setText("Location:");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblLocation);

    Text txtLocation = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(txtLocation);
    Binding locationBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(txtLocation))
            .validatingAfterGet(new MandatoryStringValidator("Please specify a location for you project"))
            .converting(
                    IConverter.create(String.class, IPath.class, NewLauncherProjectWizardPage::string2IPath))
            .to(BeanProperties.value(NewLauncherProjectModel.LOCATION_PROPERTY).observe(model)).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(txtLocation)).notUpdatingParticipant()
            .to(BeanProperties.value(NewLauncherProjectModel.USE_DEFAULT_LOCATION_PROPERTY).observe(model))
            .converting(new InvertingBooleanConverter()).in(dbc);
    ControlDecorationSupport.create(locationBinding, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());

    // separator
    Label launcherSeparator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataFactory.fillDefaults().indent(0, 10).span(2, 1).align(SWT.FILL, SWT.CENTER)
            .applyTo(launcherSeparator);

    // maven artifact
    Label mavenArtifactExplanation = new Label(parent, SWT.None);
    mavenArtifactExplanation.setText("Maven Artifact:");
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).applyTo(mavenArtifactExplanation);
    createTextWidget(parent, dbc, "Artifact id:", NewLauncherProjectModel.ARTIFACTID_PROPERTY,
            new MandatoryStringValidator("Please specify an artifact id"));
    createTextWidget(parent, dbc, "Group id:", NewLauncherProjectModel.GROUPID_PROPERTY,
            new MandatoryStringValidator("Please specify a group id"));
    createTextWidget(parent, dbc, "Version:", NewLauncherProjectModel.VERSION_PROPERTY,
            new MandatoryStringValidator("Please specify a version"));

    loadCatalog();
}

From source file:org.jboss.tools.internal.deltacloud.ui.wizards.CloudConnectionPage.java

License:Open Source License

/**
 * Binds the given url text widget to the model type property and uses a
 * converter to transfer urls to cloud types. Furthermore it binds the given
 * cloud type label to the result of this conversion. The binding returned
 * is the binding that connects the url text widget to the cloud type
 * property in the model.//from w ww  . j ava2s  . c om
 * 
 * @param dbc
 *            the databinding context to use
 * @param urlText
 *            the url text widget
 * @param typeLabel
 *            the cloud type label to display the cloud type in
 * @return
 * @return
 * @return the binding that was created
 */
private Binding bindCloudType(DataBindingContext dbc, Text urlText, final Label typeLabel) {

    // bind driver value to driver label
    Binding typeLabelBinding = dbc.bindValue(WidgetProperties.text().observe(typeLabel),
            BeanProperties.value(CloudConnectionPageModel.PROPERTY_DRIVER).observe(connectionModel),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
            new UpdateValueStrategy().setConverter(new Driver2Label()).setAfterGetValidator(new IValidator() {
                @Override
                public IStatus validate(Object value) {
                    if (connectionModel.isKnownCloud(value)) {
                        return ValidationStatus.ok();
                    } else {
                        return ValidationStatus.warning(WizardMessages.getString("IllegalCloudUrl.msg"));
                    }
                }
            }));

    // set driver value when user stops typing or moves focus away
    DataBindingUtils.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            String url = (String) event.diff.getNewValue();
            connectionModel.setDriverByUrl(url);
        }
    }, WidgetProperties.text(SWT.Modify).observeDelayed(CLOUDTYPE_CHECK_DELAY, urlText), urlText);
    return typeLabelBinding;
}

From source file:org.jboss.tools.internal.deltacloud.ui.wizards.NewInstancePage.java

License:Open Source License

private void bindArchLabel(final Label architectureLabel, IObservableValue imageObservable,
        DataBindingContext dbc) {/*w ww .ja  va  2  s.co m*/
    dbc.bindValue(WidgetProperties.text().observe(architectureLabel), imageObservable,
            new UpdateValueStrategy(UpdateSetStrategy.POLICY_NEVER),
            new UpdateValueStrategy().setConverter(new Converter(DeltaCloudImage.class, String.class) {

                @Override
                public Object convert(Object fromObject) {
                    if (!(fromObject instanceof DeltaCloudImage)) {
                        return null;
                    }
                    return ((DeltaCloudImage) fromObject).getArchitecture();
                }
            }));
}

From source file:org.jboss.tools.openshift.express.internal.ui.wizard.connection.ConnectionWizardPage.java

License:Open Source License

private Composite createNewConnectionComposite(Composite container, DataBindingContext dbc) {
    Composite connectionWidgets = new Composite(container, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(connectionWidgets);

    // use default server
    Button defaultServerCheckbox = new Button(connectionWidgets, SWT.CHECK);
    defaultServerCheckbox.setText("Use default server");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).applyTo(defaultServerCheckbox);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(defaultServerCheckbox))
            .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USE_DEFAULTSERVER).observe(pageModel))
            .in(dbc);/*from  w w w. j a  va2 s  .c  om*/

    // host
    Label serverLabel = new Label(connectionWidgets, SWT.NONE);
    serverLabel.setText("&Server:");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(serverLabel);
    Combo serversCombo = new Combo(connectionWidgets, SWT.BORDER);
    ComboViewer serverComboViewer = new ComboViewer(serversCombo);
    serverComboViewer.setLabelProvider(new ServerLabelProvider());
    serverComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    serverComboViewer.setInput(pageModel.getServers());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(serversCombo);
    IObservableValue serverObservable = WidgetProperties.text().observe(serversCombo);
    Binding serverBinding = ValueBindingBuilder.bind(serverObservable)
            .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_HOST).observe(pageModel)).in(dbc);
    ControlDecorationSupport.create(serverBinding, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());
    ValidationStatusProvider hostValidation = new RequiredStringValidationProvider(serverObservable, "server");
    dbc.addValidationStatusProvider(hostValidation);
    ControlDecorationSupport.create(hostValidation, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(serversCombo)).notUpdatingParticipant()
            .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USE_DEFAULTSERVER).observe(pageModel))
            .converting(new InvertingBooleanConverter()).in(dbc);

    // username
    Label rhLoginLabel = new Label(connectionWidgets, SWT.NONE);
    rhLoginLabel.setText("&Username:");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(rhLoginLabel);
    connectionCompositeUsernameText = new Text(connectionWidgets, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(connectionCompositeUsernameText);
    IObservableValue usernameObservable = WidgetProperties.text(SWT.Modify)
            .observe(connectionCompositeUsernameText);
    ValueBindingBuilder.bind(usernameObservable).converting(new TrimmingStringConverter())
            .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USERNAME).observe(pageModel)).in(dbc);
    ValidationStatusProvider usernameValidation = new RequiredStringValidationProvider(usernameObservable,
            "username");
    dbc.addValidationStatusProvider(usernameValidation);
    ControlDecorationSupport.create(usernameValidation, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());

    // password
    Label passwordLabel = new Label(connectionWidgets, SWT.NONE);
    passwordLabel.setText("&Password:");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(passwordLabel);
    this.connectionCompositePasswordText = new Text(connectionWidgets, SWT.BORDER | SWT.PASSWORD);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(connectionCompositePasswordText);
    IObservableValue passwordObservable = WidgetProperties.text(SWT.Modify)
            .observe(connectionCompositePasswordText);
    ValueBindingBuilder.bind(passwordObservable)
            .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_PASSWORD).observe(pageModel)).in(dbc);
    ValidationStatusProvider passwordValidation = new RequiredStringValidationProvider(passwordObservable,
            "password");
    dbc.addValidationStatusProvider(passwordValidation);
    ControlDecorationSupport.create(passwordValidation, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());

    Button rememberPasswordCheckBox = new Button(connectionWidgets, SWT.CHECK);
    rememberPasswordCheckBox.setText(OpenshiftUIMessages.OpenshiftWizardSavePassword);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).grab(true, false)
            .applyTo(rememberPasswordCheckBox);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(rememberPasswordCheckBox))
            .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_REMEMBER_PASSWORD).observe(pageModel))
            .in(dbc);
    // credentials status
    IObservableValue credentialsStatusObservable = BeanProperties
            .value(ConnectionWizardPageModel.PROPERTY_VALID, IStatus.class).observe(pageModel);
    final CredentialsValidator credentialsValidator = new CredentialsValidator(credentialsStatusObservable);
    dbc.addValidationStatusProvider(credentialsValidator);

    return connectionWidgets;
}

From source file:org.jboss.tools.openshift.express.internal.ui.wizard.markers.ConfigureMarkersWizardPage.java

License:Open Source License

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);

    // markers table
    Composite tableContainer = new Composite(parent, SWT.NONE);
    this.viewer = createTable(tableContainer);
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, 250).grab(true, true)
            .applyTo(tableContainer);//from   w w  w . j a  v  a  2 s  . c om
    dbc.bindSet(ViewerProperties.checkedElements(IOpenShiftMarker.class).observe(viewer),
            BeanProperties.set(ConfigureMarkersWizardPageModel.PROPERTY_CHECKED_MARKERS).observe(pageModel));
    ValueBindingBuilder
            .bind(ViewerProperties.singleSelection().observe(viewer)).to(BeanProperties
                    .value(ConfigureMarkersWizardPageModel.PROPERTY_SELECTED_MARKER).observe(pageModel))
            .in(dbc);

    // marker description
    Group descriptionGroup = new Group(parent, SWT.NONE);
    descriptionGroup.setText("Marker Description");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(descriptionGroup);
    GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(descriptionGroup);
    StyledText descriptionText = new StyledText(descriptionGroup, SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
    descriptionText.setAlwaysShowScrollBars(false);
    StyledTextUtils.setTransparent(descriptionText);
    GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 80).align(SWT.FILL, SWT.FILL).grab(true, false)
            .applyTo(descriptionText);
    dbc.bindSet(ViewersObservables.observeCheckedElements(viewer, IOpenShiftMarker.class),
            BeanProperties.set(ConfigureMarkersWizardPageModel.PROPERTY_CHECKED_MARKERS).observe(pageModel));
    ValueBindingBuilder
            .bind(WidgetProperties.text().observe(descriptionText)).notUpdating(BeanProperties
                    .value(ConfigureMarkersWizardPageModel.PROPERTY_SELECTED_MARKER).observe(pageModel))
            .converting(new Converter(IOpenShiftMarker.class, String.class) {

                @Override
                public Object convert(Object fromObject) {
                    if (!(fromObject instanceof BaseOpenShiftMarker)) {
                        return null;
                    }
                    return ((IOpenShiftMarker) fromObject).getDescription();
                }

            }).in(dbc);
}

From source file:org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPage.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override// w  w  w  .  j av  a  2 s . com
protected void doCreateControls(final Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).applyTo(parent);

    // userdoc link (JBIDE-20401)
    this.userdocLink = new StyledText(parent, SWT.WRAP); // text set in #showHideUserdocLink
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).applyTo(userdocLink);
    showHideUserdocLink();
    IObservableValue userdocUrlObservable = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USERDOCURL)
            .observe(pageModel);
    StyledTextUtils.emulateLinkAction(userdocLink, r -> onUserdocLinkClicked(userdocUrlObservable));
    userdocUrlObservable.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            showHideUserdocLink();
        }
    });

    IObservableValue connectionFactoryObservable = BeanProperties
            .value(ConnectionWizardPageModel.PROPERTY_CONNECTION_FACTORY).observe(pageModel);

    // filler
    Label fillerLabel = new Label(parent, SWT.NONE);
    GridDataFactory.fillDefaults().span(3, 3).hint(SWT.DEFAULT, 6).applyTo(fillerLabel);

    // existing connections combo
    Label connectionLabel = new Label(parent, SWT.NONE);
    connectionLabel.setText("Connection:");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(connectionLabel);
    Combo connectionCombo = new Combo(parent, SWT.DEFAULT);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(connectionCombo);
    ComboViewer connectionComboViewer = new ComboViewer(connectionCombo);
    connectionComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    connectionComboViewer.setLabelProvider(new ConnectionColumLabelProvider());
    connectionComboViewer.setInput(pageModel.getAllConnections());
    Binding selectedConnectionBinding = ValueBindingBuilder
            .bind(ViewerProperties.singleSelection().observe(connectionComboViewer))
            .validatingAfterGet(new IsNotNullValidator(
                    ValidationStatus.cancel("You have to select or create a new connection.")))
            .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION, IConnection.class)
                    .observe(pageModel))
            .in(dbc);
    ControlDecorationSupport.create(selectedConnectionBinding, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());

    // server type
    Label connectionFactoryLabel = new Label(parent, SWT.NONE);
    connectionFactoryLabel.setText("Server type:");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT)
            .applyTo(connectionFactoryLabel);
    Combo connectionFactoryCombo = new Combo(parent, SWT.DEFAULT);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(connectionFactoryCombo);
    ComboViewer connectionFactoriesViewer = new ComboViewer(connectionFactoryCombo);
    connectionFactoriesViewer.setContentProvider(ArrayContentProvider.getInstance());
    connectionFactoriesViewer.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (!(element instanceof IConnectionFactory)) {
                return element.toString();
            } else {
                return ((IConnectionFactory) element).getName();
            }
        }
    });
    connectionFactoriesViewer.setInput(pageModel.getAllConnectionFactories());
    final IViewerObservableValue selectedServerType = ViewerProperties.singleSelection()
            .observe(connectionFactoriesViewer);
    ValueBindingBuilder.bind(selectedServerType).to(connectionFactoryObservable).in(dbc);

    // server
    Button useDefaultServerCheckbox = new Button(parent, SWT.CHECK);
    useDefaultServerCheckbox.setText("Use default server");
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.FILL).applyTo(useDefaultServerCheckbox);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(useDefaultServerCheckbox)).to(BeanProperties
            .value(ConnectionWizardPageModel.PROPERTY_USE_DEFAULT_HOST, IConnection.class).observe(pageModel))
            .in(dbc);

    IObservableValue hasDefaultHostObservable = BeanProperties
            .value(ConnectionWizardPageModel.PROPERTY_HAS_DEFAULT_HOST).observe(pageModel);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(useDefaultServerCheckbox))
            .notUpdating(hasDefaultHostObservable).in(dbc);

    Label serverLabel = new Label(parent, SWT.NONE);
    serverLabel.setText("Server:");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(serverLabel);
    Combo serversCombo = new Combo(parent, SWT.BORDER);
    ComboViewer serversViewer = new ComboViewer(serversCombo);
    serversViewer.setContentProvider(new ObservableListContentProvider());
    serversViewer
            .setInput(BeanProperties.list(ConnectionWizardPageModel.PROPERTY_ALL_HOSTS).observe(pageModel));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(serversCombo);
    final IObservableValue serverUrlObservable = WidgetProperties.text().observe(serversCombo);
    serversCombo.addFocusListener(onServerFocusLost(serverUrlObservable));
    ValueBindingBuilder.bind(serverUrlObservable).converting(new TrimTrailingSlashConverter())
            .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_HOST).observe(pageModel)).in(dbc);

    MultiValidator serverUrlValidator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            Object value = serverUrlObservable.getValue();
            if (!(value instanceof String) || StringUtils.isEmpty((String) value)) {
                return ValidationStatus.cancel("Please provide an OpenShift server url.");
            } else if (!UrlUtils.isValid((String) value)) {
                return ValidationStatus.error("Please provide a valid OpenShift server url.");
            }
            return ValidationStatus.ok();
        }
    };
    ControlDecorationSupport.create(serverUrlValidator, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());
    dbc.addValidationStatusProvider(serverUrlValidator);

    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(serversCombo)).notUpdatingParticipant()
            .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USE_DEFAULT_HOST).observe(pageModel))
            .converting(new InvertingBooleanConverter()).in(dbc);

    // connect error
    dbc.addValidationStatusProvider(new MultiValidator() {
        IObservableValue observable = BeanProperties
                .value(ConnectionWizardPageModel.PROPERTY_CONNECTED_STATUS, IStatus.class).observe(pageModel);

        @Override
        protected IStatus validate() {
            return (IStatus) observable.getValue();
        }
    });

    // connection editors
    Group authenticationDetailsGroup = new Group(parent, SWT.NONE);
    authenticationDetailsGroup.setText("Authentication");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(3, 1).applyTo(authenticationDetailsGroup);
    GridLayoutFactory.fillDefaults().margins(0, 0).applyTo(authenticationDetailsGroup);
    // additional nesting required because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=478618
    Composite authenticationDetailsContainer = new Composite(authenticationDetailsGroup, SWT.None);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true)
            .applyTo(authenticationDetailsContainer);
    this.connectionEditors = new ConnectionEditorsStackedView(connectionFactoryObservable, this,
            authenticationDetailsContainer, dbc);
    connectionEditors.createControls();

    // adv editors
    Composite advEditorContainer = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).applyTo(authenticationDetailsGroup);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(3, 1).grab(true, true)
            .applyTo(advEditorContainer);
    this.advConnectionEditors = new AdvancedConnectionEditorsStackedView(connectionFactoryObservable, pageModel,
            advEditorContainer, dbc);
    advConnectionEditors.createControls();
}

From source file:org.jboss.tools.openshift.internal.ui.server.ServerSettingsWizardPage.java

License:Open Source License

private void createInfoControls(Composite container, ServerSettingsWizardPageModel model,
        DataBindingContext dbc) {//ww  w . j  a v a 2 s.co m
    Composite composite = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().span(4, 1).applyTo(composite);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);

    ValueBindingBuilder.bind(WidgetProperties.visible().observe(composite))
            .to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model))
            .converting(new Converter(IStatus.class, Boolean.class) {

                @Override
                public Object convert(Object fromObject) {
                    return !((IStatus) fromObject).isOK();
                }

            }).in(dbc);

    Label label = new Label(composite, SWT.NONE);
    ValueBindingBuilder.bind(WidgetProperties.image().observe(label))
            .to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model))
            .converting(new Converter(IStatus.class, Image.class) {

                @Override
                public Object convert(Object fromObject) {
                    switch (((IStatus) fromObject).getSeverity()) {
                    case IStatus.WARNING:
                        return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
                    case IStatus.ERROR:
                        return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
                    }
                    return null;
                }
            }).in(dbc);

    Link link = new Link(composite, SWT.WRAP);
    ValueBindingBuilder.bind(WidgetProperties.text().observe(link))
            .to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model))
            .converting(new Converter(IStatus.class, String.class) {

                @Override
                public Object convert(Object fromObject) {
                    return ((IStatus) fromObject).getMessage();
                }

            }).in(dbc);
    link.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if ("download".equals(e.text)) {
                new BrowserUtility().checkedCreateExternalBrowser(DOWNLOAD_INSTRUCTIONS_URL,
                        OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
            } else {
                int rc = PreferencesUtil.createPreferenceDialogOn(getShell(), OPEN_SHIFT_PREFERENCE_PAGE_ID,
                        new String[] { OPEN_SHIFT_PREFERENCE_PAGE_ID }, null).open();
                if (rc == Dialog.OK) {
                    new Job("Checking oc binary") {

                        @Override
                        protected IStatus run(IProgressMonitor monitor) {
                            OCBinary ocBinary = OCBinary.getInstance();
                            boolean valid = ocBinary.isCompatibleForPublishing(monitor);
                            ServerSettingsWizardPage.this.model
                                    .setOCBinaryStatus(getOCBinaryStatus(valid, ocBinary.getLocation()));
                            return Status.OK_STATUS;
                        }
                    }.schedule();
                }
            }
        }
    });
    GridDataFactory.fillDefaults().hint(600, SWT.DEFAULT).applyTo(link);
    MultiValidator validator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            IObservableValue<IStatus> observable = BeanProperties
                    .value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model);
            Status status = (Status) observable.getValue();
            switch (status.getSeverity()) {
            case IStatus.ERROR:
                return OpenShiftUIActivator.statusFactory()
                        .errorStatus(OpenShiftUIMessages.OCBinaryErrorMessage);
            case IStatus.WARNING:
                return OpenShiftUIActivator.statusFactory()
                        .warningStatus(OpenShiftUIMessages.OCBinaryWarningMessage);
            }
            return status;
        }
    };
    dbc.addValidationStatusProvider(validator);
}