org.jboss.forge.addon.ui.context.UIValidationContext Java Examples

The following examples show how to use org.jboss.forge.addon.ui.context.UIValidationContext. 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: SpringBootConfigurationFileCompleter.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that the given selected directory and fileName are valid and that the file doesn't already exist
 */
public void validateFileDoesNotExist(UIInput<String> directory, UIInput<String> fileName, UIValidationContext validator) {
    String resourcePath = CamelXmlHelper.createFileName(directory, fileName);
    if (files.contains(resourcePath)) {
        validator.addValidationError(fileName, "A file with that name already exists!");
    }
}
 
Example #2
Source File: XmlFileCompleter.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that the given selected directory and fileName are valid and that the file doesn't already exist
 */
public void validateFileDoesNotExist(UIInput<String> directory, UIInput<String> fileName, UIValidationContext validator) {
    String resourcePath = CamelXmlHelper.createFileName(directory, fileName);
    if (files.contains(resourcePath)) {
        validator.addValidationError(fileName, "A file with that name already exists!");
    }
}
 
Example #3
Source File: ScaffoldableEntitySelectionWizard.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void validate(UIValidationContext context)
{
   // Verify if the selected JPA entities have corresponding JAX-RS resources.
   // If yes, then raise warnings if they will be overwritten
   Boolean shouldGenerateRestResources = generateRestResources.getValue();
   List<String> entitiesWithRestResources = new ArrayList<>();
   if (shouldGenerateRestResources.equals(Boolean.TRUE) && targets.getValue() != null)
   {
      for (JavaClassSource klass : targets.getValue())
      {
         Project project = getSelectedProject(context.getUIContext());
         JavaSourceFacet javaSource = project.getFacet(JavaSourceFacet.class);
         RestResourceTypeVisitor restTypeVisitor = new RestResourceTypeVisitor();
         String entityTable = getEntityTable(klass);
         String proposedResourcePath = "/" + inflector.pluralize(entityTable.toLowerCase());
         restTypeVisitor.setProposedPath(proposedResourcePath);
         javaSource.visitJavaSources(restTypeVisitor);
         if (restTypeVisitor.isFound())
         {
            entitiesWithRestResources.add(klass.getQualifiedName());
         }
      }
   }
   if (!entitiesWithRestResources.isEmpty())
   {
      context.addValidationWarning(targets, "Some of the selected entities " + entitiesWithRestResources.toString()
               + " already have associated REST resources that will be overwritten.");
   }
}
 
Example #4
Source File: WindupCommand.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void validate(UIValidationContext context)
{
    for (Entry<ConfigurationOption, InputComponent<?, ?>> entry : this.inputOptions.entrySet())
    {
        final InputComponent<?, ?> inputComponent = entry.getValue();

        ConfigurationOption option = entry.getKey();
        Object inputValue = getValueForInput(option, inputComponent);
        if (inputValue == null && !option.isRequired())
            return;

        ValidationResult result = option.validate(inputValue);

        switch (result.getLevel())
        {
            case ERROR:
                context.addValidationError(inputComponent, result.getMessage());
                break;
            case WARNING:
                context.addValidationWarning(inputComponent, result.getMessage());
                break;
            case PROMPT_TO_CONTINUE:
                this.promptMessages.add(result);
                break;
        }
    }
}
 
Example #5
Source File: Apply.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
    public void initializeUI(UIBuilder builder) throws Exception {
        super.initializeUI(builder);

        // TODO complete on files
/*
        file.setCompleter(new UICompleter<String>() {
            @Override
            public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
                List<String> list = new ArrayList<String>();
                ServiceList services = getKubernetes().getServices();
                if (services != null) {
                    List<Service> items = services.getItems();
                    if (items != null) {
                        for (Service item : items) {
                            String id = item.getName();
                            list.add(id);
                        }
                    }
                }
                Collections.sort(list);
                return list;
            }
        });
*/
        file.addValidator(new UIValidator() {
            @Override
            public void validate(UIValidationContext validationContext) {
                InputComponent<?, ?> inputComponent = validationContext.getCurrentInputComponent();
                Object value = inputComponent.getValue();
                if (value instanceof File) {
                    File aFile = (File) value;
                    if (!aFile.exists()) {
                        validationContext.addValidationError(inputComponent, "File does not exist!");
                    } else if (!aFile.isFile()) {
                        validationContext.addValidationError(inputComponent, "File is a directory!");
                    } else {
                        String extension = Files.getFileExtension(aFile);
                        if (extension == null || !extension.toLowerCase().equals("json")) {
                            validationContext.addValidationWarning(inputComponent, "File does not use the .json extension");
                        }
                    }
                }
            }
        });

        builder.add(file);
    }
 
Example #6
Source File: CamelNewCamelContextXmlCommand.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public void validate(UIValidationContext validator) {
    XmlFileCompleter xmlFileCompleter = createXmlFileCompleter(validator.getUIContext(), null);
    xmlFileCompleter.validateFileDoesNotExist(directory, name, validator);
    super.validate(validator);
}
 
Example #7
Source File: WindupUpdateRulesetCommand.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void validate(UIValidationContext context)
{

}
 
Example #8
Source File: WindupUpdateDistributionCommand.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void validate(UIValidationContext context)
{

}