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

The following examples show how to use org.jboss.forge.addon.ui.context.UIContext. 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: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected CurrentLineCompleter createCurrentLineCompleter(int lineNumber, String file, UIContext context) throws Exception {
    Project project = getSelectedProject(context);

    JavaSourceFacet sourceFacet = null;
    ResourcesFacet resourcesFacet = null;
    WebResourcesFacet webResourcesFacet = null;
    if (project.hasFacet(JavaSourceFacet.class)) {
        sourceFacet = project.getFacet(JavaSourceFacet.class);
    }
    if (project.hasFacet(ResourcesFacet.class)) {
        resourcesFacet = project.getFacet(ResourcesFacet.class);
    }
    if (project.hasFacet(WebResourcesFacet.class)) {
        webResourcesFacet = project.getFacet(WebResourcesFacet.class);
    }

    String relativeFile = asRelativeFile(context, file);
    return new CurrentLineCompleter(lineNumber, relativeFile, sourceFacet, resourcesFacet, webResourcesFacet);
}
 
Example #2
Source File: CamelContextCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
    List<String> answer = new ArrayList<>();
    try {
        List<Map<String, String>> contexts = controller.getCamelContexts();
        for (Map<String, String> row : contexts) {
            final String name = row.get("name");
            if (value == null || name.startsWith(value)) {
                answer.add(name);
            }
        }
    } catch (Exception e) {
        // ignore
    }

    Collections.sort(answer);
    return answer;
}
 
Example #3
Source File: ReplicationControllerDelete.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception {
    super.initializeUI(builder);

    // populate autocompletion options
    replicationControllerId.setCompleter(new UICompleter<String>() {
        @Override
        public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
            List<String> list = new ArrayList<String>();
            ReplicationControllerList replicationControllers = getKubernetes().replicationControllers().inNamespace(getNamespace()).list();
            if (replicationControllers != null) {
                List<ReplicationController> items = replicationControllers.getItems();
                if (items != null) {
                    for (ReplicationController item : items) {
                        String id = KubernetesHelper.getName(item);
                        list.add(id);
                    }
                }
            }
            Collections.sort(list);
            return list;
        }
    });

    builder.add(replicationControllerId);
}
 
Example #4
Source File: CamelDeleteNodeXmlCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEnabled(UIContext context) {
    boolean enabled = super.isEnabled(context);
    if (enabled) {
        // we should only be enabled in non gui
        boolean gui = isRunningInGui(context);
        enabled = !gui;
    }
    if (enabled) {
        // must have xml files with camel routes to be enabled
        Project project = getSelectedProject(context);
        String currentFile = getSelectedFile(context);
        String selected = configureXml(project, xml, currentFile);
        return selected != null;
    }
    return false;
}
 
Example #5
Source File: CamelAddEndpointXmlCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEnabled(UIContext context) {
    boolean enabled = super.isEnabled(context);
    if (enabled) {
        // we should only be enabled in non gui
        boolean gui = isRunningInGui(context);
        enabled = !gui;
    }
    if (enabled) {
        // must have xml files with camel routes to be enabled
        Project project = getSelectedProject(context);
        String currentFile = getSelectedFile(context);
        String selected = configureXml(project, xml, currentFile);
        return selected != null;
    }
    return false;
}
 
Example #6
Source File: CamelAddNodeXmlCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEnabled(UIContext context) {
    // TODO: Allow to add in GUI from current cursor position
    boolean enabled = super.isEnabled(context);
    if (enabled) {
        // we should only be enabled in non gui
        boolean gui = isRunningInGui(context);
        enabled = !gui;
    }
    if (enabled) {
        // must have xml files with camel routes to be enabled
        Project project = getSelectedProject(context);
        String currentFile = getSelectedFile(context);
        String selected = configureXml(project, xml, currentFile);
        return selected != null;
    }
    return false;
}
 
Example #7
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected String asRelativeFile(UIContext context, String currentFile) {
    Project project = getSelectedProject(context);

    JavaSourceFacet javaSourceFacet = null;
    ResourcesFacet resourcesFacet = null;
    WebResourcesFacet webResourcesFacet = null;
    if (project.hasFacet(JavaSourceFacet.class)) {
        javaSourceFacet = project.getFacet(JavaSourceFacet.class);
    }
    if (project.hasFacet(ResourcesFacet.class)) {
        resourcesFacet = project.getFacet(ResourcesFacet.class);
    }
    if (project.hasFacet(WebResourcesFacet.class)) {
        webResourcesFacet = project.getFacet(WebResourcesFacet.class);
    }
    return asRelativeFile(currentFile, javaSourceFacet, resourcesFacet, webResourcesFacet);
}
 
