use of org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater in project jbosstools-openshift by jbosstools.
the class DeployImagePage method createDockerConnectionControl.
private void createDockerConnectionControl(Composite parent, DataBindingContext dbc) {
createDockerConnectionLabel(parent);
StructuredViewer connectionViewer = new ComboViewer(parent);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(NUM_COLUMS - 2, 1).applyTo(connectionViewer.getControl());
connectionViewer.setContentProvider(new ObservableListContentProvider());
connectionViewer.setLabelProvider(new ObservableTreeItemLabelProvider() {
@Override
public String getText(Object element) {
return (element instanceof IDockerConnection) ? dockerConnectionToString((IDockerConnection) element) : "";
}
});
connectionViewer.setInput(BeanProperties.list(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTIONS).observe(model));
IObservableValue<IDockerConnection> dockerConnectionObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model);
DockerConnectionStatusProvider validator = new DockerConnectionStatusProvider(dockerConnectionObservable);
IObservableValue<?> selectedConnectionObservable = ViewerProperties.singleSelection().observe(connectionViewer);
Binding selectedConnectionBinding = ValueBindingBuilder.bind(selectedConnectionObservable).converting(new ObservableTreeItem2ModelConverter(IDockerConnection.class)).validatingAfterConvert(validator).to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).in(dbc);
ControlDecorationSupport.create(selectedConnectionBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
Button newDockerConnectionButton = new Button(parent, SWT.PUSH);
newDockerConnectionButton.setText("New...");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(newDockerConnectionButton);
UIUtils.setDefaultButtonWidth(newDockerConnectionButton);
newDockerConnectionButton.addSelectionListener(onNewDockerConnectionClicked());
dbc.addValidationStatusProvider(validator);
}
use of org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater in project jbosstools-openshift by jbosstools.
the class ServicePortDialog method doCreateControls.
@Override
protected void doCreateControls(final Composite parent, final DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().margins(1, 1).applyTo(parent);
final Composite dialogArea = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(dialogArea);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(dialogArea);
// service port
final Label servicePortLabel = new Label(dialogArea, SWT.NONE);
servicePortLabel.setText("Service port:");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(servicePortLabel);
final Spinner servicePortSpinner = new Spinner(dialogArea, SWT.BORDER);
servicePortSpinner.setMinimum(1);
servicePortSpinner.setMaximum(65535);
servicePortSpinner.setToolTipText("The port exposed by the service that will route to the pod.");
servicePortSpinner.addModifyListener(e -> {
Spinner source = (Spinner) e.getSource();
if (!String.valueOf(source.getSelection()).equals(source.getText())) {
source.setSelection(source.getSelection());
}
});
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(servicePortSpinner);
final Binding servicePortBinding = ValueBindingBuilder.bind(WidgetProperties.selection().observe(servicePortSpinner)).validatingAfterConvert(new ServicePortValidator(model.getPort(), this.ports)).to(BeanProperties.value(PROPERTY_SERVICE_PORT).observe(model)).in(dbc);
ControlDecorationSupport.create(servicePortBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
// Pod port
final Label podPortLabel = new Label(dialogArea, SWT.NONE);
podPortLabel.setText("Pod port:");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(podPortLabel);
final Text podPortText = new Text(dialogArea, SWT.BORDER);
podPortText.setToolTipText("The port exposed by the pod which will accept traffic.\nIt must be an integer or the name of a port in the backend Pods.");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(podPortText);
final Binding podPortBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(podPortText)).validatingAfterConvert(new PodPortValidator(this.model.getTargetPort(), this.ports)).to(BeanProperties.value(PROPERTY_POD_PORT).observe(model)).in(dbc);
ControlDecorationSupport.create(podPortBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
final Button routePortButton = new Button(dialogArea, SWT.CHECK);
routePortButton.setText("Used by route");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(routePortButton);
ValueBindingBuilder.bind(WidgetProperties.selection().observe(routePortButton)).to(BeanProperties.value(ServicePortAdapter.ROUTE_PORT).observe(model)).in(dbc);
}
use of org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater 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.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createRouteControls.
@SuppressWarnings("unchecked")
private void createRouteControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
Group routeGroup = new Group(container, SWT.NONE);
routeGroup.setText("Route");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(routeGroup);
GridLayoutFactory.fillDefaults().applyTo(routeGroup);
// additional nesting required because of
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=478618
Composite routeContainer = new Composite(routeGroup, SWT.None);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(routeContainer);
GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(2).applyTo(routeContainer);
Button promptRouteButton = new Button(routeContainer, SWT.CHECK);
promptRouteButton.setSelection(true);
promptRouteButton.setText("Prompt for route when multiple routes available to show in browser");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(promptRouteButton);
Label routeLabel = new Label(routeContainer, SWT.NONE);
routeLabel.setText("Use Route: ");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(routeLabel);
StructuredViewer routesViewer = new ComboViewer(routeContainer);
GridDataFactory.fillDefaults().span(1, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(routesViewer.getControl());
routesViewer.setContentProvider(new ObservableListContentProvider());
routesViewer.setLabelProvider(new RouteLabelProvider());
routesViewer.setInput(BeanProperties.list(ServerSettingsWizardPageModel.PROPERTY_ROUTES).observe(model));
// routesViewer.setComparer(new IElementComparer() {
//
// @Override
// public boolean equals(Object object1, Object object2) {
// if (object1 instanceof IRoute) {
// if (!(object2 instanceof IRoute)) {
// return false;
// }
//
// IRoute route1 = (IRoute) object1;
// IRoute route2 = (IRoute) object2;
//
// return Objects.equals(route1.getServiceName(), route2.getServiceName())
// && Objects.equals(route1.getURL(), route2.getURL());
// } else if (object2 instanceof IRoute) {
// return false;
// } else {
// return Objects.equals(object1, object2);
// }
// }
//
// @Override
// public int hashCode(Object element) {
// if (element instanceof IRoute) {
// IRoute route = (IRoute) element;
// return new HashCodeBuilder()
// .append(route.getServiceName())
// .append(route.getURL())
// .toHashCode();
// }
// return element.hashCode();
// }
// });
IObservableValue<IResource> selectedRouteObservable = ViewerProperties.singleSelection().observe(routesViewer);
ValueBindingBuilder.bind(selectedRouteObservable).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_ROUTE).observe(model)).in(dbc);
final IObservableValue<Boolean> isSelectDefaultRouteObservable = WidgetProperties.selection().observe(promptRouteButton);
final IObservableValue<Boolean> selectDefaultRouteModelObservable = BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_SELECT_DEFAULT_ROUTE).observe(model);
ValueBindingBuilder.bind(isSelectDefaultRouteObservable).converting(new InvertingBooleanConverter()).to(selectDefaultRouteModelObservable).converting(new InvertingBooleanConverter()).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(routesViewer.getControl())).notUpdating(selectDefaultRouteModelObservable).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(routeLabel)).notUpdating(selectDefaultRouteModelObservable).in(dbc);
RouteValidator routeValidator = new RouteValidator(isSelectDefaultRouteObservable, selectedRouteObservable);
dbc.addValidationStatusProvider(routeValidator);
ControlDecorationSupport.create(routeValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
}
use of org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createEnableDebuggingControls.
@SuppressWarnings("unchecked")
private void createEnableDebuggingControls(Composite parent, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
Label enableDevmodeLabel = new Label(parent, SWT.None);
enableDevmodeLabel.setText("Enable debugging:");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(enableDevmodeLabel);
Button useImageDevmodeKey = new Button(parent, SWT.CHECK);
useImageDevmodeKey.setText("use image provided key");
GridDataFactory.fillDefaults().span(4, 1).align(SWT.FILL, SWT.CENTER).applyTo(useImageDevmodeKey);
IObservableValue<Boolean> useImageDevmodeKeyObservable = BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_USE_IMAGE_DEVMODE_KEY).observe(model);
ValueBindingBuilder.bind(WidgetProperties.selection().observe(useImageDevmodeKey)).to(useImageDevmodeKeyObservable).in(dbc);
// filler
new Label(parent, SWT.NONE);
Label keyLabel = new Label(parent, SWT.NONE);
keyLabel.setText("Key:");
GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).applyTo(keyLabel);
Text devmodeKeyText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(devmodeKeyText);
IObservableValue<String> devmodeKeyObservable = WidgetProperties.text(SWT.Modify).observe(devmodeKeyText);
ValueBindingBuilder.bind(devmodeKeyObservable).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_DEVMODE_KEY).observe(model)).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(devmodeKeyText)).notUpdating(useImageDevmodeKeyObservable).converting(new InvertingBooleanConverter()).in(dbc);
ValidationStatusProvider devmodeKeyValidator = new DisableableMultiValitdator<String>(useImageDevmodeKeyObservable, devmodeKeyObservable, new OpenShiftIdentifierValidator());
dbc.addValidationStatusProvider(devmodeKeyValidator);
ControlDecorationSupport.create(devmodeKeyValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
}
Aggregations