protected boolean isGitIgnoreSelected(UIContext context) { return context.getInitialSelection().get() instanceof GitIgnoreResource; }
@Override public boolean accept(UIContext type) { final boolean result; UISelection<Object> initialSelection = type.getInitialSelection(); if (initialSelection.isEmpty()) { result = false; } else { result = initialSelection.get() instanceof JavaResource; } return result; } }
@Override public Result execute(UIExecutionContext context) { UISelection<Resource<?>> initialSelection = context.getUIContext().getInitialSelection(); Resource<?> directory = initialSelection.get(); Iterator<String> argIterator = arguments.getValue().iterator(); FileResource<?> sourceResource = resolveFirstResource(directory, argIterator.next()); FileResource<?> targetResource = resolveFirstResource(directory, argIterator.next()); sourceResource.moveTo(targetResource); return Results.success(); }
if ("~~".equals(token)) UISelection<Object> selection = current.getInitialSelection(); if (!selection.isEmpty())
@Override public Result execute(UIExecutionContext context) throws Exception { UISelection<Resource<?>> initialSelection = context.getUIContext().getInitialSelection(); Resource<?> directory = initialSelection.get(); Iterator<String> argIterator = arguments.getValue().iterator(); Resource<?> sourceResource = resolveFirstResource(directory, argIterator.next()); String targetResource = argIterator.next(); if (isDirectory(sourceResource)) { copyRecursively(sourceResource, directory, targetResource); } else if (isFile(sourceResource)) { copy(sourceResource, directory, targetResource); } else { throw new RuntimeException("cannot copy resource type: " + sourceResource.getClass().getSimpleName()); } return Results.success(); }
/** * @return true if {@link UIContext#getInitialSelection()} returns a path containing a project, false otherwise */ public static boolean containsProject(ProjectFactory projectFactory, UIContext context) { Assert.notNull(projectFactory, "Project Factory cannot be null"); UISelection<?> selection = context.getInitialSelection(); if (!selection.isEmpty() && selection.get() instanceof Resource) { return projectFactory.containsProject((Resource<?>) selection.get()); } return false; }
@Override public Result execute(UIExecutionContext shellContext) throws Exception { UIContext uiContext = shellContext.getUIContext(); UISelection<Resource<?>> selection = uiContext.getInitialSelection(); Resource<?> currentResource = selection.get(); if (currentResource != null) { UIOutput output = uiContext.getProvider().getOutput(); output.out().println(currentResource.getFullyQualifiedName()); } return Results.success(); }
@Override public boolean isEnabled(UIContext context) { boolean enabled = super.isEnabled(context); if (enabled) { Object initialSelection = context.getInitialSelection().get(); if (initialSelection instanceof JavaResource) { try { enabled = ((JavaResource) initialSelection).getJavaType().isClass(); } catch (FileNotFoundException e) { enabled = false; } } else { enabled = false; } } return enabled; }
@Override public Result execute(UIExecutionContext context) throws Exception Resource<?> currentResource = (Resource<?>) context.getUIContext().getInitialSelection().get(); Iterable<String> value = arguments.getValue(); Iterator<String> it = value == null ? Collections.<String> emptyIterator() : value.iterator();
Resource<?> currentResource = (Resource<?>) uiContext.getInitialSelection().get(); try
@Override public Result execute(UIExecutionContext context) throws Exception Resource<?> currentResource = (Resource<?>) context.getUIContext().getInitialSelection().get(); Iterable<String> value = arguments.getValue(); Iterator<String> it = value == null ? Collections.<String> emptyIterator() : value.iterator();
UISelection<Resource> us = context.getUIContext().getInitialSelection(); Resource<?> rs = us.get();
Resource<?> currentResource = (Resource<?>) uiContext.getInitialSelection().get(); Iterator<String> it = arguments.getValue() == null ? Collections.<String> emptyList().iterator() : arguments .getValue().iterator();
@Override public Result execute(UIExecutionContext context) throws Exception { JavaResource javaResource = (JavaResource) context.getUIContext().getInitialSelection().get(); JavaClassSource commandClass = javaResource.getJavaType(); commandClass = createCommand(commandClass, named.getValue(), categories.getValue()); javaResource.setContents(commandClass); return Results.success("Annotated UICommand created"); }
@Override public Result execute(UIExecutionContext context) throws Exception Resource<?> currentResource = (Resource<?>) context.getUIContext().getInitialSelection().get(); for (String path : arguments.getValue())
private void configureTargetLocationInput(InputComponentFactory factory, final UIContext uiContext) { final ResourceFactory resourceFactory = SimpleContainer .getServices(getClass().getClassLoader(), ResourceFactory.class).get(); targetLocation = factory.createInput("targetLocation", DirectoryResource.class).setLabel("Project location"); final DirectoryResource defaultValue; UISelection<Resource<?>> currentSelection = uiContext.getInitialSelection(); if (currentSelection.isEmpty()) { defaultValue = resourceFactory.create(DirectoryResource.class, OperatingSystemUtils.getUserHomeDir()); } else { Resource<?> resource = currentSelection.get(); if (resource instanceof DirectoryResource) { defaultValue = (DirectoryResource) resource; } else { defaultValue = resourceFactory.create(DirectoryResource.class, OperatingSystemUtils.getUserHomeDir()); } } targetLocation.setDefaultValue(defaultValue).setValueConverter(defaultValue::resolveAsDirectory); }
@Override public Result execute(UIExecutionContext context) throws Exception { Resource<?> currentResource = (Resource<?>) context.getUIContext().getInitialSelection().get(); for (String path : arguments.getValue()) { List<Resource<?>> resources = currentResource.resolveChildren(path); for (Resource<?> resource : resources) { if (resource.exists()) { return Results.fail(path + ": Resource already exists."); } else { DirectoryResource directory = resourceFactory.create(DirectoryResource.class, new File(resource.getFullyQualifiedName())); directory.mkdirs(); } } } return Results.success(); }
@Override public void initializeUI(UIBuilder builder) throws Exception { Project project = getSelectedProject(builder); InputComponentFactory inputFactory = builder.getInputComponentFactory(); Furnace furnace = Furnace.instance(getClass().getClassLoader()); AddonRegistry addonRegistry = furnace.getAddonRegistry(); ConverterFactory converterFactory = addonRegistry.getServices(ConverterFactory.class).get(); ProjectOperations projectOperations = addonRegistry.getServices(ProjectOperations.class).get(); List<JavaResource> projectClasses = projectOperations.getProjectClasses(project); targetClasses = inputFactory.createSelectMany("targetClasses", String.class) .setLabel("Target Class") .setDescription("The class where the field will be created").setRequired(true) .setValueChoices( projectClasses.stream() .filter(JavaGenerateSerialVersionUIDCommand::isSerializable) .map(Objects::toString) .collect(Collectors.toList())); UIContext uiContext = builder.getUIContext(); UISelection<Object> initialSelection = uiContext.getInitialSelection(); if (initialSelection.get() instanceof JavaResource) { InputComponents.setValueFor(converterFactory, targetClasses, ((JavaResource) initialSelection.get()).getJavaType().getQualifiedName()); } useDefaultValue = inputFactory.createInput("useDefaultValue", Boolean.class) .setLabel("Generate Default Value?") .setDescription("If true, sets the serialVersionUID field to 1L"); builder.add(targetClasses).add(useDefaultValue); }
UISelection<Object> initialSelection = uiContext.getInitialSelection(); if (initialSelection.get() instanceof JavaResource)
type.setRequired(true); Object selection = builder.getUIContext().getInitialSelection().get(); if (selection instanceof JavaResource) type.setDefaultValue((JavaResource) selection);