1 19 20 25 package org.netbeans.modules.j2ee.dd.impl.commonws; 26 27 import org.netbeans.modules.schema2beans.Version; 28 import org.netbeans.modules.j2ee.dd.api.common.*; 29 import org.openide.ErrorManager; 30 31 public abstract class ComponentBeanMultiple extends DescriptionBeanMultiple implements DisplayNameInterface, IconInterface { 32 33 public ComponentBeanMultiple(java.util.Vector comps, Version version) { 34 super(comps, version); 35 } 36 public void setIcon(int index, org.netbeans.modules.j2ee.dd.api.common.Icon icon){} 38 public void setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon[] icons){} 39 public org.netbeans.modules.j2ee.dd.api.common.Icon getIcon(int i){return null;} 40 public org.netbeans.modules.j2ee.dd.api.common.Icon[] getIcon(){return null;} 41 public int sizeIcon(){return 0;} 42 public int addIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon){return 0;} 43 public int removeIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon){return 0;} 44 45 public abstract void setDisplayName(int index, java.lang.String value); 46 public abstract String getDisplayName(int index); 47 public abstract void setDisplayName(java.lang.String [] value); 48 public abstract int sizeDisplayName(); 50 public abstract int addDisplayName(java.lang.String value); 51 public abstract void setDisplayNameXmlLang(int index, java.lang.String value); 53 public abstract String getDisplayNameXmlLang(int index); 54 55 public void setDisplayName(String locale, String displayName) throws VersionNotSupportedException { 56 if (displayName==null) removeDisplayNameForLocale(locale); 57 else { 58 int size = sizeDisplayName(); 59 boolean found=false; 60 for (int i=0;i<size;i++) { 61 String loc=getDisplayNameXmlLang(i); 62 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 63 found=true; 64 setDisplayName(i, displayName); 65 break; 66 } 67 } 68 if (!found) { 69 addDisplayName(displayName); 70 if (locale!=null) setDisplayNameXmlLang(size, locale.toLowerCase()); 71 } 72 } 73 } 74 75 public void setDisplayName(String displayName) { 76 try { 77 setDisplayName(null,displayName); 78 } catch (VersionNotSupportedException ex){ 79 ErrorManager.getDefault().notify(ex); 80 } 81 } 82 83 public void setAllDisplayNames(java.util.Map displayNames) throws VersionNotSupportedException { 84 removeAllDisplayNames(); 85 if (displayNames!=null) { 86 java.util.Iterator keys = displayNames.keySet().iterator(); 87 int i=0; 88 while (keys.hasNext()) { 89 String key = (String ) keys.next(); 90 addDisplayName((String )displayNames.get(key)); 91 setDisplayNameXmlLang(i++, key); 92 } 93 } 94 } 95 96 public String getDisplayName(String locale) throws VersionNotSupportedException { 97 for (int i=0;i<sizeDisplayName();i++) { 98 String loc=getDisplayNameXmlLang(i); 99 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 100 return getDisplayName(i); 101 } 102 } 103 return null; 104 } 105 public String getDefaultDisplayName() { 106 try { 107 return getDisplayName(null); 108 } catch (VersionNotSupportedException ex){return null;} 109 } 110 public java.util.Map getAllDisplayNames() { 111 java.util.Map map =new java.util.HashMap (); 112 for (int i=0;i<sizeDisplayName();i++) { 113 String desc=getDisplayName(i); 114 String loc=getDisplayNameXmlLang(i); 115 map.put(loc, desc); 116 } 117 return map; 118 } 119 120 public void removeDisplayNameForLocale(String locale) throws VersionNotSupportedException { 121 java.util.Map map = new java.util.HashMap (); 122 for (int i=0;i<sizeDisplayName();i++) { 123 String desc=getDisplayName(i); 124 String loc=getDisplayNameXmlLang(i); 125 if ((locale==null && loc!=null) || (locale!=null && !locale.equalsIgnoreCase(loc))) 126 map.put(loc, desc); 127 } 128 setAllDisplayNames(map); 129 } 130 131 public void removeDisplayName() { 132 try { 133 removeDisplayNameForLocale(null); 134 } catch (VersionNotSupportedException ex){ 135 ErrorManager.getDefault().notify(ex); 136 } 137 } 138 public void removeAllDisplayNames() { 139 setDisplayName(new String []{}); 140 } 141 142 public void setSmallIcon(String locale, String icon) throws VersionNotSupportedException { 144 setIcon(locale, icon, true); 145 } 146 public void setSmallIcon(String icon) { 147 try { 148 setSmallIcon(null,icon); 149 } catch (VersionNotSupportedException ex){ 150 ErrorManager.getDefault().notify(ex); 151 } 152 } 153 public void setLargeIcon(String locale, String icon) throws VersionNotSupportedException { 154 setIcon(locale, icon, false); 155 } 156 public void setLargeIcon(String icon) { 157 try { 158 setLargeIcon(null,icon); 159 } catch (VersionNotSupportedException ex){ 160 ErrorManager.getDefault().notify(ex); 161 } 162 } 163 public void setAllIcons(String [] locales, String [] smallIcons, String [] largeIcons) throws VersionNotSupportedException { 164 org.netbeans.modules.j2ee.dd.api.common.Icon[] newIcons = new org.netbeans.modules.j2ee.dd.api.common.Icon[locales.length]; 165 for (int i=0;i<locales.length;i++) { 166 try { 167 newIcons[i] = (org.netbeans.modules.j2ee.dd.api.common.Icon)createBean("Icon"); if (smallIcons[i]!=null) newIcons[i].setSmallIcon(smallIcons[i]); 169 if (largeIcons[i]!=null) newIcons[i].setLargeIcon(largeIcons[i]); 170 if (locales[i]!=null) newIcons[i].setXmlLang(locales[i]); 171 } catch (ClassNotFoundException ex){} 172 } 173 setIcon(newIcons); 174 } 175 176 public void setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon) { 177 if (icon==null) removeIcon(); 178 else { 179 org.netbeans.modules.j2ee.dd.api.common.Icon[] oldIcons = getIcon(); 180 boolean found=false; 181 try { 182 String locale = icon.getXmlLang(); 183 for (int i=0;i<oldIcons.length;i++) { 184 String loc=oldIcons[i].getXmlLang(); 185 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 186 found=true; 187 setIcon(i, icon); 188 } 189 } 190 } catch (VersionNotSupportedException ex){} 191 if (!found) { 192 addIcon(icon); 193 } 194 } 195 } 196 197 public String getSmallIcon(String locale) throws VersionNotSupportedException { 198 return getIcon(locale,true); 199 } 200 public String getSmallIcon() { 201 try { 202 return getSmallIcon(null); 203 } catch (VersionNotSupportedException ex){return null;} 204 } 205 public String getLargeIcon(String locale) throws VersionNotSupportedException { 206 return getIcon(locale,false); 207 } 208 public String getLargeIcon() { 209 try { 210 return getLargeIcon(null); 211 } catch (VersionNotSupportedException ex){return null;} 212 } 213 public org.netbeans.modules.j2ee.dd.api.common.Icon getDefaultIcon() { 214 org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon(); 215 for (int i=0;i<icons.length;i++) { 216 try { 217 String loc=icons[i].getXmlLang(); 218 if (loc==null) return icons[i]; 219 } catch (VersionNotSupportedException ex){} 220 } 221 return null; 222 } 223 public java.util.Map getAllIcons() { 224 java.util.Map map =new java.util.HashMap (); 225 org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon(); 226 for (int i=0;i<icons.length;i++) { 227 String [] iconPair = new String [] {icons[i].getSmallIcon(),icons[i].getLargeIcon()}; 228 String loc=null; 229 try { 230 loc=icons[i].getXmlLang(); 231 } catch (VersionNotSupportedException ex){ 232 ErrorManager.getDefault().notify(ex); 233 } 234 map.put(loc, iconPair); 235 } 236 return map; 237 } 238 239 public void removeSmallIcon(String locale) throws VersionNotSupportedException { 240 removeIcon(locale, true); 241 } 242 public void removeLargeIcon(String locale) throws VersionNotSupportedException { 243 removeIcon(locale, false); 244 } 245 public void removeIcon(String locale) throws VersionNotSupportedException { 246 org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon(); 247 for (int i=0;i<icons.length;i++) { 248 String loc=icons[i].getXmlLang(); 249 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 250 removeIcon(icons[i]); 251 } 252 } 253 } 254 public void removeSmallIcon() { 255 try { 256 removeSmallIcon(null); 257 } catch (VersionNotSupportedException ex){ 258 ErrorManager.getDefault().notify(ex); 259 } 260 } 261 public void removeLargeIcon() { 262 try { 263 removeLargeIcon(null); 264 } catch (VersionNotSupportedException ex){ 265 ErrorManager.getDefault().notify(ex); 266 } 267 } 268 public void removeIcon() { 269 org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon(); 270 for (int i=0;i<icons.length;i++) { 271 try { 272 String loc=icons[i].getXmlLang(); 273 if (loc==null) removeIcon(icons[i]); 274 } catch (VersionNotSupportedException ex){} 275 } 276 } 277 public void removeAllIcons() { 278 setIcon(new org.netbeans.modules.j2ee.dd.api.common.Icon[]{}); 279 } 280 private void setIcon(String locale, String icon, boolean isSmall) throws VersionNotSupportedException { 281 if (icon==null) { 282 if (isSmall) removeSmallIcon(locale); 283 else removeLargeIcon(locale); 284 } else { 285 org.netbeans.modules.j2ee.dd.api.common.Icon[] oldIcons = getIcon(); 286 boolean found=false; 287 for (int i=0;i<oldIcons.length;i++) { 288 String loc=oldIcons[i].getXmlLang(); 289 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 290 found=true; 291 if (isSmall) oldIcons[i].setSmallIcon(icon); 292 else oldIcons[i].setLargeIcon(icon); 293 break; 294 } 295 } 296 if (!found) { 297 try { 298 org.netbeans.modules.j2ee.dd.api.common.Icon newIcon = (org.netbeans.modules.j2ee.dd.api.common.Icon)createBean("Icon"); if (locale!=null) newIcon.setXmlLang(locale.toLowerCase()); 300 if (isSmall) newIcon.setSmallIcon(icon); 301 else newIcon.setLargeIcon(icon); 302 addIcon(newIcon); 303 } catch (ClassNotFoundException ex){} 304 } 305 } 306 } 307 private String getIcon(String locale, boolean isSmall) throws VersionNotSupportedException { 308 for (int i=0;i<sizeIcon();i++) { 309 org.netbeans.modules.j2ee.dd.api.common.Icon icon = getIcon(i); 310 String loc=icon.getXmlLang(); 311 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 312 if (isSmall) return icon.getSmallIcon(); 313 else return icon.getLargeIcon(); 314 } 315 } 316 return null; 317 } 318 319 public void removeIcon(String locale, boolean isSmall) throws VersionNotSupportedException { 320 org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon(); 321 java.util.List iconList = new java.util.ArrayList (); 322 for (int i=0;i<icons.length;i++) { 323 String loc=icons[i].getXmlLang(); 324 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 325 if (isSmall) { 326 icons[i].setSmallIcon(null); 327 if (icons[i].getLargeIcon()==null) iconList.add(icons[i]); 328 } else { 329 icons[i].setLargeIcon(null); 330 if (icons[i].getSmallIcon()==null) iconList.add(icons[i]); 331 } 332 } 333 } 334 java.util.Iterator it = iconList.iterator(); 335 while(it.hasNext()) removeIcon((org.netbeans.modules.j2ee.dd.api.common.Icon)it.next()); 336 } 337 } 338 | Popular Tags |