Example usage for org.eclipse.jface.databinding.viewers ViewerProperties singleSelection

List of usage examples for org.eclipse.jface.databinding.viewers ViewerProperties singleSelection

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.viewers ViewerProperties singleSelection.

Prototype

public static IViewerValueProperty singleSelection() 

Source Link

Document

Returns a value property for observing the single selection of a ISelectionProvider .

Usage

From source file:org.fusesource.ide.camel.editor.component.wizard.SelectComponentWizardPage.java

License:Open Source License

/**
 * @param componentSelectionGroup//from ww w . j a v  a  2 s.c om
 * @return
 */
private FilteredTree createFilteredTree(Group componentSelectionGroup) {
    final int treeStyle = SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER;
    final FilteredTree filteredTree = new FilteredTree(componentSelectionGroup, treeStyle,
            new ComponentNameAndTagPatternFilter(), true);
    filteredTree.getFilterControl().setMessage(UIMessages.GlobalEndpointWizardPage_filterSearchMessage);
    final int xHint = getShell().getSize().x - 20;
    filteredTree
            .setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).hint(xHint, 400).create());
    final TreeViewer treeViewer = filteredTree.getViewer();
    treeViewer.setContentProvider(new ComponentListTreeContentProvider());
    treeViewer.setComparator(new ViewerComparator());
    treeViewer.setLabelProvider(new ComponentLabelProvider());
    treeViewer.setInput(new ComponentManager(componentModel));
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value instanceof Component) {
                return Status.OK_STATUS;
            }
            return ValidationStatus
                    .error(UIMessages.GlobalEndpointWizardPage_componentSelectionMandatoryMessage);
        }
    });

    dbc.bindValue(ViewerProperties.singleSelection().observe(treeViewer),
            PojoProperties.value(SelectComponentWizardPage.class, "componentSelected", Component.class) //$NON-NLS-1$
                    .observe(this), strategy, null);
    return filteredTree;
}

From source file:org.fusesource.ide.camel.editor.globalconfiguration.dataformat.wizards.pages.DataFormatSelectionPage.java

License:Open Source License

/**
 * @param container//from w  w  w .  j a  va  2s .  co  m
 */
private void createDataFormatSelectionLine(Composite container) {
    Label l = new Label(container, SWT.NONE);
    l.setText(UIMessages.dataFormatSelectionPage_dataformatLabel);
    l.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 1, 1));

    ComboViewer dataformatComboViewer = new ComboViewer(container, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    dataformatComboViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    dataformatComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    dataformatComboViewer.setLabelProvider(new DataFormatLabelProvider());
    dataformatComboViewer.setComparator(new ViewerComparator());
    dataformatComboViewer.setInput(dfModel.getSupportedDataFormats().toArray());

    dbc.bindValue(ViewerProperties.singleSelection().observe(dataformatComboViewer), PojoProperties
            .value(DataFormatSelectionPage.class, "dataFormatSelected", DataFormat.class).observe(this)); //$NON-NLS-1$
    dataformatComboViewer.setSelection(new StructuredSelection(dataformatComboViewer.getElementAt(0)));
}

From source file:org.jboss.mapper.eclipse.internal.wizards.FirstPage.java

License:Open Source License

