Bug 1580 - Run in Package dialog should select the current context (1GE32AE)
Summary: Run in Package dialog should select the current context (1GE32AE)
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P1 minor (vote)
Target Milestone: ---   Edit
Assignee: Darin Swanson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 4126
Blocks:
  Show dependency tree
 
Reported: 2001-10-10 22:15 EDT by Darin Swanson CLA
Modified: 2001-12-17 16:55 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Swanson CLA 2001-10-10 22:15:43 EDT
DS (5/21/01 10:51:52 AM)
	When selecting a new context, the current context should be selected.

DW (5/24/01 9:35:14 PM)
	Fixed.

JGS (5/29/01 4:16:15 PM)
	This works for real packages and package fragments, but for default packages,
	if I select the default package for my project, then come back in, the default
	package for rt.jar is selected.

DW (5/30/01 1:58:34 PM)
	Not easily improved. The interaction between the "run in package" action and
	the scrapbook is via package name - not package handles. Would require
	changing the interaction to use element handle, and persisting the handle id.

DW (5/30/01 3:04:47 PM)
	Deferred to post-june.

DW (8/10/01 11:09:22 AM)
	This is a non-breaking change that we can fix in ZRH code.
	
JGS (8/15/01 3:22:09 PM)
	Made changes to RunInPackageAction and JavaSnippetEditor to persist the IPackageFragment
	handle identifier instead of just the package name.  Outstanding problem is that the SelectionDialog
	returned by JavaUI.createPackageDialog() only seems to take package names in its
	setInitialSelection() method.  We need a way to set the intial selection on the dialog with the
	actual IPackageFragment.  Sent mail to EG for advice.

JGS (8/16/01 5:13:15 PM)
	Changes made to JavaSnippetEditor:

	Changed member def:
		private String fPackageHandle= null;

	Changed method def:
		protected void doSetInput(IEditorInput input) throws CoreException {
			super.doSetInput(input);
		fPackageHandle = getPage().getPersistentProperty(new QualifiedName(JavaPlugin.getPluginId(), PACKAGE_CONTEXT));
		}

	Changed methods def:
	/**
	 * Set the handle identifier of the run-in package fragment
	 */
	public void setPackage(String packageHandle) {
		fPackageHandle= packageHandle;
		// persist
		try {
			getPage().setPersistentProperty(new QualifiedName(JavaPlugin.getPluginId(), PACKAGE_CONTEXT), packageHandle);
		} catch (CoreException e) {
			ErrorDialog.openError(getShell(), SnippetMessages.getString("SnippetEditor.error.packagecontext"), null, e.getStatus()); //$NON-NLS-1$
		}
	}
	
	/**
	 * Get the handle identifier of the run-in package fragment
	 */
	public String getPackage() {
		return fPackageHandle;
	}
	
	Changed method def:
	protected IEvaluationContext getEvaluationContext() {
		if (fEvaluationContext == null) {
			IJavaProject project= getJavaProject();
			fEvaluationContext= project.newEvaluationContext();
		}
		if (fPackageHandle != null) {	
			String packageName = JavaCore.create(fPackageHandle).getElementName();	
			fEvaluationContext.setPackageName(packageName);
		}
		return fEvaluationContext;
	}

	Changes made to RunInPackageAction:
		Changed methods def:	
	/**
	 * The user has invoked this action.
	 */
	public void run() {
		Shell s= fEditor.getSite().getShell();
		IPackageFragment result= choosePackage(s);
		if (result != null) {
			fEditor.setPackage(result.getHandleIdentifier());
		}
	} 

	private IPackageFragment choosePackage(Shell shell) {
		try {
			IJavaProject p= fEditor.getJavaProject();
			//fix for 1G472LK: ITPJUI:WIN2000 - Package selection dialog must qualify package names regarding source folders
			SelectionDialog dialog= JavaUI.createPackageDialog(shell, p, IJavaElementSearchConstants.CONSIDER_BINARIES);
			dialog.setTitle(SnippetMessages.getString("RunInPackage.dialog.title")); //$NON-NLS-1$
			dialog.setMessage(SnippetMessages.getString("RunInPackage.dialog.message")); //$NON-NLS-1$
			String pkgHandle= fEditor.getPackage();
			if (pkgHandle != null) {
				//String pkgName = JavaCore.create(pkgHandle).getElementName();
				IPackageFragment pf = (IPackageFragment)JavaCore.create(pkgHandle);
				dialog.setInitialSelections(new Object[] {pf});
			}
			dialog.open();		
			Object[] res= dialog.getResult();
			if (res != null && res.length > 0) 
				return (IPackageFragment)res[0];
		} catch (JavaModelException e) {
		}
		return null;
	}

JGS (8/17/01 10:42:55 AM)
	Need to integrate above code, as well as whatever fix is found for setting initial selection on dialog.

JGS (8/20/01 9:43:14 AM)
	New PR created to address inability to set initial selection.
	[1GIRGYV: ITPJUI:WIN2000 - SelectionDialog.setInitialSelection broken for all JDT dialogs]
Comment 1 Joe Szurszewski CLA 2001-10-16 18:31:47 EDT
Waiting for #4126 to be fixed.
Comment 2 Joe Szurszewski CLA 2001-11-20 14:25:08 EST
Bug #4126 claims to be fixed, but it isn't.  The 'setInitialSelections()" 
method DOES take an array of Objects as an argument, however, it doesn't seem 
to do anything with them.  When I try to pop up a selection dialog populated 
with package fragments, I call 'setInitialSelections()' passing in an array 
containing a single IPackageFragment.  When I debug this call, it seems the 
failure happens when setSelection() is called on ElementListSelectionDialog.  
This method calls fFilteredList.setSelection().  This method does nothing when 
an array of one element is passed in because fFoldedCount is zero.  Thus, the 
selection dialog pops up with nothing in the list, and an 'A' in the filter.

Cannot make any progress on this bug until #4126 is really fixed.
Comment 3 Erich Gamma CLA 2001-11-20 16:53:47 EST
P1 since it is blocking progress
Comment 4 Claude Knaus CLA 2001-11-29 09:59:31 EST
Ugh, I had commented on this a week ago, but somehow it didn't make into the
bug system.

The filter defines which elements are in the list. Only elements in the list
can be selected. The default filter is 'A'. If you want to filter nothing, you 
have to specify an empty string as filter. See below:

SelectionDialog dialog= JavaUI.createPackageDialog(shell, p, 
IJavaElementSearchConstants.CONSIDER_BINARIES, ""); // <- filter
Comment 5 Claude Knaus CLA 2001-11-29 10:01:35 EST
duh, I realized the other comment was done on #4126
Comment 6 Joe Szurszewski CLA 2001-12-17 16:51:14 EST
Fixed.  Claude was correct - the correct createPackageDialog() call was not 
being made.  It is now, and everything works.
Comment 7 Joe Szurszewski CLA 2001-12-17 16:51:26 EST
Please verify.
Comment 8 Darin Swanson CLA 2001-12-17 16:55:59 EST
Verified.