Search in sources :

Example 6 with Converter

use of org.eclipse.core.databinding.conversion.Converter in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createRSyncControls.

private void createRSyncControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    final RSyncValidator rsyncValidator = RSyncValidator.get();
    Composite composite = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().applyTo(composite);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
    ValueBindingBuilder.bind(WidgetProperties.visible().observe(composite)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model)).converting(new Converter(RsyncStatus.class, Boolean.class) {

        @Override
        public Object convert(Object fromObject) {
            return fromObject != RsyncStatus.OK;
        }
    }).in(dbc);
    Label label = new Label(composite, SWT.NONE);
    ValueBindingBuilder.bind(WidgetProperties.image().observe(label)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model)).converting(new Converter(RsyncStatus.class, Image.class) {

        @Override
        public Object convert(Object fromObject) {
            switch((RsyncStatus) fromObject) {
                case OK:
                    return null;
                default:
                    return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
            }
        }
    }).in(dbc);
    Link link = new Link(composite, SWT.WRAP);
    ValueBindingBuilder.bind(WidgetProperties.text().observe(link)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model)).converting(new Converter(RsyncStatus.class, String.class) {

        @Override
        public Object convert(Object fromObject) {
            switch((RsyncStatus) fromObject) {
                case OK:
                    return null;
                default:
                    return ((RsyncStatus) fromObject).getDetailedMessage(rsyncValidator.getBasePath());
            }
        }
    }).in(dbc);
    GridDataFactory.fillDefaults().hint(LINK_DEFAULT_WIDTH, SWT.DEFAULT).applyTo(link);
    link.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (REFRESH_LINK_TEXT.equals(e.text)) {
                new Job("Checking rsync environment") {

                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                        rsyncValidator.refresh();
                        model.setRsyncStatus(rsyncValidator.getStatus());
                        return Status.OK_STATUS;
                    }
                }.schedule();
            } else {
                new BrowserUtility().checkedCreateExternalBrowser(e.text, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
            }
        }
    });
    MultiValidator validator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            RsyncStatus status = (RsyncStatus) BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model).getValue();
            switch(status) {
                case OK:
                    return ValidationStatus.ok();
                default:
                    return OpenShiftUIActivator.statusFactory().warningStatus(status.getMessage());
            }
        }
    };
    dbc.addValidationStatusProvider(validator);
    BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model).addValueChangeListener(event -> getShell().pack());
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) RsyncStatus(org.jboss.tools.openshift.internal.core.util.RSyncValidator.RsyncStatus) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) RSyncValidator(org.jboss.tools.openshift.internal.core.util.RSyncValidator) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Converter(org.eclipse.core.databinding.conversion.Converter) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) Job(org.eclipse.core.runtime.jobs.Job) Link(org.eclipse.swt.widgets.Link)

Aggregations

Converter (org.eclipse.core.databinding.conversion.Converter)6 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)4 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)4 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)3 IStatus (org.eclipse.core.runtime.IStatus)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Button (org.eclipse.swt.widgets.Button)3 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)3 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 Group (org.eclipse.swt.widgets.Group)2 Link (org.eclipse.swt.widgets.Link)2 Text (org.eclipse.swt.widgets.Text)2 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)2 BrowserUtility (org.jboss.tools.foundation.ui.util.BrowserUtility)2