void createPage(final Composite parent) {

    final Composite page = new Composite(parent, SWT.NONE);
    setControl(page);/*  www. j  a v a 2 s  .  co  m*/
    page.setLayout(GridLayoutFactory.swtDefaults().spacing(0, 5).numColumns(3).create());

    // Create project widgets
    Label label = new Label(page, SWT.NONE);
    label.setText("Project:");
    label.setToolTipText("The project that will contain the mapping file.");
    final ComboViewer projectViewer = new ComboViewer(new Combo(page, SWT.READ_ONLY));
    projectViewer.getCombo().setLayoutData(
            GridDataFactory.swtDefaults().grab(true, false).span(2, 1).align(SWT.FILL, SWT.CENTER).create());
    projectViewer.getCombo().setToolTipText(label.getToolTipText());
    projectViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(final Object element) {
            return ((IProject) element).getName();
        }
    });

    // Create ID widgets
    label = new Label(page, SWT.NONE);
    label.setText("ID:");
    label.setToolTipText("The transformation ID that will be shown in the Fuse editor");
    final Text idText = new Text(page, SWT.BORDER);
    idText.setLayoutData(
            GridDataFactory.swtDefaults().span(2, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).create());
    idText.setToolTipText(label.getToolTipText());

    // Create file path widgets
    label = new Label(page, SWT.NONE);
    label.setText("Dozer File path: ");
    label.setToolTipText("The path to the Dozer transformation file.");
    final Text pathText = new Text(page, SWT.BORDER);
    pathText.setLayoutData(
            GridDataFactory.swtDefaults().span(2, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).create());
    pathText.setToolTipText(label.getToolTipText());

    // Create camel file path widgets
    label = new Label(page, SWT.NONE);
    label.setText("Camel File path: ");
    label.setToolTipText("Path to the Camel configuration file.");
    final Text camelFilePathText = new Text(page, SWT.BORDER);
    camelFilePathText.setLayoutData(
            GridDataFactory.swtDefaults().span(1, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).create());
    camelFilePathText.setToolTipText(label.getToolTipText());

    final Button camelPathButton = new Button(page, SWT.NONE);
    camelPathButton.setText("...");
    camelPathButton.setToolTipText("Browse to select an available Camel file.");
    camelPathButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            final IResource res = Util.selectResourceFromWorkspace(getShell(), ".xml", model.getProject());
            if (res != null) {
                final IPath respath = JavaUtil.getJavaPathForResource(res);
                final String path = respath.makeRelative().toString();
                model.setCamelFilePath(path);
                camelFilePathText.setText(path);
                camelFilePathText.notifyListeners(SWT.Modify, new Event());
            }
        }
    });

    // Create source widgets
    Group group = new Group(page, SWT.SHADOW_ETCHED_IN);
    Label fileLabel = new Label(group, SWT.NONE);
    final Text sourcePathText = new Text(group, SWT.BORDER);
    final Button sourcePathButton = new Button(group, SWT.NONE);
    Label typeLabel = new Label(group, SWT.NONE);
    final ComboViewer sourceTypeViewer = new ComboViewer(new Combo(group, SWT.READ_ONLY));
    createFileControls(group, fileLabel, "Source", sourcePathText, sourcePathButton, typeLabel,
            sourceTypeViewer);

    // Create target widgets
    group = new Group(page, SWT.SHADOW_ETCHED_IN);
    fileLabel = new Label(group, SWT.NONE);
    final Text targetPathText = new Text(group, SWT.BORDER);
    final Button targetPathButton = new Button(group, SWT.NONE);
    typeLabel = new Label(group, SWT.NONE);
    final ComboViewer targetTypeViewer = new ComboViewer(new Combo(group, SWT.READ_ONLY));
    createFileControls(group, fileLabel, "Target", targetPathText, targetPathButton, typeLabel,
            targetTypeViewer);

    // Bind project widget to UI model
    projectViewer.setContentProvider(new ObservableListContentProvider());
    IObservableValue widgetValue = ViewerProperties.singleSelection().observe(projectViewer);
    IObservableValue modelValue = BeanProperties.value(Model.class, "project").observe(model);
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null) {
                sourcePathButton.setEnabled(false);
                targetPathButton.setEnabled(false);
                return ValidationStatus.error("A project must be selected");
            }
            sourcePathButton.setEnabled(true);
            targetPathButton.setEnabled(true);
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT);
    projectViewer.setInput(Properties.selfList(IProject.class).observe(model.projects));

    // Bind transformation ID widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(idText);
    modelValue = BeanProperties.value(Model.class, "id").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null || value.toString().trim().isEmpty()) {
                return ValidationStatus.error("A transformation ID must be supplied");
            }
            final String id = value.toString().trim();
            final StringCharacterIterator iter = new StringCharacterIterator(id);
            for (char chr = iter.first(); chr != StringCharacterIterator.DONE; chr = iter.next()) {
                if (!Character.isJavaIdentifierPart(chr)) {
                    return ValidationStatus.error("The transformation ID may only contain letters, "
                            + "digits, currency symbols, or underscores");
                }
            }
            if (model.camelConfigBuilder != null) {
                for (final String endpointId : model.camelConfigBuilder.getTransformEndpointIds()) {
                    if (id.equalsIgnoreCase(endpointId)) {
                        return ValidationStatus.error("A transformation with the supplied ID already exists");
                    }
                }
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT);

    // Bind file path widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(pathText);
    modelValue = BeanProperties.value(Model.class, "filePath").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null || value.toString().trim().isEmpty()) {
                return ValidationStatus.error("The transformation file path must be supplied");
            }
            if (!(value.toString().trim().isEmpty())) {
                final IFile file = model.getProject().getFile(Util.RESOURCES_PATH + (String) value);
                if (file.exists()) {
                    return ValidationStatus.warning("A transformation file with that name already exists.");
                }
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT);

    // Bind camel file path widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(camelFilePathText);
    modelValue = BeanProperties.value(Model.class, "camelFilePath").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null || value.toString().trim().isEmpty()) {
                return ValidationStatus.error("The Camel file path must be supplied");
            }
            if (!(value.toString().trim().isEmpty())) {
                File testFile = null;
                final String path = (String) value;
                testFile = new File(model.getProject().getFile(path).getLocationURI());
                if (!testFile.exists()) {
                    testFile = new File(
                            model.getProject().getFile(Util.RESOURCES_PATH + path).getLocationURI());
                    if (!testFile.exists()) {
                        return ValidationStatus.error("The Camel file path must be a valid file location");
                    }
                }
                try {
                    CamelConfigBuilder.loadConfig(testFile);
                } catch (final Exception e) {
                    return ValidationStatus.error("The Camel file path must refer to a valid Camel file");
                }
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null),
            SWT.LEFT | SWT.TOP);

    final ControlDecorationUpdater sourceUpdator = new ControlDecorationUpdater();
    final ControlDecorationUpdater targetUpdator = new ControlDecorationUpdater();

    // Bind source file path widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(sourcePathText);
    modelValue = BeanProperties.value(Model.class, "sourceFilePath").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            final String path = value == null ? null : value.toString().trim();
            if (path == null || path.isEmpty()) {
                return ValidationStatus
                        .error("A source file path must be supplied for the supplied target file path");
            }
            if (model.getProject().findMember(path) == null) {
                return ValidationStatus.error("Unable to find a source file with the supplied path");
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT, null,
            sourceUpdator);

    // Bind target file path widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(targetPathText);
    modelValue = BeanProperties.value(Model.class, "targetFilePath").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            final String path = value == null ? null : value.toString().trim();
            if (path == null || path.isEmpty()) {
                return ValidationStatus
                        .error("A target file path must be supplied for the supplied source file path");
            }
            if (model.getProject().findMember(path) == null) {
                return ValidationStatus.error("Unable to find a target file with the supplied path");
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT, null,
            targetUpdator);

    // Bind source type widget to UI model
    sourceTypeViewer.setContentProvider(new ObservableListContentProvider());
    widgetValue = ViewerProperties.singleSelection().observe(sourceTypeViewer);
    modelValue = BeanProperties.value(Model.class, "sourceType").observe(model);
    context.bindValue(widgetValue, modelValue);
    sourceTypeViewer.setInput(Properties.selfList(ModelType.class).observe(Arrays.asList(ModelType.values())));

    // Bind target type widget to UI model
    targetTypeViewer.setContentProvider(new ObservableListContentProvider());
    widgetValue = ViewerProperties.singleSelection().observe(targetTypeViewer);
    modelValue = BeanProperties.value(Model.class, "targetType").observe(model);
    context.bindValue(widgetValue, modelValue);
    targetTypeViewer.setInput(Properties.selfList(ModelType.class).observe(Arrays.asList(ModelType.values())));

    // Set focus to appropriate control
    page.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(final PaintEvent event) {
            if (model.getProject() == null) {
                projectViewer.getCombo().setFocus();
            } else {
                idText.setFocus();
            }
            page.removePaintListener(this);
        }
    });

    for (final Object observable : context.getValidationStatusProviders()) {
        ((Binding) observable).getTarget().addChangeListener(new IChangeListener() {

            @Override
            public void handleChange(final ChangeEvent event) {
                validatePage();
            }
        });
    }

    if (model.getProject() == null) {
        validatePage();
    } else {
        projectViewer.setSelection(new StructuredSelection(model.getProject()));
    }
}

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/*w w w .j  av  a2  s  .c  om*/
    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.fuse.transformation.editor.internal.wizards.OtherPage.java

