Search in sources :

Example 6 with MultiValidator

use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.

the class ServicesAndRoutingPage method createExposedPortsControl.

private void createExposedPortsControl(Composite parent, DataBindingContext dbc) {
    Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(container);
    Label label = new Label(container, SWT.NONE);
    label.setText("Service Ports:");
    label.setToolTipText("The exposed ports of the image.");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(label);
    Composite tableContainer = new Composite(container, SWT.NONE);
    IObservableList<IServicePort> portsObservable = BeanProperties.list(IServiceAndRoutingPageModel.PROPERTY_SERVICE_PORTS).observe(model);
    portsViewer = createTable(tableContainer);
    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    portsViewer.setContentProvider(contentProvider);
    ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(Properties.observeEach(contentProvider.getKnownElements(), BeanProperties.values(ServicePortAdapter.NAME, ServicePortAdapter.PORT, ServicePortAdapter.TARGET_PORT, /* ROUTE_PORT_COLUMN_INDEX = 3 */
    ServicePortAdapter.ROUTE_PORT))) {

        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == ROUTE_PORT_COLUMN_INDEX) {
                Object selected = attributeMaps[columnIndex].get(element);
                return selected != null && (boolean) selected ? OpenShiftImages.CHECKED_IMG : OpenShiftImages.UNCHECKED_IMG;
            }
            return null;
        }

        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (columnIndex != ROUTE_PORT_COLUMN_INDEX) {
                Object result = attributeMaps[columnIndex].get(element);
                // $NON-NLS-1$
                return result == null ? "" : result.toString();
            }
            return null;
        }
    };
    portsViewer.setLabelProvider(labelProvider);
    GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
    ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(portsViewer)).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_SELECTED_SERVICE_PORT).observe(model)).in(dbc);
    portsViewer.setInput(portsObservable);
    dbc.addValidationStatusProvider(new MultiValidator() {

        @Override
        protected IStatus validate() {
            if (portsObservable.isEmpty()) {
                return ValidationStatus.error("At least 1 port is required when generating the service for the deployed image");
            }
            return Status.OK_STATUS;
        }
    });
    portsViewer.getTable().addMouseListener(onTableCellClicked());
    Button btnEdit = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(btnEdit);
    btnEdit.setText("Edit...");
    btnEdit.setToolTipText("Edit a port to be exposed by the service.");
    btnEdit.addSelectionListener(new EditHandler());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnEdit)).notUpdatingParticipant().to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_SELECTED_SERVICE_PORT).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
    UIUtils.setDefaultButtonWidth(btnEdit);
    Button btnReset = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(btnReset);
    btnReset.setText("Reset");
    btnReset.setToolTipText("Resets the list of ports to the exposed ports of the image.");
    btnReset.addSelectionListener(onReset());
    UIUtils.setDefaultButtonWidth(btnReset);
}
Also used : ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) ObservableMapLabelProvider(org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) IServicePort(com.openshift.restclient.model.IServicePort) Button(org.eclipse.swt.widgets.Button) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)

Example 7 with MultiValidator

use of org.eclipse.core.databinding.validation.MultiValidator 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 8 with MultiValidator

use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.

the class ApplicationSourceListPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    super.doCreateControls(parent, dbc);
    IObservableValue selectedEclipseProject = createEclipseProjectControls(parent, dbc);
    SashForm listAndDetailsContainer = new SashForm(parent, SWT.VERTICAL);
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(listAndDetailsContainer);
    GridLayoutFactory.fillDefaults().applyTo(listAndDetailsContainer);
    TabFolder tabContainer = new TabFolder(listAndDetailsContainer, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(tabContainer);
    tabContainer.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            // JBIDE-21072: force re-layout of the parent upon tab switching
            parent.layout(true, true);
        }
    });
    IObservableValue useLocalTemplateObservable = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_USE_LOCAL_APP_SOURCE).observe(model);
    ValueBindingBuilder.bind(new TabFolderSelectionProperty().observe(tabContainer)).converting(new Converter(Integer.class, Boolean.class) {

        @Override
        public Object convert(Object fromObject) {
            return Integer.valueOf(LOCAL_TEMPLATE_TAB_INDEX).equals(fromObject);
        }
    }).to(useLocalTemplateObservable).converting(new Converter(Boolean.class, Integer.class) {

        @Override
        public Object convert(Object fromObject) {
            return (fromObject != null && (Boolean) fromObject) ? LOCAL_TEMPLATE_TAB_INDEX : 0;
        }
    }).in(dbc);
    model.setUseLocalAppSource(false);
    TabFolderTraverseListener tabFolderTraverseListener = new TabFolderTraverseListener(tabContainer);
    IObservableValue serverTemplate = createServerTemplateControls(tabContainer, tabFolderTraverseListener, useLocalTemplateObservable, dbc);
    IObservableValue localTemplateFilename = createLocalTemplateControls(tabContainer, tabFolderTraverseListener, useLocalTemplateObservable, dbc);
    dbc.addValidationStatusProvider(new MultiValidator() {

        @Override
        protected IStatus validate() {
            return (IStatus) BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_APP_SOURCE_STATUS, IStatus.class).observe(model).getValue();
        }
    });
    createDetailsGroup(listAndDetailsContainer, dbc);
    // template list initially takes twice the height of the details pane
    listAndDetailsContainer.setWeights(new int[] { 2, 1 });
    // validate required template
    IObservableValue selectedTemplate = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_SELECTED_APP_SOURCE).observe(model);
    TemplateListPageValidator pageValidator = new TemplateListPageValidator(useLocalTemplateObservable, localTemplateFilename, serverTemplate, selectedTemplate, selectedEclipseProject, parent);
    dbc.addValidationStatusProvider(pageValidator);
    ControlDecorationSupport.create(pageValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    ProjectNameValidator projectNameValidator = new ProjectNameValidator(selectedEclipseProject, parent);
    dbc.addValidationStatusProvider(projectNameValidator);
    ControlDecorationSupport.create(projectNameValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) SelectionListener(org.eclipse.swt.events.SelectionListener) IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) KeyListener(org.eclipse.swt.events.KeyListener) TabFolder(org.eclipse.swt.widgets.TabFolder) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) SashForm(org.eclipse.swt.custom.SashForm) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) KeyEvent(org.eclipse.swt.events.KeyEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) PageChangingEvent(org.eclipse.jface.dialogs.PageChangingEvent) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Converter(org.eclipse.core.databinding.conversion.Converter) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) TabFolderSelectionProperty(org.jboss.tools.openshift.internal.common.ui.databinding.TabFolderSelectionProperty)

