~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to j2ee/ddapi/src/org/netbeans/modules/j2ee/dd/impl/common/ComponentBeanMultiple.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
/**
 
43
 * Superclass that implements DisplayNameInterface and IconInterface for Servlet2.4 beans.
 
44
 *
 
45
 * @author  Milan Kuchtiak
 
46
 */
 
47
package org.netbeans.modules.j2ee.dd.impl.common;
 
48
 
 
49
import org.netbeans.modules.schema2beans.BaseBean;
 
50
import org.netbeans.modules.schema2beans.Version;
 
51
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
 
52
import org.netbeans.modules.j2ee.dd.api.common.IconInterface;
 
53
import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
 
54
import org.netbeans.modules.j2ee.dd.api.common.DisplayNameInterface;
 
55
 
 
56
public abstract class ComponentBeanMultiple extends DescriptionBeanMultiple implements DisplayNameInterface, IconInterface {
 
57
    
 
58
    public ComponentBeanMultiple(java.util.Vector comps, Version version) {
 
59
        super(comps, version);
 
60
    }
 
61
    // methods implemented by specific BaseBeans e.g. Servlet
 
62
    public void setIcon(int index, org.netbeans.modules.j2ee.dd.api.common.Icon icon){}
 
63
    public void  setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon[] icons){}
 
64
    public org.netbeans.modules.j2ee.dd.api.common.Icon getIcon(int i){return null;}
 
65
    public org.netbeans.modules.j2ee.dd.api.common.Icon[] getIcon(){return null;}
 
66
    public int sizeIcon(){return 0;}
 
67
    public int addIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon){return 0;}
 
68
    public int removeIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon){return 0;}
 
69
    
 
70
    public abstract void setDisplayName(int index, java.lang.String value);
 
71
    public abstract String getDisplayName(int index);
 
72
    public abstract void setDisplayName(java.lang.String[] value);
 
73
    //public abstract java.lang.String[] getDisplayName();
 
74
    public abstract int sizeDisplayName();
 
75
    public abstract int addDisplayName(java.lang.String value);
 
76
    //public abstract int removeDisplayName(java.lang.String value);
 
77
    public abstract void setDisplayNameXmlLang(int index, java.lang.String value);
 
78
    public abstract String getDisplayNameXmlLang(int index);
 
79
    
 
80
    public void setDisplayName(String locale, String displayName) throws VersionNotSupportedException {
 
81
        if (displayName==null) removeDisplayNameForLocale(locale);
 
82
        else {
 
83
            int size = sizeDisplayName();
 
84
            boolean found=false;
 
85
            for (int i=0;i<size;i++) {
 
86
                String loc=getDisplayNameXmlLang(i);
 
87
                if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
 
88
                    found=true;
 
89
                    setDisplayName(i, displayName);
 
90
                    break;
 
91
                }
 
92
            }
 
93
            if (!found) {
 
94
                addDisplayName(displayName);
 
95
                if (locale!=null) setDisplayNameXmlLang(size, locale.toLowerCase());
 
96
            }
 
97
        }
 
98
    }
 
99
    
 
100
    public void setDisplayName(String displayName) {
 
101
        try {
 
102
            setDisplayName(null,displayName);
 
103
        } catch (VersionNotSupportedException ex){}
 
104
    }
 
105
    
 
106
    public void setAllDisplayNames(java.util.Map displayNames) throws VersionNotSupportedException {
 
107
        removeAllDisplayNames();
 
108
        if (displayNames!=null) {
 
109
            java.util.Iterator keys = displayNames.keySet().iterator();
 
110
            String[] newDisplayName = new String[displayNames.size()]; 
 
111
            int i=0;
 
112
            while (keys.hasNext()) {
 
113
                String key = (String) keys.next();
 
114
                addDisplayName((String)displayNames.get(key));
 
115
                setDisplayNameXmlLang(i++, key);
 
116
            }
 
117
        }
 
118
    }
 
119
    
 
120
    public String getDisplayName(String locale) throws VersionNotSupportedException {
 
121
        for (int i=0;i<sizeDisplayName();i++) {
 
122
            String loc=getDisplayNameXmlLang(i);
 
123
            if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
 
124
                return getDisplayName(i);
 
125
            }
 
126
        }
 
127
        return null;
 
128
    }
 
129
    public String getDefaultDisplayName() {
 
130
        try {
 
131
            return getDisplayName(null);
 
132
        } catch (VersionNotSupportedException ex){return null;}
 
133
    }
 
134
    public java.util.Map getAllDisplayNames() {
 
135
        java.util.Map map =new java.util.HashMap();
 
136
        for (int i=0;i<sizeDisplayName();i++) {
 
137
            String desc=getDisplayName(i);
 
138
            String loc=getDisplayNameXmlLang(i);
 
139
            map.put(loc, desc);
 
140
        }
 
141
        return map;
 
142
    }
 