License:Open Source License

public void initialize() {

    // Bind id widget to UI model
    IObservableValue widgetValue = ViewerProperties.singleSelection().observe(_dataFormatIdCombo);
    idModelValue = null;/*from  w  w w.  j av  a  2s.  c o  m*/

    WritableList dfList = new WritableList();
    CamelConfigBuilder configBuilder = new CamelConfigBuilder();

    Collection<AbstractCamelModelElement> dataFormats = configBuilder.getDataFormats();
    for (Iterator<AbstractCamelModelElement> iterator = dataFormats.iterator(); iterator.hasNext();) {
        AbstractCamelModelElement df = iterator.next();
        if (df.getId() != null) {
            dfList.add(df.getId());
        }
    }
    if (dfList.isEmpty()) {
        _dfErrorLabel.setText(Messages.OtherPage_errormessageNoAvailableDataFormats);
        _dfErrorLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
        _dataFormatIdCombo.getCombo().setEnabled(false);
    } else {
        _dfErrorLabel.setText(""); //$NON-NLS-1$
        _dataFormatIdCombo.getCombo().setEnabled(true);
    }
    _dataFormatIdCombo.setInput(dfList);
    if (isSourcePage()) {
        idModelValue = BeanProperties.value(Model.class, "sourceDataFormatid").observe(model); //$NON-NLS-1$
    } else {
        idModelValue = BeanProperties.value(Model.class, "targetDataFormatid").observe(model); //$NON-NLS-1$
    }
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            final String path = value == null ? null : value.toString().trim();
            if (path == null || path.isEmpty()) {
                return ValidationStatus.error(Messages.OtherPage_errormessageNoDataFormatId);
            }
            return ValidationStatus.ok();
        }
    });
    _binding2 = context.bindValue(widgetValue, idModelValue, strategy, null);
    ControlDecorationSupport.create(_binding2, decoratorPosition, _javaClassText.getParent());
}

