Search in sources :

Example 1 with Status2IconConverter

use of org.jboss.tools.openshift.internal.common.ui.databinding.Status2IconConverter in project jbosstools-openshift by jbosstools.

the class OpenShiftPreferencePage method validateLocation.

private void validateLocation(final String location) {
    setValid(false);
    ocVersionLabel.setText("Checking OpenShift client version...");
    Job validationJob = new UIUpdatingJob("Checking oc binary...") {

        private OCBinaryValidator validator = new OCBinaryValidator(location);

        private Version version = Version.emptyVersion;

        private IStatus status = Status.OK_STATUS;

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            this.version = validator.getVersion(monitor);
            this.status = validator.getStatus(version);
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            } else {
                return Status.OK_STATUS;
            }
        }

        @Override
        protected IStatus updateUI(IProgressMonitor monitor) {
            if (!ocMessageComposite.isDisposed() && !monitor.isCanceled()) {
                ocVersionLabel.setText(getOcVersionMessage());
                ocMessageLabel.setText(removePreferencesLink(status.getMessage()));
                Image messageIcon = (Image) new Status2IconConverter().convert(status);
                ocMessageIcon.setImage(messageIcon);
                ocMessageComposite.setVisible(!status.isOK());
                ocMessageComposite.layout(true);
                setValid(true);
            }
            // always have page valid so that user can always leave the page
            return Status.OK_STATUS;
        }

        /**
         * Removes a link to the preferences that exists in the message. Does nothing
         * otherwise. We already are in the preferences, so there's no use to have a
         * link (that opens up the preferences in other places) to configure.
         *
         * @param message
         * @return the message without the link-markup. Returns the unaltered message
         *         otherwise.
         */
        private String removePreferencesLink(String message) {
            if (StringUtils.isEmpty(message)) {
                return message;
            }
            return message.replaceAll(OpenShiftCoreMessages.OCBinaryPreferencesLink, OpenShiftCoreMessages.OCBinaryPreferencesDeactivatedLink);
        }

        private String getOcVersionMessage() {
            if (version == null || Version.emptyVersion.equals(version)) {
                return "Could not determine your OpenShift client version.";
            } else {
                return NLS.bind("Your OpenShift client version is {0}.{1}.{2}", new Object[] { version.getMajor(), version.getMinor(), version.getMicro() });
            }
        }
    };
    validationJob.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Version(org.osgi.framework.Version) UIUpdatingJob(org.jboss.tools.openshift.internal.common.ui.job.UIUpdatingJob) Job(org.eclipse.core.runtime.jobs.Job) UIUpdatingJob(org.jboss.tools.openshift.internal.common.ui.job.UIUpdatingJob) Image(org.eclipse.swt.graphics.Image) Status2IconConverter(org.jboss.tools.openshift.internal.common.ui.databinding.Status2IconConverter)

Example 2 with Status2IconConverter

use of org.jboss.tools.openshift.internal.common.ui.databinding.Status2IconConverter in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createOCWarningControls.

@SuppressWarnings("unchecked")
private void createOCWarningControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Composite warningComposite = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().applyTo(warningComposite);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(warningComposite);
    IObservableValue<IStatus> ocBinaryStatus = BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model);
    ValueBindingBuilder.bind(WidgetProperties.visible().observe(warningComposite)).to(ocBinaryStatus).converting(new Converter(IStatus.class, Boolean.class) {

        @Override
        public Object convert(Object fromObject) {
            return !((IStatus) fromObject).isOK();
        }
    }).in(dbc);
    Label icon = new Label(warningComposite, SWT.NONE);
    ValueBindingBuilder.bind(WidgetProperties.image().observe(icon)).to(ocBinaryStatus).converting(new Status2IconConverter()).in(dbc);
    Link link = new Link(warningComposite, SWT.WRAP);
    ValueBindingBuilder.bind(WidgetProperties.text().observe(link)).to(ocBinaryStatus).in(dbc);
    link.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (OpenShiftCoreMessages.OCBinaryDownloadDeactivatedLink.equals(e.text)) {
                new BrowserUtility().checkedCreateExternalBrowser(DOWNLOAD_URL, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
            } else {
                int rc = PreferencesUtil.createPreferenceDialogOn(getShell(), OPEN_SHIFT_PREFERENCE_PAGE_ID, new String[] { OPEN_SHIFT_PREFERENCE_PAGE_ID }, null).open();
                if (rc == Dialog.OK) {
                    new Job("Checking oc binary...") {

                        @Override
                        protected IStatus run(IProgressMonitor monitor) {
                            model.validateOCBinary(monitor);
                            return Status.OK_STATUS;
                        }
                    }.schedule();
                }
            }
        }
    });
    GridDataFactory.fillDefaults().hint(LINK_DEFAULT_WIDTH, SWT.DEFAULT).applyTo(link);
    MultiValidator validator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            IStatus status = ocBinaryStatus.getValue();
            switch(status.getSeverity()) {
                case IStatus.ERROR:
                    return OpenShiftUIActivator.statusFactory().errorStatus(OpenShiftUIMessages.OCBinaryErrorMessage);
                case IStatus.WARNING:
                    return OpenShiftUIActivator.statusFactory().warningStatus(OpenShiftUIMessages.OCBinaryWarningMessage);
                default:
                    return status;
            }
        }
    };
    dbc.addValidationStatusProvider(validator);
    ocBinaryStatus.addValueChangeListener(event -> layoutWarningComposite(event.diff.getNewValue(), warningComposite));
    layoutWarningComposite(ocBinaryStatus.getValue(), warningComposite);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) 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) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Status2IconConverter(org.jboss.tools.openshift.internal.common.ui.databinding.Status2IconConverter) 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) Status2IconConverter(org.jboss.tools.openshift.internal.common.ui.databinding.Status2IconConverter) Link(org.eclipse.swt.widgets.Link)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Job (org.eclipse.core.runtime.jobs.Job)2 Status2IconConverter (org.jboss.tools.openshift.internal.common.ui.databinding.Status2IconConverter)2 Converter (org.eclipse.core.databinding.conversion.Converter)1 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Image (org.eclipse.swt.graphics.Image)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 UIUpdatingJob (org.jboss.tools.openshift.internal.common.ui.job.UIUpdatingJob)1 OCBinaryValidator (org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator)1 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)1 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)1