Search in sources :

Example 16 with RequiredControlDecorationUpdater

use of org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater in project jbosstools-openshift by jbosstools.

the class BuildConfigWizardPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(parent);
    GridLayoutFactory.fillDefaults().applyTo(parent);
    Group buildConfigsGroup = new Group(parent, SWT.NONE);
    buildConfigsGroup.setText("Existing Build Configs:");
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(buildConfigsGroup);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(buildConfigsGroup);
    // build configs tree
    TreeViewer buildConfigsViewer = createBuildConfigsViewer(new Tree(buildConfigsGroup, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL), model, dbc);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(SWT.DEFAULT, 200).span(1, 2).applyTo(buildConfigsViewer.getControl());
    final IObservableValue selectedItem = BeanProperties.value(IBuildConfigPageModel.PROPERTY_SELECTED_ITEM).observe(model);
    Binding selectedBuildConfigBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(buildConfigsViewer)).converting(new ObservableTreeItem2ModelConverter()).to(selectedItem).converting(new Model2ObservableTreeItemConverter()).in(dbc);
    dbc.addValidationStatusProvider(new MultiValidator() {

        @Override
        protected IStatus validate() {
            if (!(selectedItem.getValue() instanceof IBuildConfig)) {
                return ValidationStatus.cancel("Please select the existing build config that you want to import");
            } else {
                return ValidationStatus.ok();
            }
        }
    });
    IObservableValue connectionObservable = BeanProperties.value(IBuildConfigPageModel.PROPERTY_CONNECTION).observe(model);
    DataBindingUtils.addDisposableValueChangeListener(onConnectionChanged(buildConfigsViewer, model), connectionObservable, buildConfigsViewer.getTree());
    ControlDecorationSupport.create(selectedBuildConfigBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    // refresh button
    Button refreshButton = new Button(buildConfigsGroup, SWT.PUSH);
    refreshButton.setText("&Refresh");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(100, SWT.DEFAULT).applyTo(refreshButton);
    refreshButton.addSelectionListener(onRefresh(buildConfigsViewer, model));
    // filler
    Label fillerLabel = new Label(buildConfigsGroup, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, true).applyTo(fillerLabel);
    // details
    ExpandableComposite expandable = new ExpandableComposite(buildConfigsGroup, SWT.None);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(expandable);
    expandable.setText("Build config Details");
    expandable.setExpanded(true);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(0, 0).applyTo(expandable);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(expandable);
    Composite detailsContainer = new Composite(expandable, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(detailsContainer);
    IObservableValue selectedService = new WritableValue();
    ValueBindingBuilder.bind(selectedItem).to(selectedService).notUpdatingParticipant().in(dbc);
    new BuildConfigDetailViews(selectedService, detailsContainer, dbc).createControls();
    expandable.setClient(detailsContainer);
    expandable.addExpansionListener(new IExpansionListener() {

        @Override
        public void expansionStateChanging(ExpansionEvent e) {
        }

        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            buildConfigsGroup.update();
            buildConfigsGroup.layout(true);
        }
    });
    loadBuildConfigs(model);
}
Also used : Binding(org.eclipse.core.databinding.Binding) Group(org.eclipse.swt.widgets.Group) IStatus(org.eclipse.core.runtime.IStatus) IExpansionListener(org.eclipse.ui.forms.events.IExpansionListener) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) BuildConfigDetailViews(org.jboss.tools.openshift.internal.ui.server.BuildConfigDetailViews) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.wizard.importapp.BuildConfigTreeItems.Model2ObservableTreeItemConverter) IBuildConfig(com.openshift.restclient.model.IBuildConfig) Button(org.eclipse.swt.widgets.Button) Tree(org.eclipse.swt.widgets.Tree) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent)

Example 17 with RequiredControlDecorationUpdater

use of org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater in project jbosstools-openshift by jbosstools.