From source file:org.jboss.tools.fuse.transformation.editor.internal.wizards.StartPage.java

License:Open Source License

private void bindControls() {

    IObservableValue dozerPathTextValue = WidgetProperties.text(SWT.Modify).observe(_dozerPathText);
    IObservableValue dozerPathValue = BeanProperties.value(Model.class, "filePath").observe(model); //$NON-NLS-1$

    // bind the project dropdown
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override//from   w  w w  . j  av a  2 s  .c o m
        public IStatus validate(final Object value) {
            if (value == null) {
                return ValidationStatus.error(Messages.StartPage_errorMessageProjectMustBeSelected);
            }
            return ValidationStatus.ok();
        }
    });

    // Bind transformation ID widget to UI model
    IObservableValue idTextValue = WidgetProperties.text(SWT.Modify).observe(_idText);
    IObservableValue idValue = BeanProperties.value(Model.class, "id").observe(model); //$NON-NLS-1$

    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null || value.toString().trim().isEmpty()) {
                return ValidationStatus.error(Messages.StartPage_errorMessageIDMustBeSupplied);
            }
            final String id = value.toString().trim();
            final StringCharacterIterator iter = new StringCharacterIterator(id);
            for (char chr = iter.first(); chr != StringCharacterIterator.DONE; chr = iter.next()) {
                if (!Character.isJavaIdentifierPart(chr)) {
                    return ValidationStatus.error(Messages.StartPage_errorMessageInvalidCharacters);
                }
            }
            CamelConfigBuilder configBuilder = new CamelConfigBuilder();
            for (final String endpointId : configBuilder.getTransformEndpointIds()) {
                if (id.equalsIgnoreCase(endpointId)) {
                    return ValidationStatus.error(Messages.StartPage_errorMessageIDAlreadyExists);
                }
            }
            return ValidationStatus.ok();
        }
    });
    _endpointIdBinding = context.bindValue(idTextValue, idValue, strategy, null);
    ControlDecorationSupport.create(_endpointIdBinding, decoratorPosition, _idText.getParent());

    // Bind file path widget to UI model
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null || value.toString().trim().isEmpty()) {
                return ValidationStatus.error(Messages.StartPage_errorMessageFlePathMissing);
            }
            if (!(value.toString().trim().isEmpty())) {
                if (CamelUtils.project() != null) {
                    final IFile file = CamelUtils.project().getFile(MavenUtils.RESOURCES_PATH + (String) value);
                    if (file != null && file.exists()) {
                        return ValidationStatus.warning(Messages.StartPage_errorMessageNameFileAlreadyExists);
                    }
                }
            }
            return ValidationStatus.ok();
        }
    });
    _filePathBinding = context.bindValue(dozerPathTextValue, dozerPathValue, strategy, null);
    ControlDecorationSupport.create(_filePathBinding, decoratorPosition, _dozerPathText.getParent());

    // bind the source type string dropdown
    _sourceCV.setContentProvider(new ObservableListContentProvider());
    IObservableValue widgetValue = ViewerProperties.singleSelection().observe(_sourceCV);
    IObservableValue modelValue = BeanProperties.value(Model.class, "sourceTypeStr").observe(model); //$NON-NLS-1$
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            getModel().setSourceFilePath("");
            ((NewTransformationWizard) getWizard()).resetSourceAndTargetPages();
            if (StartPage.this.getSourcePage() != null) {
                ((XformWizardPage) StartPage.this.getSourcePage()).clearControls();
            }
            UIJob uiJob = new UIJob(Messages.StartPage_openErroUiJobName) {
                @Override
                public IStatus runInUIThread(IProgressMonitor monitor) {
                    if (StartPage.this.getTargetPage() != null) {
                        ((XformWizardPage) StartPage.this.getTargetPage()).pingBinding();
                    }
                    return Status.OK_STATUS;
                }
            };
            uiJob.setSystem(true);
            uiJob.schedule();

            if (value == null || ((String) value).trim().isEmpty()) {
                resetFinish();
                return ValidationStatus.error(Messages.StartPage_errorMessageSourceTypeMissing);
            }
            return ValidationStatus.ok();
        }
    });

    WritableList sourceList = new WritableList();
    sourceList.add("Java"); //$NON-NLS-1$
    sourceList.add("XML"); //$NON-NLS-1$
    sourceList.add("JSON"); //$NON-NLS-1$
    sourceList.add("Other"); //$NON-NLS-1$
    sourceList.add(""); //$NON-NLS-1$
    _sourceCV.setInput(sourceList);
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null),
            decoratorPosition, null);

    // bind the source type string dropdown
    _targetCV.setContentProvider(new ObservableListContentProvider());
    widgetValue = ViewerProperties.singleSelection().observe(_targetCV);
    modelValue = BeanProperties.value(Model.class, "targetTypeStr").observe(model); //$NON-NLS-1$
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            getModel().setTargetFilePath("");
            ((NewTransformationWizard) getWizard()).resetSourceAndTargetPages();
            if (StartPage.this.getTargetPage() != null) {
                ((XformWizardPage) StartPage.this.getTargetPage()).clearControls();
            }
            UIJob uiJob = new UIJob(Messages.StartPage_openErroruiJobName) {
                @Override
                public IStatus runInUIThread(IProgressMonitor monitor) {
                    if (StartPage.this.getSourcePage() != null) {
                        ((XformWizardPage) StartPage.this.getSourcePage()).pingBinding();
                    }
                    return Status.OK_STATUS;
                }
            };
            uiJob.setSystem(true);
            uiJob.schedule();

            if (value == null || ((String) value).trim().isEmpty()) {
                resetFinish();
                return ValidationStatus.error(Messages.StartPage_errorMessageTargetTypeMissing);
            }
            return ValidationStatus.ok();
        }
    });

    WritableList targetList = new WritableList();
    targetList.add("Java"); //$NON-NLS-1$
    targetList.add("XML"); //$NON-NLS-1$
    targetList.add("JSON"); //$NON-NLS-1$
    targetList.add("Other"); //$NON-NLS-1$
    targetList.add(""); //$NON-NLS-1$
    _targetCV.setInput(targetList);
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null),
            decoratorPosition, null);

    listenForValidationChanges();
}