Example #8
Source File: CamelEipsLabelCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<String> getCompletionProposals(UIContext context, InputComponent input, String value) {
    if (core == null) {
        return null;
    }

    // find all available component labels
    Iterable<String> names = getValueChoices();

    List<String> filtered = new ArrayList<String>();
    for (String name : names) {
        if (value == null || name.startsWith(value)) {
            filtered.add(name);
        }
    }

    return filtered;
}
 
Example #9
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 #10
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected int getCurrentCursorLine(UIContext context) {
    int answer = -1;
    Optional<UIRegion<Object>> region = context.getSelection().getRegion();
    if (region.isPresent()) {
        answer = region.get().getStartLine();
    }
    return answer;
}
 
Example #11
Source File: DevOpsEditStep.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public UICommandMetadata getMetadata(UIContext context) {
    return Metadata.forCommand(getClass())
            .category(Categories.create(AbstractDevOpsCommand.CATEGORY))
            .name(AbstractDevOpsCommand.CATEGORY + ": Configure Pipeline")
            .description("Configure the Pipeline for the new project");
}
 
Example #12
Source File: CurrentLineCompleter.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<String> getCompletionProposals(UIContext uiContext, InputComponent<?, String> inputComponent, String value) {
    List<String> answer = new ArrayList<String>();

    if (line != null && (value == null || line.startsWith(value))) {
        answer.add(line);
    }

    return answer;
}
 
Example #13
Source File: CamelXmlHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static List<ContextDto> loadCamelContext(CamelCatalog camelCatalog, UIContext context, Project project, String xmlResourceName) throws Exception {
    List<ContextDto> camelContexts = null;

    // try with src/main/resources or src/main/webapp/WEB-INF
    String xmlFileName = joinPaths("src/main/resources", xmlResourceName);
    File xmlFile = CommandHelpers.getProjectContextFile(context, project, xmlFileName);
    if (!Files.isFile(xmlFile)) {
        xmlFileName = joinPaths("src/main/webapp/", xmlResourceName);
        xmlFile = CommandHelpers.getProjectContextFile(context, project, xmlFileName);
    }
    if (Files.isFile(xmlFile)) {
        camelContexts = parseCamelContexts(camelCatalog, xmlFile);
    }
    return camelContexts;
}
 
Example #14
Source File: DevOpsEditCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public UICommandMetadata getMetadata(UIContext context) {
    return Metadata.forCommand(getClass())
            .category(Categories.create(AbstractDevOpsCommand.CATEGORY))
            .name(AbstractDevOpsCommand.CATEGORY + ": Edit")
            .description("Edit the DevOps configuration for this project");
}
 
Example #15
Source File: NewIntegrationTestBuildCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public UICommandMetadata getMetadata(UIContext context) {
    return Metadata.from(super.getMetadata(context), getClass())
            .category(Categories.create(CATEGORY))
            .name(CATEGORY + ": New Integration Test Build")
            .description("Create a new integration test build configuration");
}
 
Example #16
Source File: StringCompleter.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<String> getCompletionProposals(UIContext context, InputComponent input, String value) {
    List<String> answer = new ArrayList<String>();
    for (String name : valueSet) {
        if (value == null || value.isEmpty() || name.contains(value)) {
            answer.add(name);
        }
    }

    return answer;
}
 
Example #17
Source File: SetupCommand.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public UICommandMetadata getMetadata(UIContext context)
{
   return Metadata.from(super.getMetadata(context), getClass()).name("Thorntail: Setup")
            .description("Setup Thorntail in your web application")
            .category(Categories.create("Thorntail"));
}
 
Example #18
Source File: NewIntegrationTestClassCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled(UIContext context) {
    // must be fabric8 and java project
    boolean answer = isFabric8Project(getSelectedProjectOrNull(context));
    if (answer) {
        Project project = getCurrentSelectedProject(context);
        answer = project.hasFacet(JavaSourceFacet.class);
    }
    return answer;
}
 
