Example usage for org.eclipse.jface.databinding.fieldassist ControlDecorationSupport create

List of usage examples for org.eclipse.jface.databinding.fieldassist ControlDecorationSupport create

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.fieldassist ControlDecorationSupport create.

Prototype

public static ControlDecorationSupport create(ValidationStatusProvider validationStatusProvider, int position,
        Composite composite) 

Source Link

Document

Creates a ControlDecorationSupport which observes the validation status of the specified ValidationStatusProvider , and displays a ControlDecoration over the underlying SWT control of all target observables that implement ISWTObservable or IViewerObservable .

Usage

From source file:org.eclipse.core.databinding.validation.jsr303.samples.Jsr303PersonSnippet.java

License:Open Source License

public static void main(String[] args) {
    // Display state of JSR-303 Bean Support
    System.out.println("JSR-303 Bean Support available?: " + Jsr303BeanValidationSupport.isAvailable());
    System.out.println("OSGi context?: " + Jsr303BeanValidationSupport.isOSGi());
    System.out.println("JSR-303 Bean Support ValidatorFactory Implementation: "
            + Jsr303BeanValidationSupport.getValidatorFactoryClassName());
    System.out.println("JSR-303 Bean Support strategy resolver?: " + Jsr303BeanValidationSupport.getStrategy());

    // Create UI+Binding
    final Display display = new Display();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            final Shell shell = new Shell(display);

            shell.setLayout(new FillLayout());

            Composite parent = new Composite(shell, SWT.NONE);
            parent.setLayout(new GridLayout(2, false));
            parent.setLayoutData(new GridData(GridData.FILL_BOTH));
            Person model = new Person();

            // UI Name
            Label nameLabel = new Label(parent, SWT.NONE);
            nameLabel.setText("Name:");
            Text nameText = new Text(parent, SWT.BORDER);
            nameText.setLayoutData(new GridData(GridData.FILL_BOTH));

            // UI Email
            Label emailLabel = new Label(parent, SWT.NONE);
            emailLabel.setText("Email:");
            Text emailText = new Text(parent, SWT.BORDER);
            emailText.setLayoutData(new GridData(GridData.FILL_BOTH));

            DataBindingContext dataBindingContext = new DataBindingContext(SWTObservables.getRealm(display));

            // Binding Name
            IObservableValue nameTextObserveTextObserveWidget = SWTObservables.observeText(nameText,
                    SWT.Modify);/*  w w w  .j av  a2s .  co  m*/
            IObservableValue modelNameObserveValue = PojoObservables.observeValue(model, "name");

            Binding binding = dataBindingContext.bindValue(nameTextObserveTextObserveWidget,
                    modelNameObserveValue, Jsr303BeansUpdateValueStrategyFactory.create(modelNameObserveValue),
                    null);
            ControlDecorationSupport.create(binding, SWT.LEFT, parent);

            // Binding Email
            IObservableValue emailTextObserveTextObserveWidget = SWTObservables.observeText(emailText,
                    SWT.Modify);
            IObservableValue modelEmailObserveValue = PojoObservables.observeValue(model, "email");

            binding = dataBindingContext.bindValue(emailTextObserveTextObserveWidget, modelEmailObserveValue,
                    Jsr303BeansUpdateValueStrategyFactory.create(modelEmailObserveValue), null);
            ControlDecorationSupport.create(binding, SWT.LEFT, parent);

            shell.setSize(200, 100);
            shell.open();

            // The SWT event loop
            Display display = Display.getCurrent();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            }
        }
    });
}

From source file:org.eclipse.core.databinding.validation.jsr303.samples.rcp.editor.OverviewPage.java

License:Open Source License