From source file:org.jboss.tools.fuse.transformation.editor.internal.wizards.XMLPage.java

License:Open Source License

private void bindControls() {

    // Bind source file path widget to UI model
    IObservableValue widgetValue = WidgetProperties.text(SWT.Modify).observe(_xmlFileText);
    IObservableValue modelValue;// www.  j  av  a2s .c  o m
    if (isSourcePage()) {
        modelValue = BeanProperties.value(Model.class, "sourceFilePath").observe(model); //$NON-NLS-1$
    } else {
        modelValue = BeanProperties.value(Model.class, "targetFilePath").observe(model); //$NON-NLS-1$
    }
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            final String path = value == null ? null : value.toString().trim();
            String pathEmptyError;
            String unableToFindError;
            String unableToParseXMLError;
            if (isSourcePage()) {
                pathEmptyError = Messages.XMLPage_errorMessageEmptySourcepath;
                unableToFindError = Messages.XMLPage_errorMessageUnableToFindSourceFile;
                unableToParseXMLError = Messages.XMLPage_errorMessageSourceParseError;
            } else {
                pathEmptyError = Messages.XMLPage_errorMessageEmptyTargetpath;
                unableToFindError = Messages.XMLPage_errorMessageUnableToFindTargetFile;
                unableToParseXMLError = Messages.XMLPage_errorMessageTargetParseError;
            }
            if (path == null || path.isEmpty()) {
                clearSelection();
                return ValidationStatus.error(pathEmptyError);
            }
            if (CamelUtils.project().findMember(path) == null) {
                clearSelection();
                return ValidationStatus.error(unableToFindError);
            }
            IResource resource = CamelUtils.project().findMember(path);
            if (resource == null || !resource.exists() || !(resource instanceof IFile)) {
                clearSelection();
                return ValidationStatus.error(unableToFindError);
            }
            XmlMatchingStrategy strategy = new XmlMatchingStrategy();
            if (!strategy.matches((IFile) resource)) {
                clearSelection();
                return ValidationStatus.error(unableToParseXMLError);
            }
            return ValidationStatus.ok();
        }
    });
    widgetValue.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            if (!XMLPage.this.isCurrentPage()) {
                return;
            }
            Object value = event.diff.getNewValue();
            String path = null;
            if (value != null && !value.toString().trim().isEmpty()) {
                path = value.toString().trim();
            }
            if (path == null) {
                return;
            }
            XmlModelGenerator modelGen = new XmlModelGenerator();
            List<QName> elements = null;
            IResource resource = CamelUtils.project().findMember(path);
            if (resource == null || !resource.exists() || !(resource instanceof IFile)) {
                return;
            }
            IPath filePath = resource.getLocation();
            path = filePath.makeAbsolute().toPortableString();
            if (model != null) {
                updateSettingsBasedOnFilePath(path);
                if (isSourcePage() && model.getSourceType() != null) {
                    if (model.getSourceType().equals(ModelType.XSD)) {
                        try {
                            elements = modelGen.getElementsFromSchema(new File(path));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else if (model.getSourceType().equals(ModelType.XML)) {
                        try {
                            QName element = modelGen.getRootElementName(new File(path));
                            if (element != null) {
                                elements = new ArrayList<>();
                                elements.add(element);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                } else if (!isSourcePage() && model.getTargetType() != null) {
                    if (model.getTargetType().equals(ModelType.XSD)) {
                        try {
                            elements = modelGen.getElementsFromSchema(new File(path));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else if (model.getTargetType().equals(ModelType.XML)) {
                        try {
                            QName element = modelGen.getRootElementName(new File(path));
                            if (element != null) {
                                elements = new ArrayList<>();
                                elements.add(element);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
                updatePreview(resource.getProjectRelativePath().toString());
            }
            WritableList elementList = new WritableList();
            if (elements != null && !elements.isEmpty()) {
                ArrayList<String> tempList = new ArrayList<>();
                Iterator<QName> iter = elements.iterator();
                while (iter.hasNext()) {
                    QName qname = iter.next();
                    tempList.add(qname.getLocalPart());
                    _xmlRootsCombo.setData(qname.getLocalPart(), qname.getNamespaceURI());
                }
                Collections.sort(tempList);
                elementList.addAll(tempList);
            }
            _xmlRootsCombo.setInput(elementList);
            if (!elementList.isEmpty()) {
                _xmlRootsCombo.setSelection(new StructuredSelection(elementList.get(0)));
                String elementName = (String) elementList.get(0);
                if (isSourcePage()) {
                    model.setSourceClassName(elementName);
                } else {
                    model.setTargetClassName(elementName);
                }
                _xmlRootsCombo.getCombo().setEnabled(true);
                if (elementList.size() == 1) {
                    _xmlRootsCombo.getCombo().setToolTipText(Messages.XMLPage_tooltipErrorOnlyOneElement);
                } else {
                    _xmlRootsCombo.getCombo().setToolTipText(Messages.XMLPage_tooltipSelectFromList);
                }
            }
        }
    });
    _binding = context.bindValue(widgetValue, modelValue, strategy, null);
    _binding.getModel().addChangeListener(new IChangeListener() {

        @Override
        public void handleChange(ChangeEvent event) {
            pingBinding();
        }
    });
    ControlDecorationSupport.create(_binding, decoratorPosition, _xmlFileText.getParent());

    IObservableValue comboWidgetValue = ViewerProperties.singleSelection().observe(_xmlRootsCombo);
    IObservableValue comboModelValue;
    if (isSourcePage()) {
        comboModelValue = BeanProperties.value(Model.class, "sourceClassName").observe(model); //$NON-NLS-1$
    } else {
        comboModelValue = BeanProperties.value(Model.class, "targetClassName").observe(model); //$NON-NLS-1$
    }

    UpdateValueStrategy combostrategy = new UpdateValueStrategy();
    combostrategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            final String name = value == null ? null : value.toString().trim();
            if (name == null || name.isEmpty()) {
                return ValidationStatus.error(Messages.XMLPage_errorMessageNoRootElementName);
            }
            return ValidationStatus.ok();
        }
    });
    _binding2 = context.bindValue(comboWidgetValue, comboModelValue, combostrategy, null);
    ControlDecorationSupport.create(_binding2, decoratorPosition, _xmlRootsCombo.getControl().getParent());

    listenForValidationChanges();
}

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

License:Open Source License

/**
 * Creates the SWT Group in which a table which will display the existing applications with their corresponding
 * type. Before each application, a radio button will let the user choose which application to import in his
 * workspace./*w  ww.  j  a v a  2s. c o m*/
 * 
 * @param container
 * @param dbc
 */
@Override
protected Control createDialogArea(Composite parent) {
    Label titleSeparator = new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(titleSeparator);

    Composite dialogArea = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(dialogArea);
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(dialogArea);

    Label applicationLabel = new Label(dialogArea, SWT.NONE);
    applicationLabel.setText("Existing Applications on OpenShift");
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).span(5, 1)
            .applyTo(applicationLabel);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(dialogArea);

    Composite tableContainer = new Composite(dialogArea, SWT.NONE);
    tableViewer = createTable(tableContainer);
    tableViewer.setInput(dialogModel.getApplications());
    GridDataFactory.fillDefaults().span(1, 2).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 200)
            .applyTo(tableContainer);
    tableViewer.addDoubleClickListener(onApplicationDoubleClick());
    Binding selectedApplicationBinding = dbc.bindValue(
            ViewerProperties.singleSelection().observe(tableViewer), BeanProperties
                    .value(ApplicationSelectionDialogModel.PROPERTY_SELECTED_APPLICATION).observe(dialogModel),
            new UpdateValueStrategy().setAfterGetValidator(new IValidator() {
                @Override
                public IStatus validate(Object value) {
                    if (value != null) {
                        return ValidationStatus.ok();
                    } else {
                        return ValidationStatus.cancel("Select an application in the list below.");
                    }
                }
            }), null);

    tableViewer.setSorter(new ViewerSorter() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof IApplication && e2 instanceof IApplication) {
                return ((IApplication) e1).getName().compareTo(((IApplication) e2).getName());
            }
            return super.compare(viewer, e1, e2);
        }

    });
    Button refreshButton = new Button(dialogArea, SWT.PUSH);
    refreshButton.setText("R&efresh");
    GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.TOP).grab(false, false).hint(80, SWT.DEFAULT)
            .applyTo(refreshButton);
    refreshButton.addSelectionListener(onRefresh(dbc));

    Button detailsButton = new Button(dialogArea, SWT.PUSH);
    detailsButton.setText("De&tails...");
    GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.TOP).grab(false, true).hint(80, SWT.DEFAULT)
            .applyTo(detailsButton);
    DataBindingUtils.bindEnablementToValidationStatus(detailsButton, IStatus.OK, dbc,
            selectedApplicationBinding);
    detailsButton.addSelectionListener(onDetails(dbc));
    // bottom filler
    Composite spacer = new Composite(dialogArea, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(spacer);
    // horizontal line to separate content from buttons
    Label buttonsSeparator = new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(buttonsSeparator);

    return dialogArea;
}

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

