Bug 6454 - Have option for showing packages hierarchically
Summary: Have option for showing packages hierarchically
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 2.1 M3   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 10029 24425 (view as bug list)
Depends on:
Blocks:
 
Reported: 2001-11-30 03:18 EST by Jon Skeet CLA
Modified: 2005-04-27 12:28 EDT (History)
10 users (show)

See Also:


Attachments
Beta patch (15.07 KB, patch)
2002-10-04 02:39 EDT, Scott Rutledge CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Skeet CLA 2001-11-30 03:18:43 EST
I'm fully aware that Java packages *aren't* hierarchical in nature, but in 
order to find a certain package, it makes things much easier if they can be 
*displayed* hierarchically. Going through the list of packages in my workspace 
trying to find the right one takes much longer now than it would with a 
hierarchical display. I know many people prefer a flat display, and that's 
fine - I'd only suggest this as an option, and not even a default one at that. 
Please let those of us who understand the philosophical situation but have 
practical difficulties with it get round those practical difficulties :)

Jon
Comment 1 Dirk Baeumer CLA 2002-01-10 05:53:13 EST
FYI.
Comment 2 Marco Qualizza CLA 2002-04-02 12:40:55 EST
I second this, for both the Java and Java Browsing packages views.
Comment 3 Erich Gamma CLA 2002-05-12 08:59:58 EDT
revisit after 2.0
Comment 4 Dani Megert CLA 2002-08-19 10:04:32 EDT
*** Bug 10029 has been marked as a duplicate of this bug. ***
Comment 5 Dani Megert CLA 2002-08-19 10:08:36 EDT
Added "helpwanted" keyword. Nothing planned for 2.1 unless patch/code is provided.
Comment 6 Dan Cristian CLA 2002-10-01 12:37:44 EDT
This feature request is similar with what Microsoft has in Visual J++ 6.0
I really believe we need this feature, as it makes your life easier when you 
have large projects. I'm considering to switch from Visual J++, but this not 
hierarchical display is one of the reasons I'm not doing it yet.
Comment 7 Dan Cristian CLA 2002-10-01 12:39:50 EDT
Added my email address in CC list
Comment 8 Scott Rutledge CLA 2002-10-04 02:39:34 EDT
Created attachment 2101 [details]
Beta patch
Comment 9 Scott Rutledge CLA 2002-10-04 02:55:56 EDT
I came up with this patch after looking at the package explorer code for a bit. It affects only 
org.eclipse.jdt.internal.ui.packageview.PackageExplorerContentProvider. Set the 
fHierarchy field of PackageExplorerContentProvider to true to enable it (needs to be hooked up 
to a preference or other UI option).

It works by wrapping IPackageFragments: the wrapper 
reporting sub-packages as non-java elements, which in turn are contibuted to the tree. This 
approach requires minimal changes to the existing code (only one method overridden, and one 
inner-class), and all existing functionality should be retained because the wrapper behaves as a 
normal package for all java operations.

One known artifact is that refactoring operations 
on a package will not affect sub-packages (due to the way refactoring works). Also, empty parent 
packages will not be filtered (ie. the entire hierarchy is shown).
Comment 10 Dani Megert CLA 2002-10-04 09:35:48 EDT
Scott, thanks for your patch. The patch is a good start. The problem with the
approach is that it violates API of IPackageFragment which says:

 * <p>
 * This interface is not intended to be implemented by clients.
 * </p>

Hence we can not go down this road.

Other problems of the patch are:
- the resulting content provider does not handle changes to the model. All Java
element deltas need to be mapped to this new artifical layout e.g. if you add a
package it will not be shown. Deleting a package leads to zombies.
- problem markers are not shown for the artifical nodes
- code does not work for "projects as source folder" layout
- I think label provider also needs to be changed. I would expect to see:
    + java
        - io
   instead of 
    + java
        - java.io
   Comments?
- introducing a proxy (most often) leads to troubles e.g. if you select a
package (type PackageNode) in the Package Explorer the Browsing views will not
be able to set the selection because the packages are not equal ==> the equals
and hash dance has to be done.