private void createBindings() {

    Person person = getEditor().getPerson();
    DataBindingContext dataBindingContext = new DataBindingContext();

    // Binding name
    IObservableValue textObserveTextObserveWidget = SWTObservables.observeText(personNameText, SWT.Modify);
    IObservableValue modelNameObserveValue = PojoObservables.observeValue(person, "name");
    Binding binding = dataBindingContext.bindValue(textObserveTextObserveWidget, modelNameObserveValue,
            Jsr303BeansUpdateValueStrategyFactory.create(modelNameObserveValue), null);
    ControlDecorationSupport.create(binding, SWT.LEFT, parent);

    // Binding email
    IObservableValue emailTextObserveTextObserveWidget = SWTObservables.observeText(personEmailText,
            SWT.Modify);/*from  w w w.  j  a v  a 2s  .  c  o  m*/
    IObservableValue modelEmailObserveValue = PojoObservables.observeValue(person, "email");
    binding = dataBindingContext.bindValue(emailTextObserveTextObserveWidget, modelEmailObserveValue,
            Jsr303BeansUpdateValueStrategyFactory.create(modelEmailObserveValue), null);
    ControlDecorationSupport.create(binding, SWT.LEFT, parent);
}

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

License:Open Source License

private void bindControls() {

    // Bind source file path widget to UI model
    final IObservableValue widgetValue = WidgetProperties.text(SWT.Modify).observe(hl7FileText);
    IObservableValue modelValue;/*from  w w w.j a  v a  2  s . c  om*/
    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$
    }
    final UpdateValueStrategy strategy = new UpdateValueStrategy();

    PathValidator pathValidator = new PathValidator();
    FileEmptyValidator fileEmptyValidator = new FileEmptyValidator();
    JSONValidator jsonValidator = new JSONValidator();
    CompoundValidator compoundJSONTextValidator = new CompoundValidator(pathValidator, fileEmptyValidator,
            jsonValidator);
    strategy.setBeforeSetValidator(compoundJSONTextValidator);

    _binding = context.bindValue(widgetValue, modelValue, strategy, null);
    ControlDecorationSupport.create(_binding, decoratorPosition, hl7FileText.getParent());

    widgetValue.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            if (!Hl7Page.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) {
                try {
                    IResource resource = CamelUtils.project().findMember(path);
                    if (resource == null || !resource.exists() || !(resource instanceof IFile)) {
                        return;
                    }
                    if (fileIsEmpty(path)) {
                        return;
                    }
                    String jsonText = getJsonText((IFile) resource);
                    if (!Util.jsonValid(jsonText)) {
                        return;
                    }
                    IPath filePath = resource.getLocation();
                    String fullpath = filePath.makeAbsolute().toPortableString();
                    updateSettingsBasedOnFilePath(fullpath);
                    if (isSourcePage()) {
                        model.setSourceFilePath(path);
                    } else {
                        model.setTargetFilePath(path);
                    }
                    updatePreview(resource.getProjectRelativePath().toString());
                    hl7FileText.notifyListeners(SWT.Modify, new Event());
                } catch (final Exception e) {
                    Activator.error(e);
                }
            }
        }
    });

    listenForValidationChanges();
}

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

License:Open Source License

private void bindControls() {

    // Bind source file path widget to UI model
    IObservableValue widgetValue = WidgetProperties.text(SWT.Modify).observe(_javaClassText);
    IObservableValue modelValue;/*from  www  . jav a  2s  .  c om*/
    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;
            if (isSourcePage()) {
                pathEmptyError = Messages.JavaPage_pathEmptyError_source;
                unableToFindError = Messages.JavaPage_unableToFindError_source;
            } else {
                pathEmptyError = Messages.JavaPage_pathEmptyError_target;
                unableToFindError = Messages.JavaPage_unableToFindError_target;
            }
            if (path == null || path.isEmpty()) {
                return ValidationStatus.error(pathEmptyError);
            }
            NewTransformationWizard wizard = (NewTransformationWizard) getWizard();
            try {
                Class<?> tempClass = wizard.loader().loadClass(path);
                if (tempClass == null) {
                    return ValidationStatus.error(unableToFindError);
                }
            } catch (ClassNotFoundException e) {
                return ValidationStatus.error(unableToFindError);
            }
            return ValidationStatus.ok();
        }
    });
    _binding = context.bindValue(widgetValue, modelValue, strategy, null);
    ControlDecorationSupport.create(_binding, decoratorPosition, _javaClassText.getParent());

    listenForValidationChanges();
}

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

