1 11 package org.eclipse.jdt.ui; 12 13 import org.eclipse.core.resources.IStorage; 14 15 import org.eclipse.swt.graphics.Image; 16 17 import org.eclipse.jface.viewers.LabelProvider; 18 19 import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; 20 import org.eclipse.jdt.internal.ui.viewsupport.StorageLabelProvider; 21 22 33 public class JavaElementLabelProvider extends LabelProvider { 34 35 38 public final static int SHOW_RETURN_TYPE= 0x001; 39 40 43 public final static int SHOW_PARAMETERS= 0x002; 44 45 50 public final static int SHOW_CONTAINER= 0x004; 51 52 57 public final static int SHOW_CONTAINER_QUALIFICATION= 0x008; 58 59 63 public final static int SHOW_OVERLAY_ICONS= 0x010; 64 65 68 public final static int SHOW_TYPE= 0x020; 69 70 74 public final static int SHOW_ROOT= 0x040; 75 76 81 public final static int SHOW_POSTIFIX_QUALIFICATION= 0x080; 82 83 87 public final static int SHOW_SMALL_ICONS= 0x100; 88 89 93 public final static int SHOW_VARIABLE= 0x200; 94 95 102 public final static int SHOW_QUALIFIED= 0x400; 103 104 111 public final static int SHOW_POST_QUALIFIED= 0x800; 112 113 114 118 public final static int SHOW_BASICS= 0x000; 119 120 121 126 public final static int SHOW_DEFAULT= new Integer (SHOW_PARAMETERS | SHOW_OVERLAY_ICONS).intValue(); 127 128 private JavaElementImageProvider fImageLabelProvider; 129 130 private StorageLabelProvider fStorageLabelProvider; 131 private int fFlags; 132 private int fImageFlags; 133 private long fTextFlags; 134 135 141 public JavaElementLabelProvider() { 142 this(SHOW_DEFAULT); 143 } 144 145 150 public JavaElementLabelProvider(int flags) { 151 fImageLabelProvider= new JavaElementImageProvider(); 152 fStorageLabelProvider= new StorageLabelProvider(); 153 fFlags= flags; 154 updateImageProviderFlags(); 155 updateTextProviderFlags(); 156 } 157 158 private boolean getFlag( int flag) { 159 return (fFlags & flag) != 0; 160 } 161 162 167 public void turnOn(int flags) { 168 fFlags |= flags; 169 updateImageProviderFlags(); 170 updateTextProviderFlags(); 171 } 172 173 178 public void turnOff(int flags) { 179 fFlags &= (~flags); 180 updateImageProviderFlags(); 181 updateTextProviderFlags(); 182 } 183 184 private void updateImageProviderFlags() { 185 fImageFlags= 0; 186 if (getFlag(SHOW_OVERLAY_ICONS)) { 187 fImageFlags |= JavaElementImageProvider.OVERLAY_ICONS; 188 } 189 if (getFlag(SHOW_SMALL_ICONS)) { 190 fImageFlags |= JavaElementImageProvider.SMALL_ICONS; 191 } 192 } 193 194 private void updateTextProviderFlags() { 195 fTextFlags= JavaElementLabels.T_TYPE_PARAMETERS; 196 if (getFlag(SHOW_RETURN_TYPE)) { 197 fTextFlags |= JavaElementLabels.M_APP_RETURNTYPE; 198 } 199 if (getFlag(SHOW_PARAMETERS)) { 200 fTextFlags |= JavaElementLabels.M_PARAMETER_TYPES; 201 } 202 if (getFlag(SHOW_CONTAINER)) { 203 fTextFlags |= JavaElementLabels.P_POST_QUALIFIED | JavaElementLabels.T_POST_QUALIFIED | JavaElementLabels.CF_POST_QUALIFIED | JavaElementLabels.CU_POST_QUALIFIED | JavaElementLabels.M_POST_QUALIFIED | JavaElementLabels.F_POST_QUALIFIED; 204 } 205 if (getFlag(SHOW_POSTIFIX_QUALIFICATION)) { 206 fTextFlags |= (JavaElementLabels.T_POST_QUALIFIED | JavaElementLabels.CF_POST_QUALIFIED | JavaElementLabels.CU_POST_QUALIFIED); 207 } else if (getFlag(SHOW_CONTAINER_QUALIFICATION)) { 208 fTextFlags |=(JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED); 209 } 210 if (getFlag(SHOW_TYPE)) { 211 fTextFlags |= JavaElementLabels.F_APP_TYPE_SIGNATURE; 212 } 213 if (getFlag(SHOW_ROOT)) { 214 fTextFlags |= JavaElementLabels.APPEND_ROOT_PATH; 215 } 216 if (getFlag(SHOW_VARIABLE)) { 217 fTextFlags |= JavaElementLabels.ROOT_VARIABLE; 218 } 219 if (getFlag(SHOW_QUALIFIED)) { 220 fTextFlags |= (JavaElementLabels.F_FULLY_QUALIFIED | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.I_FULLY_QUALIFIED 221 | JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.D_QUALIFIED | JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED); 222 } 223 if (getFlag(SHOW_POST_QUALIFIED)) { 224 fTextFlags |= (JavaElementLabels.F_POST_QUALIFIED | JavaElementLabels.M_POST_QUALIFIED | JavaElementLabels.I_POST_QUALIFIED 225 | JavaElementLabels.T_POST_QUALIFIED | JavaElementLabels.D_POST_QUALIFIED | JavaElementLabels.CF_POST_QUALIFIED | JavaElementLabels.CU_POST_QUALIFIED); 226 } 227 } 228 229 232 public Image getImage(Object element) { 233 Image result= fImageLabelProvider.getImageLabel(element, fImageFlags); 234 if (result != null) { 235 return result; 236 } 237 238 if (element instanceof IStorage) 239 return fStorageLabelProvider.getImage(element); 240 241 return result; 242 } 243 244 247 public String getText(Object element) { 248 String text= JavaElementLabels.getTextLabel(element, fTextFlags); 249 if (text.length() > 0) { 250 return text; 251 } 252 253 if (element instanceof IStorage) 254 return fStorageLabelProvider.getText(element); 255 256 return text; 257 } 258 259 263 public void dispose() { 264 fStorageLabelProvider.dispose(); 265 fImageLabelProvider.dispose(); 266 } 267 } 268 | Popular Tags |