@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; } }
/** * @return the project if {@link UISelection#isEmpty()} does not return false, null otherwise */ public static Project getSelectedProject(ProjectFactory projectFactory, UISelection<?> selection) { Assert.notNull(projectFactory, "Project Factory cannot be null"); Project project = null; if (!selection.isEmpty() && selection.get() instanceof Resource) { Resource<?> resource = (Resource<?>) selection.get(); project = projectFactory.findProject(resource); } return project; }
if (!selection.isEmpty())
/** * @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; }
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); }
if (selection != null && !selection.isEmpty())