use of org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter in project jbosstools-openshift by jbosstools.
the class OAuthDetailView method bindWidgetsToInternalModel.
private void bindWidgetsToInternalModel(DataBindingContext dbc) {
IValidator validator = new RequiredStringValidator("token");
this.tokenBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(tokenText)).converting(new TrimmingStringConverter()).validatingAfterConvert(validator).to(tokenObservable).validatingBeforeSet(validator).in(dbc);
ControlDecorationSupport.create(tokenBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
org.jboss.tools.common.ui.databinding.DataBindingUtils.addDisposableValueChangeListener(changeListener, tokenObservable, tokenText);
}
use of org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter in project jbosstools-openshift by jbosstools.
the class BasicAuthenticationDetailView method bindWidgetsToInternalModel.
private void bindWidgetsToInternalModel(DataBindingContext dbc) {
// username
this.usernameBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(usernameText)).converting(new TrimmingStringConverter()).validatingAfterConvert(new RequiredStringValidator("v3 username")).to(usernameObservable).in(dbc);
ControlDecorationSupport.create(usernameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
org.jboss.tools.common.ui.databinding.DataBindingUtils.addDisposableValueChangeListener(changeListener, usernameObservable, usernameText);
// password
this.passwordBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(passwordText)).converting(new TrimmingStringConverter()).validatingAfterConvert(new RequiredStringValidator("v3 password")).to(passwordObservable).in(dbc);
ControlDecorationSupport.create(passwordBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
org.jboss.tools.common.ui.databinding.DataBindingUtils.addDisposableValueChangeListener(changeListener, passwordObservable, passwordText);
connectionAuthProvider = new ConnectionAuthenticationProvider();
}
use of org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter in project jbosstools-openshift by jbosstools.
the class DeployImagePage method createImageNameControls.
private void createImageNameControls(final Composite parent, final DataBindingContext dbc) {
// Image
final Label imageNameLabel = new Label(parent, SWT.NONE);
imageNameLabel.setText("Image Name: ");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(imageNameLabel);
final Text imageNameText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(imageNameText);
final IObservableValue<String> imageNameTextObservable = WidgetProperties.text(SWT.Modify).observeDelayed(500, imageNameText);
final IObservableValue<String> imageNameObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_IMAGE_NAME).observe(model);
Binding imageBinding = ValueBindingBuilder.bind(imageNameTextObservable).converting(new TrimmingStringConverter()).validatingAfterConvert(new DockerImageValidator()).to(imageNameObservable).in(dbc);
ControlDecorationSupport.create(imageBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
imageNameProposalAdapter = new ContentProposalAdapter(imageNameText, // move the cursor to the end of the selected value
new TextContentAdapter() {
@Override
public void insertControlContents(Control control, String text, int cursorPosition) {
final Text imageNameText = (Text) control;
final Point selection = imageNameText.getSelection();
imageNameText.setText(text);
selection.x = text.length();
selection.y = selection.x;
imageNameText.setSelection(selection);
}
}, getImageNameContentProposalProvider(imageNameText), null, null);
// List local Docker images
Button btnDockerBrowse = new Button(parent, SWT.NONE);
btnDockerBrowse.setText("Browse...");
btnDockerBrowse.setToolTipText("Look-up an image by browsing the Docker daemon");
btnDockerBrowse.addSelectionListener(onBrowseImage());
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(btnDockerBrowse);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnDockerBrowse)).notUpdatingParticipant().to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
// search on Docker registry (Docker Hub)
Button btnDockerSearch = new Button(parent, SWT.NONE);
btnDockerSearch.setText("Search...");
btnDockerSearch.setToolTipText("Search an image on the Docker registry");
btnDockerSearch.addSelectionListener(onSearchImage(imageNameText));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(btnDockerSearch);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnDockerSearch)).notUpdatingParticipant().to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
}
use of org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter in project jbosstools-openshift by jbosstools.
the class ServicesAndRoutingPage method doCreateControls.
@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);
createExposedPortsControl(parent, dbc);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).applyTo(new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL));
// routing
Composite routingContainer = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(routingContainer);
GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(2).applyTo(routingContainer);
Button btnAddRoute = new Button(routingContainer, SWT.CHECK);
btnAddRoute.setText("Add Route");
btnAddRoute.setToolTipText("Adding a route to the service will make the image accessible\noutside of the OpenShift cluster on all the available service ports. \nYou can target a specific port by editing the route later.");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, false).span(2, 1).applyTo(btnAddRoute);
final IObservableValue<Boolean> addRouteModelObservable = BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ADD_ROUTE).observe(model);
ValueBindingBuilder.bind(WidgetProperties.selection().observe(btnAddRoute)).to(addRouteModelObservable).in(dbc);
Label labelRouteHostname = new Label(routingContainer, SWT.NONE);
labelRouteHostname.setText("Hostname:");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(labelRouteHostname);
Text textRouteHostname = new Text(routingContainer, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(textRouteHostname);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(textRouteHostname)).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ADD_ROUTE).observe(model)).in(dbc);
final IObservableValue<String> routeHostnameObservable = WidgetProperties.text(SWT.Modify).observe(textRouteHostname);
ValueBindingBuilder.bind(routeHostnameObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ROUTE_HOSTNAME).observe(model)).in(dbc);
MultiValidator validator = new MultiValidator() {
@Override
protected IStatus validate() {
IStatus status = ValidationStatus.ok();
boolean isAddRoute = addRouteModelObservable.getValue();
String hostName = routeHostnameObservable.getValue();
final IObservableList<IServicePort> portsObservable = BeanProperties.list(IServiceAndRoutingPageModel.PROPERTY_SERVICE_PORTS).observe(model);
final IServicePort routingPort = (IServicePort) BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ROUTING_PORT).observe(model).getValue();
if (isAddRoute) {
if (StringUtils.isBlank(hostName)) {
status = ValidationStatus.info(NLS.bind(OpenShiftUIMessages.EmptyHostNameErrorMessage, hostName));
} else if (!DomainValidator.getInstance(true).isValid(hostName)) {
status = ValidationStatus.error(NLS.bind(OpenShiftUIMessages.InvalidHostNameErrorMessage, hostName));
}
if (!status.matches(IStatus.ERROR) && isAddRoute && (portsObservable.size() > 1) && (routingPort == null)) {
if (status.matches(IStatus.INFO)) {
status = ValidationStatus.info(status.getMessage() + "\n " + OpenShiftUIMessages.RoundRobinRoutingMessage);
} else {
status = ValidationStatus.info(OpenShiftUIMessages.RoundRobinRoutingMessage);
}
}
}
return status;
}
};
dbc.addValidationStatusProvider(validator);
ControlDecorationSupport.create(validator, SWT.LEFT | SWT.TOP);
}
use of org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter in project jbosstools-openshift by jbosstools.
the class AdvancedConnectionEditor method createControls.
@SuppressWarnings("unchecked")
@Override
public Composite createControls(Composite parent, Object context, DataBindingContext dbc) {
this.pageModel = (ConnectionWizardPageModel) context;
this.selectedConnection = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION).observe(pageModel);
this.model = new AdvancedConnectionEditorModel();
Composite composite = setControl(new Composite(parent, SWT.None));
GridLayoutFactory.fillDefaults().applyTo(composite);
DialogAdvancedPart part = new DialogAdvancedPart() {
@Override
protected void createAdvancedContent(Composite advancedComposite) {
Label lblRegistry = new Label(advancedComposite, SWT.NONE);
lblRegistry.setText("Image Registry URL:");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblRegistry);
Text txtRegistry = new Text(advancedComposite, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(txtRegistry);
Button registryDiscover = new Button(advancedComposite, SWT.PUSH);
registryDiscover.setText("Discover...");
registryDiscover.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
discoverRegistryPressed(registryDiscover.getShell());
}
});
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(registryDiscover);
UIUtils.setDefaultButtonWidth(registryDiscover);
registryURLObservable = WidgetProperties.text(SWT.Modify).observeDelayed(DELAY, txtRegistry);
Binding registryURLBinding = ValueBindingBuilder.bind(registryURLObservable).validatingAfterConvert(new URLValidator(VALIDATOR_URL_TYPE, true)).converting(new TrimTrailingSlashConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_REGISTRY_URL).observe(model)).in(dbc);
ControlDecorationSupport.create(registryURLBinding, SWT.LEFT | SWT.TOP);
Label lblNamespace = new Label(advancedComposite, SWT.NONE);
lblNamespace.setText("Cluster namespace:");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblNamespace);
Text txtClusterNamespace = new Text(advancedComposite, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(txtClusterNamespace);
clusterNamespaceObservable = WidgetProperties.text(SWT.Modify).observeDelayed(DELAY, txtClusterNamespace);
ValueBindingBuilder.bind(clusterNamespaceObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_CLUSTER_NAMESPACE).observe(model)).in(dbc);
Link ocWorkspace = new Link(advancedComposite, SWT.PUSH);
ocWorkspace.setText("<a>Workspace OC Settings</a>");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).applyTo(ocWorkspace);
// Override OC location widgets
Button overrideOC = new Button(advancedComposite, SWT.CHECK);
overrideOC.setText("Override 'oc' location: ");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblRegistry);
IObservableValue<Boolean> overrideOCObservable = WidgetProperties.selection().observe(overrideOC);
ValueBindingBuilder.bind(overrideOCObservable).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_OC_OVERRIDE).observe(model)).in(dbc);
final Text ocText = new Text(advancedComposite, SWT.SINGLE | SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(ocText);
IObservableValue<String> ocLocationObservable = WidgetProperties.text(SWT.Modify).observe(ocText);
Binding ocLocationBinding = ValueBindingBuilder.bind(ocLocationObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_OC_OVERRIDE_LOCATION).observe(model)).in(dbc);
overrideOCObservable.addValueChangeListener(new IValueChangeListener<Boolean>() {
@Override
public void handleValueChange(ValueChangeEvent<? extends Boolean> event) {
updateOcObservables();
}
});
ocLocationBinding.getValidationStatus().addValueChangeListener(new IValueChangeListener<IStatus>() {
@Override
public void handleValueChange(ValueChangeEvent<? extends IStatus> event) {
updateOcObservables();
}
});
ValueBindingBuilder.bind(overrideOCObservable).to(WidgetProperties.enabled().observe(ocText)).notUpdatingParticipant().in(dbc);
Button ocBrowse = new Button(advancedComposite, SWT.PUSH);
ocBrowse.setText("Browse...");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(ocBrowse);
UIUtils.setDefaultButtonWidth(ocBrowse);
ocWorkspace.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
PreferenceDialog pd = PreferencesUtil.createPreferenceDialogOn(null, IOpenShiftCoreConstants.OPEN_SHIFT_PREFERENCE_PAGE_ID, new String[] {}, null);
pd.open();
if (!overrideOC.getSelection()) {
String ocLoc = OpenShiftCorePreferences.INSTANCE.getOCBinaryLocation();
String nullsafe = ocLoc == null ? "" : ocLoc;
ocText.setText(nullsafe);
}
updateOcObservables();
}
});
// Validation here is done via a listener rather than dbc validators
// because dbc validators will validate in the UI thread, but validation
// of this field requires a background job.
ocBrowse.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog fd = new FileDialog(ocBrowse.getShell());
fd.setText(ocText.getText());
IPath p = new Path(ocText.getText());
if (p.segmentCount() > 1) {
fd.setFilterPath(p.removeLastSegments(1).toOSString());
}
String result = fd.open();
if (result != null) {
ocLocationObservable.setValue(result);
}
}
});
ValueBindingBuilder.bind(overrideOCObservable).to(WidgetProperties.enabled().observe(ocBrowse)).notUpdatingParticipant().in(dbc);
ValidationStatusProvider ocValidator = new MultiValidator() {
public IObservableList getTargets() {
WritableList targets = new WritableList();
targets.add(ocLocationObservable);
targets.add(ocLocationValidity);
targets.add(ocVersionValidity);
return targets;
}
@Override
protected IStatus validate() {
// access all observables that the framework should listen to
IStatus ocLocationStatus = ocLocationValidity.getValue();
IStatus ocVersionStatus = ocVersionValidity.getValue();
IStatus status;
if (!ocLocationStatus.isOK()) {
status = ocLocationStatus;
} else {
status = ocVersionStatus;
}
return status;
}
};
dbc.addValidationStatusProvider(ocValidator);
ControlDecorationSupport.create(ocValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
}
protected GridLayoutFactory adjustAdvancedCompositeLayout(GridLayoutFactory gridLayoutFactory) {
return gridLayoutFactory.numColumns(3);
}
};
part.createAdvancedGroup(composite, 1);
this.connectionAdvancedPropertiesProvider = new ConnectionAdvancedPropertiesProvider();
updateOcObservables();
return composite;
}
Aggregations