Java Code Examples for org.eclipse.ui.dialogs.ElementTreeSelectionDialog#addFilter()

The following examples show how to use org.eclipse.ui.dialogs.ElementTreeSelectionDialog#addFilter() . 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: TestabilityLaunchConfigurationTab.java    From testability-explorer with Apache License 2.0 5 votes vote down vote up
private void setUpWhitelistPackagesDialog() {
  IJavaProject project = getSelectedProject();
  ElementTreeSelectionDialog dialog =
      new ElementTreeSelectionDialog(getControl().getShell(),
          new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_BASICS),
          new JavaPackageElementContentProvider());
  dialog.setInput(project);
  dialog.addFilter(new ViewerFilter() {

    @Override
    public boolean select(Viewer viewer, Object parentElement, Object element) {
      if (element instanceof IPackageFragment) {
        return !((IPackageFragment) element).getElementName().equals("");
      }
      if (element instanceof ICompilationUnit) {
        return false;
      }
      return true;
    }
    
  });
  dialog.setMessage("Choose packages to whitelist:");

  if (dialog.open() == Window.OK) {
    Object[] results = dialog.getResult();
    String[] stringArray = new String[results.length];
    for (int i = 0; i < results.length; i++) {
      if (results[i] instanceof IJavaElement) {
        stringArray[i] = ((IJavaElement) results[i]).getElementName();
      }
    }
    whiteListList.add(stringArray);
    setTabDirty();
  }
}
 
Example 2
Source File: JarManifestWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates and returns a dialog to choose an existing workspace file.
 * @param title the title
 * @param message the dialog message
 * @return the dialog
 */
protected ElementTreeSelectionDialog createWorkspaceFileSelectionDialog(String title, String message) {
	int labelFlags= JavaElementLabelProvider.SHOW_BASICS
					| JavaElementLabelProvider.SHOW_OVERLAY_ICONS
					| JavaElementLabelProvider.SHOW_SMALL_ICONS;
	final DecoratingLabelProvider provider= new DecoratingLabelProvider(new JavaElementLabelProvider(labelFlags), new ProblemsLabelDecorator(null));
	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), provider, new StandardJavaElementContentProvider());
	dialog.setComparator(new JavaElementComparator());
	dialog.setAllowMultiple(false);
	dialog.setValidator(new ISelectionStatusValidator() {
		public IStatus validate(Object[] selection) {
			StatusInfo res= new StatusInfo();
			// only single selection
			if (selection.length == 1 && (selection[0] instanceof IFile))
				res.setOK();
			else
				res.setError(""); //$NON-NLS-1$
			return res;
		}
	});
	dialog.addFilter(new EmptyInnerPackageFilter());
	dialog.addFilter(new LibraryFilter());
	dialog.setTitle(title);
	dialog.setMessage(message);
	dialog.setStatusLineAboveButtons(true);
	dialog.setInput(JavaCore.create(JavaPlugin.getWorkspace().getRoot()));
	return dialog;
}
 
Example 3
Source File: NativeLibrariesConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String chooseInternal() {
	String initSelection= fPathField.getText();

	ILabelProvider lp= new WorkbenchLabelProvider();
	ITreeContentProvider cp= new WorkbenchContentProvider();
	Class<?>[] acceptedClasses= new Class[] { IProject.class, IFolder.class };
	TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, true);
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses);

	IResource initSel= null;
	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
	if (initSelection.length() > 0) {
		initSel= root.findMember(new Path(initSelection));
	}
	if (initSel == null) {
		initSel= root.findMember(fEntry.getPath());
	}

	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(fShell, lp, cp);
	dialog.setAllowMultiple(false);
	dialog.setValidator(validator);
	dialog.addFilter(filter);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	dialog.setTitle(NewWizardMessages.NativeLibrariesDialog_intfiledialog_title);
	dialog.setMessage(NewWizardMessages.NativeLibrariesDialog_intfiledialog_message);
	dialog.setInput(root);
	dialog.setInitialSelection(initSel);
	dialog.setHelpAvailable(false);
	if (dialog.open() == Window.OK) {
		IResource res= (IResource) dialog.getFirstResult();
		return res.getFullPath().makeRelative().toString();
	}
	return null;
}
 
