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

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

Introduction

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

Prototype

public static IWidgetValueProperty enabled() 

Source Link

Document

Returns a value property for observing the enablement state of a Control , Menu (since 1.5), MenuItem (since 1.5), ScrollBar (since 1.5) or ToolItem (since 1.5).

Usage

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

License:Open Source License

/**
 * Enables/disable the source when the property is respectively true/false
 * @param source the UI object/*from   ww w .j  av a 2 s .  co m*/
 * @param property the name of the property
 * @throws GkException GkException
 */
public void addEnableBinding(Widget source, String property) throws GkException {
    verifyGetter(dataModel, property);
    verifySetter(dataModel, property);

    IObservableValue target = WidgetProperties.enabled().observe(source);
    IObservableValue model = BeansObservables.observeValue(dataModel, property);

    Binding binding = bindingContext.bindValue(target, model);
    bindings.add(binding);
}

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

License:Open Source License

/**
 * Enables/disable the source when the property is respectively false/true
 * @param source the UI object//  w w w .  j a v a 2 s  . c  o m
 * @param property the name of the property
 * @throws GkException GkException
 */
public void addEnableReverseBinding(Widget source, String property) throws GkException {
    verifyGetter(dataModel, property);
    verifySetter(dataModel, property);

    IObservableValue target = WidgetProperties.enabled().observe(source);
    IObservableValue model = BeanProperties.value(property).observe(dataModel);

    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setConverter(new NegateBooleanConverter());

    Binding binding = bindingContext.bindValue(target, model,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), strategy);
    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 w  ww. j ava2  s.  co  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.common.ui.databinding.DataBindingUtils.java

License:Open Source License

public static void bindEnablementToValidationStatus(final Control control, int enabledSeverityMask,
        DataBindingContext dbc, Binding... bindings) {
    dbc.bindValue(WidgetProperties.enabled().observe(control), createAggregateValidationStatus(dbc, bindings),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
            new UpdateValueStrategy().setConverter(new StatusSeverity2BooleanConverter(enabledSeverityMask)));
}

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

License:Open Source License

/**
 * Enables/Disables (credentials) test button on changes in the driver
 * property of the model.//from  w w  w . j  ava  2s  .c  o m
 * 
 * @param testButton
 *            the test button to bind
 * @param dbc
 *            the databinding context to use
 */
private void bindTestButtonEnablement(final Button testButton, DataBindingContext dbc) {
    dbc.bindValue(WidgetProperties.enabled().observe(testButton),
            BeanProperties.value(CloudConnectionPageModel.PROPERTY_DRIVER).observe(connectionModel),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
            new UpdateValueStrategy().setConverter(new Converter(DeltaCloudDriver.class, Boolean.class) {
                @Override
                public Object convert(Object fromObject) {
                    return connectionModel.isKnownCloud(fromObject);
                }
            }));
}

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

License:Open Source License

private Button createDeleteButton(Composite container, DataBindingContext dbc) {
    Button deleteButton = new Button(container, SWT.NULL);
    deleteButton.setText(WizardMessages.getString(DELETE));
    deleteButton.addSelectionListener(onDeletePressed());
    // bind enablement
    dbc.bindValue(WidgetProperties.enabled().observe(deleteButton),
            BeanProperties.value(ManageKeysPageModel.PROP_SELECTED_KEY).observe(model),
            new UpdateValueStrategy(UpdateSetStrategy.POLICY_NEVER),
            new UpdateValueStrategy().setConverter(new ObjectNotNullToBoolean()));
    return deleteButton;
}

