The JDT-UI API provides several classes to present the Java model or parts of it in a standard JFace viewer. This functionality is provided primarily by:
...In addition to the Java model the
IJavaProject jProject= ...;
TreeViewer viewer= new TreeViewer(parent);
// Provide members of a compilation unit or class file, but no working copy elements
ITreeContentProvider contentProvider= new StandardJavaElementContentProvider(true, false);
viewer.setContentProvider(contentProvider);
// There are more flags defined in class JavaElementLabelProvider
ILabelProvider labelProvider= new JavaElementLabelProvider(
JavaElementLabelProvider.SHOW_DEFAULT |
JavaElementLabelProvider.SHOW_QUALIFIED |
JavaElementLabelProvider.SHOW_ROOT);
viewer.setLabelProvider(labelProvider);
// Using the Java model as the viewers input present Java projects on the first level.
viewer.setInput(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()));
...
StandardJavaElementContentProvider
class supports the following input element types: IJavaProject
,
IPackageFragmentRoot
, IPackageFragment
and IFolder
....In the same way the OverrideIndicatorLabelDecorator can be used to decorate a normal label provider to show the implement and override indicators for methods.
DecoratingLabelProvider decorator= new DecoratingLabelProvider(labelProvider, new ProblemsLabelDecorator());
viewer.setLabelProvider(decorator);
...
OverrideIndicatorLabelDecorator
nor the
ProblemsLabelDecorator
listen to model changes. Hence, the viewer doesn't
update its presentation if the Java or resource marker model changes. The reason
for pushing the update onto the client for these classes is that there isn't yet
a generic implementation that fulfills all performance concerns. Handling Java
model delta inspection and viewer refreshing in each label decorator or provider
would lead to multiple delta inspections and unnecessary viewer updates.OverrideIndicatorLabelDecorator
: the client must listen to
Java model changes (see JavaCore.addElementChangedListener
)
and decide if the change(s) described by the delta invalidates the override
indicator of elements presented in the viewer. If so, the class inspecting
the delta should trigger a repaint of the corresponding Java elements using
the standard JFace viewer API (see update methods on StructuredViewer).ProblemsLabelDecorator
: the client should listen to changes
notified by the decorator via a
ProblemsLabelChangedEvent
(see also
ProblemsLabelDecorator.addListener
). Since the marker model is resource based, the listener has
to map the resource notifications to its underlying data model. For
an example showing how to do this for viewers presenting Java elements
see the internal classes ProblemTreeViewer.handleLabelProviderChanged.