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