It also shows that lots of other areas are affected
- label provider
  - see my comments above
- image provider
  - currently a folder icon is used for a package with only resources. This looks
    odd when looking at a package tree
- sorter
  - packages with only resources are sorted at the end. This might lead to 
     + java
     + com
    if com has a resource
- filters
  * filters are attached to the view. Not all filters might be useful/applicable
    to both layouts. This one is tricky because plug-in developers can add 
    filters to the Package Explorer.
    You solved one of this problems (empty package filter) by changing the 
    semantics of hasChildren(). This can have various side effects for those 
    relying on the real semantic and is violating the API spec of
    IJavaElement.hasChildren().

Given the interest in this PR we also started to experiment with package tree
view to get a feeling of the issues.

Comment 11 Scott Rutledge CLA 2002-10-04 23:23:46 EDT
Thanks for the feedback, Daniel. I have reworked it to not use proxies, and instead do everything 
directly through the content provider (still only a 1 file fix). I can post the new patch if you 
like.

I agree that the labels should be modified to only display the partial name. This should 
doable by adding another flag to the JavaElementLabels class, taking care not to compress the 
name in such a case. Might this affect some label decorators, though?

The number of classes 
needing to know about the hierarchical view seems to indicate that a public flag must be available 
(eg. through IPackagesViewPart). This way external filters will be able to behave properly in 
either mode.

Comment 12 Adam Kiezun CLA 2002-10-07 04:37:43 EDT
*** Bug 24425 has been marked as a duplicate of this bug. ***
Comment 13 Dani Megert CLA 2002-10-07 11:00:34 EDT
Jon, yes please attach the new version. Does the new version now handle resource
and Java element changes?

Regarding the label:
- compression is not a problem since the last segment is never compressed anyway
- we have to see if we add a flag to JavaElementLabels - it already has lots
- decorators: it depends on the implementation: are packages from different
  roots mixed together? Example:
  - have JUnit packages from a JAR (=> read-only and binary)
  - load source code from CVS with package junit.tests
  => if both "junit" nodes are folded together there will be problems but if
     two "junit" nodes appear it should be OK (though looking a bit odd)

>The number of classes needing to know about the hierarchical view seems to
>indicate that a public flag must be available 
>(eg. through IPackagesViewPart). This way external filters will be able to
>behave properly in either mode.
This can't be done via IPackagesViewPart until 3.0 since API must remain as is
for 2.1. I guess since the empty packages filters are already provided by JDT we
don't need new API. Or do you see another new filter that would really need to
test if the package is empty? Suggest to add this for 3.0 if there will be a
concrete demand/PR for it.

Comment 14 Dani Megert CLA 2002-10-08 12:35:11 EDT
Sorry - previous answer was of course for Scott.
Comment 15 Scott Rutledge CLA 2002-10-10 20:03:32 EDT
Working on handling deltas. PackageFragments are still displayed seperately, so there should 
be no problem there.

The API change I suggested only because other plugins CAN contribute 
their own filters (even if none do currently), and any such filters might need to know about the 
setting (such as the 'empty parent packages'). For now I'm sure it's not an issue, but I can see it 
coming up in the future.

Work continues...
Comment 16 Dani Megert CLA 2002-10-29 06:34:46 EST
For M3 this feature will go into the Package Explorer.
Still investigating how it can be integrated into the Packages view (not
committed for M3).
Comment 17 Dani Megert CLA 2002-10-30 13:45:03 EST
Released first cut of this feature to HEAD - will be in tonight's nightly build
and next Tuesdays integration build.

The Package Explorer has a new view menu called "Layout" which allows to switch
between "Flat" and "Hierarchical" (default is flat).

There is also a preference (Java -> Appearance) which allows to set if empty
package fragments are folded together when in hierarchical view (default is true).

Please assign bugs you find with this new feature directly to me.

Note: Hierarchical layout for Packages view is still under investigation.
Comment 18 Dani Megert CLA 2002-10-31 09:32:02 EST
Added a new feature for Hierarchical packages in Pacakges view (feature 25583)