1 11 package org.eclipse.jdt.internal.ui.refactoring.nls; 12 13 import org.eclipse.jdt.core.IJavaElement; 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.jface.window.Window; 19 20 import org.eclipse.ui.dialogs.ElementListSelectionDialog; 21 22 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; 23 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter; 24 25 import org.eclipse.jdt.ui.JavaElementLabelProvider; 26 27 class PackageSelectionStringButtonAdapter implements IStringButtonAdapter { 28 29 private final SourceFirstPackageSelectionDialogField fPackageSelectionField; 30 private String fEmtpyListMessage; 31 private String fMessage; 32 private String fTitle; 33 34 PackageSelectionStringButtonAdapter(SourceFirstPackageSelectionDialogField field, String title, String message, 35 String emtpyListMessage) { 36 fPackageSelectionField= field; 37 fTitle= title; 38 fMessage= message; 39 fEmtpyListMessage= emtpyListMessage; 40 } 41 42 public void changeControlPressed(DialogField field) { 43 IPackageFragmentRoot root= fPackageSelectionField.getSelectedFragmentRoot(); 44 45 IJavaElement[] packages= null; 46 try { 47 if (root != null && root.exists()) { 48 packages= root.getChildren(); 49 } 50 } catch (JavaModelException e) { 51 } 53 54 if (packages == null) { 55 packages= new IJavaElement[0]; 56 } 57 58 ElementListSelectionDialog dialog= new ElementListSelectionDialog(field.getLabelControl(null).getShell(), 59 new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT)); 60 dialog.setIgnoreCase(true); 61 62 dialog.setTitle(fTitle); 63 dialog.setMessage(fMessage); 64 dialog.setEmptyListMessage(fEmtpyListMessage); 65 dialog.setElements(packages); 66 67 72 if (dialog.open() == Window.OK) { 73 IPackageFragment fragment= (IPackageFragment)dialog.getFirstResult(); 74 fPackageSelectionField.setSelected(fragment); 75 } 76 } 77 } 78 | Popular Tags |