org.eclipse.ui.views.navigator.ResourceComparator Java Examples

The following examples show how to use org.eclipse.ui.views.navigator.ResourceComparator. 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: HiveTab.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void chooseWorkspace ()
{
    final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog ( getShell (), new WorkbenchLabelProvider (), new WorkbenchContentProvider () );
    dialog.setTitle ( "Select driver exporter configuration file" );
    dialog.setMessage ( "Choose a driver exporter file for the configuration" );
    dialog.setInput ( ResourcesPlugin.getWorkspace ().getRoot () );
    dialog.setComparator ( new ResourceComparator ( ResourceComparator.NAME ) );
    dialog.setAllowMultiple ( true );
    dialog.setDialogBoundsSettings ( getDialogBoundsSettings ( HiveTab.WORKSPACE_SELECTION_DIALOG ), Dialog.DIALOG_PERSISTSIZE );
    if ( dialog.open () == IDialogConstants.OK_ID )
    {
        final IResource resource = (IResource)dialog.getFirstResult ();
        if ( resource != null )
        {
            final String arg = resource.getFullPath ().toString ();
            final String fileLoc = VariablesPlugin.getDefault ().getStringVariableManager ().generateVariableExpression ( "workspace_loc", arg ); //$NON-NLS-1$
            this.fileText.setText ( fileLoc );
            makeDirty ();
        }
    }
}
 
Example #2
Source File: ResourceTreeSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Constructs an instance of <code>ResourceTreeSelectionDialog</code>.
 * 
 * @param parent the parent shell for the dialog
 * @param title dialog title
 * @param message dialog message
 * @param rootResource resource that serves as the root of the tree. This
 *          resource's descendants are visible in the tree, but the root
 *          itself is not.
 * @param initialResource the initially-selected resource
 * @param visibleResourceTypes a set of {@link IResource} types that are
 *          visible in the tree (e.g.
 *          <code>IResource.FILE | IResource.FOLDER</code>)
 * @param acceptedResourceTypes a set of {@link IResource} types that can be
 *          selected
 * @param multiSelection whether or not to allow selection of multiple
 *          resources
 */
public ResourceTreeSelectionDialog(Shell parent, String title,
    String message, IContainer rootResource, IResource initialResource,
    int visibleResourceTypes, int acceptedResourceTypes,
    boolean multiSelection) {
  super(parent, new WorkbenchLabelProvider(), new WorkbenchContentProvider());

  setTitle(title);
  setMessage(message);
  setHelpAvailable(false);

  setInput(rootResource);
  if (initialResource != null) {
    setInitialSelection(initialResource);
  }
  setComparator(new ResourceComparator(ResourceComparator.NAME));
  setValidator(new ResourceFilter(acceptedResourceTypes, multiSelection));
  addFilter(new ResourceFilter(visibleResourceTypes));
}
 
Example #3
Source File: MultipleFolderSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the tree viewer.
 *
 * @param parent the parent composite
 * @return the tree viewer
 */
protected CheckboxTreeViewer createTreeViewer(Composite parent) {
	fViewer = new CheckboxTreeViewer(parent, SWT.BORDER);

	fViewer.setContentProvider(fContentProvider);
	fViewer.setLabelProvider(fLabelProvider);
	fViewer.addCheckStateListener(new ICheckStateListener() {
		public void checkStateChanged(CheckStateChangedEvent event) {
			updateOKStatus();
		}
	});

	fViewer.setComparator(new ResourceComparator(ResourceComparator.NAME));
	if (fFilters != null) {
		for (int i = 0; i != fFilters.size(); i++)
			fViewer.addFilter(fFilters.get(i));
	}

	fViewer.setInput(fInput);

	return fViewer;
}
 
Example #4
Source File: BuildPathDialogAccess.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Shows the UI to configure a JAR or ZIP archive located in the workspace.
 * The dialog returns the configured classpath entry path or <code>null</code> if the dialog has
 * been canceled. The dialog does not apply any changes.
 *
 * @param shell The parent shell for the dialog.
 * @param initialEntry The path of the initial archive entry
 * @param usedEntries An array of paths that are already on the classpath and therefore should not be
 * selected again.
 * @return Returns the configured JAR path or <code>null</code> if the dialog has
 * been canceled by the user.
 */