License:Open Source License

private void createNewApplicationControls(Composite parent, SelectObservableValue useExitingApplication,
        IObservableValue useExistingApplication, DataBindingContext dbc) {
    // existing app radio
    Button newApplicationButton = new Button(parent, SWT.RADIO);
    newApplicationButton.setText("Create a new OpenShift application:");
    newApplicationButton.setToolTipText("If selected we will create a new application in OpenShift.");
    GridDataFactory.fillDefaults().span(2, 1).indent(0, 8).align(SWT.FILL, SWT.CENTER).grab(true, false)
            .applyTo(newApplicationButton);

    useExitingApplication.addOption(Boolean.FALSE, WidgetProperties.selection().observe(newApplicationButton));

    // new app explanatory label
    Label existingAppLabel = new Label(parent, SWT.None);
    existingAppLabel.setText(/*www . j  a  va  2 s.c o m*/
            "You can create an application form scratch or handpick from existing cartridges you need.");
    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);

    Composite applicationTemplatesTreeComposite = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, true)
            .applyTo(applicationTemplatesTreeComposite);
    GridLayoutFactory.fillDefaults().spacing(2, 2).applyTo(applicationTemplatesTreeComposite);

    // filter text
    Text templateFilterText = UIUtils.createSearchText(applicationTemplatesTreeComposite);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(templateFilterText);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(templateFilterText)).notUpdatingParticipant()
            .to(useExistingApplication).converting(new InvertingBooleanConverter()).in(dbc);

    // application templates tree
    final TreeViewer applicationTemplatesViewer = createApplicationTemplatesViewer(
            applicationTemplatesTreeComposite, templateFilterText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(400, 180)
            .applyTo(applicationTemplatesViewer.getControl());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(applicationTemplatesViewer.getControl()))
            .notUpdatingParticipant().to(useExistingApplication).converting(new InvertingBooleanConverter())
            .in(dbc);
    templateFilterText.addModifyListener(onFilterTextModified(applicationTemplatesViewer));

    IObservableValue selectedApplicationTemplateViewerObservable = ViewerProperties.singleSelection()
            .observe(applicationTemplatesViewer);
    IObservableValue selectedApplicationTemplateModelObservable = BeanProperties
            .value(ApplicationTemplateWizardPageModel.PROPERTY_SELECTED_APPLICATION_TEMPLATE)
            .observe(pageModel);
    ValueBindingBuilder.bind(selectedApplicationTemplateViewerObservable)
            .to(selectedApplicationTemplateModelObservable).in(dbc);

    ApplicationTemplateValidator selectedApplicationTemplateValidator = new ApplicationTemplateValidator(
            useExitingApplication, selectedApplicationTemplateViewerObservable);
    dbc.addValidationStatusProvider(selectedApplicationTemplateValidator);
    ControlDecorationSupport.create(selectedApplicationTemplateValidator, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater(true));

    // selected application template details
    final Group detailsContainer = new Group(applicationTemplatesTreeComposite, SWT.NONE);
    detailsContainer.setText("Details");
    enableTemplateDetailsControls(detailsContainer, !pageModel.isUseExistingApplication());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, 106).applyTo(detailsContainer);
    useExistingApplication.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            final Boolean enabled = Boolean.FALSE.equals(event.diff.getNewValue());
            enableTemplateDetailsControls(detailsContainer, enabled);
        }

    });

    new ApplicationTemplateDetailViews(selectedApplicationTemplateModelObservable, useExitingApplication,
            detailsContainer, dbc).createControls();
}

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

