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

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


   @Override
   public NavigationResult next(UINavigationContext context) throws Exception
   {
      ConstraintType constraintType = constraint.getValue();
      UIContext uiContext = context.getUIContext();
      Map<Object, Object> attributeMap = uiContext.getAttributeMap();
      attributeMap.put(Property.class, onProperty.getValue());
      attributeMap.put(ConstraintType.class, constraintType);
      attributeMap.put("onAccessor", onAccessor.getValue());
      if (constraintType == CoreConstraints.VALID)
      {
View Full Code Here


   @Override
   public void postCommandFailure(UICommand command, UIExecutionContext context, Throwable failure)
   {
      if (failure != null)
      {
         UIContext uiContext = context.getUIContext();
         if (uiContext instanceof ShellContext)
         {
            ShellContext shellContext = (ShellContext) uiContext;
            PrintStream err = shellContext.getProvider().getOutput().err();
            UICommandMetadata metadata = command.getMetadata(shellContext);
View Full Code Here

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      Result result = Results.fail("Error executing script.");
      UIContext uiContext = context.getUIContext();
      Resource<?> currentResource = (Resource<?>) uiContext.getInitialSelection().get();
      final UIOutput output = uiContext.getProvider().getOutput();
      if (command.hasValue())
      {
         String[] commands = command.getValue().split(" ");
         ProcessBuilder processBuilder = new ProcessBuilder(commands);
         Object currentDir = currentResource.getUnderlyingResourceObject();
         if (currentDir instanceof File)
         {
            processBuilder.directory((File) currentDir);
         }
         final Process process = processBuilder.start();
         ExecutorService executor = Executors.newFixedThreadPool(2);
         // Read std out
         executor.submit(new Runnable()
         {
            @Override
            public void run()
            {
               Streams.write(process.getInputStream(), output.out());
            }
         });
         // Read std err
         executor.submit(new Runnable()
         {
            @Override
            public void run()
            {
               Streams.write(process.getErrorStream(), output.err());
            }
         });
         executor.shutdown();
         int returnCode = process.waitFor();
         if (returnCode == 0)
         {
            result = Results.success();
         }
         else
         {
            result = Results.fail("Error while executing native command. See output for more details");
         }
      }
      else
      {
         Resource<?> selectedResource = currentResource;
         ALL: for (String path : arguments.getValue())
         {
            List<Resource<?>> resources = new ResourcePathResolver(resourceFactory, currentResource, path).resolve();
            for (Resource<?> resource : resources)
            {
               if (resource.exists())
               {
                  final PipedOutputStream stdin = new PipedOutputStream();
                  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));

                  PrintStream stdout = new UncloseablePrintStream(output.out());
                  PrintStream stderr = new UncloseablePrintStream(output.err());
                 
                  Shell currentShell = (Shell) uiContext.getProvider();
                  final TerminalSize terminalSize = currentShell.getConsole().getShell().getSize();
                  ForgeTerminal terminal = new ForgeTerminal(
                           new Terminal()
                           {

                              @Override
                              public void close() throws IOException
                              {

                              }

                              @Override
                              public void initialize()
                              {

                              }

                              @Override
                              public int getWidth()
                              {
                                 return terminalSize.getWidth();
                              }

                              @Override
                              public int getHeight()
                              {
                                 return terminalSize.getHeight();
                              }
                           });

                  Settings settings = new SettingsBuilder()
                           .inputStream(new PipedInputStream(stdin))
                           .outputStream(stdout)
                           .outputStreamError(stderr)
                           .terminal(terminal)
                           .create();

                  try (Shell scriptShell = shellFactory.createShell(currentResource, settings))
                  {

                     scriptShell.getConsole().setPrompt(new Prompt(""));
                     try (BufferedReader reader = new BufferedReader(new InputStreamReader(
                              resource.getResourceInputStream())))
                     {
                        long startTime = System.currentTimeMillis();
                        while (reader.ready())
                        {
                           try
                           {
                              String line = readLine(reader);
                              if (skipsLine(line))
                              {
                                 // Skip Comments
                                 continue;
                              }
                              Integer timeoutValue = timeout.getValue();
                              result = execute(scriptShell, writer, line, timeoutValue,
                                       TimeUnit.SECONDS, startTime);

                              if (result instanceof Failed)
                              {
                                 break ALL;
                              }
                              else
                              {
                                 selectedResource = scriptShell.getCurrentResource();
                              }
                           }
                           catch (TimeoutException e)
                           {
                              result = Results.fail(path + ": timed out.");
                              break ALL;
                           }
                        }
                     }
                  }
               }
               else
               {
                  result = Results.fail(path + ": not found.");
                  break ALL;
               }
            }
         }
         if (!(result instanceof Failed))
         {
            uiContext.setSelection(selectedResource);
         }
      }
      return result;
   }
View Full Code Here

   }

   @Override
   public void initializeUI(UIBuilder builder) throws Exception
   {
      final UIContext uiContext = builder.getUIContext();
      PersistenceContainer pc = (PersistenceContainer) uiContext.getAttributeMap().get(PersistenceContainer.class);
      initDBType(uiContext);
      initDatasourceName(uiContext);
      initPersistenceUnitName(builder);
      builder.add(dbType);
      overwritePersistenceUnit.setEnabled(new Callable<Boolean>()
View Full Code Here

   }

   @Override
   public void validate(UIValidationContext validator)
   {
      UIContext uiContext = validator.getUIContext();
      JPADataSource ds = getDataSource(uiContext);
      try
      {
         ds.validate();
      }
View Full Code Here

   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      UIContext uiContext = context.getUIContext();
      Project project = getSelectedProject(uiContext);
      JPADataSource dataSource = getDataSource(uiContext);
      Boolean configureMetadata = (Boolean) uiContext.getAttributeMap().get("ConfigureMetadata");
      String puName = persistenceUnitName.getValue();
      persistenceOperations.setup(puName, project, dataSource, configureMetadata);
      return Results.success("Persistence (JPA) is installed.");

   }
View Full Code Here

   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      UIContext uiContext = context.getUIContext();
      GitIgnoreResource resource = gitIgnoreResource(uiContext);
      uiContext.setSelection(resource);
      return Results.success();
   }
View Full Code Here

            project = projectFactory.createProject(targetDir, buildSystem.getValue());
         }

         if (project != null)
         {
            UIContext uiContext = context.getUIContext();
            MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
            metadataFacet.setProjectName(named.getValue());
            metadataFacet.setProjectVersion(version.getValue());
            metadataFacet.setTopLevelPackage(topLevelPackage.getValue());

            if (finalName.hasValue())
            {
               PackagingFacet packagingFacet = project.getFacet(PackagingFacet.class);
               packagingFacet.setFinalName(finalName.getValue());
            }

            uiContext.setSelection(project.getRoot());
            uiContext.getAttributeMap().put(Project.class, project);
         }
         else
            result = Results.fail("Could not create project of type: [" + value + "]");
      }
      else
