Java Code Examples for org.eclipse.core.databinding.validation.ValidationStatus#ok()

The following examples show how to use org.eclipse.core.databinding.validation.ValidationStatus#ok() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectVersionValidator.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * @param input the prospective version string
 * @return OK status if valid, or an ERROR status with a description why invalid
 */
@Override
public IStatus validate(Object input) {
  // https://cloud.google.com/appengine/docs/java/config/appref
  // "The version specifier can contain lowercase letters, digits, and hyphens.
  // It cannot begin with the prefix ah- and the names default and latest are
  // reserved and cannot be used."
  if (!(input instanceof String)) {
    return ValidationStatus.error(Messages.getString("version.invalid")); //$NON-NLS-1$
  }
  String value = (String) input;
  if (value.isEmpty()) {
    return ValidationStatus.ok();
  } else if (APPENGINE_PROJECT_VERSION_PATTERN.matcher(value).matches()) {
    if (value.startsWith(RESERVED_PREFIX) || RESERVED_VALUES.contains(value)) {
      return ValidationStatus.error(Messages.getString("version.reserved")); //$NON-NLS-1$
    }
    return ValidationStatus.ok();
  } else {
    return ValidationStatus.error(Messages.getString("version.invalid")); //$NON-NLS-1$
  }
}
 
Example 2
Source File: ImportWorkspaceControlSupplier.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private IStatus scannerValidator(Object value) {
    final String path = value.toString();
    if (path.isEmpty()) {
        return ValidationStatus.ok();
    }
    workspaceModel = parseFolder(path);
    final IStatus status = workspaceModel.getStatus();
    if (!status.isOK()) {
        return status;
    }
    if (workspaceModel.getRepositories()
            .map(ImportRepositoryModel::getStatus)
            .anyMatch(IStatus::isOK)) {
        return ValidationStatus.ok();
    }
    return ValidationStatus.error(Messages.noValidRepositoryFoundAtLocation);
}
 
Example 3
Source File: OperationReturnTypesValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected IStatus validateSetDocumentOperation(final Expression expression, final Operation operation) {
    final boolean isTask = operation.eContainer() instanceof Task;
    final Expression storageExpression = operation.getLeftOperand();
    if (!String.class.getName().equals(storageExpression.getReturnType())) {
        return ValidationStatus.error(Messages.bind(Messages.incompatibleStorageReturnType, storageExpression.getName(),
                operatorLabelProvider.getText(operation.getOperator())));
    }
    if (expression != null && expression.getContent() != null && !expression.getContent().isEmpty()) {
        final String typeName = storageExpression.getReturnType();
        final String actionExpressionReturnType = expression.getReturnType();
        if (!((DocumentValue.class.getName().equals(actionExpressionReturnType)
                || FileInputValue.class.getName().equals(actionExpressionReturnType))
                && typeName.equals(String.class.getName()))) {
            return isTask
                    ? ValidationStatus
                            .warning(Messages.incompatibleType + " " + Messages.messageOperationWithDocumentInTask)
                    : ValidationStatus
                            .warning(Messages.incompatibleType + " " + Messages.messageOperationWithDocumentInForm);
        } else {
            return ValidationStatus.ok();
        }
    } else {
        return isTask ? ValidationStatus.info(Messages.messageOperationWithDocumentInTask) : ValidationStatus
                .info(Messages.messageOperationWithDocumentInForm);
    }
}
 
Example 4
Source File: DeployApplicationHandler.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected IStatus openDeployWizard(RepositoryAccessor repositoryAccessor, Shell shell, DeployApplicationAction action,
        String application, DependencyResolver<ApplicationFileStore> dependencyResolver) {
    Optional<ApplicationFileStore> applicationFileStore = findApplicationToDeploy(repositoryAccessor,
            application);
    if (applicationFileStore.isPresent()) {
        DeployArtifactsHandler deployArtifactsHandler = new DeployArtifactsHandler();
        List<IRepositoryFileStore> defaultSelection = new ArrayList<>();
        ApplicationFileStore fileStore = applicationFileStore.get();
        defaultSelection.add(fileStore);
        defaultSelection.addAll(dependencyResolver.findDependencies(fileStore));
        deployArtifactsHandler.setDefaultSelection(defaultSelection);
        try {
            deployArtifactsHandler.deploy(shell, repositoryAccessor, PlatformUI.getWorkbench().getProgressService());
        } catch (InvocationTargetException | InterruptedException e) {
            BonitaStudioLog.error(e);
        }
    } else {
        action.selectAndDeploy(shell);
    }
    return ValidationStatus.ok();
}
 
