Bug 111501 - [API] Public api for PackageSelectionDialog ...
Summary: [API] Public api for PackageSelectionDialog ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M4   Edit
Assignee: Benno Baumgartner CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 117020
Blocks:
  Show dependency tree
 
Reported: 2005-10-04 14:50 EDT by Vikas Trivedi CLA
Modified: 2005-12-13 09:00 EST (History)
2 users (show)

See Also:


Attachments
proposed fix (2.95 KB, patch)
2005-10-20 10:09 EDT, Benno Baumgartner CLA
no flags Details | Diff
proposed fix (2.58 KB, patch)
2005-11-11 05:48 EST, Benno Baumgartner CLA
no flags Details | Diff
test (2.99 KB, patch)
2005-11-11 05:49 EST, Benno Baumgartner CLA
no flags Details | Diff
example how to add the default package (4.20 KB, patch)
2005-11-11 06:17 EST, Martin Aeschlimann CLA
no flags Details | Diff
don't use search infrastructure (7.02 KB, patch)
2005-11-11 09:23 EST, Benno Baumgartner CLA
no flags Details | Diff
proposed fix (8.92 KB, patch)
2005-11-29 05:30 EST, Benno Baumgartner CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vikas Trivedi CLA 2005-10-04 14:50:01 EDT
We are using internal jdt calls to perform some of our operations. In order to
bring up the package selection dialog we needed to use PackageSelectionDialog. 

We couldn't find public API to replace this usage.
JavaUI.createPackageDialog(..) does not provide any way to use the workspace
scope for the dialog which is what we need in our usecase.

This is blocking our effort to remove access to JDT internal source.
Comment 1 Martin Aeschlimann CLA 2005-10-05 13:02:11 EDT
Yes we should add new API JavaUI.createPackageDialog(Shell parent,
IPackageFragmentRoot root, int style, String filter)
and use the PackageSelectionDialog for this and also for the other API methods.
Comment 2 Vikas Trivedi CLA 2005-10-12 10:11:38 EDT
Would requiring an IPackageFragmentRoot argument still allow us to create the
dialog with Workspace scope (i.e. dialog shows all packages in all projects in
the workspace)?
Comment 3 Martin Aeschlimann CLA 2005-10-14 03:11:25 EDT
Oops, sorry, what I wrote makes no sense:
It would be something like

public static SelectionDialog createPackageDialog(Shell parent, IRunnableContext
context, IJavaSearchScope scope, int style, boolean multipleSelection, String
filter)

This API would use the PackageSelectionDialog.
If possible also the other API's createPackageDialog(...IJavaProject...) should
use the PackageSelectionDialog.
Comment 4 Benno Baumgartner CLA 2005-10-20 10:09:07 EDT
Created attachment 28515 [details]
proposed fix

Adds 

public static SelectionDialog createPackageDialog(Shell parent,
IRunnableContext context, IJavaSearchScope scope, int flags, boolean
multipleSelection, String filter)

to JavaUI
Comment 5 Martin Aeschlimann CLA 2005-11-07 03:54:45 EST
I think the patch neds some more work.
PackageSelectionDialog is internal, so the constants there need to be made public. 
Note that we don't need to make them all public, verify and decide if they make
sense to be public API.
Also have a look on how to change the existing API
  createPackageDialog(...IJavaProject...)
to use the PackageSelectionDialog.
Comment 6 Benno Baumgartner CLA 2005-11-11 05:46:46 EST
I've tried to change the existing code to use the new PackageSelectionDialog but
the problem is, that the search for packages does not report any empty packages,
wheras the old implementation does show empty packages. see
MatchLocator#locatePackageDeclarations :

IPackageFragment pkg = (IPackageFragment) pkgs[k];
IJavaElement[] children= pkg.getChildren();
if (children.length > 0 && ...) {
   ... report match ...
}

I don't know why search does not report empty pkgs, maybe we should file a pr
against search?
Comment 7 Benno Baumgartner CLA 2005-11-11 05:48:31 EST
Created attachment 29766 [details]
proposed fix

Create a PackageSelectionDialog with the same options as JDT/UI uses:
REMOVE_DUPLICATES and SHOW_PARENTS and HIDE_DEFAULT_PACKAGE
Comment 8 Benno Baumgartner CLA 2005-11-11 05:49:07 EST
Created attachment 29767 [details]
test
Comment 9 Martin Aeschlimann CLA 2005-11-11 06:15:02 EST
It seems they made that on purpose. I suggest to add code in
PackageSelectionDialog. I tried something, but didn't test. See attachment.

In your patch, it seems to me that the null check on 'filter' is either too much
or the spec should mention that 'null' is a valid option.
Comment 10 Martin Aeschlimann CLA 2005-11-11 06:17:08 EST
Created attachment 29769 [details]
example how to add the default package
Comment 11 Benno Baumgartner CLA 2005-11-11 09:22:37 EST
I see your point but the problem is that empty packages aren't shown. Your 
patch shows only the default package and only if there are only empty packages 
in the project. Let us assum we use the API in the new class wizard (which we 
should IMHO) and having following use case:
- create new project
- create new package
- create new class
- open package selection dialog in new class wizard
- only the default package is schown (if you select this package you even get 
a warning that the usage of default package is discouraged)
- File a pr against JDT/UI

What about not using the search infrastructure at all and do something like in 
the following attachment?
Comment 12 Benno Baumgartner CLA 2005-11-11 09:23:35 EST
Created attachment 29775 [details]
don't use search infrastructure
Comment 13 Benno Baumgartner CLA 2005-11-11 09:25:00 EST
The null check on filter is due to my paranoia;-) It's not realy required.
Comment 14 Martin Aeschlimann CLA 2005-11-14 03:33:22 EST
It is the choice of the client if a default package is shown or not (-> flag).
So in the case of the new type wizard, we obviously should not show the default
package.

So I thought the problem we have is the scenario: User wants default package,
but no search matches. If we have search matches, the code in
PackageSelectionDialog line 115 will add one.

Your patch in comment 12 isn't accurate as fScope.enclosingProjectsAndJars()
doesn't fully describe a search scope. These are the roots, but the scope is
more complex than that. 
Comment 15 Benno Baumgartner CLA 2005-11-29 05:30:00 EST
Created attachment 30763 [details]
proposed fix

After fix of bug 117020 empty packages are returned by search and the old implementation can be replaced by the new one.
Comment 16 Martin Aeschlimann CLA 2005-11-29 09:45:26 EST
patch released > 20051129

This adds new API
JavaUI.createPackageDialog(
  Shell parent, IRunnableContext context, IJavaSearchScope scope,
  boolean multipleSelection, boolean removeDuplicates, String filter)

Vikas, is that serving your needs?
Comment 17 Vikas Trivedi CLA 2005-11-29 09:54:54 EST
(In reply to comment #16)

Yes this looks good. Thanks.
Comment 18 Philip Mayer CLA 2005-12-13 08:46:39 EST
Marking as verified then (I20051213-0010).