Search in sources :

Example 6 with RequiredControlDecorationUpdater

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);
}
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 7 with RequiredControlDecorationUpdater

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);
}
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)

Example 8 with RequiredControlDecorationUpdater

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());
}
Also used : RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IStatus(org.eclipse.core.runtime.IStatus) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue)

Example 9 with RequiredControlDecorationUpdater

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));
}
Also used : Group(org.eclipse.swt.widgets.Group) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) Label(org.eclipse.swt.widgets.Label) RouteLabelProvider(org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog.RouteLabelProvider) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IResource(com.openshift.restclient.model.IResource)

Example 10 with RequiredControlDecorationUpdater

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

Aggregations

RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)23 Label (org.eclipse.swt.widgets.Label)18 Button (org.eclipse.swt.widgets.Button)15 Binding (org.eclipse.core.databinding.Binding)14 Text (org.eclipse.swt.widgets.Text)13 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)9 IStatus (org.eclipse.core.runtime.IStatus)8 Composite (org.eclipse.swt.widgets.Composite)8 IValidator (org.eclipse.core.databinding.validation.IValidator)5 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)5 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)5 ComboViewer (org.eclipse.jface.viewers.ComboViewer)5 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)5 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)5 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)4 Group (org.eclipse.swt.widgets.Group)4 ValidationStatusProvider (org.eclipse.core.databinding.ValidationStatusProvider)3 TrimmingStringConverter (org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter)3 IProject (com.openshift.restclient.model.IProject)2 Converter (org.eclipse.core.databinding.conversion.Converter)2