From source file:org.jboss.tools.livereload.internal.configuration.LiveReloadLaunchWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    setControl(container);/*from w  w  w .j  ava2 s  .  c om*/
    GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).margins(10, 10).applyTo(container);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, true).applyTo(container);

    // Web sockets port
    final Label websocketPortLabel = new Label(container, SWT.NONE);
    websocketPortLabel.setText(WEBSOCKET_SERVER_PORT_LABEL);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(websocketPortLabel);
    final Text websocketPortText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(websocketPortText);
    final IObservableValue websocketPortTextObservable = WidgetProperties.text(SWT.Modify)
            .observe(websocketPortText);
    final IObservableValue websocketPortModelObservable = BeanProperties
            .value(LiveReloadLaunchWizardModel.PROPERTY_WEBSOCKET_SERVER_PORT).observe(wizardModel);
    ValueBindingBuilder.bind(websocketPortTextObservable).to(websocketPortModelObservable).in(dbc);

    // Proxy Server enablement
    final Button useProxyServerBtn = new Button(container, SWT.CHECK);
    useProxyServerBtn.setText(PROXY_SERVER_CHECKBOX);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(false, false)
            .applyTo(useProxyServerBtn);
    final IObservableValue useProxyServerModelObservable = BeanProperties
            .value(LiveReloadLaunchWizardModel.PROPERTY_USE_PROXY_SERVER).observe(wizardModel);
    final IObservableValue useProxyServerSelection = WidgetProperties.selection().observe(useProxyServerBtn);
    dbc.bindValue(useProxyServerSelection, useProxyServerModelObservable);

    // Proxy Server port
    final Label proxyPortLabel = new Label(container, SWT.NONE);
    proxyPortLabel.setText(PROXY_SERVER_PORT_LABEL);
    GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).indent(10, 0).applyTo(proxyPortLabel);
    final Text proxyPortText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(proxyPortText);
    final IObservableValue proxyPortTextObservable = WidgetProperties.text(SWT.Modify).observe(proxyPortText);
    final IObservableValue proxyPortModelObservable = BeanProperties
            .value(LiveReloadLaunchWizardModel.PROPERTY_PROXY_SERVER_PORT).observe(wizardModel);
    ValueBindingBuilder.bind(proxyPortTextObservable).to(proxyPortModelObservable).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(proxyPortText))
            .notUpdating(useProxyServerModelObservable).in(dbc);

    // Proxy Server brief description
    final Link proxyServerDescription = new Link(container, SWT.WRAP);
    proxyServerDescription.setText(PROXY_SERVER_DESCRIPTION);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(100, SWT.DEFAULT).indent(00, 10).span(2, 1)
            .applyTo(proxyServerDescription);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(container);
    proxyServerDescription.addSelectionListener(onBrowse());

    // validation
    final ServerPortsValidator validationStatusProvider = new ServerPortsValidator(websocketPortTextObservable,
            useProxyServerSelection, proxyPortTextObservable);
    dbc.addValidationStatusProvider(validationStatusProvider);

}

From source file:org.jboss.tools.openshift.express.internal.core.portforward.ApplicationPortForwardingWizardPage.java

License:Open Source License

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(parent);
    Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(container);

    Composite tableContainer = new Composite(container, SWT.NONE);
    this.viewer = createTable(tableContainer, dbc);
    GridDataFactory.fillDefaults().span(1, 3).align(SWT.FILL, SWT.FILL).grab(true, true)
            .applyTo(tableContainer);//  w w w.j  a  va2 s .co  m

    refreshButton = new Button(container, SWT.PUSH);
    refreshButton.setText("Refresh");
    GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).align(SWT.FILL, SWT.TOP).applyTo(refreshButton);
    refreshButton.addSelectionListener(onRefreshPorts());

    startButton = new Button(container, SWT.PUSH);
    startButton.setText("Start All");
    startButton.setEnabled(wizardModel.hasForwardablePorts());
    GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).align(SWT.FILL, SWT.TOP).applyTo(startButton);
    startButton.addSelectionListener(onStartPortForwarding());

    stopButton = new Button(container, SWT.PUSH);
    stopButton.setText("Stop All");
    stopButton.setEnabled(false);
    GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).align(SWT.FILL, SWT.TOP).applyTo(stopButton);
    stopButton.addSelectionListener(onStopPortForwarding());

    // checkbox to use the default "127.0.0.1" local IP address
    final Button useLocalIpAddressButton = new Button(container, SWT.CHECK);
    useLocalIpAddressButton.setText("Use '127.0.0.1' as the local address for all Services");
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(false, false)
            .applyTo(useLocalIpAddressButton);
    final IObservableValue useLocalIpAddressObservable = BeanProperties
            .value(ApplicationPortForwardingWizardModel.PROPERTY_USE_DEFAULT_LOCAL_IP_ADDRESS)
            .observe(wizardModel);
    final IObservableValue useLocalIpAddressButtonSelection = WidgetProperties.selection()
            .observe(useLocalIpAddressButton);
    dbc.bindValue(useLocalIpAddressButtonSelection, useLocalIpAddressObservable);
    useLocalIpAddressObservable.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void handleValueChange(ValueChangeEvent event) {
            refreshViewerInput();
        }
    });

    // checkbox to use the default "127.0.0.1" local IP address
    final Button findFreesPortButton = new Button(container, SWT.CHECK);
    findFreesPortButton.setText("Find free ports for all Services");
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(false, false)
            .applyTo(findFreesPortButton);
    final IObservableValue findFreePortsButtonObservable = BeanProperties
            .value(ApplicationPortForwardingWizardModel.PROPERTY_USE_FREE_PORTS).observe(wizardModel);
    final IObservableValue findFreePortsButtonSelection = WidgetProperties.selection()
            .observe(findFreesPortButton);
    dbc.bindValue(findFreePortsButtonSelection, findFreePortsButtonObservable);
    findFreePortsButtonObservable.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void handleValueChange(ValueChangeEvent event) {
            refreshViewerInput();
        }
    });

    // enabling/disabling controls
    IObservableValue portForwardingStartedObservable = BeanProperties
            .value(ApplicationPortForwardingWizardModel.PROPERTY_PORT_FORWARDING).observe(wizardModel);

    IObservableValue forwardablePortsExistObservable = BeanProperties
            .value(ApplicationPortForwardingWizardModel.PROPERTY_FORWARDABLE_PORTS).observe(wizardModel);

    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(startButton))
            .notUpdating(portForwardingStartedObservable).converting(new InvertingBooleanConverter()).in(dbc);

    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(startButton))
            .notUpdating(forwardablePortsExistObservable).converting(new Converter(List.class, Boolean.class) {

                @Override
                public Object convert(Object fromObject) {
                    if (fromObject instanceof List<?>) {
                        return !((List<?>) fromObject).isEmpty();
                    }
                    return Boolean.FALSE;
                }
            }).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(stopButton))
            .notUpdating(portForwardingStartedObservable).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(useLocalIpAddressButton))
            .notUpdating(portForwardingStartedObservable).converting(new InvertingBooleanConverter()).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(findFreesPortButton))
            .notUpdating(portForwardingStartedObservable).converting(new InvertingBooleanConverter()).in(dbc);

}

