1 11 package org.eclipse.jdt.internal.ui.refactoring.nls; 12 13 import org.eclipse.jdt.core.IJavaProject; 14 import org.eclipse.jdt.core.IPackageFragment; 15 import org.eclipse.jdt.core.IPackageFragmentRoot; 16 import org.eclipse.jdt.core.JavaModelException; 17 18 import org.eclipse.jdt.internal.ui.JavaPlugin; 19 import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaPackageCompletionProcessor; 20 import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField; 21 22 import org.eclipse.jdt.ui.JavaElementLabelProvider; 23 24 public final class PackageSelectionDialogButtonField extends StringButtonDialogField { 25 26 private IPackageFragment fPackageFragment; 27 28 public PackageSelectionDialogButtonField(String label, String button, PackageBrowseAdapter adapter, IJavaProject root) { 29 super(adapter); 30 setContentAssistProcessor(new JavaPackageCompletionProcessor(new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_ROOT))); 31 32 IPackageFragmentRoot[] roots; 33 try { 34 roots= root.getAllPackageFragmentRoots(); 35 ((JavaPackageCompletionProcessor)getContentAssistProcessor()).setPackageFragmentRoot(roots[0]); 36 } catch (JavaModelException e) { 37 JavaPlugin.log(e); 38 } 40 setLabelText(label); 41 setButtonLabel(button); 42 adapter.setReceiver(this); 43 } 44 45 public void setPackage(IPackageFragment packageFragment) { 46 fPackageFragment= packageFragment; 47 if (fPackageFragment != null) { 48 setText(fPackageFragment.getElementName()); 49 50 JavaPackageCompletionProcessor contentAssist= (JavaPackageCompletionProcessor)getContentAssistProcessor(); 51 contentAssist.setPackageFragmentRoot((IPackageFragmentRoot)packageFragment.getParent()); 52 } 53 } 54 } 55 | Popular Tags |