View Full Code Here

   public NavigationResult next(UINavigationContext context) throws Exception
   {
      ScaffoldProvider selectedProvider = provider.getValue();
      Project project = getSelectedProject(context);
      ((AbstractFacet) selectedProvider).setFaceted(project);
      UIContext uiContext = context.getUIContext();
      Map<Object, Object> attributeMap = uiContext.getAttributeMap();
      attributeMap.put(ScaffoldProvider.class, selectedProvider);
      attributeMap.put(ScaffoldSetupContext.class, createSetupContext());

      // Get the step sequence from the selected scaffold provider
      List<Class<? extends UICommand>> setupFlow = selectedProvider.getSetupFlow();
View Full Code Here

   @Override
   public NavigationResult next(UINavigationContext context) throws Exception
   {
      ScaffoldProvider selectedProvider = provider.getValue();
      UIContext uiContext = context.getUIContext();
      Project project = getSelectedProject(uiContext);
      Map<Object, Object> attributeMap = uiContext.getAttributeMap();

      attributeMap.put(Project.class, project);
      attributeMap.put(ScaffoldProvider.class, selectedProvider);
      attributeMap.put(ScaffoldGenerationContext.class, populateGenerationContext(uiContext));
      ((AbstractFacet) selectedProvider).setFaceted(project);
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.