Package org.jboss.forge.addon.ui.context

Examples of org.jboss.forge.addon.ui.context.UIContext


   }

   @Test
   public void testNoExceptionsOnCommandsNames()
   {
      UIContext context = new UIContextImpl(true, Selections.emptySelection());
      Set<String> commandNames = commandFactory.getCommandNames(context);
      Assert.assertEquals(5, commandNames.size());

   }
View Full Code Here


   }

   @Test
   public void testNotRequired()
   {
      UIContext ctx = new MockUIContext();
      MockValidationContext context = new MockValidationContext(ctx);
      notRequired.validate(context);
      List<String> errors = context.getErrorsFor(notRequired);
      Assert.assertThat(errors, nullValue());
   }
View Full Code Here

   }

   @Test
   public void testAdditionalValidator()
   {
      UIContext ctx = new MockUIContext();
      MockValidationContext context = new MockValidationContext(ctx);
      withValidator.addValidator(new UIValidator()
      {
         @Override
         public void validate(UIValidationContext validator)
View Full Code Here

   }

   @Test
   public void testDoNotValidateOnNullValues()
   {
      UIContext ctx = new MockUIContext();
      MockValidationContext context = new MockValidationContext(ctx);
      withValidator.addValidator(new UIValidator()
      {
         @Override
         public void validate(UIValidationContext validator)
View Full Code Here

   }

   @Test
   public void testRequiredAndAdditionalValidator()
   {
      UIContext ctx = new MockUIContext();
      MockValidationContext context = new MockValidationContext(ctx);
      requiredNoMessage.addValidator(new UIValidator()
      {
         @Override
         public void validate(UIValidationContext validator)
View Full Code Here

   public Result execute(UIExecutionContext context) throws Exception
   {
      String beanName = named.getValue();
      String beanPackage = targetPackage.getValue();
      DirectoryResource targetDir = targetLocation.getValue();
      UIContext uiContext = context.getUIContext();
      Project project = getSelectedProject(uiContext);
      JavaResource javaResource;
      if (project == null)
      {
         javaResource = facesOperations.newBackingBean(targetDir, beanName, beanPackage);
      }
      else
      {
         javaResource = facesOperations.newBackingBean(project, beanName, beanPackage);
      }
      uiContext.setSelection(javaResource);
      return Results.success("Backing bean " + javaResource + " created");
   }
View Full Code Here

   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      UIContext uiContext = context.getUIContext();
      Shell shell = (Shell) uiContext.getProvider();
      TerminalSize terminalSize = shell.getConsole().getShell().getSize();
      List<String> display = new ArrayList<>();

      Iterable<UICommand> commands = commandFactory.getCommands();
      for (UICommand command : commands)
      {
         UICommandMetadata metadata = command.getMetadata(uiContext);
         String name = commandFactory.getCommandName(uiContext, command);
         boolean enabled = command.isEnabled(uiContext);
         display.add(metadata.getCategory()
                  + " > "
                  + new TerminalString(name, new TerminalColor(enabled ? Color.CYAN : Color.RED,
                           Color.DEFAULT)).toString() + " - " + metadata.getDescription());
      }
      UIOutput output = uiContext.getProvider().getOutput();
      PrintStream out = output.out();
      out.println(Parser.formatDisplayList(display.toArray(new String[display.size()]),
               terminalSize.getHeight(), terminalSize.getWidth()));

      return Results.success();
View Full Code Here

   @SuppressWarnings({ "rawtypes", "unchecked" })
   @Override
   public void initializeUI(UIBuilder builder) throws Exception
   {
      UIContext context = builder.getUIContext();
      Project project = getSelectedProject(context);
      JPAFacet<PersistenceCommonDescriptor> persistenceFacet = project.getFacet(JPAFacet.class);
      JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
      List<JavaClassSource> allEntities = persistenceFacet.getAllEntities();
      List<JavaClassSource> supportedEntities = new ArrayList<>();
      for (JavaClassSource entity : allEntities)
      {
         if (isEntityWithSimpleKey(entity))
         {
            supportedEntities.add(entity);
         }
      }
      targets.setValueChoices(supportedEntities);
      targets.setItemLabelConverter(new Converter<JavaClassSource, String>()
      {
         @Override
         public String convert(JavaClassSource source)
         {
            return source == null ? null : source.getQualifiedName();
         }
      });
      List<String> persistenceUnits = new ArrayList<>();
      List<PersistenceUnitCommon> allUnits = persistenceFacet.getConfig().getAllPersistenceUnit();
      for (PersistenceUnitCommon persistenceUnit : allUnits)
      {
         persistenceUnits.add(persistenceUnit.getName());
      }
      if (!persistenceUnits.isEmpty())
      {
         persistenceUnit.setValueChoices(persistenceUnits).setDefaultValue(persistenceUnits.get(0));
      }

      // TODO: May detect where @Path resources are located
      packageName.setDefaultValue(javaSourceFacet.getBasePackage() + ".rest");

      contentType.setCompleter(new UICompleter<String>()
      {
         @Override
         public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value)
         {
            List<String> options = new ArrayList<>();
            options.add(MediaType.APPLICATION_XML);
            options.add(MediaType.APPLICATION_JSON);
            return options;
         }
      });
      generator.setDefaultValue(defaultResourceGenerator);
      if (context.getProvider().isGUI())
      {
         generator.setItemLabelConverter(new Converter<RestResourceGenerator, String>()
         {
            @Override
            public String convert(RestResourceGenerator source)
View Full Code Here

   }

   @Override
   public Result execute(final UIExecutionContext context) throws Exception
   {
      UIContext uiContext = context.getUIContext();
      RestGenerationContext generationContext = createContextFor(uiContext);
      Set<JavaClassSource> endpoints = generateEndpoints(generationContext);
      Project project = generationContext.getProject();
      JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
      List<JavaResource> selection = new ArrayList<>();

      for (JavaClassSource javaClass : endpoints)
      {
         selection.add(javaSourceFacet.saveJavaSource(javaClass));
      }
      uiContext.setSelection(selection);
      return Results.success("Endpoint created");
   }
View Full Code Here

   }

   private UICommand findCommand(Iterable<UICommand> commands, UIContext context, String name)
   {
      CommandNameUIProvider provider = new CommandNameUIProvider(context.getProvider());
      final UIContext delegatingContext = new DelegatingUIContext(context, provider);
      if (commands != null)
         for (UICommand cmd : commands)
         {
            // Test non-gui command name
            {
View Full Code Here

TOP

Related Classes of org.jboss.forge.addon.ui.context.UIContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.