License:Open Source License

protected void doCreateControls(Composite container, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(container);

    Link signupLink = new Link(container, SWT.WRAP);
    signupLink.setText("If you do not have an account on OpenShift, please sign up <a>here</a>.");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(signupLink);
    signupLink.addSelectionListener(onSignupLinkClicked());

    Label fillerLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).hint(SWT.DEFAULT, 6).applyTo(fillerLabel);

    Label connectionLabel = new Label(container, SWT.NONE);
    connectionLabel.setText("Connection:");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(connectionLabel);
    Combo connectionCombo = new Combo(container, SWT.DEFAULT);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(connectionCombo);
    final ComboViewer connectionComboViewer = new ComboViewer(connectionCombo);
    connectionComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    connectionComboViewer.setLabelProvider(new ConnectionColumLabelProvider());
    connectionComboViewer.setInput(pageModel.getConnections());
    connectionComboViewer.setComparer(new NewConnectionAwareConnectionComparer());

    Binding selectedConnectionBinding = ValueBindingBuilder
            .bind(ViewerProperties.singleSelection().observe(connectionComboViewer))
            .validatingAfterGet(new IValidator() {

                @Override//from   w  w w . j a va  2 s .c  o  m
                public IStatus validate(Object value) {
                    if (value == null) {
                        return ValidationStatus.cancel("You have to select or create a new connection.");
                    }
                    return ValidationStatus.ok();
                }
            }).to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION, Connection.class)
                    .observe(pageModel))
            .in(dbc);
    ControlDecorationSupport.create(selectedConnectionBinding, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());

    // stack with connection widgets / password widget
    Composite connectionWidgetsContainer = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(connectionWidgetsContainer);
    StackLayout stackLayout = new StackLayout();
    connectionWidgetsContainer.setLayout(stackLayout);
    Composite connectionWidgets = createNewConnectionComposite(connectionWidgetsContainer, dbc);
    Composite passwordWidgets = createExistingConnectionComposite(connectionWidgetsContainer, dbc);

    showConnectionWidgets(pageModel.isCreateNewConnection(), passwordWidgets, connectionWidgets, stackLayout,
            connectionWidgetsContainer);

    BeanProperties.value(ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION).observe(pageModel)
            .addValueChangeListener(onNewConnectionSelected(passwordWidgets, connectionWidgets, stackLayout,
                    connectionWidgetsContainer));
}