143
    
 
144
    public void removeDisplayNameForLocale(String locale) throws VersionNotSupportedException {
 
145
        java.util.Map map = new java.util.HashMap();
 
146
        for (int i=0;i<sizeDisplayName();i++) {
 
147
            String desc=getDisplayName(i);
 
148
            String loc=getDisplayNameXmlLang(i);
 
149
            if ((locale==null && loc!=null) || (locale!=null && !locale.equalsIgnoreCase(loc)))
 
150
                map.put(loc, desc);
 
151
        }
 
152
        setAllDisplayNames(map);
 
153
    }
 
154
    
 
155
    public void removeDisplayName() {
 
156
        try {
 
157
            removeDisplayNameForLocale(null);
 
158
        } catch (VersionNotSupportedException ex){}
 
159
    }
 
160
    public void removeAllDisplayNames() {
 
161
        setDisplayName(new String[]{});
 
162
    }
 
163
    
 
164
    // setters    
 
165
    public void setSmallIcon(String locale, String icon) throws VersionNotSupportedException {
 
166
        setIcon(locale, icon, true);
 
167
    }
 
168
    public void setSmallIcon(String icon) {
 
169
        try {
 
170
            setSmallIcon(null,icon);
 
171
        } catch (VersionNotSupportedException ex){}
 
172
    }
 
173
    public void setLargeIcon(String locale, String icon) throws VersionNotSupportedException {
 
174
        setIcon(locale, icon, false);
 
175
    }
 
176
    public void setLargeIcon(String icon) {
 
177
        try {
 
178
            setLargeIcon(null,icon);
 
179
        } catch (VersionNotSupportedException ex){}
 
180
    }
 
181
    public void setAllIcons(String[] locales, String[] smallIcons, String[] largeIcons) throws VersionNotSupportedException {
 
182
        org.netbeans.modules.j2ee.dd.api.common.Icon[] newIcons = new org.netbeans.modules.j2ee.dd.api.common.Icon[locales.length];
 
183
        for (int i=0;i<locales.length;i++) {
 
184
            try {
 
185
                newIcons[i] = (org.netbeans.modules.j2ee.dd.api.common.Icon)createBean("Icon"); //NOI18N
 
186
                if (smallIcons[i]!=null) newIcons[i].setSmallIcon(smallIcons[i]);
 
187
                if (largeIcons[i]!=null) newIcons[i].setLargeIcon(largeIcons[i]);
 
188
                if (locales[i]!=null) newIcons[i].setXmlLang(locales[i]);
 
189
            } catch (ClassNotFoundException ex){}
 
190
        }
 
191
        setIcon(newIcons);
 
192
    }
 
193
    
 
194
    public void setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon) {
 
195
        if (icon==null) removeIcon();
 
196
        else {
 
197
            org.netbeans.modules.j2ee.dd.api.common.Icon[] oldIcons = getIcon();
 
198
            boolean found=false;
 
199
            try {
 
200
                String locale = icon.getXmlLang();
 
201
                for (int i=0;i<oldIcons.length;i++) {
 
202
                    String loc=oldIcons[i].getXmlLang();
 
203
                        if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
 
204
                        found=true;
 
205
                        setIcon(i, icon);
 
206
                    }
 
207
                }
 
208
            } catch (VersionNotSupportedException ex){}
 
209
            if (!found) {
 
210
                addIcon(icon);
 
211
            }
 
212
        }
 
213
    }
 
214
    
 
215
    public String getSmallIcon(String locale) throws VersionNotSupportedException {
 
216
        return getIcon(locale,true);
 
217
    }
 
218
    public String getSmallIcon() {
 
219
        try {
 
220
            return getSmallIcon(null);
 
221
        } catch (VersionNotSupportedException ex){return null;}
 
222
    }
 
223
    public String getLargeIcon(String locale) throws VersionNotSupportedException {
 
224
        return getIcon(locale,false);
 
225
    }
 
226
    public String getLargeIcon() {
 
227
        try {
 
228
            return getLargeIcon(null);
 
229
        } catch (VersionNotSupportedException ex){return null;}
 
230
    }
 
231
    public org.netbeans.modules.j2ee.dd.api.common.Icon getDefaultIcon() {
 
232
        org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
 
233
        for (int i=0;i<icons.length;i++) {
 
234
            try {
 
235
                String loc=icons[i].getXmlLang();
 
236
                if (loc==null) return icons[i];
 
237
            } catch (VersionNotSupportedException ex){}
 
238
        }
 
239
        return null;
 
240
    }
 