License:Open Source License

private void bindControls() {

    // Bind source file path widget to UI model
    final IObservableValue widgetValue = WidgetProperties.text(SWT.Modify).observe(_jsonFileText);
    IObservableValue modelValue;/*w w w.j  av a2s . com*/
    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$
    }
    final UpdateValueStrategy strategy = new UpdateValueStrategy();

    PathValidator pathValidator = new PathValidator();
    FileEmptyValidator fileEmptyValidator = new FileEmptyValidator();
    JSONValidator jsonValidator = new JSONValidator();
    CompoundValidator compoundJSONTextValidator = new CompoundValidator(pathValidator, fileEmptyValidator,
            jsonValidator);
    strategy.setBeforeSetValidator(compoundJSONTextValidator);

    _binding = context.bindValue(widgetValue, modelValue, strategy, null);
    ControlDecorationSupport.create(_binding, decoratorPosition, _jsonFileText.getParent());

    widgetValue.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            if (!JSONPage.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) {
                try {
                    IResource resource = CamelUtils.project().findMember(path);
                    if (resource == null || !resource.exists() || !(resource instanceof IFile)) {
                        return;
                    }
                    if (fileIsEmpty(path)) {
                        return;
                    }
                    String jsonText = getJsonText((IFile) resource);
                    if (!Util.jsonValid(jsonText)) {
                        return;
                    }
                    IPath filePath = resource.getLocation();
                    String fullpath = filePath.makeAbsolute().toPortableString();
                    updateSettingsBasedOnFilePath(fullpath);
                    if (isSourcePage()) {
                        model.setSourceFilePath(path);
                    } else {
                        model.setTargetFilePath(path);
                    }
                    updatePreview(resource.getProjectRelativePath().toString());
                    _jsonFileText.notifyListeners(SWT.Modify, new Event());
                } catch (final Exception e) {
                    Activator.error(e);
                }
            }
        }
    });

    listenForValidationChanges();
}

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

License:Open Source License

private void bindControls() {

    // Bind source file path widget to UI model
    IObservableValue widgetValue = WidgetProperties.text(SWT.Modify).observe(_javaClassText);
    IObservableValue modelValue;//from  w w  w.ja  va  2 s . co 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;
            if (isSourcePage()) {
                pathEmptyError = Messages.OtherPage_errorMessagePathEmptySource;
                unableToFindError = Messages.OtherPage_errorMessageNotFoundSource;
            } else {
                pathEmptyError = Messages.OtherPage_errorMessagePathEmptyTarget;
                unableToFindError = Messages.OtherPage_errorMessageNotFoundTarget;
            }
            if (path == null || path.isEmpty()) {
                return ValidationStatus.error(pathEmptyError);
            }
            NewTransformationWizard wizard = (NewTransformationWizard) getWizard();
            try {
                Class<?> tempClass = wizard.loader().loadClass(path);
                if (tempClass == null) {
                    return ValidationStatus.error(unableToFindError);
                }
            } catch (ClassNotFoundException e) {
                return ValidationStatus.error(unableToFindError);
            }
            return ValidationStatus.ok();
        }
    });
    _binding = context.bindValue(widgetValue, modelValue, strategy, null);
    ControlDecorationSupport.create(_binding, decoratorPosition, _javaClassText.getParent());

    listenForValidationChanges();
}

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 a  v  a 2s  . c  om*/

    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// ww  w  . ja  v a  2s  . 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;/*from   w  w w. j  av  a  2  s  .  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();
}