Java Code Examples for org.jboss.forge.addon.ui.context.UIBuilder#getUIContext()

The following examples show how to use org.jboss.forge.addon.ui.context.UIBuilder#getUIContext() . 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: CamelAddNodeXmlCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception {
    UIContext context = builder.getUIContext();
    Map<Object, Object> attributeMap = context.getAttributeMap();
    attributeMap.remove("navigationResult");

    Project project = getSelectedProject(context);
    String currentFile = getSelectedFile(context);

    String selected = configureXml(project, xml, currentFile);
    parents = configureXmlNodes(context, project, selected, xml, parent);

    nameFilter.setValueChoices(CamelCommandsHelper.createEipLabelValues(project, getCamelCatalog()));
    nameFilter.setDefaultValue("<all>");

    name.setValueChoices(CamelCommandsHelper.createAllEipDtoValues(project, getCamelCatalog(), nameFilter));
    // include converter from string->dto
    name.setValueConverter(text -> createEipDto(getCamelCatalog(), text));

    builder.add(xml).add(parent).add(nameFilter).add(name);
}
 
Example 2
Source File: CamelAddEndpointXmlCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception {
    UIContext context = builder.getUIContext();
    Map<Object, Object> attributeMap = context.getAttributeMap();
    attributeMap.remove("navigationResult");

    Project project = getSelectedProject(context);
    String currentFile = getSelectedFile(context);

    // include custom components
    discoverCustomCamelComponentsOnClasspathAndAddToCatalog(camelCatalog, project);

    configureComponentName(project, componentName, false, false);

    String selected = configureXml(project, xml, currentFile);
    nodes = configureXmlNodes(context, project, selected, xml, node);

    builder.add(xml).add(node).add(componentName);
}
 
Example 3
Source File: ScaffoldableEntitySelectionWizard.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception
{
   UIContext uiContext = builder.getUIContext();
   Project project = getSelectedProject(uiContext);

   JPAFacet<?> persistenceFacet = project.getFacet(JPAFacet.class);
   List<JavaClassSource> allEntities = persistenceFacet.getAllEntities();
   List<JavaClassSource> supportedEntities = new ArrayList<>();
   for (JavaClassSource entity : allEntities)
   {
      for (Member<?> member : entity.getMembers())
      {
         // FORGE-823 Only add entities with @Id as valid entities for REST resource generation.
         // Composite keys are not yet supported.
         if (member.hasAnnotation(Id.class))
         {
            supportedEntities.add(entity);
         }
      }
   }
   targets.setValueChoices(supportedEntities);
   targets.setItemLabelConverter(JavaClassSource::getQualifiedName);
   builder.add(targets).add(generateRestResources);
}
 
Example 4
Source File: DevOpsEditOptionalStep.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
    public void initializeUI(UIBuilder builder) throws Exception {
        StopWatch watch = new StopWatch();

        final UIContext context = builder.getUIContext();

        letsChat = (LetsChatClient) builder.getUIContext().getAttributeMap().get("letsChatClient");
        taigaClient = (TaigaClient) builder.getUIContext().getAttributeMap().get("taigaClient");

/*        chatRoom.setCompleter(new UICompleter<String>() {
            @Override
            public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
                // TODO: call only once to init getChatRoomNames
                return filterCompletions(getChatRoomNames(), value);
            }
        });
        issueProjectName.setCompleter(new UICompleter<String>() {
            @Override
            public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
                // TODO: call only once to init getIssueProjectNames
                return filterCompletions(getIssueProjectNames(), value);
            }
        });*/

        // lets initialise the data from the current config if it exists
        ProjectConfig config = (ProjectConfig) context.getAttributeMap().get("projectConfig");
        if (config != null) {
            CommandHelpers.setInitialComponentValue(chatRoom, config.getChatRoom());
            CommandHelpers.setInitialComponentValue(issueProjectName, config.getIssueProjectName());
            CommandHelpers.setInitialComponentValue(codeReview, config.getCodeReview());
        }

        builder.add(chatRoom);
        builder.add(issueProjectName);
        builder.add(codeReview);

        LOG.info("initializeUI took " + watch.taken());
    }
 