public static IPath configureJAREntry(Shell shell, IPath initialEntry, IPath[] usedEntries) {
	if (initialEntry == null || usedEntries == null) {
		throw new IllegalArgumentException();
	}

	Class<?>[] acceptedClasses= new Class[] { IFile.class };
	TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);

	ArrayList<IResource> usedJars= new ArrayList<IResource>(usedEntries.length);
	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
	for (int i= 0; i < usedEntries.length; i++) {
		IPath curr= usedEntries[i];
		if (!curr.equals(initialEntry)) {
			IResource resource= root.findMember(usedEntries[i]);
			if (resource instanceof IFile) {
				usedJars.add(resource);
			}
		}
	}

	IResource existing= root.findMember(initialEntry);

	FilteredElementTreeSelectionDialog dialog= new FilteredElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
	dialog.setValidator(validator);
	dialog.setTitle(NewWizardMessages.BuildPathDialogAccess_JARArchiveDialog_edit_title);
	dialog.setMessage(NewWizardMessages.BuildPathDialogAccess_JARArchiveDialog_edit_description);
	dialog.setInitialFilter(ArchiveFileFilter.JARZIP_FILTER_STRING);
	dialog.addFilter(new ArchiveFileFilter(usedJars, true, true));
	dialog.setInput(root);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	dialog.setInitialSelection(existing);

	if (dialog.open() == Window.OK) {
		IResource element= (IResource) dialog.getFirstResult();
		return element.getFullPath();
	}
	return null;
}
 
Example #5
Source File: BuildPathDialogAccess.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Shows the UI to select new JAR or ZIP archive entries located in the workspace.
 * The dialog returns the selected entries or <code>null</code> if the dialog has
 * been canceled. The dialog does not apply any changes.
 *
 * @param shell The parent shell for the dialog.
 * @param initialSelection The path of the element (container or archive) to initially select or <code>null</code> to not select an entry.
 * @param usedEntries An array of paths that are already on the classpath and therefore should not be
 * selected again.
 * @return Returns the new JAR paths or <code>null</code> if the dialog has
 * been canceled by the user.
 */
public static IPath[] chooseJAREntries(Shell shell, IPath initialSelection, IPath[] usedEntries) {
	if (usedEntries == null) {
		throw new IllegalArgumentException();
	}

	Class<?>[] acceptedClasses= new Class[] { IFile.class };
	TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, true);
	ArrayList<IResource> usedJars= new ArrayList<IResource>(usedEntries.length);
	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
	for (int i= 0; i < usedEntries.length; i++) {
		IResource resource= root.findMember(usedEntries[i]);
		if (resource instanceof IFile) {
			usedJars.add(resource);
		}
	}
	IResource focus= initialSelection != null ? root.findMember(initialSelection) : null;

	FilteredElementTreeSelectionDialog dialog= new FilteredElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
	dialog.setHelpAvailable(false);
	dialog.setValidator(validator);
	dialog.setTitle(NewWizardMessages.BuildPathDialogAccess_JARArchiveDialog_new_title);
	dialog.setMessage(NewWizardMessages.BuildPathDialogAccess_JARArchiveDialog_new_description);
	dialog.setInitialFilter(ArchiveFileFilter.JARZIP_FILTER_STRING);
	dialog.addFilter(new ArchiveFileFilter(usedJars, true, true));
	dialog.setInput(root);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	dialog.setInitialSelection(focus);

	if (dialog.open() == Window.OK) {
		Object[] elements= dialog.getResult();
		IPath[] res= new IPath[elements.length];
		for (int i= 0; i < res.length; i++) {
			IResource elem= (IResource)elements[i];
			res[i]= elem.getFullPath();
		}
		return res;
	}
	return null;
}
 
