use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class ServicesAndRoutingPage method createExposedPortsControl.
private void createExposedPortsControl(Composite parent, DataBindingContext dbc) {
Composite container = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(container);
GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(container);
Label label = new Label(container, SWT.NONE);
label.setText("Service Ports:");
label.setToolTipText("The exposed ports of the image.");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(label);
Composite tableContainer = new Composite(container, SWT.NONE);
IObservableList<IServicePort> portsObservable = BeanProperties.list(IServiceAndRoutingPageModel.PROPERTY_SERVICE_PORTS).observe(model);
portsViewer = createTable(tableContainer);
ObservableListContentProvider contentProvider = new ObservableListContentProvider();
portsViewer.setContentProvider(contentProvider);
ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(Properties.observeEach(contentProvider.getKnownElements(), BeanProperties.values(ServicePortAdapter.NAME, ServicePortAdapter.PORT, ServicePortAdapter.TARGET_PORT, /* ROUTE_PORT_COLUMN_INDEX = 3 */
ServicePortAdapter.ROUTE_PORT))) {
@Override
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == ROUTE_PORT_COLUMN_INDEX) {
Object selected = attributeMaps[columnIndex].get(element);
return selected != null && (boolean) selected ? OpenShiftImages.CHECKED_IMG : OpenShiftImages.UNCHECKED_IMG;
}
return null;
}
@Override
public String getColumnText(Object element, int columnIndex) {
if (columnIndex != ROUTE_PORT_COLUMN_INDEX) {
Object result = attributeMaps[columnIndex].get(element);
// $NON-NLS-1$
return result == null ? "" : result.toString();
}
return null;
}
};
portsViewer.setLabelProvider(labelProvider);
GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(portsViewer)).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_SELECTED_SERVICE_PORT).observe(model)).in(dbc);
portsViewer.setInput(portsObservable);
dbc.addValidationStatusProvider(new MultiValidator() {
@Override
protected IStatus validate() {
if (portsObservable.isEmpty()) {
return ValidationStatus.error("At least 1 port is required when generating the service for the deployed image");
}
return Status.OK_STATUS;
}
});
portsViewer.getTable().addMouseListener(onTableCellClicked());
Button btnEdit = new Button(container, SWT.PUSH);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(btnEdit);
btnEdit.setText("Edit...");
btnEdit.setToolTipText("Edit a port to be exposed by the service.");
btnEdit.addSelectionListener(new EditHandler());
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnEdit)).notUpdatingParticipant().to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_SELECTED_SERVICE_PORT).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
UIUtils.setDefaultButtonWidth(btnEdit);
Button btnReset = new Button(container, SWT.PUSH);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(btnReset);
btnReset.setText("Reset");
btnReset.setToolTipText("Resets the list of ports to the exposed ports of the image.");
btnReset.addSelectionListener(onReset());
UIUtils.setDefaultButtonWidth(btnReset);
}
use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class ResourcePayloadPage method createLocalSourceControls.
private void createLocalSourceControls(DataBindingContext dbc, Group sourceGroup) {
Label label = new Label(sourceGroup, SWT.NONE);
GridDataFactory.fillDefaults().span(3, 1).applyTo(label);
label.setText("Enter a file path (workspace or local) or a full URL.");
// local template file name
Text sourceText = new Text(sourceGroup, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(3, 1).applyTo(sourceText);
final IObservableValue source = WidgetProperties.text(SWT.Modify).observe(sourceText);
final WritableValue<IStatus> sourceStatus = new WritableValue<IStatus>(Status.OK_STATUS, IStatus.class);
final ResourceContentValidator contentValidator = new ResourceContentValidator(sourceStatus);
ValueBindingBuilder.bind(source).validatingBeforeSet(contentValidator).to(BeanProperties.value(IResourcePayloadPageModel.PROPERTY_SOURCE).observe(model)).validatingBeforeSet(contentValidator).in(dbc);
MultiValidator validator = new MultiValidator() {
@Override
protected IStatus validate() {
String sourceValue = (String) source.getValue();
if (StringUtils.isEmpty(sourceValue)) {
return ValidationStatus.cancel("You need to provide a file path or an URL");
}
return !OpenshiftUIConstants.URL_VALIDATOR.isValid(sourceValue) && !isFile(sourceValue) ? ValidationStatus.error(sourceValue + " is not a file") : ValidationStatus.ok();
}
};
dbc.addValidationStatusProvider(validator);
dbc.addValidationStatusProvider(new MultiValidator() {
@Override
protected IStatus validate() {
source.getValue();
return sourceStatus.getValue();
}
});
ControlDecorationSupport.create(validator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
// browse button
Button btnBrowseFiles = new Button(sourceGroup, SWT.NONE);
btnBrowseFiles.setText("Browse File System...");
GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).span(2, 1).grab(true, false).applyTo(btnBrowseFiles);
btnBrowseFiles.addSelectionListener(onFileSystemBrowseClicked());
// browse button
Button btnBrowseWorkspaceFiles = new Button(sourceGroup, SWT.NONE);
btnBrowseWorkspaceFiles.setText("Browse Workspace...");
GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(btnBrowseWorkspaceFiles);
btnBrowseWorkspaceFiles.addSelectionListener(onBrowseWorkspaceClicked());
}
use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class ApplicationSourceListPage method doCreateControls.
@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
super.doCreateControls(parent, dbc);
IObservableValue selectedEclipseProject = createEclipseProjectControls(parent, dbc);
SashForm listAndDetailsContainer = new SashForm(parent, SWT.VERTICAL);
GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(listAndDetailsContainer);
GridLayoutFactory.fillDefaults().applyTo(listAndDetailsContainer);
TabFolder tabContainer = new TabFolder(listAndDetailsContainer, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(tabContainer);
tabContainer.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
// JBIDE-21072: force re-layout of the parent upon tab switching
parent.layout(true, true);
}
});
IObservableValue useLocalTemplateObservable = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_USE_LOCAL_APP_SOURCE).observe(model);
ValueBindingBuilder.bind(new TabFolderSelectionProperty().observe(tabContainer)).converting(new Converter(Integer.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
return Integer.valueOf(LOCAL_TEMPLATE_TAB_INDEX).equals(fromObject);
}
}).to(useLocalTemplateObservable).converting(new Converter(Boolean.class, Integer.class) {
@Override
public Object convert(Object fromObject) {
return (fromObject != null && (Boolean) fromObject) ? LOCAL_TEMPLATE_TAB_INDEX : 0;
}
}).in(dbc);
model.setUseLocalAppSource(false);
TabFolderTraverseListener tabFolderTraverseListener = new TabFolderTraverseListener(tabContainer);
IObservableValue serverTemplate = createServerTemplateControls(tabContainer, tabFolderTraverseListener, useLocalTemplateObservable, dbc);
IObservableValue localTemplateFilename = createLocalTemplateControls(tabContainer, tabFolderTraverseListener, useLocalTemplateObservable, dbc);
dbc.addValidationStatusProvider(new MultiValidator() {
@Override
protected IStatus validate() {
return (IStatus) BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_APP_SOURCE_STATUS, IStatus.class).observe(model).getValue();
}
});
createDetailsGroup(listAndDetailsContainer, dbc);
// template list initially takes twice the height of the details pane
listAndDetailsContainer.setWeights(new int[] { 2, 1 });
// validate required template
IObservableValue selectedTemplate = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_SELECTED_APP_SOURCE).observe(model);
TemplateListPageValidator pageValidator = new TemplateListPageValidator(useLocalTemplateObservable, localTemplateFilename, serverTemplate, selectedTemplate, selectedEclipseProject, parent);
dbc.addValidationStatusProvider(pageValidator);
ControlDecorationSupport.create(pageValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
ProjectNameValidator projectNameValidator = new ProjectNameValidator(selectedEclipseProject, parent);
dbc.addValidationStatusProvider(projectNameValidator);
ControlDecorationSupport.create(projectNameValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
}
use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class ConnectionValidatorsTest method testBasicAuthenticationValidatorInUI.
@Test
public void testBasicAuthenticationValidatorInUI() {
Connection connection1 = mockConnection(HOST1, USER1, null);
mockConnection(HOST2, USER2, null);
ConnectionWizardPageModel pageModel = mockConnectionWizardPageModel(connection1);
Mockito.when(pageModel.getHost()).thenReturn(HOST2);
IValueChangeListener<Object> l = new IValueChangeListener<Object>() {
@Override
public void handleValueChange(ValueChangeEvent<? extends Object> event) {
}
};
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Composite composite = new Composite(shell, SWT.NONE);
try {
BasicAuthenticationDetailView view = new BasicAuthenticationDetailView(pageModel, l, null);
DataBindingContext dbc = new DataBindingContext();
view.createControls(shell, null, dbc);
view.onVisible(null, dbc);
view.getPasswordTextControl().setText("pass");
view.getUsernameTextControl().setText(USER2);
MultiValidator v = findValidator(dbc);
Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
view.getUsernameTextControl().setText(USER3);
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
} finally {
composite.dispose();
}
}
use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class ConnectionValidatorsTest method testBasicAuthenticationValidator.
@Test
public void testBasicAuthenticationValidator() {
Connection connection1 = mockConnection(HOST1, USER1, null);
mockConnection(HOST2, USER2, null);
ConnectionWizardPageModel pageModel = mockConnectionWizardPageModel(connection1);
WritableValue<String> usernameObservable = new WritableValue<String>();
WritableValue<String> urlObservable = new WritableValue<String>();
MultiValidator v = ConnectionValidatorFactory.createBasicAuthenticationValidator(pageModel, usernameObservable, urlObservable);
v.observeValidatedValue(urlObservable);
// New connection
urlObservable.setValue(HOST3);
usernameObservable.setValue(USER3);
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
urlObservable.setValue(HOST2);
// Host exists, but token is different
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
usernameObservable.setValue(USER2);
// Existing not selected connection
Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
// Selected connection
urlObservable.setValue(HOST1);
usernameObservable.setValue(USER1);
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
}
Aggregations