Search in sources :

Example 6 with BrowserUtility

use of org.jboss.tools.foundation.ui.util.BrowserUtility 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

BrowserUtility (org.jboss.tools.foundation.ui.util.BrowserUtility)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 Link (org.eclipse.swt.widgets.Link)3 Converter (org.eclipse.core.databinding.conversion.Converter)2 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Job (org.eclipse.core.runtime.jobs.Job)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)2 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)2 RsyncStatus (org.jboss.tools.openshift.internal.core.util.RSyncValidator.RsyncStatus)2 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)2 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)2 IResource (com.openshift.restclient.model.IResource)1 ValidationStatus (org.eclipse.core.databinding.validation.ValidationStatus)1