241
    public java.util.Map getAllIcons() {
 
242
        java.util.Map map =new java.util.HashMap();
 
243
        org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
 
244
        for (int i=0;i<icons.length;i++) {
 
245
            String[] iconPair = new String[] {icons[i].getSmallIcon(),icons[i].getLargeIcon()};
 
246
            String loc=null;
 
247
            try {
 
248
                loc=icons[i].getXmlLang();
 
249
            } catch (VersionNotSupportedException ex){}
 
250
            map.put(loc, iconPair);
 
251
        }
 
252
        return map;
 
253
    }
 
254
    
 
255
    public void removeSmallIcon(String locale) throws VersionNotSupportedException {
 
256
        removeIcon(locale, true);
 
257
    }
 
258
    public void removeLargeIcon(String locale) throws VersionNotSupportedException {
 
259
        removeIcon(locale, false);
 
260
    }
 
261
    public void removeIcon(String locale) throws VersionNotSupportedException {
 
262
        org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
 
263
        for (int i=0;i<icons.length;i++) {
 
264
            String loc=icons[i].getXmlLang();
 
265
            if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
 
266
                removeIcon(icons[i]);                    
 
267
            }
 
268
        }
 
269
    }
 
270
    public void removeSmallIcon() {
 
271
        try {
 
272
            removeSmallIcon(null);
 
273
        } catch (VersionNotSupportedException ex){}
 
274
    }
 
275
    public void removeLargeIcon() {
 
276
        try {
 
277
            removeLargeIcon(null);
 
278
        } catch (VersionNotSupportedException ex){}
 
279
    }
 
280
    public void removeIcon() {
 
281
        org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
 
282
        for (int i=0;i<icons.length;i++) {
 
283
            try {
 
284
                String loc=icons[i].getXmlLang();
 
285
                if (loc==null) removeIcon(icons[i]);
 
286
            } catch (VersionNotSupportedException ex){}
 
287
        }
 
288
    }
 
289
    public void removeAllIcons() {
 
290
        setIcon(new org.netbeans.modules.j2ee.dd.api.common.Icon[]{});
 
291
    }
 
292
    private void setIcon(String locale, String icon, boolean isSmall) throws VersionNotSupportedException {
 
293
        if (icon==null) {
 
294
            if (isSmall) removeSmallIcon(locale);
 
295
            else removeLargeIcon(locale);
 
296
        }
 
297
        else {
 
298
            org.netbeans.modules.j2ee.dd.api.common.Icon[] oldIcons = getIcon();
 
299
            boolean found=false;
 
300
            for (int i=0;i<oldIcons.length;i++) {
 
301
                String loc=oldIcons[i].getXmlLang();
 
302
                if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
 
303
                    found=true;
 
304
                    if (isSmall) oldIcons[i].setSmallIcon(icon);
 
305
                    else oldIcons[i].setLargeIcon(icon);
 
306
                    break;
 
307
                }
 
308
            }
 
309
            if (!found) {
 
310
                try {
 
311
                    org.netbeans.modules.j2ee.dd.api.common.Icon newIcon = (org.netbeans.modules.j2ee.dd.api.common.Icon)createBean("Icon"); //NOI18N
 
312
                    if (locale!=null) newIcon.setXmlLang(locale.toLowerCase());
 
313
                    if (isSmall) newIcon.setSmallIcon(icon);
 
314
                    else newIcon.setLargeIcon(icon);
 
315
                    addIcon(newIcon);
 
316
                } catch (ClassNotFoundException ex){}
 
317
            }
 
318
        }
 
319
    }
 
320
    private String getIcon(String locale, boolean isSmall) throws VersionNotSupportedException {
 
321
        for (int i=0;i<sizeIcon();i++) {
 
322
            org.netbeans.modules.j2ee.dd.api.common.Icon icon = getIcon(i);
 
323
            String loc=icon.getXmlLang();
 
324
            if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
 
325
                if (isSmall) return icon.getSmallIcon();
 
326
                else return icon.getLargeIcon();
 
327
            }
 
328
        }
 
329
        return null;
 
330
    }
 
331
    
 
332
    public void removeIcon(String locale, boolean isSmall) throws VersionNotSupportedException  {
 
333
        org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
 
334
        java.util.List iconList = new java.util.ArrayList();
 
335
        for (int i=0;i<icons.length;i++) {
 
336
            String loc=icons[i].getXmlLang();
 
337
            if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
 
338
                if (isSmall) {
 
339
                    icons[i].setSmallIcon(null);
 
340
                    if (icons[i].getLargeIcon()==null) iconList.add(icons[i]);
 
341
                } else {
 
342
                    icons[i].setLargeIcon(null);
 
343
                    if (icons[i].getSmallIcon()==null) iconList.add(icons[i]);                    
 
344
                }
 
345
            }
 
346
        }
 
347
        java.util.Iterator it = iconList.iterator();
 
348
        while(it.hasNext()) removeIcon((org.netbeans.modules.j2ee.dd.api.common.Icon)it.next());
 
349
    }
 
350
}