From source file:org.jboss.tools.openshift.express.internal.ui.portforward.PortForwardingWizardPage.java

License:Open Source License

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(parent);
    Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(container);

    Composite tableContainer = new Composite(container, SWT.NONE);
    this.viewer = createTable(tableContainer, dbc);
    GridDataFactory.fillDefaults().span(1, 3).align(SWT.FILL, SWT.FILL).grab(true, true)
            .applyTo(tableContainer);/*  www  . j  a v a2  s  .c  o  m*/

    refreshButton = new Button(container, SWT.PUSH);
    refreshButton.setText("Refresh");
    GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).align(SWT.FILL, SWT.TOP).applyTo(refreshButton);
    refreshButton.addSelectionListener(onRefreshPorts());

    startButton = new Button(container, SWT.PUSH);
    startButton.setText("Start All");
    startButton.setEnabled(wizardModel.hasForwardablePorts());
    GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).align(SWT.FILL, SWT.TOP).applyTo(startButton);
    startButton.addSelectionListener(onStartPortForwarding());

    stopButton = new Button(container, SWT.PUSH);
    stopButton.setText("Stop All");
    stopButton.setEnabled(false);
    GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).align(SWT.FILL, SWT.TOP).applyTo(stopButton);
    stopButton.addSelectionListener(onStopPortForwarding());

    // checkbox to use the default "127.0.0.1" local IP address
    final Button useLocalIpAddressButton = new Button(container, SWT.CHECK);
    useLocalIpAddressButton.setText("Use '127.0.0.1' as the local address for all Services");
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(false, false)
            .applyTo(useLocalIpAddressButton);
    final IObservableValue useLocalIpAddressObservable = BeanProperties
            .value(PortForwardingWizardModel.PROPERTY_USE_DEFAULT_LOCAL_IP_ADDRESS).observe(wizardModel);
    final IObservableValue useLocalIpAddressButtonSelection = WidgetProperties.selection()
            .observe(useLocalIpAddressButton);
    dbc.bindValue(useLocalIpAddressButtonSelection, useLocalIpAddressObservable);
    useLocalIpAddressObservable.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void handleValueChange(ValueChangeEvent event) {
            refreshViewerInput(wizardModel.getForwardablePorts());
        }
    });

    // checkbox to use the default "127.0.0.1" local IP address
    final Button findFreesPortButton = new Button(container, SWT.CHECK);
    findFreesPortButton.setText("Find free ports for all Services");
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(false, false)
            .applyTo(findFreesPortButton);
    final IObservableValue findFreePortsButtonObservable = BeanProperties
            .value(PortForwardingWizardModel.PROPERTY_USE_FREE_PORTS).observe(wizardModel);
    final IObservableValue findFreePortsButtonSelection = WidgetProperties.selection()
            .observe(findFreesPortButton);
    dbc.bindValue(findFreePortsButtonSelection, findFreePortsButtonObservable);
    findFreePortsButtonObservable.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void handleValueChange(ValueChangeEvent event) {
            refreshViewerInput(wizardModel.getForwardablePorts());
        }
    });

    // enabling/disabling controls
    IObservableValue portForwardingStartedObservable = BeanProperties
            .value(PortForwardingWizardModel.PROPERTY_PORT_FORWARDING).observe(wizardModel);

    IObservableValue forwardablePortsExistObservable = BeanProperties
            .value(PortForwardingWizardModel.PROPERTY_FORWARDABLE_PORTS).observe(wizardModel);

    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(startButton))
            .notUpdating(portForwardingStartedObservable).converting(new InvertingBooleanConverter()).in(dbc);

    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(startButton))
            .notUpdating(forwardablePortsExistObservable).converting(new Converter(List.class, Boolean.class) {

                @Override
                public Object convert(Object fromObject) {
                    if (fromObject instanceof List<?>) {
                        return !((List<?>) fromObject).isEmpty();
                    }
                    return Boolean.FALSE;
                }
            }).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(stopButton))
            .notUpdating(portForwardingStartedObservable).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(useLocalIpAddressButton))
            .notUpdating(portForwardingStartedObservable).converting(new InvertingBooleanConverter()).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(findFreesPortButton))
            .notUpdating(portForwardingStartedObservable).converting(new InvertingBooleanConverter()).in(dbc);

}

