Search in sources :

Example 1 with Binding

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));
}
Also used : Binding(org.eclipse.core.databinding.Binding) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) ResourceNameValidator(org.jboss.tools.openshift.internal.ui.validator.ResourceNameValidator)

Example 2 with Binding

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);
}
Also used : Binding(org.eclipse.core.databinding.Binding) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) TrimmingStringConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter) ResourceNameControl(org.jboss.tools.openshift.internal.ui.wizard.common.ResourceNameControl) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter) DockerImageValidator(org.jboss.tools.openshift.internal.ui.validator.DockerImageValidator)

Example 3 with Binding

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();
    }
}
Also used : Binding(org.eclipse.core.databinding.Binding)

Example 4 with Binding

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);
}
Also used : Binding(org.eclipse.core.databinding.Binding) ObservableTreeItemLabelProvider(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemLabelProvider) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer)

Example 5 with Binding

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);
}
Also used : Binding(org.eclipse.core.databinding.Binding) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) Spinner(org.eclipse.swt.widgets.Spinner) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text)

Aggregations

Binding (org.eclipse.core.databinding.Binding)21 Label (org.eclipse.swt.widgets.Label)14 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)14 Button (org.eclipse.swt.widgets.Button)11 Text (org.eclipse.swt.widgets.Text)10 Composite (org.eclipse.swt.widgets.Composite)8 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)7 IStatus (org.eclipse.core.runtime.IStatus)6 IValidator (org.eclipse.core.databinding.validation.IValidator)4 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)4 ComboViewer (org.eclipse.jface.viewers.ComboViewer)4 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)4 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)3 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)3 Group (org.eclipse.swt.widgets.Group)3 IProject (com.openshift.restclient.model.IProject)2 ValidationStatusProvider (org.eclipse.core.databinding.ValidationStatusProvider)2 TextContentAdapter (org.eclipse.jface.fieldassist.TextContentAdapter)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2