Example 9 with MultiValidator

use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.

the class ConnectionValidatorsTest method testBasicAuthenticationValidatorInUI.

@Test
public void testBasicAuthenticationValidatorInUI() {
    Connection connection1 = mockConnection(HOST1, USER1, null);
    mockConnection(HOST2, USER2, null);
    ConnectionWizardPageModel pageModel = mockConnectionWizardPageModel(connection1);
    Mockito.when(pageModel.getHost()).thenReturn(HOST2);
    IValueChangeListener<Object> l = new IValueChangeListener<Object>() {

        @Override
        public void handleValueChange(ValueChangeEvent<? extends Object> event) {
        }
    };
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    Composite composite = new Composite(shell, SWT.NONE);
    try {
        BasicAuthenticationDetailView view = new BasicAuthenticationDetailView(pageModel, l, null);
        DataBindingContext dbc = new DataBindingContext();
        view.createControls(shell, null, dbc);
        view.onVisible(null, dbc);
        view.getPasswordTextControl().setText("pass");
        view.getUsernameTextControl().setText(USER2);
        MultiValidator v = findValidator(dbc);
        Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
        view.getUsernameTextControl().setText(USER3);
        Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
    } finally {
        composite.dispose();
    }
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) BasicAuthenticationDetailView(org.jboss.tools.openshift.internal.ui.wizard.connection.BasicAuthenticationDetailView) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel) Connection(org.jboss.tools.openshift.core.connection.Connection) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) Test(org.junit.Test)

Example 10 with MultiValidator

use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.

the class ConnectionValidatorsTest method testBasicAuthenticationValidator.

@Test
public void testBasicAuthenticationValidator() {
    Connection connection1 = mockConnection(HOST1, USER1, null);
    mockConnection(HOST2, USER2, null);
    ConnectionWizardPageModel pageModel = mockConnectionWizardPageModel(connection1);
    WritableValue<String> usernameObservable = new WritableValue<String>();
    WritableValue<String> urlObservable = new WritableValue<String>();
    MultiValidator v = ConnectionValidatorFactory.createBasicAuthenticationValidator(pageModel, usernameObservable, urlObservable);
    v.observeValidatedValue(urlObservable);
    // New connection
    urlObservable.setValue(HOST3);
    usernameObservable.setValue(USER3);
    Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
    urlObservable.setValue(HOST2);
    // Host exists, but token is different
    Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
    usernameObservable.setValue(USER2);
    // Existing not selected connection
    Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
    // Selected connection
    urlObservable.setValue(HOST1);
    usernameObservable.setValue(USER1);
    Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
}
Also used : ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel) Connection(org.jboss.tools.openshift.core.connection.Connection) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) Test(org.junit.Test)

Aggregations

MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)27 IStatus (org.eclipse.core.runtime.IStatus)12 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)11 Composite (org.eclipse.swt.widgets.Composite)11 Label (org.eclipse.swt.widgets.Label)11 Button (org.eclipse.swt.widgets.Button)6 Connection (org.jboss.tools.openshift.core.connection.Connection)6 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)5 Text (org.eclipse.swt.widgets.Text)5 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)5 WritableValue (org.eclipse.core.databinding.observable.value.WritableValue)4 ConnectionWizardPageModel (org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel)4 Test (org.junit.Test)4 DatePicker (name.abuchen.portfolio.ui.util.DatePicker)3 SimpleDateTimeDateSelectionProperty (name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty)3 Binding (org.eclipse.core.databinding.Binding)3 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)3 Converter (org.eclipse.core.databinding.conversion.Converter)3 IValueChangeListener (org.eclipse.core.databinding.observable.value.IValueChangeListener)3 ValueChangeEvent (org.eclipse.core.databinding.observable.value.ValueChangeEvent)3