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();
}
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);
}
Aggregations