Bug 28166 Selecting an element in package view is eagerly populating the Java model
Build 20021210 Without even expanding any node, the UI will cause the model to be populated as soon as a node is selected (seems like it is precomputing action to put in the menu). So if simply navigating amongst items in the tree, it will cause lots of activity which is mostly useless. at org.eclipse.jdt.internal.core.PackageFragment.openWhenClosed (PackageFragment.java:313) at org.eclipse.jdt.internal.core.JavaElement.openHierarchy (JavaElement.java:509) at org.eclipse.jdt.internal.core.JavaElement.getElementInfo (JavaElement.java:296) at org.eclipse.jdt.internal.core.JavaElement.getChildren (JavaElement.java:252) at org.eclipse.jdt.internal.core.JavaElement.getChildrenOfType (JavaElement.java:261) at org.eclipse.jdt.internal.core.PackageFragment.getCompilationUnits (PackageFragment.java:190) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.isEnabled (OrganizeImportsAction.java:213) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.selectionChanged (OrganizeImportsAction.java:148) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged (SelectionDispatchAction.java:181) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged (SelectionDispatchAction.java:176) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:148) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1151) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:540) at org.eclipse.jface.viewers.StructuredViewer$1.widgetSelected (StructuredViewer.java:564) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent (OpenStrategy.java:172) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:167) at org.eclipse.jface.util.OpenStrategy$1.handleEvent (OpenStrategy.java:302) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:77) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:825) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1692) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1410) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1403) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1386) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:845) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:462) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:247) at org.eclipse.core.launcher.Main.run(Main.java:703) at org.eclipse.core.launcher.Main.main(Main.java:539)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OrganizeImportsAction.java
* Method declared on SelectionDispatchAction.
	 */
	protected void selectionChanged(IStructuredSelection selection) {
		setEnabled(isEnabled(selection));
	}
	
	private ICompilationUnit[] getCompilationUnits(IStructuredSelection selection) {
		HashSet result= new HashSet();
		Object[] selected= selection.toArray();
		for (int i= 0; i < selected.length; i++) {
			try {
				if (selected[i] instanceof IJavaElement) {
					IJavaElement elem= (IJavaElement) selected[i];
					switch (elem.getElementType()) {
						case IJavaElement.COMPILATION_UNIT:
							result.add(elem);
							break;
						case IJavaElement.IMPORT_CONTAINER:
							result.add(elem.getParent());
							break;
						case IJavaElement.PACKAGE_FRAGMENT:
							collectCompilationUnits((IPackageFragment) elem, result);
							break;
						case IJavaElement.PACKAGE_FRAGMENT_ROOT:
							collectCompilationUnits((IPackageFragmentRoot) elem, result);
							break;
						case IJavaElement.JAVA_PROJECT:
							IPackageFragmentRoot[] roots= ((IJavaProject) elem).getPackageFragmentRoots();
							for (int k= 0; k < roots.length; k++) {
								collectCompilationUnits(roots[i], result);