Search in sources :

Example 1 with TypedElementSelectionValidator

use of org.erlide.ui.util.TypedElementSelectionValidator in project erlide_eclipse by erlang.

the class DirectorySelectUtil method chooseLocation.

public static IContainer chooseLocation(final String dialogTitle, final String labelText, final IProject project2, final String outputLocation, final Shell shell) {
    final IWorkspaceRoot root = project2.getWorkspace().getRoot();
    final Class<?>[] acceptedClasses = new Class[] { IProject.class, IFolder.class };
    final IProject[] allProjects = root.getProjects();
    final List<IProject> rejectedElements = new ArrayList<>(allProjects.length);
    for (IProject allProject : allProjects) {
        if (!allProject.equals(project2)) {
            rejectedElements.add(allProject);
        }
    }
    final ViewerFilter filter = new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());
    final ILabelProvider lp = new WorkbenchLabelProvider();
    final ITreeContentProvider cp = new WorkbenchContentProvider();
    IResource initSelection = null;
    if (outputLocation != null) {
        initSelection = root.findMember(outputLocation);
    }
    final FolderSelectionDialog dialog = new FolderSelectionDialog(shell, lp, cp);
    dialog.setTitle(dialogTitle);
    final ISelectionStatusValidator validator = new ISelectionStatusValidator() {

        ISelectionStatusValidator myValidator = new TypedElementSelectionValidator(acceptedClasses, false);

        @Override
        public IStatus validate(final Object[] selection) {
            final IStatus typedStatus = myValidator.validate(selection);
            if (!typedStatus.isOK()) {
                return typedStatus;
            }
            if (selection[0] instanceof IFolder) {
                // }
                return new StatusInfo();
            }
            return new StatusInfo(IStatus.ERROR, "");
        }
    };
    dialog.setValidator(validator);
    dialog.setMessage(labelText);
    dialog.addFilter(filter);
    dialog.setInput(root);
    dialog.setInitialSelection(initSelection);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (dialog.open() == Window.OK) {
        return (IContainer) dialog.getFirstResult();
    }
    return null;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TypedViewerFilter(org.erlide.ui.util.TypedViewerFilter) ArrayList(java.util.ArrayList) FolderSelectionDialog(org.erlide.ui.util.FolderSelectionDialog) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TypedElementSelectionValidator(org.erlide.ui.util.TypedElementSelectionValidator) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) StatusInfo(org.erlide.ui.util.StatusInfo) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) TypedViewerFilter(org.erlide.ui.util.TypedViewerFilter)

Aggregations

ArrayList (java.util.ArrayList)1 IContainer (org.eclipse.core.resources.IContainer)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IStatus (org.eclipse.core.runtime.IStatus)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)1 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)1 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)1 ResourceComparator (org.eclipse.ui.views.navigator.ResourceComparator)1 FolderSelectionDialog (org.erlide.ui.util.FolderSelectionDialog)1 StatusInfo (org.erlide.ui.util.StatusInfo)1 TypedElementSelectionValidator (org.erlide.ui.util.TypedElementSelectionValidator)1 TypedViewerFilter (org.erlide.ui.util.TypedViewerFilter)1