Search in sources :

Example 1 with RSyncValidator

use of org.jboss.tools.openshift.internal.core.util.RSyncValidator 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)1 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Link (org.eclipse.swt.widgets.Link)1 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)1 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)1 BrowserUtility (org.jboss.tools.foundation.ui.util.BrowserUtility)1 RSyncValidator (org.jboss.tools.openshift.internal.core.util.RSyncValidator)1 RsyncStatus (org.jboss.tools.openshift.internal.core.util.RSyncValidator.RsyncStatus)1 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)1 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)1