org.eclipse.cdt.internal.ui.util
Class SelectionUtil

java.lang.Object
  extended by org.eclipse.cdt.internal.ui.util.SelectionUtil

public class SelectionUtil
extends java.lang.Object

Provides utilities for checking the validity of selections.

This class provides static methods only; it is not intended to be instantiated or subclassed.


Method Summary
static boolean allResourcesAreOfType(org.eclipse.jface.viewers.IStructuredSelection selection, int resourceMask)
          Returns whether the types of the resources in the given selection are among the specified resource types.
static java.lang.Object getFirstElement(org.eclipse.jface.viewers.ISelection selection)
          Returns the first element of the given selection.
static java.lang.Object getSingleElement(org.eclipse.jface.viewers.ISelection s)
           
static boolean resourceIsType(org.eclipse.core.resources.IResource resource, int resourceMask)
          Returns whether the type of the given resource is among the specified resource types.
static java.lang.Object[] toArray(org.eclipse.jface.viewers.ISelection selection)
          Returns the elements of the given selection.
static java.util.List toList(org.eclipse.jface.viewers.ISelection selection)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFirstElement

public static java.lang.Object getFirstElement(org.eclipse.jface.viewers.ISelection selection)
Returns the first element of the given selection. Returns null if the selection is empty or if the given selection is not of type IStructuredSelection.

Parameters:
selection - the selection
Returns:
the selected elements

getSingleElement

public static java.lang.Object getSingleElement(org.eclipse.jface.viewers.ISelection s)

toArray

public static java.lang.Object[] toArray(org.eclipse.jface.viewers.ISelection selection)
Returns the elements of the given selection. Returns an empty array if the selection is empty or if the given selection is not of type IStructuredSelection.

Parameters:
selection - the selection
Returns:
the selected elements

toList

public static java.util.List toList(org.eclipse.jface.viewers.ISelection selection)

allResourcesAreOfType

public static boolean allResourcesAreOfType(org.eclipse.jface.viewers.IStructuredSelection selection,
                                            int resourceMask)
Returns whether the types of the resources in the given selection are among the specified resource types.

Parameters:
selection - the selection
resourceMask - resource mask formed by bitwise OR of resource type constants (defined on IResource)
Returns:
true if all selected elements are resources of the right type, and false if at least one element is either a resource of some other type or a non-resource
See Also:
IResource.getType()

resourceIsType

public static boolean resourceIsType(org.eclipse.core.resources.IResource resource,
                                     int resourceMask)
Returns whether the type of the given resource is among the specified resource types.

Parameters:
resource - the resource
resourceMask - resource mask formed by bitwise OR of resource type constants (defined on IResource)
Returns:
true if the resources has a matching type, and false otherwise
See Also:
IResource.getType()