use of org.eclipse.core.databinding.Binding in project jbosstools-openshift by jbosstools.
the class ResourceNameControl method doCreateControl.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void doCreateControl(Composite parent, DataBindingContext dbc, Object model) {
// Resource Name
final Label resourceNameLabel = new Label(parent, SWT.NONE);
resourceNameLabel.setText(label);
resourceNameLabel.setToolTipText("The name used to identify the resources that will support the deployed image.");
layoutLabel(resourceNameLabel);
final Text resourceNameText = new Text(parent, SWT.BORDER);
layoutText(resourceNameText);
final IObservableValue resourceNameTextObservable = WidgetProperties.text(SWT.Modify).observe(resourceNameText);
ResourceNameValidator validator = new ResourceNameValidator(resourceNameTextObservable);
final Binding nameBinding = ValueBindingBuilder.bind(resourceNameTextObservable).validatingAfterConvert(validator).to(BeanProperties.value(PROPERTY_RESOURCE_NAME).observe(model)).in(dbc);
dbc.addValidationStatusProvider(validator);
ControlDecorationSupport.create(nameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
}
use of org.eclipse.core.databinding.Binding 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.eclipse.core.databinding.Binding in project jbosstools-openshift by jbosstools.
the class DataBindingUtils method validateTargetsToModels.
/**
* Triggers (model to target) validation of all bindings within the given databinding context.
*
* @param dbc the databinding context
*
* @see DataBindingContext
* @see Binding#validateTargetToModel()
*/
public static void validateTargetsToModels(DataBindingContext dbc) {
for (Iterator<?> iterator = dbc.getBindings().iterator(); iterator.hasNext(); ) {
Binding binding = (Binding) iterator.next();
binding.validateTargetToModel();
}
}
use of org.eclipse.core.databinding.Binding 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.eclipse.core.databinding.Binding 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);
}
Aggregations