Example 5
Source File: AbstractFileStore.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public IStatus export(final String targetAbsoluteFilePath) throws IOException {
    checkWritePermission(new File(targetAbsoluteFilePath));
    final IResource file = getResource();
    if (file != null) {
        final File to = new File(targetAbsoluteFilePath);
        to.mkdirs();
        final File target = new File(to, file.getName());
        if (target.exists()) {
            if (FileActionDialog.overwriteQuestion(file.getName())) {
                PlatformUtil.delete(target, Repository.NULL_PROGRESS_MONITOR);
            } else {
                return ValidationStatus.cancel("");
            }
        }
        PlatformUtil.copyResource(to, file.getLocation().toFile(), Repository.NULL_PROGRESS_MONITOR);
        return ValidationStatus.ok();
    }
    return ValidationStatus.error(String.format(Messages.failedToRetrieveResourceToExport, getName()));
}
 
Example 6
Source File: SmartImportBdmValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected IStatus validateCompatibility(BusinessObjectModel model1, BusinessObjectModel model2) {
    List<BusinessObject> duplicatedBo = model1.getBusinessObjects().stream()
            .filter(boFromModel1 -> {
                return model2.getBusinessObjects().stream()
                        .anyMatch(boFromModel2 -> areBusinessObjectsConflicting(boFromModel1, boFromModel2));
            }).collect(Collectors.toList());
    if (!duplicatedBo.isEmpty()) {
        MultiStatus status = new MultiStatus(BusinessObjectPlugin.PLUGIN_ID, 0, Messages.smartImportImpossible, null);
        duplicatedBo.stream()
                .map(BusinessObject::getSimpleName)
                .map(name -> String.format(Messages.businessObjectNameDuplicated, name))
                .map(ValidationStatus::error)
                .forEach(status::add);
        return status;
    }
    return ValidationStatus.ok();
}
 