Example 4
Source File: NewSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IFolder chooseFolder(String title, String message, IPath initialPath) {
	Class<?>[] acceptedClasses= new Class[] { IFolder.class };
	ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, null);

	ILabelProvider lp= new WorkbenchLabelProvider();
	ITreeContentProvider cp= new WorkbenchContentProvider();

	IProject currProject= fCurrJProject.getProject();

	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), lp, cp);
	dialog.setValidator(validator);
	dialog.setTitle(title);
	dialog.setMessage(message);
	dialog.addFilter(filter);
	dialog.setInput(currProject);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	IResource res= currProject.findMember(initialPath);
	if (res != null) {
		dialog.setInitialSelection(res);
	}

	if (dialog.open() == Window.OK) {
		return (IFolder) dialog.getFirstResult();
	}
	return null;
}
 
Example 5
Source File: AddSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IFolder chooseFolder(String title, String message, IPath initialPath) {
	Class<?>[] acceptedClasses= new Class[] { IFolder.class };
	ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, null);

	ILabelProvider lp= new WorkbenchLabelProvider();
	ITreeContentProvider cp= new WorkbenchContentProvider();

	IProject currProject= fNewElement.getJavaProject().getProject();

	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), lp, cp) {
		@Override
		protected Control createDialogArea(Composite parent) {
			Control result= super.createDialogArea(parent);
			PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJavaHelpContextIds.BP_CHOOSE_EXISTING_FOLDER_TO_MAKE_SOURCE_FOLDER);
			return result;
		}
	};
	dialog.setValidator(validator);
	dialog.setTitle(title);
	dialog.setMessage(message);
	dialog.addFilter(filter);
	dialog.setInput(currProject);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	IResource res= currProject.findMember(initialPath);
	if (res != null) {
		dialog.setInitialSelection(res);
	}

	if (dialog.open() == Window.OK) {
		return (IFolder) dialog.getFirstResult();
	}
	return null;
}
 
Example 6
Source File: JarManifestWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a selection dialog that lists all packages under the given package
 * fragment root.
 * The caller is responsible for opening the dialog with <code>Window.open</code>,
 * and subsequently extracting the selected packages (of type
 * <code>IPackageFragment</code>) via <code>SelectionDialog.getResult</code>.
 *
 * @param packageFragments the package fragments
 * @return a new selection dialog
 */
protected SelectionDialog createPackageDialog(Set<IJavaElement> packageFragments) {
	List<IPackageFragment> packages= new ArrayList<IPackageFragment>(packageFragments.size());
	for (Iterator<IJavaElement> iter= packageFragments.iterator(); iter.hasNext();) {
		IPackageFragment fragment= (IPackageFragment)iter.next();
		boolean containsJavaElements= false;
		int kind;
		try {
			kind= fragment.getKind();
			containsJavaElements= fragment.getChildren().length > 0;
		} catch (JavaModelException ex) {
			ExceptionHandler.handle(ex, getContainer().getShell(), JarPackagerMessages.JarManifestWizardPage_error_jarPackageWizardError_title, Messages.format(JarPackagerMessages.JarManifestWizardPage_error_jarPackageWizardError_message, JavaElementLabels.getElementLabel(fragment, JavaElementLabels.ALL_DEFAULT)));
			continue;
		}
		if (kind != IPackageFragmentRoot.K_BINARY && containsJavaElements)
			packages.add(fragment);
	}
	StandardJavaElementContentProvider cp= new StandardJavaElementContentProvider() {
		@Override
		public boolean hasChildren(Object element) {
			// prevent the + from being shown in front of packages
			return !(element instanceof IPackageFragment) && super.hasChildren(element);
		}
	};
	final DecoratingLabelProvider provider= new DecoratingLabelProvider(new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), new ProblemsLabelDecorator(null));
	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getContainer().getShell(), provider, cp);
	dialog.setDoubleClickSelects(false);
	dialog.setComparator(new JavaElementComparator());
	dialog.setInput(JavaCore.create(JavaPlugin.getWorkspace().getRoot()));
	dialog.addFilter(new EmptyInnerPackageFilter());
	dialog.addFilter(new LibraryFilter());
	dialog.addFilter(new SealPackagesFilter(packages));
	dialog.setValidator(new ISelectionStatusValidator() {
		public IStatus validate(Object[] selection) {
			StatusInfo res= new StatusInfo();
			for (int i= 0; i < selection.length; i++) {
				if (!(selection[i] instanceof IPackageFragment)) {
					res.setError(JarPackagerMessages.JarManifestWizardPage_error_mustContainPackages);
					return res;
				}
			}
			res.setOK();
			return res;
		}
	});
	return dialog;
}