Source Code Cross Referenced for BindingTargetNode.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » faces » dt » binding » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.faces.dt.binding 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.visualweb.faces.dt.binding;
042:
043:        import java.awt.*;
044:        import java.awt.event.*;
045:        import java.beans.*;
046:        import java.lang.reflect.*;
047:        import java.util.*;
048:        import java.util.List;
049:        import javax.faces.context.*;
050:        import javax.faces.el.*;
051:        import javax.swing.*;
052:        import javax.swing.tree.*;
053:        import com.sun.rave.designtime.*;
054:        import com.sun.rave.designtime.faces.*;
055:        import com.sun.rave.designtime.markup.*;
056:        import org.netbeans.modules.visualweb.faces.dt.util.ComponentBundle;
057:
058:        public abstract class BindingTargetNode implements  TreeNode {
059:
060:            private static final ComponentBundle bundle = ComponentBundle
061:                    .getBundle(BindingTargetNode.class);
062:
063:            //------------------------------------------------------------------------------- STATIC METHODS
064:
065:            private static List factoryList = new ArrayList();
066:
067:            public static void _registerTargetNodeFactory(TargetNodeFactory tnf) {
068:                factoryList.add(0, tnf);
069:            }
070:
071:            public static BindingTargetNode _createTargetNode(
072:                    DefaultTreeModel treeModel, DesignBean bean,
073:                    PropertyDescriptor[] propPath, Object propInstance) {
074:
075:                if (bean == null)
076:                    return null;
077:                Class targetClass = propInstance != null ? propInstance
078:                        .getClass() : null;
079:                if (targetClass == null && propPath != null
080:                        && propPath.length > 0) {
081:                    Object o = getPropInstance(bean, propPath);
082:                    if (o != null) {
083:                        propInstance = o;
084:                        targetClass = o.getClass();
085:                    } else {
086:                        targetClass = propPath[propPath.length - 1]
087:                                .getPropertyType();
088:                    }
089:                }
090:                if (targetClass == null) {
091:                    Object o = bean.getInstance();
092:                    if (o != null) {
093:                        propInstance = o;
094:                        targetClass = o.getClass();
095:                    } else {
096:                        targetClass = bean.getBeanInfo().getBeanDescriptor()
097:                                .getBeanClass();
098:                    }
099:                }
100:                for (int i = 0; i < factoryList.size(); i++) {
101:                    TargetNodeFactory tnf = (TargetNodeFactory) factoryList
102:                            .get(i);
103:                    if (tnf.supportsTargetClass(targetClass)) {
104:                        BindingTargetNode btn = tnf.createTargetNode(treeModel,
105:                                bean, propPath, propInstance);
106:                        if (btn != null) {
107:                            return btn;
108:                        }
109:                    }
110:                }
111:                return new PropertyTargetNode(treeModel, bean, propPath,
112:                        propInstance);
113:            }
114:
115:            //---------------------------------------------------------------------------- BindingTargetNode
116:
117:            //----------------------------------------------------------------------------- abstract methods
118:
119:            public abstract boolean lazyLoad();
120:
121:            public abstract boolean isValidBindingTarget();
122:
123:            public abstract String getBindingExpressionPart();
124:
125:            public abstract Class getTargetTypeClass();
126:
127:            public abstract String getDisplayText(boolean enabled);
128:
129:            public BindingTargetNode(DefaultTreeModel treeModel) {
130:                this .treeModel = treeModel;
131:            }
132:
133:            protected DefaultTreeModel treeModel;
134:            protected HashMap userDataHash = new HashMap();
135:
136:            public Map getUserDataMap() {
137:                return userDataHash;
138:            }
139:
140:            public boolean hasDisplayIcon() {
141:                return false;
142:            }
143:
144:            public Icon getDisplayIcon(boolean enabled) {
145:                // subclasses can put their custom icon here - only called if hasCustomDisplayIcon() returns true
146:                return null;
147:            }
148:
149:            public JComponent getCustomDisplayPanel(
150:                    ActionListener updateCallback) {
151:                return null;
152:            }
153:
154:            public String getTargetTypeDisplayName() {
155:                Class c = getTargetTypeClass();
156:                if (c != null) {
157:                    return decodeTypeName(c.getName());
158:                }
159:                return ""; //NOI18N
160:            }
161:
162:            protected TreeNode parent;
163:            protected Vector children = new Vector();
164:            protected boolean loaded = false;
165:
166:            public void add(BindingTargetNode child) {
167:                if (child instanceof  BindingTargetNode) {
168:                    children.add(child);
169:                    child.setParent(this );
170:                }
171:            }
172:
173:            public void add(int index, BindingTargetNode child) {
174:                if (child instanceof  BindingTargetNode) {
175:                    children.add(index, child);
176:                    child.setParent(this );
177:                }
178:            }
179:
180:            public void remove(BindingTargetNode child) {
181:                children.remove(child);
182:            }
183:
184:            public void removeAll() {
185:                children.clear();
186:                loaded = false;
187:            }
188:
189:            public void setParent(TreeNode parent) {
190:                this .parent = parent;
191:            }
192:
193:            //------------------------------------------------------------------------------------- TreeNode
194:
195:            public TreeNode getChildAt(int childIndex) {
196:                if (!loaded) {
197:                    loaded = lazyLoad();
198:                }
199:                if (children.size() > childIndex) {
200:                    return (TreeNode) children.get(childIndex);
201:                }
202:                return null;
203:            }
204:
205:            public int getChildCount() {
206:                if (!loaded) {
207:                    loaded = lazyLoad();
208:                }
209:                return children.size();
210:            }
211:
212:            public TreeNode getParent() {
213:                return parent;
214:            }
215:
216:            public int getIndex(TreeNode node) {
217:                if (!loaded) {
218:                    loaded = lazyLoad();
219:                }
220:                return children.indexOf(node);
221:            }
222:
223:            public boolean getAllowsChildren() {
224:                return true;
225:            }
226:
227:            public boolean isLeaf() {
228:                if (!loaded) {
229:                    loaded = lazyLoad();
230:                }
231:                return children.size() == 0;
232:            }
233:
234:            public Enumeration children() {
235:                if (!loaded) {
236:                    loaded = lazyLoad();
237:                }
238:                return children.elements();
239:            }
240:
241:            //------------------------------------------------------------------- BindingTargetNode.RootNode
242:
243:            public static class RootTargetNode extends BindingTargetNode {
244:                public RootTargetNode() {
245:                    super (null);
246:                }
247:
248:                public boolean lazyLoad() {
249:                    return true;
250:                }
251:
252:                public String getDisplayText(boolean enableNode) {
253:                    return null;
254:                }
255:
256:                public boolean isValidBindingTarget() {
257:                    return false;
258:                }
259:
260:                public String getBindingExpressionPart() {
261:                    return null;
262:                }
263:
264:                public Class getTargetTypeClass() {
265:                    return null;
266:                }
267:            }
268:
269:            //------------------------------------------------------------- BindingTargetNode.NullTargetNode
270:
271:            public static class NullTargetNode extends BindingTargetNode {
272:                public NullTargetNode(DefaultTreeModel treeModel) {
273:                    super (treeModel);
274:                    this .displayText = "<html><b>"
275:                            + bundle.getMessage("propertyNotBound")
276:                            + "</b></html>"; //NOI18N
277:                }
278:
279:                public boolean lazyLoad() {
280:                    return true;
281:                }
282:
283:                protected String displayText;
284:
285:                public String getDisplayText(boolean enableNode) {
286:                    return displayText;
287:                }
288:
289:                public boolean isValidBindingTarget() {
290:                    return true;
291:                }
292:
293:                public String getBindingExpressionPart() {
294:                    return null;
295:                }
296:
297:                public Class getTargetTypeClass() {
298:                    return null;
299:                }
300:            }
301:
302:            //-------------------------------------------------------------- BindingTargetNode.UIDataVarNode
303:
304:            public static class UIDataVarNode extends BindingTargetNode {
305:                public UIDataVarNode(DefaultTreeModel treeModel,
306:                        DesignBean uiDataBean) {
307:                    super (treeModel);
308:                    this .uiDataBean = uiDataBean;
309:                    this .displayText = "<html>" + uiDataBean.getInstanceName()
310:                            + " var property: <b>"
311:                            + uiDataBean.getProperty("var").getValue()
312:                            + "</b></html>";
313:                }
314:
315:                protected DesignBean uiDataBean;
316:
317:                public DesignBean getUIDataBean() {
318:                    return uiDataBean;
319:                }
320:
321:                public boolean lazyLoad() {
322:                    //            UIData udb = (UIData)uiDataBean.getInstance();
323:                    //            Object value = udb.getValue();
324:                    //            if (value instanceof DataModel) {
325:                    //                DataModel dm = (DataModel)value;
326:                    //                try {
327:                    //                    Object o = null;
328:                    //                    try {
329:                    //                        int rc = dm.getRowCount();
330:                    //                        if (rc > 0) {
331:                    //                            int idx = dm.getRowIndex();
332:                    //                            if (idx < 0) {
333:                    //                                dm.setRowIndex(0);
334:                    //                            }
335:                    //                        }
336:                    //                        o = dm.getRowData();
337:                    //                    }
338:                    //                    catch (Exception x1) {
339:                    //                        x1.printStackTrace();
340:                    //                    }
341:                    //                    if (o != null) {
342:                    //                        BeanInfo bi = Introspector.getBeanInfo(o.getClass());
343:                    //                        PropertyDescriptor[] pds = bi.getPropertyDescriptors();
344:                    //                        PropertyDescriptor[] pdArray = new PropertyDescriptor[0];
345:                    //                        DesignBean b = uiDataBean;
346:                    //                        for (int i = 0; pds != null && i < pds.length; i++) {
347:                    //                            if (pds[i].getReadMethod() != null) {
348:                    //                                ArrayList pdList = new ArrayList(Arrays.asList(pdArray));
349:                    //                                pdList.add(pds[i]);
350:                    //                                PropertyDescriptor[] pdPath = (PropertyDescriptor[])pdList.toArray(
351:                    //                                    new PropertyDescriptor[pdList.size()]);
352:                    //                                BindingTargetNode btn = _createTargetNode(
353:                    //                                    treeModel, b, pdPath);
354:                    //                                super.add(btn);
355:                    //                            }
356:                    //                        }
357:                    //                    }
358:                    //                }
359:                    //                catch (Exception x) {
360:                    //                    x.printStackTrace();
361:                    //                }
362:                    //            }
363:                    return true;
364:                }
365:
366:                protected String displayText;
367:
368:                public String getDisplayText(boolean enableNode) {
369:                    return displayText;
370:                }
371:
372:                public boolean hasDisplayIcon() {
373:                    return getChildCount() < 1;
374:                }
375:
376:                Icon displayIcon = UIManager.getIcon("Tree.closedIcon"); // NOI18N
377:
378:                public Icon getDisplayIcon(boolean enableNode) {
379:                    return displayIcon;
380:                }
381:
382:                public boolean isValidBindingTarget() {
383:                    return true;
384:                }
385:
386:                public String getBindingExpressionPart() {
387:                    return "" + uiDataBean.getProperty("var").getValue();
388:                }
389:
390:                public Class getTargetTypeClass() {
391:                    return null;
392:                }
393:            }
394:
395:            //---------------------------------------------------------- BindingTargetNode.ContextTargetNode
396:
397:            public static class ContextTargetNode extends BindingTargetNode {
398:                public ContextTargetNode(DefaultTreeModel treeModel,
399:                        DesignContext context) {
400:                    super (treeModel);
401:                    this .context = context;
402:                    this .displayText = "<html><b>" + context.getDisplayName()
403:                            + "</b></html>"; //NOI18N
404:                }
405:
406:                protected DesignContext context;
407:
408:                public DesignContext getDesignContext() {
409:                    return context;
410:                }
411:
412:                public boolean lazyLoad() {
413:                    DesignBean[] kids = getDesignContext().getRootContainer()
414:                            .getChildBeans();
415:                    for (int i = 0; kids != null && i < kids.length; i++) {
416:                        super .add(_createTargetNode(treeModel, kids[i], null,
417:                                kids[i].getInstance()));
418:                    }
419:                    return true;
420:                }
421:
422:                protected String displayText;
423:
424:                public String getDisplayText(boolean enableNode) {
425:                    return displayText;
426:                }
427:
428:                public boolean hasDisplayIcon() {
429:                    return getChildCount() < 1;
430:                }
431:
432:                Icon displayIcon = UIManager.getIcon("Tree.closedIcon"); // NOI18N
433:
434:                public Icon getDisplayIcon(boolean enableNode) {
435:                    return displayIcon;
436:                }
437:
438:                public boolean isValidBindingTarget() {
439:                    return true;
440:                }
441:
442:                public String getBindingExpressionPart() {
443:                    if (context instanceof  FacesDesignContext) {
444:                        return ((FacesDesignContext) context)
445:                                .getReferenceName();
446:                    }
447:                    return context.getDisplayName();
448:                }
449:
450:                public Class getTargetTypeClass() {
451:                    return null;
452:                }
453:            }
454:
455:            //--------------------------------------------------------- BindingTargetNode.PropertyTargetNode
456:
457:            public static class PropertyTargetNode extends BindingTargetNode {
458:                public PropertyTargetNode(DefaultTreeModel treeModel,
459:                        DesignBean bean, PropertyDescriptor[] propPath,
460:                        Object propInstance) {
461:                    super (treeModel);
462:                    this .bean = bean;
463:                    this .propPath = propPath;
464:                    this .propInstance = propInstance;
465:                    this .displayTextEnabled = getDisplayText(true);
466:                    this .displayTextDisabled = getDisplayText(false);
467:                }
468:
469:                protected DesignBean bean;
470:
471:                public DesignBean getBean() {
472:                    return bean;
473:                }
474:
475:                protected PropertyDescriptor[] propPath;
476:
477:                public PropertyDescriptor[] getPropPath() {
478:                    return propPath;
479:                }
480:
481:                protected Object propInstance;
482:
483:                public Object getPropInstance() {
484:                    return propInstance;
485:                }
486:
487:                public boolean lazyLoad() {
488:                    lazyLoadCustomTargetNodes();
489:                    if (propPath == null) {
490:                        lazyLoadBeanTargetNodes();
491:                    }
492:                    if (isValidBindingTarget()) {
493:                        lazyLoadPropertyTargetNodes();
494:                    }
495:                    return true;
496:                }
497:
498:                public void lazyLoadCustomTargetNodes() {
499:                    // subclasses can put their stuff here
500:                }
501:
502:                public void lazyLoadBeanTargetNodes() {
503:                    if (bean.isContainer()) {
504:                        DesignBean[] kids = bean.getChildBeans();
505:                        for (int i = 0; kids != null && i < kids.length; i++) {
506:                            super .add(_createTargetNode(treeModel, kids[i],
507:                                    null, kids[i].getInstance()));
508:                        }
509:                    }
510:                }
511:
512:                public void lazyLoadPropertyTargetNodes() {
513:                    try {
514:                        BeanInfo bi = Introspector
515:                                .getBeanInfo(getTargetTypeClass());
516:                        PropertyDescriptor[] pds = bi.getPropertyDescriptors();
517:                        for (int i = 0; pds != null && i < pds.length; i++) {
518:                            if (pds[i].getReadMethod() != null) {
519:                                ArrayList pdList = new ArrayList();
520:                                for (int j = 0; propPath != null
521:                                        && j < propPath.length; j++) {
522:                                    pdList.add(propPath[j]);
523:                                }
524:                                pdList.add(pds[i]);
525:                                PropertyDescriptor[] pda = (PropertyDescriptor[]) pdList
526:                                        .toArray(new PropertyDescriptor[pdList
527:                                                .size()]);
528:                                BindingTargetNode btn = _createTargetNode(
529:                                        treeModel, bean, pda, null);
530:                                super .add(btn);
531:                            }
532:                        }
533:                    } catch (Exception x) {
534:                        x.printStackTrace();
535:                    }
536:                }
537:
538:                protected String displayTextEnabled;
539:                protected String displayTextDisabled;
540:
541:                public String getDisplayText(boolean enableNode) {
542:                    if (enableNode && displayTextEnabled != null) {
543:                        return displayTextEnabled;
544:                    } else if (!enableNode && displayTextDisabled != null) {
545:                        return displayTextDisabled;
546:                    }
547:                    PropertyDescriptor pd = (propPath != null && propPath.length > 0) ? propPath[propPath.length - 1]
548:                            : null;
549:                    StringBuffer sb = new StringBuffer();
550:                    sb.append("<html>"); //NOI18N
551:                    if (!enableNode) {
552:                        sb.append("<font color=\"gray\">"); //NOI18N
553:                    }
554:                    if (pd != null) {
555:                        sb.append(bundle.getMessage("property")); //NOI18N
556:                        sb.append(" "); //NOI18N
557:                    }
558:                    if (enableNode) {
559:                        sb.append("<b>"); //NOI18N
560:                    }
561:                    if (pd != null) {
562:                        sb.append(pd.getName());
563:                    } else {
564:                        sb.append(bean.getInstanceName());
565:                    }
566:                    if (enableNode) {
567:                        sb.append("</b>"); //NOI18N
568:                    }
569:                    sb.append(" &nbsp; <font size=\"-1\"><i>"); //NOI18N
570:                    sb.append(getTargetTypeDisplayName());
571:                    sb.append("</i></font>"); //NOI18N
572:                    if (!enableNode) {
573:                        sb.append("</font>"); //NOI18N
574:                    }
575:                    sb.append("</html>"); //NOI18N
576:                    return sb.toString();
577:                }
578:
579:                public boolean isValidBindingTarget() {
580:                    if (propPath == null
581:                            && bean.getDesignContext() instanceof  FacesDesignContext) {
582:                        return ((FacesDesignContext) bean.getDesignContext())
583:                                .isValidBindingTarget(bean);
584:                    }
585:                    return true;
586:                }
587:
588:                public String getBindingExpressionPart() {
589:                    if (propPath != null && propPath.length > 0) {
590:                        return propPath[propPath.length - 1].getName();
591:                    }
592:                    return bean.getInstanceName();
593:                }
594:
595:                public Class getTargetTypeClass() {
596:                    if (propInstance == null) {
597:                        propInstance = getPropInstance(bean, propPath);
598:                    }
599:                    if (propInstance != null) {
600:                        if (!propInstance.getClass().isPrimitive()) {
601:                            return propInstance.getClass();
602:                        }
603:                    }
604:                    return propPath != null && propPath.length > 0 ? propPath[propPath.length - 1]
605:                            .getPropertyType()
606:                            : bean.getInstance() != null ? bean.getInstance()
607:                                    .getClass()
608:                                    : bean.getBeanInfo() != null ? bean
609:                                            .getBeanInfo().getBeanDescriptor()
610:                                            .getBeanClass() : null;
611:                }
612:
613:                boolean iconChecked = false;
614:
615:                public boolean hasDisplayIcon() {
616:                    if (!iconChecked) {
617:                        displayIcon = getDisplayIcon(true);
618:                        iconChecked = true;
619:                    }
620:                    return displayIcon != null;
621:                }
622:
623:                Icon displayIcon = null;
624:
625:                public Icon getDisplayIcon(boolean enableNode) {
626:                    if (displayIcon == null) {
627:                        if (propInstance == null) {
628:                            propInstance = getPropInstance(bean, propPath);
629:                        }
630:                        if (propInstance != null) {
631:                            try {
632:                                BeanInfo bi = Introspector
633:                                        .getBeanInfo(propInstance.getClass());
634:                                Image img = bi
635:                                        .getIcon(BeanInfo.ICON_COLOR_16x16);
636:                                if (img != null) {
637:                                    displayIcon = new ImageIcon(img);
638:                                }
639:                            } catch (Exception x) {
640:                            }
641:                            if (displayIcon == null
642:                                    && (propPath == null || propPath.length == 0)) {
643:                                if (bean instanceof  MarkupDesignBean
644:                                        && ((MarkupDesignBean) bean)
645:                                                .getElement() != null) {
646:                                    displayIcon = TargetPanel.TAG_ICON;
647:                                }
648:                            }
649:                        }
650:                    }
651:                    if (displayIcon == null/* && propPath == null*/) {
652:                        displayIcon = TargetPanel.BEAN_ICON;
653:                    }
654:                    return displayIcon;
655:                }
656:            }
657:
658:            //------------------------------------------------------------------------------- Helper methods
659:
660:            public static Object getPropInstance(DesignBean bean,
661:                    PropertyDescriptor[] propPath) {
662:                if (propPath != null && propPath.length > 0) {
663:                    try {
664:                        ArrayList propList = new ArrayList();
665:                        for (int i = 0; i < propPath.length; i++) {
666:                            propList.add(propPath[i]);
667:                        }
668:                        Object o = bean.getInstance();
669:                        while (o != null && propList.size() > 0) {
670:                            PropertyDescriptor pdnext = (PropertyDescriptor) propList
671:                                    .get(0);
672:                            BeanInfo bi = Introspector
673:                                    .getBeanInfo(o.getClass());
674:                            PropertyDescriptor[] pdanext = bi
675:                                    .getPropertyDescriptors();
676:                            for (int i = 0; i < pdanext.length; i++) {
677:                                if (pdanext[i].getName().equals(
678:                                        pdnext.getName())) {
679:                                    //System.out.println("found: " + pdnext.getName() + " : " + propList.size() + " left");
680:                                    Method read = pdanext[i].getReadMethod();
681:                                    if (read != null) {
682:                                        try {
683:                                            o = read.invoke(o, new Object[] {});
684:                                            if (o instanceof  ValueBinding) {
685:                                                o = ((ValueBinding) o)
686:                                                        .getValue(FacesContext
687:                                                                .getCurrentInstance());
688:                                            }
689:                                        } catch (Exception x) {
690:                                            return null;
691:                                        }
692:                                        if (o != null) {
693:                                            propList.remove(0);
694:                                            continue;
695:                                        }
696:                                    } else {
697:                                        return null;
698:                                    }
699:                                }
700:                            }
701:                        }
702:                        return o;
703:                    } catch (Exception x) {
704:                        x.printStackTrace();
705:                    }
706:                } else {
707:                    return bean.getInstance();
708:                }
709:                return null;
710:            }
711:
712:            static HashMap arrayTypeKeyHash = new HashMap();
713:            static {
714:                arrayTypeKeyHash.put("B", "byte"); //NOI18N
715:                arrayTypeKeyHash.put("C", "char"); //NOI18N
716:                arrayTypeKeyHash.put("D", "double"); //NOI18N
717:                arrayTypeKeyHash.put("F", "float"); //NOI18N
718:                arrayTypeKeyHash.put("I", "int"); //NOI18N
719:                arrayTypeKeyHash.put("J", "long"); //NOI18N
720:                arrayTypeKeyHash.put("S", "short"); //NOI18N
721:                arrayTypeKeyHash.put("Z", "boolean"); //NOI18N
722:                arrayTypeKeyHash.put("V", "void"); //NOI18N
723:            }
724:
725:            public static String decodeTypeName(String tn) {
726:                if (tn.startsWith("[")) { //NOI18N
727:                    int depth = 0;
728:                    while (tn.startsWith("[")) { //NOI18N
729:                        tn = tn.substring(1);
730:                        depth++;
731:                    }
732:                    if (tn.startsWith("L")) { //NOI18N
733:                        tn = tn.substring(1);
734:                        tn = tn.substring(0, tn.length() - 1);
735:                    } else {
736:                        char typeKey = tn.charAt(0);
737:                        tn = (String) arrayTypeKeyHash.get("" + typeKey); //NOI18N
738:                    }
739:                    for (int i = 0; i < depth; i++) {
740:                        tn += "[]"; //NOI18N
741:                    }
742:                }
743:                if (tn.indexOf(".") > -1) { //NOI18N
744:                    tn = tn.substring(tn.lastIndexOf(".") + 1);
745:                }
746:                return tn;
747:            }
748:        }
749:        //    //------------------------------------------------------------- BindingTargetNode.BeanTargetNode
750:        //
751:        //    public static final String FACET_KEY = "facet"; // NOI18N
752:        //
753:        //    public static class BeanTargetNode extends BindingTargetNode {
754:        //        public BeanTargetNode(DefaultTreeModel treeModel, DesignBean bean) {
755:        //            super(treeModel);
756:        //            this.bean = bean;
757:        //            this.displayTextEnabled = getCustomDisplayText(true);
758:        //            this.displayTextDisabled = getCustomDisplayText(false);
759:        //        }
760:        //        protected DesignBean bean;
761:        //        public DesignBean getBean() {
762:        //            return bean;
763:        //        }
764:        //        public boolean lazyLoad() {
765:        //            lazyLoadCustomTargetNodes();
766:        //            lazyLoadBeanTargetNodes();
767:        //            if (isValidBindingTarget()) {
768:        //                lazyLoadPropertyTargetNodes();
769:        //            }
770:        //            return true;
771:        //        }
772:        //        public void lazyLoadCustomTargetNodes() {
773:        //            // subclasses can put their stuff here
774:        //        }
775:        //        public void lazyLoadBeanTargetNodes() {
776:        //            if (bean.isContainer()) {
777:        //                DesignBean[] kids = bean.getChildBeans();
778:        //                for (int i = 0; kids != null && i < kids.length; i++) {
779:        //                    super.add(_createTargetNode(treeModel, kids[i], null));
780:        //                }
781:        //            }
782:        //        }
783:        //        public void lazyLoadPropertyTargetNodes() {
784:        //            try {
785:        //                BeanInfo bi = Introspector.getBeanInfo(getTargetTypeClass());
786:        //                PropertyDescriptor[] pds = bi.getPropertyDescriptors();
787:        //                for (int i = 0; pds != null && i < pds.length; i++) {
788:        //                    if (pds[i].getReadMethod() != null) {
789:        //                        BindingTargetNode btn = _createTargetNode(
790:        //                            treeModel, bean, new PropertyDescriptor[] { pds[i] });
791:        //                        super.add(btn);
792:        //                    }
793:        //                }
794:        //            }
795:        //            catch (Exception x) {
796:        //                x.printStackTrace();
797:        //            }
798:        //        }
799:        //        protected String displayTextEnabled;
800:        //        protected String displayTextDisabled;
801:        //        public String getCustomDisplayText(boolean enableNode) {
802:        //            if (enableNode && displayTextEnabled != null) {
803:        //                return displayTextEnabled;
804:        //            }
805:        //            else if (!enableNode && displayTextDisabled != null) {
806:        //                return displayTextDisabled;
807:        //            }
808:        //            String facet = (String)getUserDataMap().get(FACET_KEY);
809:        //            StringBuffer sb = new StringBuffer();
810:        //            sb.append("<html>");    //NOI18N
811:        //            if (facet != null) {
812:        //                sb.append(bundle.getMessage("facet")); //NOI18N
813:        //                sb.append(" "); //NOI18N
814:        //                if (enableNode) {
815:        //                    sb.append("<b>");
816:        //                }
817:        //                sb.append(facet);
818:        //                if (enableNode) {
819:        //                    sb.append("</b>");
820:        //                }
821:        //                sb = new StringBuffer(bundle.getMessage("trailingColon", sb.toString())); //NOI18N
822:        //                sb.append(" ");  //NOI18N
823:        //            }
824:        //            if (enableNode) {
825:        //                sb.append("<b>");    //NOI18N
826:        //            }
827:        //            else {
828:        //                sb.append("<font color=\"gray\">");  //NOI18N
829:        //            }
830:        //            sb.append(bean.getInstanceName());
831:        //            if (enableNode) {
832:        //                sb.append("</b>");   //NOI18N
833:        //            }
834:        //            sb.append(" &nbsp; <font size=\"-1\"><i>");  //NOI18N
835:        //            sb.append(getTargetTypeDisplayName());
836:        //            sb.append("</i></font>");    //NOI18N
837:        //            if (!enableNode) {
838:        //                sb.append("</font>");    //NOI18N
839:        //            }
840:        //            sb.append("</html>");    //NOI18N
841:        //            return sb.toString();
842:        //        }
843:        //        public boolean hasCustomDisplayIcon() {
844:        //            return true;
845:        //        }
846:        //        Icon displayIcon = null;
847:        //        public Icon getCustomDisplayIcon(boolean enableNode) {
848:        //            if (displayIcon == null) {
849:        //                BeanInfo bi = bean.getBeanInfo();
850:        //                Image img = bi.getIcon(BeanInfo.ICON_COLOR_16x16);
851:        //                if (img != null) {
852:        //                    displayIcon = new ImageIcon(img);
853:        //                }
854:        //                else {
855:        //                    displayIcon = TargetPanel.BEAN_ICON;
856:        //                }
857:        //            }
858:        //            return displayIcon;
859:        //        }
860:        //        public boolean isValidBindingTarget() {
861:        //            if (bean.getDesignContext() instanceof FacesDesignContext) {
862:        //                return ((FacesDesignContext)bean.getDesignContext()).isValidBindingTarget(bean);
863:        //            }
864:        //            return false;
865:        //        }
866:        //        public String getBindingExpressionPart() {
867:        //            return bean.getInstanceName();
868:        //        }
869:        //        public Class getTargetTypeClass() {
870:        //            Object o = bean.getInstance();
871:        //            if (o != null) {
872:        //                if (!o.getClass().isPrimitive()) {
873:        //                    return o.getClass();
874:        //                }
875:        //            }
876:        //            return bean.getBeanInfo().getBeanDescriptor().getBeanClass();
877:        //        }
878:        //    }
w_ww.___j___ava__2___s._c_o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.