Example #19
Source File: GetOverviewCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    StopWatch watch = new StopWatch();
    UIContext uiContext = context.getUIContext();
    ProjectOverviewDTO projectOverview = getProjectOverview(uiContext);
    String result = formatResult(projectOverview);
    log.info("execute took " + watch.taken());
    return Results.success(result);
}
 
Example #20
Source File: ScanClassesCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public UICommandMetadata getMetadata(UIContext context)
{
	return Metadata
			.forCommand(getClass())
			.name("Introspector: Scan classes")
			.description("Find/filter available classes in the project")
			.category(Categories.create("Introspector"));
}
 
Example #21
Source File: DevOpsSave.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
private static String getFlowContent(String flow, UIContext context) {
    File dir = getJenkinsWorkflowFolder(context);
    if (dir != null) {
        File file = new File(dir, flow);
        if (file.isFile() && file.exists()) {
            try {
                return IOHelpers.readFully(file);
            } catch (IOException e) {
                LOG.warn("Failed to load local pipeline " + file + ". " + e, e);
            }
        }
    }
    return null;
}
 
Example #22
Source File: WindupUpdateDistributionCommand.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public UICommandMetadata getMetadata(UIContext ctx)
{
    return Metadata.forCommand(getClass()).name(Util.WINDUP_BRAND_NAME_LONG +" CLI Update Distribution")
            .description("Update the whole "+ Util.WINDUP_BRAND_NAME_LONG +" CLI installation")
            .category(Categories.create("Platform", "Migration"));
}
 
Example #23
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected boolean isSelectedFileXml(UIContext context) {
    Optional<UIRegion<Object>> region = context.getSelection().getRegion();
    if (region.isPresent()) {
        Object resource = region.get().getResource();
        if (resource instanceof FileResource) {
            return ((FileResource) resource).getFullyQualifiedName().endsWith(".xml");
        }
    }
    return false;
}
 
Example #24
Source File: CamelGetComponentsCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled(UIContext context) {
    boolean answer = super.isEnabled(context);
    if (answer) {
        // we should only be enabled in non gui
        boolean gui = isRunningInGui(context);
        answer = !gui;
    }
    return answer;
}
 
Example #25
Source File: AbstractDevOpsCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected boolean hasProjectFile(UIContext context, String fileName) {
    UISelection<Object> selection = context.getSelection();
    if (selection != null) {
        Object object = selection.get();
        if (object instanceof Resource) {
            File folder = ResourceUtil.getContextFile((Resource<?>) object);
            if (folder != null && Files.isDirectory(folder)) {
                File file = new File(folder, fileName);
                return file != null && file.exists() && file.isFile();
            }
        }
    }
    return false;
}
 
Example #26
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);
}
 
Example #27
Source File: CamelAddEndpointCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled(UIContext context) {
    boolean answer = super.isEnabled(context);
    if (answer) {
        if (isRunningInGui(context)) {
            // we are only enabled if there is a file open in the editor and we have a cursor position
            int pos = getCurrentCursorPosition(context);
            answer = pos > -1;
        }
    }
    return answer;
}
 
Example #28
Source File: ServicesList.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public UICommandMetadata getMetadata(UIContext context) {
    return Metadata.from(super.getMetadata(context), getClass())
            .category(Categories.create(CATEGORY))
            .name(CATEGORY + ": Service List")
            .description("Lists the services in a kubernetes cloud");
}
 
Example #29
Source File: PodDelete.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public UICommandMetadata getMetadata(UIContext context) {
    return Metadata.from(super.getMetadata(context), getClass())
            .category(Categories.create(CATEGORY))
            .name(CATEGORY + ": Pod Delete")
            .description("Deletes the given pod from the kubernetes cloud");
}
 
Example #30
Source File: AbstractPodCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception {
    super.initializeUI(builder);

    // populate autocompletion options
    podId.setCompleter(new UICompleter<String>() {
        @Override
        public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
            List<String> list = new ArrayList<String>();
            PodList pods = getKubernetes().pods().list();
            if (pods != null) {
                List<Pod> items = pods.getItems();
                if (items != null) {
                    for (Pod item : items) {
                        String id = KubernetesHelper.getName(item);
                        list.add(id);
                    }
                }
            }
            Collections.sort(list);
            System.out.println("Completion list is " + list);
            return list;
        }
    });

    builder.add(podId);
}