From source file:org.jboss.tools.openshift.express.internal.ui.wizard.application.ApplicationTemplateWizardPage.java

License:Open Source License

private void createExistingApplicationControls(Composite parent, SelectObservableValue useExitingApplication,
        IObservableValue useExistingApplication, DataBindingContext dbc) {
    // existing app radio
    Button useExistingApplicationButton = new Button(parent, SWT.RADIO);
    useExistingApplicationButton.setText("Use my existing OpenShift application:");
    useExistingApplicationButton.setToolTipText("If selected we will import your existing application.");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).grab(true, false)
            .applyTo(useExistingApplicationButton);

    useExitingApplication.addOption(Boolean.TRUE,
            WidgetProperties.selection().observe(useExistingApplicationButton));

    // existing app explanatory label
    Label existingAppLabel = new Label(parent, SWT.None);
    existingAppLabel.setText("We will clone and import your existing application to a workspace project.");
    existingAppLabel.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(existingAppLabel);/*from   w  ww.  j  a va  2  s  .c om*/

    // existing app name
    this.existingAppNameText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(existingAppNameText);
    IObservableValue existingAppNameTextObservable = WidgetProperties.text(SWT.Modify)
            .observe(existingAppNameText);
    ValueBindingBuilder.bind(existingAppNameTextObservable).to(BeanProperties
            .value(ApplicationTemplateWizardPageModel.PROPERTY_EXISTING_APPLICATION_NAME).observe(pageModel))
            .in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(existingAppNameText)).notUpdatingParticipant()
            .to(useExistingApplication).in(dbc);
    createExistingAppNameContentAssist(existingAppNameText);

    IObservableValue existingApplicationsLoaded = BeanProperties
            .value(ApplicationTemplateWizardPageModel.PROPERTY_RESOURCES_LOADED).observe(pageModel);
    IObservableValue existingApplicationObservable = BeanProperties
            .value(ApplicationTemplateWizardPageModel.PROPERTY_EXISTING_APPLICATION).observe(pageModel);
    final ExistingApplicationNameValidator existingAppValidator = new ExistingApplicationNameValidator(
            useExitingApplication, existingAppNameTextObservable, existingApplicationObservable,
            existingApplicationsLoaded);
    dbc.addValidationStatusProvider(existingAppValidator);
    ControlDecorationSupport.create(existingAppValidator, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater(true));

    // browse button
    Button browseAppsButton = new Button(parent, SWT.NONE);
    browseAppsButton.setText("Browse...");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).grab(false, false)
            .applyTo(browseAppsButton);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(browseAppsButton)).notUpdatingParticipant()
            .to(useExistingApplication).in(dbc);
    browseAppsButton.addSelectionListener(onBrowseExistingApps(dbc));
}