Class StandardJavaElementContentProvider

java.lang.Object
org.eclipse.jdt.ui.StandardJavaElementContentProvider
All Implemented Interfaces:
IWorkingCopyProvider, org.eclipse.jface.viewers.IContentProvider, org.eclipse.jface.viewers.IStructuredContentProvider, org.eclipse.jface.viewers.ITreeContentProvider
Direct Known Subclasses:
JavaElementContentProvider

public class StandardJavaElementContentProvider extends Object implements org.eclipse.jface.viewers.ITreeContentProvider, IWorkingCopyProvider
A base content provider for Java elements. It provides access to the Java element hierarchy without listening to changes in the Java model. If updating the presentation on Java model change is required than clients have to subclass, listen to Java model changes and have to update the UI using corresponding methods provided by the JFace viewers or their own UI presentation.

The following Java element hierarchy is surfaced by this content provider:

Java model (IJavaModel)
   Java project (IJavaProject)
      package fragment root (IPackageFragmentRoot)
         package fragment (IPackageFragment)
            compilation unit (ICompilationUnit)
            binary class file (IClassFile)
 

Note that when the entire Java project is declared to be package fragment root, the corresponding package fragment root element that normally appears between the Java project and the package fragments is automatically filtered out.

Since:
2.0
  • Field Details

    • NO_CHILDREN

      protected static final Object[] NO_CHILDREN
    • fProvideMembers

      protected boolean fProvideMembers
    • fProvideWorkingCopy

      protected boolean fProvideWorkingCopy
  • Constructor Details

    • StandardJavaElementContentProvider

      public StandardJavaElementContentProvider()
      Creates a new content provider. The content provider does not provide members of compilation units or class files.
    • StandardJavaElementContentProvider

      @Deprecated public StandardJavaElementContentProvider(boolean provideMembers, boolean provideWorkingCopy)
      Deprecated.
      Use StandardJavaElementContentProvider(boolean) instead. Since 3.0 compilation unit children are always provided as working copies. The Java Model does not support the 'original' mode anymore.
      Parameters:
      provideMembers - if true members below compilation units
      provideWorkingCopy - if true working copies are provided
    • StandardJavaElementContentProvider

      public StandardJavaElementContentProvider(boolean provideMembers)
      Creates a new StandardJavaElementContentProvider.
      Parameters:
      provideMembers - if true members below compilation units and class files are provided.
  • Method Details

    • getProvideMembers

      public boolean getProvideMembers()
      Returns whether members are provided when asking for a compilation units or class file for its children.
      Returns:
      true if the content provider provides members; otherwise false is returned
    • setProvideMembers

      public void setProvideMembers(boolean b)
      Sets whether the content provider is supposed to return members when asking a compilation unit or class file for its children.
      Parameters:
      b - if true then members are provided. If false compilation units and class files are the leaves provided by this content provider.
    • getProvideWorkingCopy

      @Deprecated public boolean getProvideWorkingCopy()
      Deprecated.
      Since 3.0 compilation unit children are always provided as working copies. The Java model does not support the 'original' mode anymore.
      Returns:
      returns true if working copies are provided
    • setProvideWorkingCopy

      @Deprecated public void setProvideWorkingCopy(boolean b)
      Deprecated.
      Since 3.0 compilation unit children are always provided from the working copy. The Java model offers a unified world and does not support the 'original' mode anymore.
      Parameters:
      b - specifies if working copies should be provided
    • providesWorkingCopies

      public boolean providesWorkingCopies()
      Description copied from interface: IWorkingCopyProvider
      Returns true if the content provider returns working copy elements; otherwise false is returned.
      Specified by:
      providesWorkingCopies in interface IWorkingCopyProvider
      Returns:
      whether working copy elements are provided.
    • getElements

      public Object[] getElements(Object parent)
      Specified by:
      getElements in interface org.eclipse.jface.viewers.IStructuredContentProvider
      Specified by:
      getElements in interface org.eclipse.jface.viewers.ITreeContentProvider
    • inputChanged

      public void inputChanged(org.eclipse.jface.viewers.Viewer viewer, Object oldInput, Object newInput)
      Specified by:
      inputChanged in interface org.eclipse.jface.viewers.IContentProvider
    • dispose

      public void dispose()
      Specified by:
      dispose in interface org.eclipse.jface.viewers.IContentProvider
    • getChildren

      public Object[] getChildren(Object element)
      Specified by:
      getChildren in interface org.eclipse.jface.viewers.ITreeContentProvider
    • hasChildren

      public boolean hasChildren(Object element)
      Specified by:
      hasChildren in interface org.eclipse.jface.viewers.ITreeContentProvider
    • getParent

      public Object getParent(Object element)
      Specified by:
      getParent in interface org.eclipse.jface.viewers.ITreeContentProvider
    • getPackageFragmentRootContent

      protected Object[] getPackageFragmentRootContent(IPackageFragmentRoot root) throws JavaModelException
      Evaluates all children of a given IPackageFragmentRoot. Clients can override this method.
      Parameters:
      root - The root to evaluate the children for.
      Returns:
      The children of the root
      Throws:
      JavaModelException - if the package fragment root does not exist or if an exception occurs while accessing its corresponding resource
      Since:
      3.3
    • getPackageFragmentRoots

      protected Object[] getPackageFragmentRoots(IJavaProject project) throws JavaModelException
      Evaluates all children of a given IJavaProject. Clients can override this method.
      Parameters:
      project - The Java project to evaluate the children for.
      Returns:
      The children of the project. Typically these are package fragment roots but can also be other elements.
      Throws:
      JavaModelException - if the Java project does not exist or if an exception occurs while accessing its corresponding resource
    • getJavaProjects

      protected Object[] getJavaProjects(IJavaModel jm) throws JavaModelException
      Evaluates all Java projects of a given IJavaModel. Clients can override this method.
      Parameters:
      jm - the Java model
      Returns:
      the projects
      Throws:
      JavaModelException - thrown if accessing the model failed
    • getPackageContent

      protected Object[] getPackageContent(IPackageFragment fragment) throws JavaModelException
      Evaluates all children of a given IPackageFragment. Clients can override this method.
      Parameters:
      fragment - The fragment to evaluate the children for.
      Returns:
      The children of the given package fragment.
      Throws:
      JavaModelException - if the package fragment does not exist or if an exception occurs while accessing its corresponding resource
      Since:
      3.3
    • getFolderContent

      protected Object[] getFolderContent(org.eclipse.core.resources.IFolder folder) throws org.eclipse.core.runtime.CoreException
      Evaluates all children of a given IFolder. Clients can override this method.
      Parameters:
      folder - The folder to evaluate the children for.
      Returns:
      The children of the given folder.
      Throws:
      org.eclipse.core.runtime.CoreException - if the folder does not exist.
      Since:
      3.3
    • isClassPathChange

      protected boolean isClassPathChange(IJavaElementDelta delta)
      Tests if the a Java element delta contains a class path change
      Parameters:
      delta - the Java element delta
      Returns:
      returns true if the delta contains a class path change
    • skipProjectPackageFragmentRoot

      protected Object skipProjectPackageFragmentRoot(IPackageFragmentRoot root)
      Note: This method is for internal use only. Clients should not call this method.
      Parameters:
      root - the package fragment root
      Returns:
      returns the element representing the root.
      Restriction:
      This method is not intended to be referenced by clients.
    • isPackageFragmentEmpty

      protected boolean isPackageFragmentEmpty(IJavaElement element) throws JavaModelException
      Tests if the given element is a empty package fragment.
      Parameters:
      element - the element to test
      Returns:
      returns true if the package fragment is empty
      Throws:
      JavaModelException - thrown if accessing the element failed
    • isProjectPackageFragmentRoot

      protected boolean isProjectPackageFragmentRoot(IPackageFragmentRoot root)
      Tests if the package fragment root is located on the project.
      Parameters:
      root - the package fragment root
      Returns:
      returns true if the package fragment root is the located on the project
    • exists

      protected boolean exists(Object element)
      Note: This method is for internal use only. Clients should not call this method.
      Parameters:
      element - the element to test
      Returns:
      returns true if the element exists
      Restriction:
      This method is not intended to be referenced by clients.
    • internalGetParent

      protected Object internalGetParent(Object element)
      Note: This method is for internal use only. Clients should not call this method.
      Parameters:
      element - the element
      Returns:
      the parent of the element
      Restriction:
      This method is not intended to be referenced by clients.
    • concatenate

      protected static Object[] concatenate(Object[] a1, Object[] a2)
      Utility method to concatenate two arrays.
      Parameters:
      a1 - the first array
      a2 - the second array
      Returns:
      the concatenated array