@Test @UI public void testErrorGoesAwayWhenFixed() { final WritableValue status1 = new WritableValue(ValidationStatus.error("error"), IStatus.class); final MultiValidator validator1 = new MultiValidator() { @Override protected IStatus validate() { return (IStatus) status1.getValue(); } }; mDataBindingContext.addValidationStatusProvider(validator1); final WritableValue status2 = new WritableValue(new RequiredStatus("required"), IStatus.class); final MultiValidator validator2 = new MultiValidator() { @Override protected IStatus validate() { return (IStatus) status2.getValue(); } }; mDataBindingContext.addValidationStatusProvider(validator2); mWizardDialog.open(); assertThat(mWizardPage.getErrorMessage(), is("error")); assertThat(mWizardPage.isPageComplete(), is(false)); status1.setValue(ValidationStatus.ok()); assertThat(mWizardPage.getErrorMessage(), nullValue()); assertThat(mWizardPage.isPageComplete(), is(false)); }
public IStatus validate(Object value) { String string = (String) value; if (string == null || string.trim().length() == 0) { return ValidationStatus.error("Please enter a value for " + fieldname + "."); } return ValidationStatus.ok(); }
/** {@inheritDoc} */ @Override public IStatus validate(final Object value) { final String s = ((String) value).trim(); // Project names are // always stripped of // whitespace (see the // Java Project Wizard) if ((s == null) || (s.length() == 0)) { return ValidationStatus.error("Enter a SAD file."); } final File sadFile = new File(s); if (!sadFile.exists()) { return ValidationStatus.error("SAD file does not exist."); } final URI fileURI = URI.createFileURI(sadFile.getAbsolutePath()); try { final SoftwareAssembly sad = ModelUtil.loadSoftwareAssembly(fileURI); if (sad == null) { return ValidationStatus.error("Invalid SAD file selected."); } } catch (final Exception e) { // SUPPRESS CHECKSTYLE Logged Error return ValidationStatus.error("Unable to parse SAD file."); } return ValidationStatus.ok(); }
@Override public IStatus validate(Object value) { if (InetAddressValidator.getInstance().isValid(value.toString()) || DomainValidator.getInstance(true).isValid(value.toString())) { return ValidationStatus.ok(); } return ValidationStatus.error("Invalid host name or IP address"); // $NON-NLS-1$ }
@Override public IStatus validate(Object value) { if (value == null) return ValidationStatus.error("select a protocol"); if (value instanceof CompoundProtocolClass) if (!relay) return ValidationStatus.error("compound protocol only possible for relay port"); return Status.OK_STATUS; }
private IStatus doValidate(Object value) { if (value != null) { if (!mapContainsValues(toType, value.getClass())) { return ValidationStatus.error(getClassHint()); } return Status.OK_STATUS; } return ValidationStatus.error(getNullHint()); }
public IStatus validate(Object value) { String string = (String) value; if (string == null || string.trim().length() == 0) { return ValidationStatus.error("Please enter a value for Hostname."); } if (!string.matches("^[-\\w.]+$")) { return ValidationStatus.error("Hostname must be of the form xxx.xxx."); } return ValidationStatus.ok(); }
public IStatus validate(Object value) { Integer i = (Integer) value; if (i == null) { return ValidationStatus.info("Please enter a value."); } if (i.intValue() < 0 || i.intValue() > 9) { return ValidationStatus.error("Value must be between 0 and 9."); } return ValidationStatus.ok(); }
@Override public IStatus validate(Object value) { String server = (String) value; if (StringUtils.isEmpty(server)) { return ValidationStatus.cancel("You have to provide a server to connect to."); } if (!urlPattern.matcher(server).matches()) { return ValidationStatus.error("You have to provide a valid server to connect to."); } return ValidationStatus.ok(); }
/* * (non-Javadoc) * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) */ @Override public IStatus validate(final Object value) { final String content = inputExpression.getContent(); final WebPageRepositoryStore repositoryStore = repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class); return repositoryStore.getChild(content) == null ? ValidationStatus.error( Messages.bind( Messages.pageDoesntExists, String.format("%s (%s)", inputExpression.getName(), content))) : ValidationStatus.ok(); }
/* * (non-Javadoc) * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) */ @Override public IStatus validate(final Object value) { final String content = inputExpression.getContent(); final WebPageRepositoryStore repositoryStore = repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class); String errorMessage = null; if (ProcessPackage.Literals.RECAP_FLOW__OVERVIEW_FORM_MAPPING.equals(feature)) { errorMessage = Messages.bind(Messages.pageDoesntExist, content); } else { errorMessage = Messages.bind(Messages.formDoesntExist, content); } return repositoryStore.getChild(content) == null ? ValidationStatus.error(errorMessage) : ValidationStatus.ok(); }
public IStatus validate(Object value) { String s = (String) value; if (s == null || s.length() == 0) { return ValidationStatus.error(message); } if (s.contains("/") || s.contains("\\")) { return ValidationStatus.error(message + " Path must not contain slash."); } else if (s.contains(" ")) { return ValidationStatus.error(message + " Path must not contain space."); } return ValidationStatus.ok(); }
/* (non-Javadoc) * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) */ @Override public IStatus validate(Object value) { if (!((Boolean) value).booleanValue()) if (port.getProtocol() instanceof CompoundProtocolClass) return ValidationStatus.error("external end port must not have compound protocol"); return Status.OK_STATUS; }
@Override public IStatus validate(Object value) { if (value instanceof String) { String name = (String) value; Result result = ValidationUtil.isUniqueName(port, name); if (!result.isOk()) return ValidationStatus.error(result.getMsg()); } return Status.OK_STATUS; }
@Test @UI public void testRegularErrorIsShown() { final WritableValue status = new WritableValue(ValidationStatus.error("error"), IStatus.class); final MultiValidator validator = new MultiValidator() { @Override protected IStatus validate() { return (IStatus) status.getValue(); } }; mDataBindingContext.addValidationStatusProvider(validator); mWizardDialog.open(); assertThat(mWizardPage.getErrorMessage(), is("error")); assertThat(mWizardPage.isPageComplete(), is(false)); status.setValue(ValidationStatus.ok()); assertThat(mWizardPage.getErrorMessage(), nullValue()); assertThat(mWizardPage.isPageComplete(), is(true)); status.setValue(ValidationStatus.error("error2")); assertThat(mWizardPage.getErrorMessage(), is("error2")); assertThat(mWizardPage.isPageComplete(), is(false)); }
@Override public IStatus validate(Object value) { if ((value != null) && !(value instanceof String)) { throw new RuntimeException(Messages.EmptyStringValidator_nonstring_msg); } if ((value == null) || ((String) value).isEmpty()) { hideDecoration(); return Status.OK_STATUS; } showDecoration(); return ValidationStatus.error(errorMessage); }
@Override public IStatus validate(Object value) { if (value != null && !(value instanceof String)) { throw new RuntimeException(Messages.NonEmptyStringValidator_non_string_error); } if (value != null && ((String) value).length() != 0) { hideDecoration(); return Status.OK_STATUS; } showDecoration(); return ValidationStatus.error(errorMessage); }
@Override public IStatus validate(Object value) { if (value instanceof Integer) { int s = (Integer) value; // We check if the string is longer then 2 signs if (s != 0) { return Status.OK_STATUS; } else { return ValidationStatus.error(StringConstants.VALIDATION_ERROR_NONBELIEBIG); } } else { throw new RuntimeException("Not supposed to be called for non-strings."); } }
@Override public IStatus validate(Object value) { if (value instanceof Integer) { int m = (Integer) value; if (m == 0) return ValidationStatus.error("multiplicity must not be 0"); if (m < -1) return ValidationStatus.error("multiplicity must be -1 or positive"); if (!mayChange) { if (old == 1 && (m > 1 || m == -1)) return ValidationStatus.error("cannot change connected port to replicated"); if ((old > 1 || old == -1) && m == 1) return ValidationStatus.error("cannot change connected port to not replicated"); } if (m == -1 && !multAnyAllowed) return ValidationStatus.error("multiplicity * not allowed (actor used replicated)"); if (port.getProtocol() != null) if (port.getProtocol() instanceof ProtocolClass && ((ProtocolClass) port.getProtocol()).getCommType() == CommunicationType.DATA_DRIVEN) { if (m != 1) return ValidationStatus.error("data driven ports can not be replicated"); } } return Status.OK_STATUS; }
@SuppressWarnings({"unchecked", "rawtypes"}) @Override protected void doCreateControls(final Composite parent, DataBindingContext dbc) { GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).applyTo(parent); // userdoc link (JBIDE-20401) this.userdocLink = new StyledText(parent, SWT.WRAP); // text set in #showHideUserdocLink GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).applyTo(userdocLink); showHideUserdocLink(); IObservableValue userdocUrlObservable = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USERDOCURL).observe(pageModel); StyledTextUtils.emulateLinkAction(userdocLink, r -> onUserdocLinkClicked(userdocUrlObservable)); userdocUrlObservable.addValueChangeListener( new IValueChangeListener() { @Override public void handleValueChange(ValueChangeEvent event) { showHideUserdocLink(); } }); IObservableValue connectionFactoryObservable = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_CONNECTION_FACTORY) .observe(pageModel); // filler Label fillerLabel = new Label(parent, SWT.NONE); GridDataFactory.fillDefaults().span(3, 3).hint(SWT.DEFAULT, 6).applyTo(fillerLabel); // existing connections combo Label connectionLabel = new Label(parent, SWT.NONE); connectionLabel.setText("Connection:"); GridDataFactory.fillDefaults() .align(SWT.LEFT, SWT.CENTER) .hint(100, SWT.DEFAULT) .applyTo(connectionLabel); Combo connectionCombo = new Combo(parent, SWT.DEFAULT); GridDataFactory.fillDefaults() .span(2, 1) .align(SWT.FILL, SWT.CENTER) .grab(true, false) .applyTo(connectionCombo); ComboViewer connectionComboViewer = new ComboViewer(connectionCombo); connectionComboViewer.setContentProvider(ArrayContentProvider.getInstance()); connectionComboViewer.setLabelProvider(new ConnectionColumLabelProvider()); connectionComboViewer.setInput(pageModel.getAllConnections()); Binding selectedConnectionBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(connectionComboViewer)) .validatingAfterGet( new IsNotNullValidator( ValidationStatus.cancel("You have to select or create a new connection."))) .to( BeanProperties.value( ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION, IConnection.class) .observe(pageModel)) .in(dbc); ControlDecorationSupport.create( selectedConnectionBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater()); // server type Label connectionFactoryLabel = new Label(parent, SWT.NONE); connectionFactoryLabel.setText("Server type:"); GridDataFactory.fillDefaults() .align(SWT.LEFT, SWT.CENTER) .hint(100, SWT.DEFAULT) .applyTo(connectionFactoryLabel); Combo connectionFactoryCombo = new Combo(parent, SWT.DEFAULT); GridDataFactory.fillDefaults() .span(2, 1) .align(SWT.FILL, SWT.CENTER) .grab(true, false) .applyTo(connectionFactoryCombo); ComboViewer connectionFactoriesViewer = new ComboViewer(connectionFactoryCombo); connectionFactoriesViewer.setContentProvider(ArrayContentProvider.getInstance()); connectionFactoriesViewer.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { if (!(element instanceof IConnectionFactory)) { return element.toString(); } else { return ((IConnectionFactory) element).getName(); } } }); connectionFactoriesViewer.setInput(pageModel.getAllConnectionFactories()); final IViewerObservableValue selectedServerType = ViewerProperties.singleSelection().observe(connectionFactoriesViewer); ValueBindingBuilder.bind(selectedServerType).to(connectionFactoryObservable).in(dbc); // server Button useDefaultServerCheckbox = new Button(parent, SWT.CHECK); useDefaultServerCheckbox.setText("Use default server"); GridDataFactory.fillDefaults() .span(3, 1) .align(SWT.FILL, SWT.FILL) .applyTo(useDefaultServerCheckbox); ValueBindingBuilder.bind(WidgetProperties.selection().observe(useDefaultServerCheckbox)) .to( BeanProperties.value( ConnectionWizardPageModel.PROPERTY_USE_DEFAULT_HOST, IConnection.class) .observe(pageModel)) .in(dbc); IObservableValue hasDefaultHostObservable = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_HAS_DEFAULT_HOST) .observe(pageModel); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(useDefaultServerCheckbox)) .notUpdating(hasDefaultHostObservable) .in(dbc); Label serverLabel = new Label(parent, SWT.NONE); serverLabel.setText("Server:"); GridDataFactory.fillDefaults() .align(SWT.LEFT, SWT.CENTER) .hint(100, SWT.DEFAULT) .applyTo(serverLabel); Combo serversCombo = new Combo(parent, SWT.BORDER); ComboViewer serversViewer = new ComboViewer(serversCombo); serversViewer.setContentProvider(new ObservableListContentProvider()); serversViewer.setInput( BeanProperties.list(ConnectionWizardPageModel.PROPERTY_ALL_HOSTS).observe(pageModel)); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.FILL) .grab(true, false) .applyTo(serversCombo); final IObservableValue serverUrlObservable = WidgetProperties.text().observe(serversCombo); serversCombo.addFocusListener(onServerFocusLost(serverUrlObservable)); ValueBindingBuilder.bind(serverUrlObservable) .converting(new TrimTrailingSlashConverter()) .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_HOST).observe(pageModel)) .in(dbc); MultiValidator serverUrlValidator = new MultiValidator() { @Override protected IStatus validate() { Object value = serverUrlObservable.getValue(); if (!(value instanceof String) || StringUtils.isEmpty((String) value)) { return ValidationStatus.cancel("Please provide an OpenShift server url."); } else if (!UrlUtils.isValid((String) value)) { return ValidationStatus.error("Please provide a valid OpenShift server url."); } return ValidationStatus.ok(); } }; ControlDecorationSupport.create( serverUrlValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater()); dbc.addValidationStatusProvider(serverUrlValidator); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(serversCombo)) .notUpdatingParticipant() .to( BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USE_DEFAULT_HOST) .observe(pageModel)) .converting(new InvertingBooleanConverter()) .in(dbc); // connect error dbc.addValidationStatusProvider( new MultiValidator() { IObservableValue observable = BeanProperties.value( ConnectionWizardPageModel.PROPERTY_CONNECTED_STATUS, IStatus.class) .observe(pageModel); @Override protected IStatus validate() { return (IStatus) observable.getValue(); } }); // connection editors Group authenticationDetailsGroup = new Group(parent, SWT.NONE); authenticationDetailsGroup.setText("Authentication"); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.FILL) .span(3, 1) .applyTo(authenticationDetailsGroup); GridLayoutFactory.fillDefaults().margins(0, 0).applyTo(authenticationDetailsGroup); // additional nesting required because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=478618 Composite authenticationDetailsContainer = new Composite(authenticationDetailsGroup, SWT.None); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.FILL) .grab(true, true) .applyTo(authenticationDetailsContainer); this.connectionEditors = new ConnectionEditorsStackedView( connectionFactoryObservable, this, authenticationDetailsContainer, dbc); connectionEditors.createControls(); // adv editors Composite advEditorContainer = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().margins(0, 0).applyTo(authenticationDetailsGroup); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.FILL) .span(3, 1) .grab(true, true) .applyTo(advEditorContainer); this.advConnectionEditors = new AdvancedConnectionEditorsStackedView( connectionFactoryObservable, pageModel, advEditorContainer, dbc); advConnectionEditors.createControls(); }
protected IStatus addDependencies(ConnectorImplementation impl, IFolder classpathFolder) throws CoreException { final IDefinitionRepositoryStore store = (IDefinitionRepositoryStore) getDefinitionStore(); final DependencyRepositoryStore depStore = (DependencyRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(DependencyRepositoryStore.class); final DefinitionResourceProvider resourceProvider = DefinitionResourceProvider.getInstance(getDefinitionStore(), getBundle()); ConnectorDefinition def = store.getDefinition(impl.getDefinitionId(), impl.getDefinitionVersion()); for (String jarName : def.getJarDependency()) { if (ignoredLibs.contains(jarName)) { continue; } IRepositoryFileStore file = depStore.getChild(jarName); if (file != null) { if (file.getResource().exists()) { if (!classpathFolder.getFile(file.getName()).exists()) { try { file.getResource() .copy( classpathFolder.getFullPath().append(file.getName()), true, Repository.NULL_PROGRESS_MONITOR); } catch (CoreException e) { BonitaStudioLog.error(e); } } } } else { // Search in provided jars InputStream is = resourceProvider.getDependencyInputStream(jarName); if (is != null) { IFile jarFile = classpathFolder.getFile(jarName); if (!jarFile.exists()) { jarFile.create(is, true, Repository.NULL_PROGRESS_MONITOR); } } else { return ValidationStatus.error(Messages.bind(Messages.implementationDepNotFound, jarName)); } } } for (String jarName : impl.getJarDependencies().getJarDependency()) { if (ignoredLibs.contains(jarName)) { continue; } IRepositoryFileStore file = depStore.getChild(jarName); if (file != null) { if (file.getResource().exists()) { if (!classpathFolder.getFile(file.getName()).exists()) { try { file.getResource() .copy( classpathFolder.getFullPath().append(file.getName()), true, Repository.NULL_PROGRESS_MONITOR); } catch (CoreException e) { BonitaStudioLog.error(e); } } } } else { // Search in provided jars InputStream is = resourceProvider.getDependencyInputStream(jarName); if (is != null) { IFile jarFile = classpathFolder.getFile(jarName); if (!jarFile.exists()) { jarFile.create(is, true, Repository.NULL_PROGRESS_MONITOR); } } else { return ValidationStatus.error(Messages.bind(Messages.implementationDepNotFound, jarName)); } } } return Status.OK_STATUS; }
public IStatus run(IProgressMonitor progressMonitor) { progressMonitor.beginTask(Messages.exporting, IProgressMonitor.UNKNOWN); IStatus status = Status.OK_STATUS; try { ignoredLibs.add( NamingUtils.toConnectorImplementationFilename( impl.getImplementationId(), impl.getImplementationVersion(), false) + ".jar"); cleanAfterExport = new ArrayList<IResource>(); final SourceRepositoryStore sourceStore = getSourceStore(); final IRepositoryStore implStore = getImplementationStore(); List<IResource> resourcesToExport = new ArrayList<IResource>(); IFolder classpathFolder = implStore.getResource().getFolder(CLASSPATH_DIR); if (classpathFolder.exists()) { classpathFolder.delete(true, Repository.NULL_PROGRESS_MONITOR); } classpathFolder.create(true, true, Repository.NULL_PROGRESS_MONITOR); resourcesToExport.add(classpathFolder); cleanAfterExport.add(classpathFolder); status = addImplementationJar(impl, classpathFolder, sourceStore, implStore, resourcesToExport); if (status.getSeverity() != IStatus.OK) { return status; } addArchiveDescriptor(sourceStore, resourcesToExport); if (addDependencies) { status = addDependencies(impl, classpathFolder); if (status.getSeverity() != IStatus.OK) { return status; } } addConnectorImplementation(impl, resourcesToExport, includeSources); addConnectorDefinition(impl, resourcesToExport); final ArchiveFileExportOperation operation = new ArchiveFileExportOperation(null, resourcesToExport, destPath); operation.setUseCompression(true); operation.setUseTarFormat(false); operation.setCreateLeadupStructure(false); operation.run(progressMonitor); if (!operation.getStatus().isOK()) { return operation.getStatus(); } } catch (CoreException e) { BonitaStudioLog.error(e); return ValidationStatus.error(e.getMessage(), e); } catch (InvocationTargetException e) { BonitaStudioLog.error(e); return ValidationStatus.error(e.getMessage(), e); } catch (InterruptedException e) { BonitaStudioLog.error(e); return ValidationStatus.error(e.getMessage(), e); } catch (FileNotFoundException e) { BonitaStudioLog.error(e); return ValidationStatus.error(e.getMessage(), e); } finally { if (implBackup != null) { final IRepositoryStore store = getImplementationStore(); String fileName = NamingUtils.getEResourceFileName(implBackup, true); if (fileName == null) { fileName = NamingUtils.toConnectorImplementationFilename( implBackup.getImplementationId(), implBackup.getImplementationVersion(), true); } IRepositoryFileStore implFile = store.getChild(fileName); if (implFile != null) { implFile.save(implBackup); } else { return ValidationStatus.error(fileName + " not found in repository"); } } for (IResource r : cleanAfterExport) { if (r.exists()) { try { r.delete(true, Repository.NULL_PROGRESS_MONITOR); } catch (CoreException e) { BonitaStudioLog.error(e); } } } } return status; }