the class KeyValueWizardPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);
    Group group = new Group(parent, SWT.NONE);
    group.setText(model.getGroupLabel());
    group.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().hint(KEYVALUE_GROUP_WIDTH, SWT.DEFAULT).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(group);
    Composite composite = new Composite(group, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(composite);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(composite);
    Label nameLabel = new Label(composite, SWT.NONE);
    // $NON-NLS-1$
    nameLabel.setText(model.getKeyLabel() + ":");
    if (model.getKeyDescription() != null) {
        nameLabel.setToolTipText(model.getKeyDescription());
    }
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(nameLabel);
    Text keyText = new Text(composite, SWT.BORDER);
    keyText.setEditable(model.isKeyEditable());
    IObservableValue<String> keyTextObservable = WidgetProperties.text(SWT.Modify).observe(keyText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(keyText);
    Binding keyBinding = ValueBindingBuilder.bind(keyTextObservable).validatingAfterConvert(model.getKeyAfterConvertValidator()).to(BeanProperties.value(IKeyValueWizardModel.PROPERTY_KEY).observe(model)).in(dbc);
    ControlDecorationSupport.create(keyBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
    Label valueLabel = new Label(composite, SWT.NONE);
    // $NON-NLS-1$
    valueLabel.setText(model.getValueLabel() + ":");
    if (model.getValueDescription() != null) {
        valueLabel.setToolTipText(model.getValueDescription());
    }
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(valueLabel);
    Text valueText = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(valueText);
    IObservableValue<String> valueTextObservable = WidgetProperties.text(SWT.Modify).observe(valueText);
    Binding valeuBinding = ValueBindingBuilder.bind(valueTextObservable).validatingAfterConvert(model.getValueAfterConvertValidator()).to(BeanProperties.value(IKeyValueWizardModel.PROPERTY_VALUE).observe(model)).in(dbc);
    ControlDecorationSupport.create(valeuBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
    if (!StringUtils.isEmpty(initialKey)) {
        DataChangedValidator validator = new DataChangedValidator(keyTextObservable, valueTextObservable);
        dbc.addValidationStatusProvider(validator);
    }
    initFocus(keyText, valueText);
}
Also used : Binding(org.eclipse.core.databinding.Binding) Group(org.eclipse.swt.widgets.Group) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text)

Example 18 with RequiredControlDecorationUpdater

use of org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater in project jbosstools-openshift by jbosstools.

the class DeployImagePage method createProjectControl.

private void createProjectControl(Composite parent, DataBindingContext dbc) {
    Label lblProject = new Label(parent, SWT.NONE);
    lblProject.setText("OpenShift Project: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblProject);
    StructuredViewer cmboProject = new ComboViewer(parent);
    GridDataFactory.fillDefaults().span(NUM_COLUMS - 2, 1).applyTo(cmboProject.getControl());
    final OpenShiftExplorerLabelProvider labelProvider = new OpenShiftExplorerLabelProvider();
    cmboProject.setContentProvider(new ObservableListContentProvider());
    cmboProject.setLabelProvider(labelProvider);
    cmboProject.setInput(BeanProperties.list(IDeployImagePageModel.PROPERTY_PROJECTS).observe(model));
    ProjectViewerComparator comparator = new ProjectViewerComparator(labelProvider);
    cmboProject.setComparator(comparator);
    model.setProjectsComparator(comparator.asProjectComparator());
    IObservableValue<IProject> projectObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_PROJECT).observe(model);
    ProjectStatusProvider validator = new ProjectStatusProvider(projectObservable);
    IObservableValue selectedProjectObservable = ViewerProperties.singleSelection().observe(cmboProject);
    Binding selectedProjectBinding = ValueBindingBuilder.bind(selectedProjectObservable).converting(new ObservableTreeItem2ModelConverter(IProject.class)).validatingAfterConvert(validator).to(projectObservable).in(dbc);
    ControlDecorationSupport.create(selectedProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    Button newProjectButton = new Button(parent, SWT.PUSH);
    newProjectButton.setText("New...");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(newProjectButton);
    UIUtils.setDefaultButtonWidth(newProjectButton);
    newProjectButton.addSelectionListener(onNewProjectClicked());
    dbc.addValidationStatusProvider(validator);
    cmboProject.getControl().forceFocus();
}
Also used : Binding(org.eclipse.core.databinding.Binding) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Label(org.eclipse.swt.widgets.Label) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) IProject(com.openshift.restclient.model.IProject) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) OpenShiftExplorerLabelProvider(org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 19 with RequiredControlDecorationUpdater

use of org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater in project jbosstools-openshift by jbosstools.

the class AdvancedConnectionEditor method createControls.

@SuppressWarnings("unchecked")
@Override
public Composite createControls(Composite parent, Object context, DataBindingContext dbc) {
    this.pageModel = (ConnectionWizardPageModel) context;
    this.selectedConnection = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION).observe(pageModel);
    this.model = new AdvancedConnectionEditorModel();
    Composite composite = setControl(new Composite(parent, SWT.None));
    GridLayoutFactory.fillDefaults().applyTo(composite);
    DialogAdvancedPart part = new DialogAdvancedPart() {

        @Override
        protected void createAdvancedContent(Composite advancedComposite) {
            Label lblRegistry = new Label(advancedComposite, SWT.NONE);
            lblRegistry.setText("Image Registry URL:");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblRegistry);
            Text txtRegistry = new Text(advancedComposite, SWT.BORDER);
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(txtRegistry);
            Button registryDiscover = new Button(advancedComposite, SWT.PUSH);
            registryDiscover.setText("Discover...");
            registryDiscover.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    discoverRegistryPressed(registryDiscover.getShell());
                }
            });
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(registryDiscover);
            UIUtils.setDefaultButtonWidth(registryDiscover);
            registryURLObservable = WidgetProperties.text(SWT.Modify).observeDelayed(DELAY, txtRegistry);
            Binding registryURLBinding = ValueBindingBuilder.bind(registryURLObservable).validatingAfterConvert(new URLValidator(VALIDATOR_URL_TYPE, true)).converting(new TrimTrailingSlashConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_REGISTRY_URL).observe(model)).in(dbc);
            ControlDecorationSupport.create(registryURLBinding, SWT.LEFT | SWT.TOP);
            Label lblNamespace = new Label(advancedComposite, SWT.NONE);
            lblNamespace.setText("Cluster namespace:");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblNamespace);
            Text txtClusterNamespace = new Text(advancedComposite, SWT.BORDER);
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(txtClusterNamespace);
            clusterNamespaceObservable = WidgetProperties.text(SWT.Modify).observeDelayed(DELAY, txtClusterNamespace);
            ValueBindingBuilder.bind(clusterNamespaceObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_CLUSTER_NAMESPACE).observe(model)).in(dbc);
            Link ocWorkspace = new Link(advancedComposite, SWT.PUSH);
            ocWorkspace.setText("<a>Workspace OC Settings</a>");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).applyTo(ocWorkspace);
            // Override OC location widgets
            Button overrideOC = new Button(advancedComposite, SWT.CHECK);
            overrideOC.setText("Override 'oc' location: ");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblRegistry);
            IObservableValue<Boolean> overrideOCObservable = WidgetProperties.selection().observe(overrideOC);
            ValueBindingBuilder.bind(overrideOCObservable).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_OC_OVERRIDE).observe(model)).in(dbc);
            final Text ocText = new Text(advancedComposite, SWT.SINGLE | SWT.BORDER);
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(ocText);
            IObservableValue<String> ocLocationObservable = WidgetProperties.text(SWT.Modify).observe(ocText);
            Binding ocLocationBinding = ValueBindingBuilder.bind(ocLocationObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_OC_OVERRIDE_LOCATION).observe(model)).in(dbc);
            overrideOCObservable.addValueChangeListener(new IValueChangeListener<Boolean>() {

                @Override
                public void handleValueChange(ValueChangeEvent<? extends Boolean> event) {
                    updateOcObservables();
                }
            });
            ocLocationBinding.getValidationStatus().addValueChangeListener(new IValueChangeListener<IStatus>() {

                @Override
                public void handleValueChange(ValueChangeEvent<? extends IStatus> event) {
                    updateOcObservables();
                }
            });
            ValueBindingBuilder.bind(overrideOCObservable).to(WidgetProperties.enabled().observe(ocText)).notUpdatingParticipant().in(dbc);
            Button ocBrowse = new Button(advancedComposite, SWT.PUSH);
            ocBrowse.setText("Browse...");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(ocBrowse);
            UIUtils.setDefaultButtonWidth(ocBrowse);
            ocWorkspace.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    PreferenceDialog pd = PreferencesUtil.createPreferenceDialogOn(null, IOpenShiftCoreConstants.OPEN_SHIFT_PREFERENCE_PAGE_ID, new String[] {}, null);
                    pd.open();
                    if (!overrideOC.getSelection()) {
                        String ocLoc = OpenShiftCorePreferences.INSTANCE.getOCBinaryLocation();
                        String nullsafe = ocLoc == null ? "" : ocLoc;
                        ocText.setText(nullsafe);
                    }
                    updateOcObservables();
                }
            });
            // Validation here is done via a listener rather than dbc validators
            // because dbc validators will validate in the UI thread, but validation
            // of this field requires a background job.
            ocBrowse.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    FileDialog fd = new FileDialog(ocBrowse.getShell());
                    fd.setText(ocText.getText());
                    IPath p = new Path(ocText.getText());
                    if (p.segmentCount() > 1) {
                        fd.setFilterPath(p.removeLastSegments(1).toOSString());
                    }
                    String result = fd.open();
                    if (result != null) {
                        ocLocationObservable.setValue(result);
                    }
                }
            });
            ValueBindingBuilder.bind(overrideOCObservable).to(WidgetProperties.enabled().observe(ocBrowse)).notUpdatingParticipant().in(dbc);
            ValidationStatusProvider ocValidator = new MultiValidator() {

                public IObservableList getTargets() {
                    WritableList targets = new WritableList();
                    targets.add(ocLocationObservable);
                    targets.add(ocLocationValidity);
                    targets.add(ocVersionValidity);
                    return targets;
                }

                @Override
                protected IStatus validate() {
                    // access all observables that the framework should listen to
                    IStatus ocLocationStatus = ocLocationValidity.getValue();
                    IStatus ocVersionStatus = ocVersionValidity.getValue();
                    IStatus status;
                    if (!ocLocationStatus.isOK()) {
                        status = ocLocationStatus;
                    } else {
                        status = ocVersionStatus;
                    }
                    return status;
                }
            };
            dbc.addValidationStatusProvider(ocValidator);
            ControlDecorationSupport.create(ocValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
        }

        protected GridLayoutFactory adjustAdvancedCompositeLayout(GridLayoutFactory gridLayoutFactory) {
            return gridLayoutFactory.numColumns(3);
        }
    };
    part.createAdvancedGroup(composite, 1);
    this.connectionAdvancedPropertiesProvider = new ConnectionAdvancedPropertiesProvider();
    updateOcObservables();
    return composite;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Label(org.eclipse.swt.widgets.Label) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) Button(org.eclipse.swt.widgets.Button) URLValidator(org.jboss.tools.openshift.internal.ui.validator.URLValidator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DialogAdvancedPart(org.jboss.tools.openshift.internal.common.ui.utils.DialogAdvancedPart) TrimTrailingSlashConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimTrailingSlashConverter) Binding(org.eclipse.core.databinding.Binding) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) ValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) TrimmingStringConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter) WritableList(org.eclipse.core.databinding.observable.list.WritableList) IConnectionAdvancedPropertiesProvider(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel.IConnectionAdvancedPropertiesProvider) FileDialog(org.eclipse.swt.widgets.FileDialog) Link(org.eclipse.swt.widgets.Link)