Example #6
Source File: JavadocConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String chooseWorkspaceArchive() {
	String initSelection= fArchiveField.getText();

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

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

	FilteredElementTreeSelectionDialog dialog= new FilteredElementTreeSelectionDialog(fShell, lp, cp);
	dialog.setInitialFilter(ArchiveFileFilter.JARZIP_FILTER_STRING);
	dialog.setAllowMultiple(false);
	dialog.setValidator(validator);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	dialog.setTitle(PreferencesMessages.JavadocConfigurationBlock_workspace_archive_selection_dialog_title);
	dialog.setMessage(PreferencesMessages.JavadocConfigurationBlock_workspace_archive_selection_dialog_description);
	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 #7
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 #8
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 #9
Source File: BuildPathsBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IContainer chooseContainer() {
	Class<?>[] acceptedClasses= new Class[] { IProject.class, IFolder.class };
	ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
	IProject[] allProjects= fWorkspaceRoot.getProjects();
	ArrayList<IProject> rejectedElements= new ArrayList<IProject>(allProjects.length);
	IProject currProject= fCurrJProject.getProject();
	for (int i= 0; i < allProjects.length; i++) {
		if (!allProjects[i].equals(currProject)) {
			rejectedElements.add(allProjects[i]);
		}
	}
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());

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

	IResource initSelection= null;
	if (fOutputLocationPath != null) {
		initSelection= fWorkspaceRoot.findMember(fOutputLocationPath);
	}

	FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp, cp);
	dialog.setTitle(NewWizardMessages.BuildPathsBlock_ChooseOutputFolderDialog_title);
	dialog.setValidator(validator);
	dialog.setMessage(NewWizardMessages.BuildPathsBlock_ChooseOutputFolderDialog_description);
	dialog.addFilter(filter);
	dialog.setInput(fWorkspaceRoot);
	dialog.setInitialSelection(initSelection);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));

	if (dialog.open() == Window.OK) {
		return (IContainer)dialog.getFirstResult();
	}
	return null;
}
 
Example #10
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 #11
Source File: ControlUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static String openProgramPathDialog(IProject project, Button button) throws OperationCancellation {
	ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
		button.getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
	dialog.setTitle(LangUIMessages.ProgramPathDialog_title);
	dialog.setMessage(LangUIMessages.ProgramPathDialog_message);
	
	dialog.setInput(project);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	if(dialog.open() == IDialogConstants.OK_ID) {
		IResource resource = (IResource) dialog.getFirstResult();
		return resource.getProjectRelativePath().toPortableString();
	}
	throw new OperationCancellation();
}
 
Example #12
Source File: OutputLocationDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IContainer chooseOutputLocation() {
	IWorkspaceRoot root= fCurrProject.getWorkspace().getRoot();
	final Class<?>[] acceptedClasses= new Class[] { IProject.class, IFolder.class };
	IProject[] allProjects= root.getProjects();
	ArrayList<IProject> rejectedElements= new ArrayList<IProject>(allProjects.length);
	for (int i= 0; i < allProjects.length; i++) {
		if (!allProjects[i].equals(fCurrProject)) {
			rejectedElements.add(allProjects[i]);
		}
	}
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());

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

	IResource initSelection= null;
	if (fOutputLocation != null) {
		initSelection= root.findMember(fOutputLocation);
	}

	FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp, cp);
	dialog.setTitle(NewWizardMessages.OutputLocationDialog_ChooseOutputFolder_title);

       dialog.setValidator(new ISelectionStatusValidator() {
           ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
           public IStatus validate(Object[] selection) {
               IStatus typedStatus= validator.validate(selection);
               if (!typedStatus.isOK())
                   return typedStatus;
               if (selection[0] instanceof IFolder) {
                   IFolder folder= (IFolder) selection[0];
                   try {
                   	IStatus result= ClasspathModifier.checkSetOutputLocationPrecondition(fEntryToEdit, folder.getFullPath(), fAllowInvalidClasspath, fCPJavaProject);
                   	if (result.getSeverity() == IStatus.ERROR)
                    	return result;
                   } catch (CoreException e) {
                    JavaPlugin.log(e);
                   }
                   return new StatusInfo();
               } else {
               	return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
               }
           }
       });
	dialog.setMessage(NewWizardMessages.OutputLocationDialog_ChooseOutputFolder_description);
	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;
}
 
Example #13
Source File: FolderSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public FolderSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
	super(parent, labelProvider, contentProvider);
	setComparator(new ResourceComparator(ResourceComparator.NAME));
}