Example 5
Source File: DevOpsEditStep.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception {
    StopWatch watch = new StopWatch();

    final UIContext context = builder.getUIContext();
    pipeline.setCompleter((context1, input, value) -> getPipelines(context1, true));
    pipeline.setValueConverter(text -> getPipelineForValue(context, text));
    if (getCurrentSelectedProject(context) != null) {
        PipelineDTO defaultValue = getPipelineForValue(context, DEFAULT_MAVEN_FLOW);
        if (defaultValue != null) {
            pipeline.setDefaultValue(defaultValue);
            pipeline.setValue(defaultValue);
        }
    }

    // lets initialise the data from the current config if it exists
    ProjectConfig config = null;
    Project project = getCurrentSelectedProject(context);
    File configFile = getProjectConfigFile(context, getSelectedProject(context));
    if (configFile != null && configFile.exists()) {
        config = ProjectConfigs.parseProjectConfig(configFile);
    }
    if (config != null) {
        PipelineDTO flow = getPipelineForValue(context, config.getPipeline());
        if (flow != null) {
            CommandHelpers.setInitialComponentValue(this.pipeline, flow);
        }
        context.getAttributeMap().put("projectConfig", config);
    }

    hasJenkinsFile = hasLocalJenkinsFile(context, project);
    if (!hasJenkinsFile) {
        builder.add(pipeline);
    }

    log.info("initializeUI took " + watch.taken());
}
 
Example 6
Source File: CamelDeleteNodeXmlCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception {
    UIContext context = builder.getUIContext();
    Project project = getSelectedProject(context);
    String currentFile = getSelectedFile(context);

    String selected = configureXml(project, xml, currentFile);
    nodes = configureXmlNodes(context, project, selected, xml, node);
    builder.add(xml).add(node);
}
 
Example 7
Source File: AddFractionCommand.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception
{
    InputComponentFactory factory = builder.getInputComponentFactory();
    fractionElements = factory.createSelectMany("fractions", FractionDescriptor.class)
                .setLabel("Fraction List")
                .setDescription("Fraction list");

    UIContext uiContext = builder.getUIContext();
    if (uiContext.getProvider().isGUI())
    {
        fractionElements.setItemLabelConverter(FractionDescriptor::getName);
    }
    else
    {
        fractionElements.setItemLabelConverter(FractionDescriptor::getArtifactId);
    }
    Project project = Projects.getSelectedProject(getProjectFactory(), uiContext);
    final Collection<FractionDescriptor> fractions;
    if (project != null && project.hasFacet(ThorntailFacet.class))
    {
        fractions = project.getFacet(ThorntailFacet.class).getFractions();
    }
    else
    {
        fractions = ThorntailFacet.getAllFractionDescriptors();
    }
    final List<FractionDescriptor> nonInternalfractions = fractions.stream()
                .filter(f -> !f.isInternal())
                .collect(Collectors.toList());
    fractionElements.setValueChoices(nonInternalfractions);

    builder.add(fractionElements);
}
 
Example 8
Source File: JSONRestResourceFromEntityCommand.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@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<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");

   RestResourceGenerator defaultResourceGenerator = null;
   for (RestResourceGenerator generator : resourceGenerators)
   {
      if (generator.getName().equals(RestGenerationConstants.JPA_ENTITY))
      {
         defaultResourceGenerator = generator;
      }
   }
   generator.setDefaultValue(defaultResourceGenerator);
   generator.setItemLabelConverter(
            context.getProvider().isGUI() ? RestResourceGenerator::getDescription : RestResourceGenerator::getName);
   builder.add(generator).add(packageName).add(persistenceUnit);
}