Example 7
Source File: BosArchive.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private IStatus validateZipStructure() {
    try (ZipFile zipFile = new ZipFile(archiveFile)) {
        if (zipFile.stream().noneMatch(this::matchRepositoryFormat)) {
            return ValidationStatus.error("Not a valid BOS archive structure");
        }
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
    return ValidationStatus.ok();
}
 
Example 8
Source File: ApplicationHomepageValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public IStatus validate(ApplicationNode applicationNode) {
    if (applicationNode.getHomePage() == null || applicationNode.getHomePage().isEmpty()) {
        return ValidationStatus
                .error(String.format(Messages.applicationWithoutHomepage,
                        applicationNode.getDisplayName()));
    }
    return applicationNode.getApplicationPages().stream().map(ApplicationPageNode::getToken)
            .anyMatch(applicationNode.getHomePage()::equals)
                    ? ValidationStatus.ok()
                    : ValidationStatus
                            .error(String.format(Messages.applicationWithUnknownHomepage,
                                    applicationNode.getDisplayName()));
}
 
Example 9
Source File: UniqueValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public IStatus validate(final Object value) {
    checkState(iterable != null);
    if (value != null) {
        return find(iterable, hasSamePropertyValue(value), null) == null ? ValidationStatus.ok() :
                ValidationStatus.error(Messages.bind(Messages.unicityErrorMessage, value));
    }
    return ValidationStatus.ok();
}
 
Example 10
Source File: AdditionalResourceBarPathValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public IStatus validate(String barPath) {
    if (Strings.isNullOrEmpty(barPath)) {
        return ValidationStatus.error(Messages.additionalresourceNameIsRequired);
    }
    return pool.getAdditionalResources().stream()
            .filter(additionalResource -> !Objects.equals(additionalResource, originalAdditionalResource))
            .filter(additionalResource -> Objects.equals(additionalResource.getName(), barPath))
            .count() > 0
                    ? ValidationStatus.error(String.format(Messages.barPathUnicityError, barPath))
                    : ValidationStatus.ok();
}
 
Example 11
Source File: ImportBdmContentValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public IStatus validate(String value) {
    if (value != null) {
        File file = new File(value);
        try (ZipFile zipFile = new ZipFile(file)) {
            if (!Objects.equals(zipFile.entries().nextElement().getName(), BusinessObjectModelFileStore.BOM_FILENAME)) {
                return ValidationStatus.error(String.format(Messages.bdmZipInvalid, file.getName()));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return ValidationStatus.ok();
}
 
Example 12
Source File: FieldNameValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private IStatus validateReservedFieldNames(String name) {
    if (name.equalsIgnoreCase(org.bonitasoft.engine.bdm.model.field.Field.PERSISTENCE_ID)) {
        return ValidationStatus.error(
                Messages.bind(Messages.reservedKeyWord, org.bonitasoft.engine.bdm.model.field.Field.PERSISTENCE_ID));
    } else if (name.equalsIgnoreCase(org.bonitasoft.engine.bdm.model.field.Field.PERSISTENCE_VERSION)) {
        return ValidationStatus.error(Messages.bind(Messages.reservedKeyWord,
                org.bonitasoft.engine.bdm.model.field.Field.PERSISTENCE_VERSION));
    }
    return ValidationStatus.ok();
}
 
Example 13
Source File: TransientDataValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public IStatus validate(final Object value) {
    if (!inputExpression.getReferencedElements().isEmpty()) {
        final EObject data = inputExpression.getReferencedElements().get(0);
        if (data instanceof Data) {
            if (((Data) data).isTransient()) {
                return ValidationStatus.warning(Messages.transientDataWarning);
            }
        }
    }

    return ValidationStatus.ok();
}
 
Example 14
Source File: UniqueConstraintFieldsValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private IStatus validateUnknownFields(UniqueConstraint constraint) {
    BusinessObject bo = (BusinessObject) constraint.eContainer();
    List<String> unkownFields = constraint.getFieldNames().stream()
            .filter(fieldName -> bo.getFields().stream().map(Field::getName).noneMatch(fieldName::equals))
            .collect(Collectors.toList());
    return unkownFields.isEmpty()
            ? ValidationStatus.ok()
            : ValidationStatus.error(String.format(Messages.constraintReferencesUnknownAttributes, constraint.getName(),
                    unkownFields.toString()));
}
 
Example 15
Source File: ConstraintExpressionEditorValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected IStatus validate() {
    final String text = (String) expressionObservable.getValue();
    if (Strings.isNullOrEmpty(text)) {
        return ValidationStatus.error(Messages.emptyExpressionContent);
    }
    if (dependenciesObservable.isEmpty()) {
        return ValidationStatus.warning(Messages.noContractInputReferencedInExpression);
    }
    return ValidationStatus.ok();
}
 
Example 16
Source File: BusinessObjectDataWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private IValidator uniqueDataNameValidator() {
    return new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (existingNames.contains(value.toString())) {
                return ValidationStatus.error(Messages.dataWithSameNameAlreadyExists);
            }
            return ValidationStatus.ok();
        }
    };
}
 
Example 17
Source File: SeveralCompositionReferencesValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public IStatus validate(BusinessObject businessObject) {

    boolean severalComposition = modelObservable.getValue().getPackages().stream()
            .map(Package::getBusinessObjects)
            .flatMap(Collection::stream)
            .mapToLong(aBo -> compositionRelations(aBo, businessObject))
            .sum() > 1;

    return severalComposition
            ? ValidationStatus.error(String.format(Messages.severalCompositionReferenceForABusinessObject,
                    businessObject.getSimpleName()))
            : ValidationStatus.ok();
}
 
Example 18
Source File: NewTmDbBaseInfoPage.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 输入验证器 ;
 */
private IStatus validator() {
	if (dbOp == null) {
		return ValidationStatus.error(Messages.getString("wizard.NewTmDbBaseInfoPage.msg1"));
	}
	//

	String dbName = dbModel.getDbName();
	String instance = dbModel.getInstance();
	String host = dbModel.getHost();
	String port = dbModel.getPort();
	String location = dbModel.getItlDBLocation();
	String username = dbModel.getUserName();
	String password = dbModel.getPassword();

	if (dbName == null || dbName.trim().length() == 0) {
		return ValidationStatus.error(Messages.getString("wizard.NewTmDbBaseInfoPage.msg2"));
	}

	String vRs = DbValidator.valiateDbName(dbName);
	if (vRs != null) {
		return ValidationStatus.error(vRs);
	}

	if (dbMetaData.instanceSupported()) {
		if (instance == null || instance.trim().length() == 0) {
			return ValidationStatus.error(Messages.getString("wizard.NewTmDbBaseInfoPage.instancemsg"));
		}
		dbMetaData.setInstance(instance == null ? "" : instance);
	}

	if (dbMetaData.dataPathSupported()) {
		if (location == null || location.trim().length() == 0) {
			return ValidationStatus.error(Messages.getString("wizard.NewTmDbBaseInfoPage.msg3"));
		}
		File f = new File(location);
		if (!f.isDirectory() || !f.exists()) {
			return ValidationStatus.error(Messages.getString("wizard.NewTmDbBaseInfoPage.msg11"));
		}
	}
	if (dbMetaData.serverNameSupported()) {
		if (host == null || host.trim().length() == 0) {
			return ValidationStatus.error(Messages.getString("wizard.NewTmDbBaseInfoPage.msg4"));
		}
	}
	if (dbMetaData.portSupported()) {
		if (port == null || !port.matches("[0-9]+")) {
			return ValidationStatus.error(Messages.getString("wizard.NewTmDbBaseInfoPage.msg5"));
		}
	}
	if (dbMetaData.userNameSupported()) {
		if (username == null || username.trim().length() == 0) {
			return ValidationStatus.error(Messages.getString("wizard.NewTmDbBaseInfoPage.msg6"));
		}
	}

	dbMetaData.setDatabaseName(dbName == null ? "" : dbName);
	dbMetaData.setDataPath(location == null ? "" : location);
	dbMetaData.setServerName(host == null ? "" : host);
	dbMetaData.setPort(port == null ? "" : port);
	dbMetaData.setUserName(username == null ? "" : username);
	dbMetaData.setPassword(password == null ? "" : password); // 密码可以为空

	return ValidationStatus.ok();
}
 
Example 19
Source File: TermDbManagerDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 输入验证器 ;
 */
private IStatus validator() {
	String instance = currServer.getInstance();
	String host = currServer.getHost();
	String port = currServer.getPort();
	String location = currServer.getItlDBLocation();
	String username = currServer.getUserName();
	MetaData dbMetaData = dbMetaDataMap.get(currServer.getDbType());
	if (dbMetaData.dataPathSupported()) {
		File f = new File(location);
		if (location == null || location.trim().length() == 0) {
			if (dbMetaData.getDbType().equals(Constants.DBTYPE_INTERNALDB)) {
				return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg5"));
			} else if (dbMetaData.getDbType().equals(Constants.DBTYPE_SQLITE)) {
				return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg11"));
			}
		} else if (!f.exists()) {
			return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg12"));
		}
	}
	if (dbMetaData.serverNameSupported()) {
		if (host == null || host.trim().length() == 0) {
			return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg6"));
		}
	}
	if (dbMetaData.portSupported()) {
		if (port == null || port.trim().length() == 0) {
			return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg7"));
		}
	}
	if (dbMetaData.userNameSupported()) {
		if (username == null || username.trim().length() == 0) {
			return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg8"));
		}
	}

	if (dbMetaData.instanceSupported()) {
		if (instance == null || instance.trim().length() == 0) {
			return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg9"));
		}
	}

	return ValidationStatus.ok();
}
 
Example 20
Source File: SelectGroupMappingWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
  public void createControl(Composite parent) {
      super.createControl(parent) ;

      final Composite mainComposite = (Composite) getControl();
      final Composite viewersComposite = new Composite(mainComposite, SWT.NONE) ;
      viewersComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(2, 1).hint(SWT.DEFAULT,250).create()) ;
      viewersComposite.setLayout(GridLayoutFactory.swtDefaults().numColumns(1).margins(0, 0).extendedMargins(0, 0, 10, 0).equalWidth(false).create()) ;

      availableGroupViewer = CheckboxTableViewer.newCheckList(viewersComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL) ;
      availableGroupViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true,true).create()) ;
      availableGroupViewer.getTable().setHeaderVisible(true) ;
      availableGroupViewer.setContentProvider(new ArrayContentProvider()) ;
      final TableLayout layout = new TableLayout() ;
      layout.addColumnData(new ColumnWeightData(100));
      availableGroupViewer.getTable().setLayout(layout) ;

      final TableViewerColumn columnViewer = new TableViewerColumn(availableGroupViewer, SWT.NONE) ;
      final TableColumn usernameColumn = columnViewer.getColumn() ;
      usernameColumn.setText(Messages.groupName);
      columnViewer.setLabelProvider(new ColumnLabelProvider());
      final TableColumnSorter sorter = new TableColumnSorter(availableGroupViewer) ;
      sorter.setColumn(usernameColumn) ;

      availableGroupViewer.setInput(availableGroups) ;
      availableGroupViewer.setCheckedElements(selectedGroups.toArray());
      
      context = new DataBindingContext();

      final IObservableSet checkedElementsObservable =  ViewersObservables.observeCheckedElements(availableGroupViewer, String.class) ;
      final MultiValidator notEmptyValidator = new MultiValidator() {

      	@Override
          protected IStatus validate() {
		if(groupSelectionIsValid(checkedElementsObservable)){
			return ValidationStatus.ok();
		}
		return ValidationStatus.error(Messages.errorSelectionGroups);
	}
      }  ;

      context.addValidationStatusProvider(notEmptyValidator);
context.bindSet(checkedElementsObservable, PojoObservables.observeSet(this, "selectedGroups"));

WizardPageSupport.create(this, context);
setControl(mainComposite);
  }