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