Search in sources :

Example 1 with ValidationResult

use of org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator.ValidationResult in project n4js by eclipse.

the class N4JSNewClassifierWizardPage method setupBindings.

/**
 * Setup additional non-component contained bindings
 */
protected void setupBindings() {
    DataBindingContext dataBindingContext = this.getDataBindingContext();
    @SuppressWarnings("unchecked") IObservableValue<String> moduleSpecifierValue = BeanProperties.value(WorkspaceWizardModel.class, WorkspaceWizardModel.MODULE_SPECIFIER_PROPERTY).observe(getModel());
    @SuppressWarnings("unchecked") IObservableValue<Boolean> suffixVisibilityValue = BeanProperties.value(SuffixText.class, SuffixText.SUFFIX_VISIBILITY_PROPERTY).observe(workspaceWizardControl.getModuleSpecifierText());
    // // Only show the suffix on input values ending with a '/' character or empty module specifiers.
    dataBindingContext.bindValue(suffixVisibilityValue, moduleSpecifierValue, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(m -> {
        String moduleSpecifier = (String) m;
        return (moduleSpecifier.isEmpty() || moduleSpecifier.charAt(moduleSpecifier.length() - 1) == IPath.SEPARATOR);
    }));
    // // interface name to module specifier suffix binding
    @SuppressWarnings("unchecked") IObservableValue<String> interfaceNameModelValue = BeanProperties.value(N4JSInterfaceWizardModel.class, N4JSClassifierWizardModel.NAME_PROPERTY).observe(getModel());
    @SuppressWarnings("unchecked") IObservableValue<String> greySuffixValue = BeanProperties.value(SuffixText.class, SuffixText.SUFFIX_PROPERTY).observe(workspaceWizardControl.getModuleSpecifierText());
    dataBindingContext.bindValue(greySuffixValue, interfaceNameModelValue, noUpdateValueStrategy(), new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
    // // Enable n4js <-> Definition value(external) is selected
    @SuppressWarnings("unchecked") IObservableValue<Boolean> externalValue = BeanProperties.value(DefinitionFileModel.class, N4JSClassifierWizardModel.DEFINITION_FILE_PROPERTY).observe(getModel());
    @SuppressWarnings("unchecked") IObservableValue<Boolean> n4jsEnabled = WidgetProperties.enabled().observe(otherClassifierModifiersComponent.getN4jsAnnotationBox());
    dataBindingContext.bindValue(n4jsEnabled, externalValue, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(input -> getModel().isDefinitionFile() && AccessModifier.PRIVATE != getModel().getAccessModifier()));
    // One way binding of the access modifiers to the enabled state of internal checkbox
    @SuppressWarnings("unchecked") IObservableValue<Boolean> internalEnabledValue = WidgetProperties.enabled().observe(accessModifierComponent.getInternalAnnotationBox());
    @SuppressWarnings("unchecked") IObservableValue<AccessModifier> accessModifierSelectObservable = BeanProperties.value(N4JSInterfaceWizardModel.class, N4JSClassifierWizardModel.ACCESS_MODIFIER_PROPERTY).observe(getModel());
    dataBindingContext.bindValue(internalEnabledValue, accessModifierSelectObservable, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(object -> {
        if (object instanceof AccessModifier) {
            return isInternalAccessModifierEnabled((AccessModifier) object);
        }
        return false;
    }));
    // N4JS annotation checkbox disabled when access modifier is private
    @SuppressWarnings("unchecked") IObservableValue<Boolean> n4jsEnabledValue = WidgetProperties.enabled().observe(otherClassifierModifiersComponent.getN4jsAnnotationBox());
    dataBindingContext.bindValue(n4jsEnabledValue, accessModifierSelectObservable, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(object -> {
        if (object instanceof AccessModifier) {
            return ((AccessModifier) object != AccessModifier.PRIVATE) && getModel().isDefinitionFile();
        }
        return false;
    }));
    // Refresh wizard state on validation change
    @SuppressWarnings("unchecked") IObservableValue<ValidationResult> observableValidationValue = BeanProperties.value(WorkspaceWizardModelValidator.VALIDATION_RESULT).observe(getValidator());
    observableValidationValue.addValueChangeListener(new IValueChangeListener<ValidationResult>() {

        @Override
        public void handleValueChange(ValueChangeEvent<? extends ValidationResult> event) {
            onValidationChange(event.diff.getNewValue());
        }
    });
}
Also used : N4JSInterfaceWizardModel(org.eclipse.n4js.ui.wizard.interfaces.N4JSInterfaceWizardModel) OtherClassifierModifiersComponent(org.eclipse.n4js.ui.wizard.components.OtherClassifierModifiersComponent) WizardPreview(org.eclipse.n4js.ui.wizard.workspace.WizardPreviewProvider.WizardPreview) IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) AccessModifierComponent(org.eclipse.n4js.ui.wizard.components.AccessModifierComponent) WorkspaceWizardGenerator(org.eclipse.n4js.ui.wizard.generator.WorkspaceWizardGenerator) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) WizardComponentDataConverters(org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) AccessModifier(org.eclipse.n4js.ui.wizard.model.AccessModifier) DefinitionFileModel(org.eclipse.n4js.ui.wizard.model.DefinitionFileModel) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) SuffixText(org.eclipse.n4js.ui.wizard.workspace.SuffixText) ModuleSpecifierSelectionDialog(org.eclipse.n4js.ui.dialog.ModuleSpecifierSelectionDialog) N4JSGlobals(org.eclipse.n4js.N4JSGlobals) IPath(org.eclipse.core.runtime.IPath) Composite(org.eclipse.swt.widgets.Composite) WorkspaceWizardModelValidator(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator) NameComponent(org.eclipse.n4js.ui.wizard.components.NameComponent) ValidationResult(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator.ValidationResult) Shell(org.eclipse.swt.widgets.Shell) Display(org.eclipse.swt.widgets.Display) WorkspaceWizardModel(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModel) ContentBlock(org.eclipse.n4js.ui.wizard.generator.ContentBlock) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) Path(org.eclipse.core.runtime.Path) PreviewableWizardPage(org.eclipse.n4js.ui.wizard.workspace.PreviewableWizardPage) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) N4JSInterfaceWizardModel(org.eclipse.n4js.ui.wizard.interfaces.N4JSInterfaceWizardModel) WorkspaceWizardModel(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModel) SuffixText(org.eclipse.n4js.ui.wizard.workspace.SuffixText) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) ValidationResult(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator.ValidationResult) AccessModifier(org.eclipse.n4js.ui.wizard.model.AccessModifier) DefinitionFileModel(org.eclipse.n4js.ui.wizard.model.DefinitionFileModel)

