Search in sources :

Example 1 with StringToPathConverter

use of org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters.StringToPathConverter in project n4js by eclipse.

the class WorkspaceWizardPage method setupBindings.

private void setupBindings(WorkspaceWizardPageForm wizardForm) {
    databindingContext = new DataBindingContext();
    WorkspaceWizardModelValidator<M> validator = getValidator();
    // Project property binding
    @SuppressWarnings("unchecked") IObservableValue<IPath> projectModelValue = BeanProperties.value(WorkspaceWizardModel.class, WorkspaceWizardModel.PROJECT_PROPERTY).observe(model);
    @SuppressWarnings("unchecked") IObservableValue<String> projectUI = WidgetProperties.text(SWT.Modify).observe(wizardForm.getProjectText());
    // Note: No model to UI conversation here as IPath is castable to String (default behavior)
    databindingContext.bindValue(projectUI, projectModelValue, new StringToPathConverter().updatingValueStrategy(), new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
    // Source folder property binding
    @SuppressWarnings("unchecked") IObservableValue<IPath> sourceFolderModelValue = BeanProperties.value(WorkspaceWizardModel.class, WorkspaceWizardModel.SOURCE_FOLDER_PROPERTY).observe(model);
    @SuppressWarnings("unchecked") IObservableValue<String> sourceFolderUI = WidgetProperties.text(SWT.Modify).observe(wizardForm.getSourceFolderText());
    // Note: No model to UI conversation (see above)
    databindingContext.bindValue(sourceFolderUI, sourceFolderModelValue, new StringToPathConverter().updatingValueStrategy(), new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
    @SuppressWarnings("unchecked") IObservableValue<Boolean> projectValidModelValue = BeanProperties.value(WorkspaceWizardModelValidator.class, WorkspaceWizardModelValidator.PROJECT_PROPERTY_VALID).observe(validator);
    @SuppressWarnings("unchecked") IObservableValue<Boolean> sourceFolderBrowseEnabled = WidgetProperties.enabled().observe(wizardForm.getSourceFolderBrowseButton());
    databindingContext.bindValue(sourceFolderBrowseEnabled, projectValidModelValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
    // Module specifier property binding
    @SuppressWarnings("unchecked") IObservableValue<String> moduleSpecifierModelValue = BeanProperties.value(WorkspaceWizardModel.class, WorkspaceWizardModel.MODULE_SPECIFIER_PROPERTY).observe(model);
    @SuppressWarnings("unchecked") IObservableValue<String> moduleSpecifierUI = BeanProperties.value(SuffixText.class, SuffixText.TEXT_PROPERTY).observe(wizardForm.getModuleSpecifierText());
    databindingContext.bindValue(moduleSpecifierUI, moduleSpecifierModelValue);
    // Conditional activation of the browse buttons according to the precedent input fields validity
    @SuppressWarnings("unchecked") IObservableValue<Boolean> moduleSpecifierBrowseEnabled = WidgetProperties.enabled().observe(wizardForm.getModuleSpecifierBrowseButton());
    @SuppressWarnings("unchecked") IObservableValue<Boolean> sourceFolderValidValue = BeanProperties.value(WorkspaceWizardModelValidator.class, WorkspaceWizardModelValidator.SOURCE_FOLDER_PROPERTY_VALID).observe(validator);
    @SuppressWarnings("unchecked") IObservableValue<Boolean> projectValidValue = BeanProperties.value(WorkspaceWizardModelValidator.class, WorkspaceWizardModelValidator.PROJECT_PROPERTY_VALID).observe(validator);
    ConditionalConverter moduleSpecifierBrowseableConverter = new ConditionalConverter() {

        @Override
        public boolean validate(Object object) {
            return validator.getSourceFolderValid() && validator.getProjectValid();
        }
    };
    // Bind model changes of project or source folder property to the enabled state of the module specifier browse
    // button.
    databindingContext.bindValue(moduleSpecifierBrowseEnabled, projectValidValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), moduleSpecifierBrowseableConverter.updatingValueStrategy());
    databindingContext.bindValue(moduleSpecifierBrowseEnabled, sourceFolderValidValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), moduleSpecifierBrowseableConverter.updatingValueStrategy());
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) IPath(org.eclipse.core.runtime.IPath) StringToPathConverter(org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters.StringToPathConverter) ConditionalConverter(org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters.ConditionalConverter) DataBindingContext(org.eclipse.core.databinding.DataBindingContext)

Aggregations

DataBindingContext (org.eclipse.core.databinding.DataBindingContext)1 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)1 IPath (org.eclipse.core.runtime.IPath)1 ConditionalConverter (org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters.ConditionalConverter)1 StringToPathConverter (org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters.StringToPathConverter)1