1 11 package org.eclipse.jdt.internal.ui.refactoring.nls; 12 13 import org.eclipse.core.runtime.IPath; 14 15 import org.eclipse.jface.dialogs.IDialogSettings; 16 17 import org.eclipse.jdt.core.IJavaElement; 18 import org.eclipse.jdt.core.IPackageFragment; 19 import org.eclipse.jdt.core.JavaCore; 20 21 import org.eclipse.jdt.ui.JavaElementLabels; 22 23 24 27 public class AccessorDescription { 28 29 private final static String KEY_ACCESSOR_NAME= "accessorName"; private final static String KEY_ACCESSOR_PACK= "accessorPackage"; private final static String KEY_RESOURCE_BUNDLE_NAME= "bundleName"; private final static String KEY_RESOURCE_BUNDLE_PACK= "bundlePackage"; 34 35 private final IPackageFragment fResourceBundlePackage; 36 private final String fAccessorClassName; 37 private final IPackageFragment fAccessorClassPackage; 38 private final String fResourceBundleName; 39 40 43 public AccessorDescription(String accessorClassName, IPackageFragment accessorClassPackage, String propertyFileName, IPackageFragment propertyFilePackage) { 44 super(); 45 fAccessorClassName= accessorClassName; 46 fAccessorClassPackage= accessorClassPackage; 47 fResourceBundleName= propertyFileName; 48 fResourceBundlePackage= propertyFilePackage; 49 } 50 51 public String getLabel() { 52 StringBuffer buf= new StringBuffer (); 53 buf.append(getAccessorClassPackage().getElementName()); 54 if (buf.length() > 0) { 55 buf.append('.'); 56 } 57 buf.append(getAccessorClassName()); 58 buf.append(JavaElementLabels.CONCAT_STRING); 59 IPath propertyFilePath= getResourceBundlePackage().getPath().append(getResourceBundleName()); 60 buf.append(propertyFilePath.makeRelative().toString()); 61 return buf.toString(); 62 } 63 64 public void serialize(IDialogSettings settings) { 65 settings.put(KEY_ACCESSOR_NAME, getAccessorClassName()); 66 settings.put(KEY_ACCESSOR_PACK, getAccessorClassPackage().getHandleIdentifier()); 67 settings.put(KEY_RESOURCE_BUNDLE_NAME, getResourceBundleName()); 68 settings.put(KEY_RESOURCE_BUNDLE_PACK, getResourceBundlePackage().getHandleIdentifier()); 69 } 70 71 74 public String getAccessorClassName() { 75 return fAccessorClassName; 76 } 77 80 public IPackageFragment getAccessorClassPackage() { 81 return fAccessorClassPackage; 82 } 83 86 public String getResourceBundleName() { 87 return fResourceBundleName; 88 } 89 92 public IPackageFragment getResourceBundlePackage() { 93 return fResourceBundlePackage; 94 } 95 96 99 public boolean equals(Object obj) { 100 if (obj != null && obj.getClass().equals(getClass())) { 101 AccessorDescription other= (AccessorDescription) obj; 102 return other == this || 103 (other.fAccessorClassName.equals(fAccessorClassName) 104 && other.fAccessorClassPackage.equals(fAccessorClassPackage) 105 && other.fResourceBundleName.equals(fResourceBundleName) 106 && other.fResourceBundlePackage.equals(fResourceBundlePackage)); 107 } 108 return false; 109 } 110 111 114 public int hashCode() { 115 return fAccessorClassName.hashCode() + fAccessorClassPackage.hashCode() + fResourceBundleName.hashCode() + fResourceBundlePackage.hashCode(); 116 } 117 118 public static AccessorDescription deserialize(IDialogSettings settings) { 119 String accessorName= settings.get(KEY_ACCESSOR_NAME); 120 if (accessorName == null) { 121 return null; 122 } 123 124 String accessorPackHandle= settings.get(KEY_ACCESSOR_PACK); 125 if (accessorPackHandle == null) { 126 return null; 127 } 128 IJavaElement accessorPack= JavaCore.create(accessorPackHandle); 129 if (!(accessorPack instanceof IPackageFragment) || !accessorPack.exists()) { 130 return null; 131 } 132 133 String bundleName= settings.get(KEY_RESOURCE_BUNDLE_NAME); 134 if (bundleName == null) { 135 return null; 136 } 137 138 String bundlePackHandle= settings.get(KEY_RESOURCE_BUNDLE_PACK); 139 if (bundlePackHandle == null) { 140 return null; 141 } 142 IJavaElement bundlePack= JavaCore.create(bundlePackHandle); 143 if (!(bundlePack instanceof IPackageFragment) || !bundlePack.exists()) { 144 return null; 145 } 146 147 return new AccessorDescription(accessorName, (IPackageFragment) accessorPack, bundleName, (IPackageFragment) bundlePack); 148 } 149 } 150 | Popular Tags |