Example 20 with RequiredControlDecorationUpdater

use of org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater in project jbosstools-openshift by jbosstools.

the class BuildConfigPage method createSourceControls.

@SuppressWarnings({ "unchecked" })
private void createSourceControls(Composite root, DataBindingContext dbc) {
    Composite parent = new Composite(root, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(parent);
    GridLayoutFactory.fillDefaults().numColumns(3).applyTo(parent);
    // url
    Label gitUrlLabel = new Label(parent, SWT.NONE);
    gitUrlLabel.setText("Git Repository URL:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(gitUrlLabel);
    final Text gitUrlText = new Text(parent, SWT.BORDER);
    gitUrlText.setToolTipText("The URL to the Git repository.");
    // TODO add 'try it' link here
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(gitUrlText);
    Binding gitUrlBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observeDelayed(500, gitUrlText)).validatingAfterConvert(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (UrlUtils.isValid((String) value)) {
                return Status.OK_STATUS;
            }
            return ValidationStatus.error("A valid URL to a Git repository is required");
        }
    }).to(BeanProperties.value(IBuildConfigPageModel.PROPERTY_GIT_REPOSITORY_URL).observe(model)).in(dbc);
    ControlDecorationSupport.create(gitUrlBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    // reference
    Label gitReferenceLabel = new Label(parent, SWT.NONE);
    gitReferenceLabel.setText("Git Reference:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(gitReferenceLabel);
    gitReferenceLabel.setToolTipText("Optional branch, tag, or commit.");
    final Text gitReferenceText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(gitReferenceText);
    IObservableValue gitReferenceTextObservable = WidgetProperties.text(SWT.Modify).observe(gitReferenceText);
    GitReferenceValidator validator = new GitReferenceValidator(gitReferenceTextObservable);
    Binding gitReferenceBinding = ValueBindingBuilder.bind(gitReferenceTextObservable).validatingAfterConvert(validator).to(BeanProperties.value(IBuildConfigPageModel.PROPERTY_GIT_REFERENCE).observe(model)).in(dbc);
    dbc.addValidationStatusProvider(validator);
    ControlDecorationSupport.create(gitReferenceBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    // context dir
    Label contextDirLabel = new Label(parent, SWT.NONE);
    contextDirLabel.setText("Context Directory:");
    contextDirLabel.setToolTipText("Optional subdirectory for the application source code, used as the context directory for the build.");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(contextDirLabel);
    final Text contextDirText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(contextDirText);
    ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(contextDirText)).to(BeanProperties.value(IBuildConfigPageModel.PROPERTY_CONTEXT_DIR).observe(model)).in(dbc);
}
Also used : Binding(org.eclipse.core.databinding.Binding) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) IValidator(org.eclipse.core.databinding.validation.IValidator) Label(org.eclipse.swt.widgets.Label) GitReferenceValidator(org.jboss.tools.openshift.internal.ui.validator.GitReferenceValidator) Text(org.eclipse.swt.widgets.Text) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Aggregations

RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)23 Label (org.eclipse.swt.widgets.Label)18 Button (org.eclipse.swt.widgets.Button)15 Binding (org.eclipse.core.databinding.Binding)14 Text (org.eclipse.swt.widgets.Text)13 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)9 IStatus (org.eclipse.core.runtime.IStatus)8 Composite (org.eclipse.swt.widgets.Composite)8 IValidator (org.eclipse.core.databinding.validation.IValidator)5 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)5 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)5 ComboViewer (org.eclipse.jface.viewers.ComboViewer)5 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)5 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)5 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)4 Group (org.eclipse.swt.widgets.Group)4 ValidationStatusProvider (org.eclipse.core.databinding.ValidationStatusProvider)3 TrimmingStringConverter (org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter)3 IProject (com.openshift.restclient.model.IProject)2 Converter (org.eclipse.core.databinding.conversion.Converter)2