public static Set<String> getPossibleProfileIds( NewLiferayPluginProjectOp op, boolean includeNewProfiles) { final String activeProfilesValue = op.getActiveProfilesValue().content(); final Path currentLocation = op.getLocation().content(); final File param = currentLocation != null ? currentLocation.toFile() : null; final List<String> systemProfileIds = op.getProjectProvider().content().getData("profileIds", String.class, param); final ElementList<NewLiferayProfile> newLiferayProfiles = op.getNewLiferayProfiles(); final Set<String> possibleProfileIds = new HashSet<String>(); if (!CoreUtil.isNullOrEmpty(activeProfilesValue)) { final String[] vals = activeProfilesValue.split(","); if (!CoreUtil.isNullOrEmpty(vals)) { for (String val : vals) { if (!possibleProfileIds.contains(val) && !val.contains(StringPool.SPACE)) { possibleProfileIds.add(val); } } } } if (!CoreUtil.isNullOrEmpty(systemProfileIds)) { for (Object systemProfileId : systemProfileIds) { if (systemProfileId != null) { final String val = systemProfileId.toString(); if (!possibleProfileIds.contains(val) && !val.contains(StringPool.SPACE)) { possibleProfileIds.add(val); } } } } if (includeNewProfiles) { for (NewLiferayProfile newLiferayProfile : newLiferayProfiles) { final String newId = newLiferayProfile.getId().content(); if ((!CoreUtil.isNullOrEmpty(newId)) && (!possibleProfileIds.contains(newId)) && (!newId.contains(StringPool.SPACE))) { possibleProfileIds.add(newId); } } } return possibleProfileIds; }
@Override protected String browse(final SapphireRenderingContext context) { final Property property = property(); final List<Path> roots = getBasePaths(); String selectedAbsolutePath = null; final List<String> extensions; if (this.fileExtensionService == null) { extensions = this.staticFileExtensionsList; } else { extensions = this.fileExtensionService.extensions(); } if (enclosed()) { final List<IContainer> baseContainers = new ArrayList<IContainer>(); for (Path path : roots) { final IContainer baseContainer = getWorkspaceContainer(path.toFile()); if (baseContainer != null) { baseContainers.add(baseContainer); } else { break; } } final ITreeContentProvider contentProvider; final ILabelProvider labelProvider; final ViewerComparator viewerComparator; final Object input; if (roots.size() == baseContainers.size()) { // All paths are in the Eclipse Workspace. Use the available content and label // providers. contentProvider = new WorkspaceContentProvider(baseContainers); labelProvider = new WorkbenchLabelProvider(); viewerComparator = new ResourceComparator(); input = ResourcesPlugin.getWorkspace().getRoot(); } else { // At least one of the roots is not in the Eclipse Workspace. Use custom file // system content and label providers. contentProvider = new FileSystemContentProvider(roots); labelProvider = new FileSystemLabelProvider(context); viewerComparator = new FileSystemNodeComparator(); input = new Object(); } final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(context.getShell(), labelProvider, contentProvider); dialog.setTitle(property.definition().getLabel(false, CapitalizationType.TITLE_STYLE, false)); dialog.setMessage( createBrowseDialogMessage( property.definition().getLabel(true, CapitalizationType.NO_CAPS, false))); dialog.setAllowMultiple(false); dialog.setHelpAvailable(false); dialog.setInput(input); dialog.setComparator(viewerComparator); final Path currentPathAbsolute = convertToAbsolute((Path) ((Value<?>) property).content()); if (currentPathAbsolute != null) { Object initialSelection = null; if (contentProvider instanceof WorkspaceContentProvider) { final URI uri = currentPathAbsolute.toFile().toURI(); final IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); final IFile[] files = wsroot.findFilesForLocationURI(uri); if (files.length > 0) { final IFile file = files[0]; if (file.exists()) { initialSelection = file; } } if (initialSelection == null) { final IContainer[] containers = wsroot.findContainersForLocationURI(uri); if (containers.length > 0) { final IContainer container = containers[0]; if (container.exists()) { initialSelection = container; } } } } else { initialSelection = ((FileSystemContentProvider) contentProvider).find(currentPathAbsolute); } if (initialSelection != null) { dialog.setInitialSelection(initialSelection); } } if (this.type == FileSystemResourceType.FILE) { dialog.setValidator(new FileSelectionStatusValidator()); } else if (this.type == FileSystemResourceType.FOLDER) { dialog.addFilter(new ContainersOnlyViewerFilter()); } if (!extensions.isEmpty()) { dialog.addFilter(new ExtensionBasedViewerFilter(extensions)); } if (dialog.open() == Window.OK) { final Object firstResult = dialog.getFirstResult(); if (firstResult instanceof IResource) { selectedAbsolutePath = ((IResource) firstResult).getLocation().toString(); } else { selectedAbsolutePath = ((FileSystemNode) firstResult).getFile().getPath(); } } } else if (this.type == FileSystemResourceType.FOLDER) { final DirectoryDialog dialog = new DirectoryDialog(context.getShell()); dialog.setText( property.definition().getLabel(true, CapitalizationType.FIRST_WORD_ONLY, false)); dialog.setMessage( createBrowseDialogMessage( property.definition().getLabel(true, CapitalizationType.NO_CAPS, false))); final Value<?> value = (Value<?>) property; final Path path = (Path) value.content(); if (path != null) { dialog.setFilterPath(path.toOSString()); } else if (roots.size() > 0) { dialog.setFilterPath(roots.get(0).toOSString()); } selectedAbsolutePath = dialog.open(); } else { final FileDialog dialog = new FileDialog(context.getShell()); dialog.setText( property.definition().getLabel(true, CapitalizationType.FIRST_WORD_ONLY, false)); final Value<?> value = (Value<?>) property; final Path path = (Path) value.content(); if (path != null && path.segmentCount() > 1) { dialog.setFilterPath(path.removeLastSegments(1).toOSString()); dialog.setFileName(path.lastSegment()); } else if (roots.size() > 0) { dialog.setFilterPath(roots.get(0).toOSString()); } if (!extensions.isEmpty()) { final StringBuilder buf = new StringBuilder(); for (String extension : extensions) { if (buf.length() > 0) { buf.append(';'); } buf.append("*."); buf.append(extension); } dialog.setFilterExtensions(new String[] {buf.toString()}); } selectedAbsolutePath = dialog.open(); } if (selectedAbsolutePath != null) { final Path relativePath = convertToRelative(new Path(selectedAbsolutePath)); if (relativePath != null) { String result = relativePath.toPortableString(); if (this.includeLeadingSlash) { result = "/" + result; } return result; } } return null; }