Example 2 with ValidationResult

use of org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator.ValidationResult in project n4js by eclipse.

the class PreviewableWizardPage method createPreview.

/**
 * Creates the right pane content, which is the preview area.
 */
private void createPreview(Composite parent) {
    wizardContentPreview = previewProvider.create(parent, SWT.NONE);
    wizardContentPreview.setLayoutData(PREVIEW_GRID_DATA_FACTORY.create());
    // Connect a delayed property change listener to the model
    getModel().addPropertyChangeListener(propertyChange -> {
        ValidationResult result = getValidator().getValidationResult();
        // Don't update if the preview is hidden
        if (!previewVisible) {
            return;
        }
        if (result.valid) {
            wizardContentPreview.setEnabled(true);
            updateContentPreview(wizardContentPreview);
        } else {
            wizardContentPreview.setEnabled(false);
            wizardContentPreview.setInfo("");
        }
    });
}
Also used : ValidationResult(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator.ValidationResult)

Aggregations

ValidationResult (org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator.ValidationResult)2 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)1 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)1 BeanProperties (org.eclipse.core.databinding.beans.BeanProperties)1 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)1 IValueChangeListener (org.eclipse.core.databinding.observable.value.IValueChangeListener)1 ValueChangeEvent (org.eclipse.core.databinding.observable.value.ValueChangeEvent)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 WidgetProperties (org.eclipse.jface.databinding.swt.WidgetProperties)1 N4JSGlobals (org.eclipse.n4js.N4JSGlobals)1 ModuleSpecifierSelectionDialog (org.eclipse.n4js.ui.dialog.ModuleSpecifierSelectionDialog)1 AccessModifierComponent (org.eclipse.n4js.ui.wizard.components.AccessModifierComponent)1 NameComponent (org.eclipse.n4js.ui.wizard.components.NameComponent)1 OtherClassifierModifiersComponent (org.eclipse.n4js.ui.wizard.components.OtherClassifierModifiersComponent)1 WizardComponentDataConverters (org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters)1 ContentBlock (org.eclipse.n4js.ui.wizard.generator.ContentBlock)1 WorkspaceWizardGenerator (org.eclipse.n4js.ui.wizard.generator.WorkspaceWizardGenerator)1 N4JSInterfaceWizardModel (org.eclipse.n4js.ui.wizard.interfaces.N4JSInterfaceWizardModel)1 AccessModifier (org.eclipse.n4js.ui.wizard.model.AccessModifier)1