org.jmlspecs.eclipse.jdt.ui
Class UIUtils

java.lang.Object
  extended by org.jmlspecs.eclipse.jdt.ui.UIUtils

public class UIUtils
extends java.lang.Object

This class contains a number of (static) utility methods for use in plugins.

Author:
David R. Cok

Field Summary
static java.lang.String eol
          A convenience holder for the end-of-line String for the current platform.
 
Constructor Summary
UIUtils()
           
 
Method Summary
static IJavaProject[] getJavaProjects()
          A convenience method for getting all of the Java projects in the workspace.
static java.lang.String getProjectClassPath(IJavaProject project)
          Computes the classpath (in terms of full absolute file-system paths to directories) from the information available in the Eclipse project.
static java.util.List getProjectClassPathEntries(IJavaProject project)
          Gets the classpath entries for the given project and adds them to the List as file-system absolute paths (String); required projects are added recursively; libraries are added once; source folders are converted to file system absolute paths (remember that source folders may be linked).
static IWorkspaceRoot getRoot()
           
static java.util.List getSelectedElements(org.eclipse.jface.viewers.ISelection selection, org.eclipse.ui.IWorkbenchWindow window)
          This method interprets the selection returning a List of IJavaElement and IResource objects that the plugin knows how to handle.
static void showMessage(org.eclipse.swt.widgets.Shell shell, java.lang.String title, java.lang.String msg)
          Displays a message in a information dialog; must be called from the UI thread.
static void showMessageInUI(org.eclipse.swt.widgets.Shell sh, java.lang.String title, java.lang.String msg)
          Displays a message in a dialog in the UI thread - this may be called from other threads.
static java.util.Map sortByPackageFragmentRoot(java.util.Collection elements)
          Creates a map indexed by IPackageFragmentRoot, with the value for each IPackageFragmentRoot being a Collection consisting of the subset of the argument that belongs to the IPackageFragmentRoot.
static java.util.Map sortByProject(java.util.Collection elements)
          Creates a map indexed by IJavaProject, with the value for each IJavaProject being a Collection consisting of the subset of the argument that belongs to the Java project.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eol

public static final java.lang.String eol
A convenience holder for the end-of-line String for the current platform.

Constructor Detail

UIUtils

public UIUtils()
Method Detail

getRoot

public static IWorkspaceRoot getRoot()
Returns:
The singleton IWorkspaceRoot for the workspace

showMessageInUI

public static void showMessageInUI(org.eclipse.swt.widgets.Shell sh,
                                   java.lang.String title,
                                   java.lang.String msg)
Displays a message in a dialog in the UI thread - this may be called from other threads.

Parameters:
sh - The shell to use to display the dialog, or a top-level shell if the parameter is null
title - The title of the dialog window
msg - The message to display in the dialog

showMessage

public static void showMessage(org.eclipse.swt.widgets.Shell shell,
                               java.lang.String title,
                               java.lang.String msg)
Displays a message in a information dialog; must be called from the UI thread.

Parameters:
shell - Either the parent shell, or null for a top-level shell
title - A title for the dialog window
msg - The message to display in the dialog window

getSelectedElements

public static java.util.List getSelectedElements(org.eclipse.jface.viewers.ISelection selection,
                                                 org.eclipse.ui.IWorkbenchWindow window)
This method interprets the selection returning a List of IJavaElement and IResource objects that the plugin knows how to handle.

Parameters:
selection - The selection to inspect
window - The window in which a selected editor exists
Returns:
A List of IJavaElement and IResource

getJavaProjects

public static IJavaProject[] getJavaProjects()
A convenience method for getting all of the Java projects in the workspace.

Returns:
An array of the IJavaProject objects in the workspace

getProjectClassPath

public static java.lang.String getProjectClassPath(IJavaProject project)
Computes the classpath (in terms of full absolute file-system paths to directories) from the information available in the Eclipse project. Note that this involves recursively processing the classpath contributions from projects that are on the Eclipse classpath for the requested project.

Parameters:
project - The project whose classpath is to be determined.
Returns:
The classpath of the argument in full absolute file-system paths, separated by the platform's path separator

getProjectClassPathEntries

public static java.util.List getProjectClassPathEntries(IJavaProject project)
Gets the classpath entries for the given project and adds them to the List as file-system absolute paths (String); required projects are added recursively; libraries are added once; source folders are converted to file system absolute paths (remember that source folders may be linked).

Parameters:
project -
Returns:
List of String containing classpath locations

sortByProject

public static java.util.Map sortByProject(java.util.Collection elements)
Creates a map indexed by IJavaProject, with the value for each IJavaProject being a Collection consisting of the subset of the argument that belongs to the Java project.

Parameters:
elements - The set of elements to sort
Returns:
The resulting Map of IJavaProject to Collection

sortByPackageFragmentRoot

public static java.util.Map sortByPackageFragmentRoot(java.util.Collection elements)
                                               throws org.eclipse.core.runtime.CoreException
Creates a map indexed by IPackageFragmentRoot, with the value for each IPackageFragmentRoot being a Collection consisting of the subset of the argument that belongs to the IPackageFragmentRoot.

Parameters:
elements - The set of elements to sort
Returns:
The resulting Map of IJavaProject to Collection
Throws:
org.eclipse.core.runtime.CoreException