protected void handleScanButtonPressed() { ScannedFilesContentProvider contentProvider = new ScannedFilesContentProvider(suffixesText.getText()); CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog( SpringUIUtils.getStandardDisplay().getActiveShell(), new ScannedFilesLabelProvider(), contentProvider) { @Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Label note = new Label(composite, SWT.WRAP); note.setText(BeansUIPlugin.getResourceString(SCAN_NOTE_LABEL)); note.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return composite; } }; dialog.setTitle(BeansUIPlugin.getResourceString(DIALOG_TITLE)); dialog.setMessage(BeansUIPlugin.getResourceString(DIALOG_MESSAGE)); dialog.addFilter(new ConfigFileFilter(project.getConfigSuffixes())); dialog.setValidator(new StorageSelectionValidator(true)); dialog.setInput(project.getProject()); dialog.setSorter(new JavaElementSorter()); dialog.setInitialSelections(contentProvider.getElements(project.getProject())); if (dialog.open() == Window.OK) { Object[] selection = dialog.getResult(); if (selection != null && selection.length > 0) { for (Object element : selection) { String config; if (element instanceof ZipEntryStorage) { ZipEntryStorage storage = (ZipEntryStorage) element; config = storage.getFullName(); } else { IFile file = (IFile) element; config = file.getProjectRelativePath().toString(); } project.addConfig(config, IBeansConfig.Type.MANUAL); } configsViewer.refresh(false); hasUserMadeChanges = true; } } }
/** * The user has pressed the add button. Opens the configuration selection dialog and adds the * selected configuration. */ private void handleAddButtonPressed() { SelectionStatusDialog dialog; if (SpringCoreUtils.isEclipseSameOrNewer(3, 2)) { FilteredElementTreeSelectionDialog selDialog = new FilteredElementTreeSelectionDialog( SpringUIUtils.getStandardDisplay().getActiveShell(), new LabelProvider(), new NonJavaResourceContentProvider()); selDialog.addFilter(new ConfigFileFilter(project.getConfigSuffixes())); selDialog.setValidator(new StorageSelectionValidator(true)); selDialog.setInput(project.getProject()); selDialog.setSorter(new JavaElementSorter()); dialog = selDialog; } else { ElementTreeSelectionDialog selDialog = new ElementTreeSelectionDialog( SpringUIUtils.getStandardDisplay().getActiveShell(), new LabelProvider(), new NonJavaResourceContentProvider()); selDialog.addFilter(new ConfigFileFilter(project.getConfigSuffixes())); selDialog.setValidator(new StorageSelectionValidator(true)); selDialog.setInput(project.getProject()); selDialog.setSorter(new JavaElementSorter()); dialog = selDialog; } dialog.setTitle(BeansUIPlugin.getResourceString(DIALOG_TITLE)); dialog.setMessage(BeansUIPlugin.getResourceString(DIALOG_MESSAGE)); if (dialog.open() == Window.OK) { Object[] selection = dialog.getResult(); if (selection != null && selection.length > 0) { for (Object element : selection) { String config = null; if (element instanceof ZipEntryStorage) { ZipEntryStorage storage = (ZipEntryStorage) element; config = storage.getFullName(); } else if (element instanceof IFile) { IFile file = (IFile) element; config = file.getProjectRelativePath().toString(); } else if (element instanceof JarEntryFile) { IPath fullPath = ((JarPackageFragmentRoot) ((JarEntryFile) element).getPackageFragmentRoot()) .getPath(); String entryName = ((JarEntryFile) element).getFullPath().toString(); for (String name : JavaCore.getClasspathVariableNames()) { IPath variablePath = JavaCore.getClasspathVariable(name); if (variablePath != null && variablePath.isPrefixOf(fullPath)) { if (MessageDialog.openQuestion( SpringUIUtils.getStandardDisplay().getActiveShell(), "Use classpath variable", "Do you want to use the classpath variable '" + name + "' to refer to the config file\n'" + entryName + "'?")) { fullPath = new Path(name) .append(fullPath.removeFirstSegments(variablePath.segmentCount())); } break; } } config = IBeansConfig.EXTERNAL_FILE_NAME_PREFIX + fullPath.toString() + ZipEntryStorage.DELIMITER + entryName; } if (config != null) { project.addConfig(config, IBeansConfig.Type.MANUAL); } } configsViewer.refresh(false); hasUserMadeChanges = true; } } }