Source Code Cross Referenced for DomProviderServiceImpl.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » designer » jsf » 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.designer.jsf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.visualweb.designer.jsf;
0043:
0044:        import com.sun.rave.designtime.Constants;
0045:        import com.sun.rave.designtime.DesignInfo;
0046:        import com.sun.rave.designtime.markup.MarkupTableDesignInfo;
0047:        import java.awt.Component;
0048:        import java.awt.Container;
0049:        import java.awt.Image;
0050:        import java.beans.BeanDescriptor;
0051:        import java.beans.BeanInfo;
0052:        import java.beans.FeatureDescriptor;
0053:        import java.util.Map;
0054:        import java.util.WeakHashMap;
0055:        import javax.swing.JTable;
0056:        import javax.swing.SwingUtilities;
0057:        import javax.swing.table.TableModel;
0058:        import org.netbeans.modules.visualweb.api.designer.Designer;
0059:        import org.netbeans.modules.visualweb.api.designer.DomProviderService;
0060:        import org.netbeans.modules.visualweb.api.designer.markup.MarkupService;
0061:        import com.sun.rave.designtime.DesignBean;
0062:        import com.sun.rave.designtime.DesignContext;
0063:        import com.sun.rave.designtime.DesignProperty;
0064:        import com.sun.rave.designtime.faces.FacesDesignContext;
0065:        import com.sun.rave.designtime.markup.MarkupDesignBean;
0066:        import com.sun.rave.designtime.markup.MarkupMouseRegion;
0067:        import org.netbeans.modules.visualweb.insync.InSyncServiceProvider;
0068:        import org.netbeans.modules.visualweb.insync.Util;
0069:        import org.netbeans.modules.visualweb.insync.faces.Entities;
0070:        import org.netbeans.modules.visualweb.insync.faces.FacesPageUnit;
0071:        import org.netbeans.modules.visualweb.insync.live.DesignBeanNode;
0072:        import org.netbeans.modules.visualweb.insync.live.LiveUnit;
0073:        import org.netbeans.modules.visualweb.insync.markup.MarkupUnit;
0074:        import org.netbeans.modules.visualweb.xhtml.F_Verbatim;
0075:        import java.util.ArrayList;
0076:        import java.util.List;
0077:        import javax.faces.component.UIComponent;
0078:        import javax.faces.component.html.HtmlOutputText;
0079:        import javax.faces.context.FacesContext;
0080:        import org.netbeans.modules.visualweb.xhtml.Jsp_Directive_Include;
0081:        import org.openide.ErrorManager;
0082:        import org.openide.windows.TopComponent;
0083:        import org.openide.windows.WindowManager;
0084:        import org.w3c.dom.Element;
0085:        import org.w3c.dom.Node;
0086:
0087:        /**
0088:         * Implements <code>DomProviderService</code>.
0089:         *
0090:         * @author Peter Zavadsky
0091:         * @author Tor Norbye (old original code)
0092:         */
0093:        public class DomProviderServiceImpl implements  DomProviderService {
0094:
0095:            /** Flag to turn off vb expression editing in inline editing mode */
0096:            private static final boolean NO_EDIT_VB_EXPR = !Boolean
0097:                    .getBoolean("rave.allow-vb-editing");
0098:
0099:            /** Creates a new instance of DomProviderServiceImpl */
0100:            public DomProviderServiceImpl() {
0101:            }
0102:
0103:            //    public MarkupDesignBean getMarkupDesignBeanForElement(Element element) {
0104:            //        return MarkupUnit.getMarkupDesignBeanForElement(element);
0105:            //    }
0106:
0107:            public MarkupMouseRegion getMarkupMouseRegionForElement(
0108:                    Element element) {
0109:                return FacesPageUnit.getMarkupMouseRegionForElement(element);
0110:            }
0111:
0112:            public int getUnexpandedOffset(String unexpanded, int expandedOffset) {
0113:                return Entities.getUnexpandedOffset(unexpanded, expandedOffset);
0114:            }
0115:
0116:            public int getExpandedOffset(String unexpanded, int unexpandedOffset) {
0117:                return Entities.getExpandedOffset(unexpanded, unexpandedOffset);
0118:            }
0119:
0120:            public String expandHtmlEntities(String html, boolean warn,
0121:                    Node node) {
0122:                return Entities.expandHtmlEntities(html, warn, node);
0123:            }
0124:
0125:            //    public ClassLoader getContextClassLoaderForDesignContext(DesignContext designContext) {
0126:            //        return InSyncServiceProvider.get().getContextClassLoader(designContext);
0127:            //    }
0128:
0129:            public String getHtmlStream(Node node) {
0130:                //        return InSyncServiceProvider.get().getHtmlStream(node);
0131:                return Util.getHtmlStream(node);
0132:            }
0133:
0134:            public String getDomDocumentReplacedEventConstant() {
0135:                return MarkupUnit.DOM_DOCUMENT_REPLACED;
0136:            }
0137:
0138:            //    public Designer[] getDesignersForDataObject(DataObject jsfJspDataObject) {
0139:            //        return JsfForm.getDesignersForDataObject(jsfJspDataObject);
0140:            //    }
0141:
0142:            //    public Designer[] findDesignersForFileObject(FileObject jsfJspFileObject) {
0143:            //        return JsfForm.findDesignersForFileObject(jsfJspFileObject);
0144:            //    }
0145:
0146:            //    public Designer[] findDesignersForDesignContext(DesignContext designContext) {
0147:            //        return JsfForm.findDesignersForDesignContext(designContext);
0148:            //    }
0149:
0150:            //    public Designer[] findDesignersForElement(Element element) {
0151:            //        return JsfForm.findDesignersForElement(element);
0152:            //    }
0153:
0154:            //    public Designer[] findDesignersForNode(org.openide.nodes.Node node) {
0155:            //        DesignBean bean = (DesignBean)node.getLookup().lookup(DesignBean.class);
0156:            //        return bean == null ? new Designer[0] : JsfForm.findDesignersForDesignContext(bean.getDesignContext());
0157:            //    }
0158:
0159:            //    public MarkupDesignBean getMarkupDesignBeanForComponentRootElement(Element element, Element parentBoxElement) {
0160:            //        if (element == null) {
0161:            //            return null;
0162:            //        }
0163:            //        MarkupDesignBean markupDesignBean = MarkupUnit.getMarkupDesignBeanForElement(element);
0164:            //
0165:            //        if (parentBoxElement != null) {
0166:            //            // XXX #6494207 There are some elements which have assigned beans but
0167:            //            // are not mapped to any boxes, and in that case we might have not find
0168:            //            // the root box.
0169:            //            if (markupDesignBean == MarkupUnit.getMarkupDesignBeanForElement(parentBoxElement)) {
0170:            //                markupDesignBean = null;
0171:            //            }
0172:            //        } else {
0173:            //            // XXX Is this needed now?
0174:            //            Node parentNode = element.getParentNode();
0175:            //            if (parentNode instanceof Element
0176:            //            && MarkupUnit.getMarkupDesignBeanForElement((Element)parentNode) == markupDesignBean) {
0177:            //                markupDesignBean = null;
0178:            //            }
0179:            //        }
0180:            //        
0181:            //        return markupDesignBean;
0182:            //    }
0183:
0184:            public boolean isPrincipalElement(Element element,
0185:                    Element parentBoxElement) {
0186:                if (element == null) {
0187:                    return false;
0188:                }
0189:                MarkupDesignBean markupDesignBean = MarkupUnit
0190:                        .getMarkupDesignBeanForElement(element);
0191:
0192:                if (parentBoxElement != null) {
0193:                    // XXX #6494207 There are some elements which have assigned beans but
0194:                    // are not mapped to any boxes, and in that case we might have not find
0195:                    // the root box.
0196:                    if (markupDesignBean == MarkupUnit
0197:                            .getMarkupDesignBeanForElement(parentBoxElement)) {
0198:                        markupDesignBean = null;
0199:                    }
0200:                } else {
0201:                    // XXX Is this needed now?
0202:                    Node parentNode = element.getParentNode();
0203:                    if (parentNode instanceof  Element
0204:                            && MarkupUnit
0205:                                    .getMarkupDesignBeanForElement((Element) parentNode) == markupDesignBean) {
0206:                        markupDesignBean = null;
0207:                    }
0208:                }
0209:
0210:                return markupDesignBean != null;
0211:            }
0212:
0213:            //    public boolean isValueBindingExpression(String value, boolean containsOK) {
0214:            //        return DesignBeanNode.isValueBindingExpression(value, containsOK);
0215:            //    }
0216:
0217:            //    public String computeFileName(Object location) {
0218:            //        return Util.computeFileName(location);
0219:            //    }
0220:
0221:            //    public int computeLineNumber(Object location, int lineno) {
0222:            //        return Util.computeLineNumber(location, lineno);
0223:            //    }
0224:
0225:            //    public URL getDocumentUrl(Document document) {
0226:            //        return Util.getDocumentUrl(document);
0227:            //    }
0228:
0229:            //    public void displayErrorForLocation(String message, Object location, int lineno, int column) {
0230:            //        Util.displayErrorForLocation(message, location, lineno, column);
0231:            //    }
0232:
0233:            //    public Element getHtmlBodyForDocument(Document document) {
0234:            //        return Util.getHtmlBodyForDocument(document);
0235:            //    }
0236:
0237:            //    public DocumentFragment getHtmlDomFragmentForDocument(Document document) {
0238:            //        return Util.getHtmlDomFragmentForDocument(document);
0239:            //    }
0240:
0241:            //    public boolean isFacesBean(MarkupDesignBean markupDesignBean) {
0242:            //        return Util.getFacesBean(markupDesignBean) != null;
0243:            //    }
0244:
0245:            //    public boolean isSpecialBean(DesignBean designBean) {
0246:            //        return Util.isSpecialBean(designBean);
0247:            //    }
0248:
0249:            //    public boolean isTrayBean(DesignBean designBean) {
0250:            //        return LiveUnit.isTrayBean(designBean);
0251:            //    }
0252:
0253:            //    public boolean isCssPositionable(DesignBean designBean) {
0254:            //        return LiveUnit.isCssPositionable(designBean);
0255:            //    }
0256:
0257:            //    public Element getElement(DesignBean designBean) {
0258:            //        return Util.getElement(designBean);
0259:            //    }
0260:
0261:            public Element getSourceElement(Element componentRootElement) {
0262:                MarkupDesignBean markupDesignBean = MarkupUnit
0263:                        .getMarkupDesignBeanForElement(componentRootElement);
0264:                return Util.getElement(markupDesignBean);
0265:            }
0266:
0267:            //    public Element getMarkupBeanElement(DesignBean designBean) {
0268:            //        MarkupBean markupBean = Util.getMarkupBean(designBean);
0269:            //        return markupBean == null ? null : markupBean.getElement();
0270:            //    }
0271:
0272:            //    public boolean setDesignProperty(MarkupDesignBean markupDesignBean, String attribute, int value) {
0273:            //        return Util.setDesignProperty(markupDesignBean, attribute, value);
0274:            //    }
0275:            //    public boolean setStyleAttribute(Element componentRootElement, String attribute, int value) {
0276:            ////        MarkupDesignBean markupDesignBean = MarkupUnit.getMarkupDesignBeanForElement(componentRootElement);
0277:            ////        if (markupDesignBean == null) {
0278:            ////            return false;
0279:            ////        }
0280:            ////        return Util.setDesignProperty(markupDesignBean, attribute, value);
0281:            //        return JsfSupportUtilities.setStyleAttribute(componentRootElement, attribute, value);
0282:            //    }
0283:
0284:            //    public Element findHtmlElementDescendant(DocumentFragment df) {
0285:            ////        return Util.findDescendant(HtmlTag.HTML.name, df);
0286:            //        return JsfSupportUtilities.findHtmlElementDescendant(df);
0287:            //    }
0288:
0289:            //    public void updateLocalStyleValuesForElement(Element e, StyleData[] setStyleData, StyleData[] removeStyleData) {
0290:            ////        Util.updateLocalStyleValuesForElement(e, setStyleData, removeStyleData);
0291:            //        JsfSupportUtilities.updateLocalStyleValuesForElement(e, setStyleData, removeStyleData);
0292:            //    }
0293:
0294:            //    public long getContextGenearation(DesignContext context) {
0295:            //        if (context instanceof LiveUnit) {
0296:            //            return ((LiveUnit)context).getContextGeneration();
0297:            //        }
0298:            //        return 0L;
0299:            //    }
0300:
0301:            //    public boolean isWebFormFileObject(FileObject fileObject) {
0302:            ////        return FacesModel.getInstance(fileObject) != null;
0303:            //        return JsfSupportUtilities.isWebFormFileObject(fileObject);
0304:            //    }
0305:
0306:            public boolean isFocusedElement(Element element) {
0307:                if (element == null) {
0308:                    return false;
0309:                }
0310:                MarkupDesignBean markupDesignBean = MarkupUnit
0311:                        .getMarkupDesignBeanForElement(element);
0312:                return isFocus(markupDesignBean);
0313:            }
0314:
0315:            /** XXX Moved from DesignerActions.
0316:             * Returns whether or not this component is the initial focus.
0317:             * @param bean The bean associated with the component
0318:             * @return whether or not that component is the initial focus
0319:             */
0320:            private static boolean isFocus(DesignBean bean) {
0321:                if (bean == null) {
0322:                    return false;
0323:                }
0324:
0325:                DesignBean body = getWebuiBody(bean);
0326:
0327:                if (body == null) {
0328:                    return false;
0329:                }
0330:
0331:                DesignProperty prop = body.getProperty("focus"); // NOI18N
0332:
0333:                if ((prop != null) && (prop.getValue() != null)) {
0334:                    // The property points to the client id, not the instance name!
0335:                    return prop.getValue().equals(getClientId(bean));
0336:                } else {
0337:                    return false;
0338:                }
0339:            }
0340:
0341:            // XXX Moved from DesignerActions.
0342:            /** Find the Body component of the page containing the given bean, if any */
0343:            private static DesignBean getWebuiBody(DesignBean bean) {
0344:                DesignBean parent = bean.getBeanParent();
0345:
0346:                while (parent != null) {
0347:                    if (parent.getInstance() instanceof  com.sun.rave.web.ui.component.Body
0348:                            || parent.getInstance() instanceof  com.sun.webui.jsf.component.Body) {
0349:                        return parent;
0350:                    }
0351:
0352:                    parent = parent.getBeanParent();
0353:                }
0354:
0355:                return null;
0356:            }
0357:
0358:            // XXX Moved from DesignerActions.
0359:            /** Get the client id for the given DesignBean */
0360:            private static String getClientId(DesignBean bean) {
0361:                Object instance = bean.getInstance();
0362:
0363:                if (!(instance instanceof  UIComponent)) {
0364:                    return null;
0365:                }
0366:
0367:                UIComponent uic = (UIComponent) instance;
0368:                DesignContext dcontext = bean.getDesignContext();
0369:                FacesContext fcontext = ((FacesDesignContext) dcontext)
0370:                        .getFacesContext();
0371:
0372:                return uic.getClientId(fcontext);
0373:            }
0374:
0375:            public boolean ignoreDesignBorder(Element element) {
0376:                if (element == null) {
0377:                    return true;
0378:                }
0379:                MarkupDesignBean bean = MarkupUnit
0380:                        .getMarkupDesignBeanForElement(element);
0381:                //        // Only add design borders for boxes that correspond to a live bean
0382:                //        // Gotta do something more here for markup beans
0383:                //        if ((bean == null) || ((
0384:                //            // Deal with the fact that we get design-ids repeated on children
0385:                //            // now, e.g. <table design-id="foo"><tr design-id="foo"> ....
0386:                //            // We only want the outer most box to have the design border
0387:                ////            parent != null) && (parent.getDesignBean() == bean))) {
0388:                //            parent != null) && (getMarkupDesignBeanForCssBox(parent) == bean))) {
0389:                //            return;
0390:                //        }
0391:
0392:                // Special case: the page separator shouldn't have a design border even
0393:                // though it renders a block box and may have dimensions set on it!
0394:                // TODO: Mark it horizontal resizable only!
0395:                if (bean.getInstance() instanceof  com.sun.rave.web.ui.component.PageSeparator
0396:                        || bean.getInstance() instanceof  com.sun.webui.jsf.component.PageSeparator) {
0397:                    return true;
0398:                }
0399:                return false;
0400:            }
0401:
0402:            public Element getSourceElementWhichRendersChildren(Element element) {
0403:                MarkupDesignBean bean = MarkupUnit
0404:                        .getMarkupDesignBeanForElement(element);
0405:                if (bean != null) {
0406:                    MarkupDesignBean parent = findClosestRendersChildren(bean);
0407:                    if (parent != null) {
0408:                        return parent.getElement();
0409:                    }
0410:                }
0411:                return null;
0412:            }
0413:
0414:            // XXX Moved from FacesSupport. !! Changed
0415:            /** Find closest (not the outermost as before) renders-children bean above the given bean, or
0416:             * the bean itself if there is no such parent.
0417:             */
0418:            //    private MarkupDesignBean findRendersChildren(MarkupDesignBean bean) {
0419:            private MarkupDesignBean findClosestRendersChildren(
0420:                    MarkupDesignBean bean) {
0421:                // Similar to FacesSupport.findHtmlContainer(bean), but
0422:                // we need to return the outermost html container itself, not
0423:                // the parent, since we're not looking for its container but
0424:                // the bean to be moved itself.
0425:                MarkupDesignBean curr = bean;
0426:
0427:                //        for (; curr != null; curr = FacesSupport.getBeanParent(curr)) {
0428:                for (; curr != null; curr = getBeanParent(curr)) {
0429:                    if (curr.getInstance() instanceof  F_Verbatim) {
0430:                        // If you have a verbatim, we're okay to add html comps below it
0431:                        return bean;
0432:                    }
0433:
0434:                    if (curr.getInstance() instanceof  UIComponent) {
0435:                        // Need to set the Thread's context classloader to be the Project's ClassLoader.
0436:                        //            	ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
0437:                        //            	try {
0438:                        //                    Thread.currentThread().setContextClassLoader(InSyncService.getProvider().getContextClassLoader(curr));
0439:                        //                    Thread.currentThread().setContextClassLoader(InSyncServiceProvider.get().getContextClassLoader(curr.getDesignContext()));
0440:                        //                    if (((UIComponent)curr.getInstance()).getRendersChildren()) {
0441:                        if (InSyncServiceProvider
0442:                                .isComponentRendersChildren(curr)) {
0443:                            bean = curr;
0444:                            //                        // Can't break here - there could be an outer
0445:                            //                        // renders-children parent
0446:                            // XXX #112580 Find the closest renders-children bean.
0447:                            return bean;
0448:                        }
0449:                        //            	} finally {
0450:                        //                    Thread.currentThread().setContextClassLoader(oldContextClassLoader);
0451:                        //            	} 
0452:                    }
0453:
0454:                }
0455:
0456:                return bean;
0457:            }
0458:
0459:            // XXX Moved from FacesSupport.
0460:            /**
0461:             * Return the parent of the given markup design bean, if the parent is
0462:             * a MarkupDesignBean.
0463:             */
0464:            private static MarkupDesignBean getBeanParent(MarkupDesignBean bean) {
0465:                DesignBean parent = bean.getBeanParent();
0466:
0467:                if (parent instanceof  MarkupDesignBean) {
0468:                    return (MarkupDesignBean) parent;
0469:                }
0470:
0471:                return null;
0472:            }
0473:
0474:            public Element[] getChildComponentRootElements(
0475:                    Element componentRootElement) {
0476:                DesignBean lb = MarkupUnit
0477:                        .getMarkupDesignBeanForElement(componentRootElement);
0478:                if (lb == null) {
0479:                    return new Element[0];
0480:                }
0481:                List<Element> childComponentRootElements = new ArrayList<Element>();
0482:                for (int i = 0, n = lb.getChildBeanCount(); i < n; i++) {
0483:                    DesignBean child = lb.getChildBean(i);
0484:                    if (child instanceof  MarkupDesignBean) {
0485:                        Element sourceElement = ((MarkupDesignBean) child)
0486:                                .getElement();
0487:                        Element childComponentRootElement = MarkupService
0488:                                .getRenderedElementForElement(sourceElement);
0489:                        if (childComponentRootElement != null) {
0490:                            childComponentRootElements
0491:                                    .add(childComponentRootElement);
0492:                        }
0493:                    }
0494:                }
0495:                return childComponentRootElements
0496:                        .toArray(new Element[childComponentRootElements.size()]);
0497:            }
0498:
0499:            //    // XXX Hack.
0500:            //    public MarkupDesignBean adjustRenderBeanHack(MarkupDesignBean renderBean) {
0501:            //        // Handle hyperlinks. We really need to render its surrounding content
0502:            //        // to see the CS stylerules for <a> apply
0503:            //        if (renderBean.getInstance() instanceof HtmlOutputText) {
0504:            //            DesignBean parent = renderBean.getBeanParent();
0505:            //
0506:            //            if ((parent != null) && (parent.getChildBeanCount() == 1) &&
0507:            //                    (parent.getInstance() instanceof HtmlCommandLink ||
0508:            //                    parent.getInstance() instanceof HtmlOutputLink)) {
0509:            //                renderBean = (MarkupDesignBean)parent;
0510:            //            }
0511:            //        }
0512:            //        
0513:            //        // Embedded table portions (rowgroups, columns) aren't happy being rendered
0514:            //        // without their surrounding table.
0515:            //        // It would be better to modify the preview code to actually go and -try- rendering
0516:            //        // components and then progressively retry on parents until it succeeds.
0517:            //        // But given that the code is freezing today I'm playing it safe
0518:            //        if (renderBean.getInstance() instanceof com.sun.rave.web.ui.component.TableColumn
0519:            //        || renderBean.getInstance() instanceof com.sun.webui.jsf.component.TableColumn) {
0520:            //            if (renderBean.getBeanParent() instanceof MarkupDesignBean) {
0521:            //                renderBean = (MarkupDesignBean)renderBean.getBeanParent();
0522:            //            } else {
0523:            //                return null;
0524:            //            }
0525:            //        } else if (renderBean.getBeanParent().getInstance() instanceof com.sun.rave.web.ui.component.TableColumn
0526:            //        || renderBean.getBeanParent().getInstance() instanceof com.sun.webui.jsf.component.TableColumn) {
0527:            //            // We also have to render components that are children of a TableColumn as part of the whole
0528:            //            // table as well, because their value binding expressions can involve data providers set up
0529:            //            // by the table. This is clearly not a clean solution. See comment above about trying arbitary
0530:            //            // rendering instead. This breaks once you nest components in a column inside a container
0531:            //            // component for example. Just doing a low risk, 90% fix now right before FCS.
0532:            //            if (renderBean.getBeanParent().getBeanParent() instanceof MarkupDesignBean) {
0533:            //                renderBean = (MarkupDesignBean)renderBean.getBeanParent().getBeanParent();
0534:            //            } else {
0535:            //                return null;
0536:            //            }
0537:            //        }
0538:            //
0539:            //        // Not else: a TableColumn can be inside a TableRowGroup so keep moving outwards if necessary:
0540:            //        if (renderBean.getInstance() instanceof com.sun.rave.web.ui.component.TableRowGroup
0541:            //        || renderBean.getInstance() instanceof com.sun.webui.jsf.component.TableRowGroup) {
0542:            //            if (renderBean.getBeanParent() instanceof MarkupDesignBean) {
0543:            //                renderBean = (MarkupDesignBean)renderBean.getBeanParent();
0544:            //            } else {
0545:            //                return null;
0546:            //            }
0547:            //        }
0548:            //        return renderBean;
0549:            //    }
0550:
0551:            //    public boolean isFacesComponentBean(DesignBean bean) {
0552:            //        return bean.getInstance() instanceof UIComponent;
0553:            //    }
0554:
0555:            //    public boolean isEscapedDesignBean(DesignBean bean) {
0556:            //        // See if the bean looks like an output text that has escape
0557:            //        // turned off. If so, it's multiline. All others are considered
0558:            //        // single line.
0559:            //        if (bean.getInstance() instanceof HtmlOutputText) {
0560:            //            DesignProperty escape = bean.getProperty("escape"); // NOI18N
0561:            //
0562:            //            if (escape != null) {
0563:            //                Object o = escape.getValue();
0564:            //
0565:            //                if (o instanceof Boolean) {
0566:            //                    return ((Boolean)o).booleanValue();
0567:            //                }
0568:            //            }
0569:            //        }
0570:            //
0571:            //        return true;
0572:            //    }
0573:
0574:            public boolean isFacesComponent(Element componentRootElement) {
0575:                MarkupDesignBean bean = MarkupUnit
0576:                        .getMarkupDesignBeanForElement(componentRootElement);
0577:                if (bean == null) {
0578:                    return false;
0579:                }
0580:                return Util.getFacesBean(bean) != null;
0581:            }
0582:
0583:            //    public Element getRenderedElement(DesignBean designBean) {
0584:            //        return MarkupService.getRenderedElementForElement(Util.getElement(designBean));
0585:            //    }
0586:
0587:            public String getRegionDisplayName(Element regionElement) {
0588:                MarkupMouseRegion region = FacesPageUnit
0589:                        .getMarkupMouseRegionForElement(regionElement);
0590:                return region == null ? null : region.getDisplayName();
0591:            }
0592:
0593:            public boolean isSameRegionOfElement(Element regionElement,
0594:                    Element element) {
0595:                if (regionElement == null) {
0596:                    return false;
0597:                }
0598:                MarkupMouseRegion region = FacesPageUnit
0599:                        .getMarkupMouseRegionForElement(regionElement);
0600:                if (region == null) {
0601:                    return false;
0602:                }
0603:
0604:                return region == FacesPageUnit
0605:                        .getMarkupMouseRegionForElement(element);
0606:            }
0607:
0608:            public Element getComponentRootElementForElement(Element element) {
0609:                //        return getComponentRootElementForDesignBean(MarkupUnit.getMarkupDesignBeanForElement(element));
0610:                return JsfSupportUtilities
0611:                        .getComponentRootElementForElement(element);
0612:            }
0613:
0614:            /*public*/private Element getComponentRootElementForMarkupDesignBean(
0615:                    MarkupDesignBean markupDesignBean) {
0616:                //        return getComponentRootElementForDesignBean(markupDesignBean);
0617:                return JsfSupportUtilities
0618:                        .getComponentRootElementForDesignBean(markupDesignBean);
0619:            }
0620:
0621:            //    public static Element getComponentRootElementForDesignBean(DesignBean designBean) {
0622:            //        if (designBean instanceof MarkupDesignBean) {
0623:            //            return DomProviderImpl.getComponentRootElementForMarkupDesignBean((MarkupDesignBean)designBean);
0624:            //        }
0625:            //        return null;
0626:            //    }
0627:
0628:            public String getInstanceName(Element componentRootElement) {
0629:                MarkupDesignBean markupDesignBean = MarkupUnit
0630:                        .getMarkupDesignBeanForElement(componentRootElement);
0631:                return markupDesignBean == null ? null : markupDesignBean
0632:                        .getInstanceName();
0633:            }
0634:
0635:            public boolean isIncludeComponentBox(Element componentRootElement) {
0636:                DesignBean bean = MarkupUnit
0637:                        .getMarkupDesignBeanForElement(componentRootElement);
0638:                if ((bean != null)
0639:                        && bean.getInstance() instanceof  org.netbeans.modules.visualweb.xhtml.Div) {
0640:                    if ((bean.getChildBeanCount() == 1)
0641:                            && bean.getChildBean(0).getInstance() instanceof  org.netbeans.modules.visualweb.xhtml.Jsp_Directive_Include) {
0642:                        return true;
0643:                    }
0644:                }
0645:                return false;
0646:            }
0647:
0648:            public boolean isSpecialComponent(Element componentRootElement) {
0649:                //        MarkupDesignBean markupDesignBean = MarkupUnit.getMarkupDesignBeanForElement(componentRootElement);
0650:                //        if (markupDesignBean == null) {
0651:                //            return false;
0652:                //        }
0653:                //        return Util.isSpecialBean(markupDesignBean);
0654:                return JsfSupportUtilities
0655:                        .isSpecialComponent(componentRootElement);
0656:            }
0657:
0658:            public boolean isTrayComponent(Element componentRootElement) {
0659:                //        MarkupDesignBean markupDesignBean = MarkupUnit.getMarkupDesignBeanForElement(componentRootElement);
0660:                //        if (markupDesignBean == null) {
0661:                //            return false;
0662:                //        }
0663:                //        return LiveUnit.isTrayBean(markupDesignBean);
0664:                return JsfSupportUtilities
0665:                        .isTrayComponent(componentRootElement);
0666:            }
0667:
0668:            public boolean isCssPositionable(Element componentRootElement) {
0669:                MarkupDesignBean markupDesignBean = MarkupUnit
0670:                        .getMarkupDesignBeanForElement(componentRootElement);
0671:                if (markupDesignBean == null) {
0672:                    return false;
0673:                }
0674:                return LiveUnit.isCssPositionable(markupDesignBean);
0675:            }
0676:
0677:            public boolean isEscapedComponent(Element componentRootElement) {
0678:                DesignBean bean = MarkupUnit
0679:                        .getMarkupDesignBeanForElement(componentRootElement);
0680:                if (bean == null) {
0681:                    return true;
0682:                }
0683:                return isEscapedDesignBean(bean);
0684:            }
0685:
0686:            static boolean isEscapedDesignBean(DesignBean bean) {
0687:                // See if the bean looks like an output text that has escape
0688:                // turned off. If so, it's multiline. All others are considered
0689:                // single line.
0690:                if (bean.getInstance() instanceof  HtmlOutputText) {
0691:                    DesignProperty escape = bean.getProperty("escape"); // NOI18N
0692:
0693:                    if (escape != null) {
0694:                        Object o = escape.getValue();
0695:
0696:                        if (o instanceof  Boolean) {
0697:                            return ((Boolean) o).booleanValue();
0698:                        }
0699:                    }
0700:                }
0701:
0702:                return true;
0703:            }
0704:
0705:            public Element getParentComponent(Element componentRootElement) {
0706:                //        MarkupDesignBean markupDesignBean = MarkupUnit.getMarkupDesignBeanForElement(componentRootElement);
0707:                //        if (markupDesignBean == null) {
0708:                //            return null;
0709:                //        }
0710:                //
0711:                //        DesignBean parent = markupDesignBean.getBeanParent();
0712:                //        return parent instanceof MarkupDesignBean ? getComponentRootElementForMarkupDesignBean((MarkupDesignBean)parent) : null;
0713:                return JsfSupportUtilities
0714:                        .getParentComponent(componentRootElement);
0715:            }
0716:
0717:            public Element[] getChildComponents(Element componentRootElement) {
0718:                MarkupDesignBean markupDesignBean = MarkupUnit
0719:                        .getMarkupDesignBeanForElement(componentRootElement);
0720:                if (markupDesignBean == null) {
0721:                    return new Element[0];
0722:                }
0723:
0724:                List<Element> children = new ArrayList<Element>();
0725:                for (int i = 0; i < markupDesignBean.getChildBeanCount(); i++) {
0726:                    DesignBean childBean = markupDesignBean.getChildBean(i);
0727:                    if (childBean instanceof  MarkupDesignBean) {
0728:                        Element child = getComponentRootElementForMarkupDesignBean((MarkupDesignBean) childBean);
0729:                        if (child != null) {
0730:                            children.add(child);
0731:                        }
0732:                    }
0733:                }
0734:
0735:                return children.toArray(new Element[children.size()]);
0736:            }
0737:
0738:            public boolean isContainerComponent(Element componentRootElement) {
0739:                MarkupDesignBean markupDesignBean = MarkupUnit
0740:                        .getMarkupDesignBeanForElement(componentRootElement);
0741:                if (markupDesignBean == null) {
0742:                    return false;
0743:                }
0744:
0745:                BeanInfo bi = markupDesignBean.getBeanInfo();
0746:                if (bi != null) {
0747:                    BeanDescriptor bd = bi.getBeanDescriptor();
0748:                    Object o = bd
0749:                            .getValue(Constants.BeanDescriptor.IS_CONTAINER);
0750:                    boolean notContainer = o == Boolean.FALSE;
0751:                    return !notContainer;
0752:                }
0753:                return true;
0754:            }
0755:
0756:            public boolean isContainerTypeComponent(Element componentRootElement) {
0757:                MarkupDesignBean markupDesignBean = MarkupUnit
0758:                        .getMarkupDesignBeanForElement(componentRootElement);
0759:                if (markupDesignBean == null) {
0760:                    return false;
0761:                }
0762:
0763:                return markupDesignBean.isContainer();
0764:            }
0765:
0766:            //    /**
0767:            //     * If the given component supports inline text editing, return the
0768:            //     * String property name which stores the text that is inline
0769:            //     * editable.
0770:            //     */
0771:            //    public String[] getEditablePropertyNames(Element componentRootElement) {
0772:            //        DesignBean bean = MarkupUnit.getMarkupDesignBeanForElement(componentRootElement);
0773:            //        return getEditablePropertyNames(bean);
0774:            //    }
0775:
0776:            public static String[] getEditablePropertyNames(DesignBean bean) {
0777:                if (bean == null) {
0778:                    return new String[0];
0779:                }
0780:
0781:                //        BeanInfo bi = bean.getBeanInfo();
0782:                //
0783:                //        if (bi != null) {
0784:                //            BeanDescriptor bd = bi.getBeanDescriptor();
0785:                //            Object o = bd.getValue(Constants.BeanDescriptor.INLINE_EDITABLE_PROPERTIES);
0786:                //
0787:                //            if (o instanceof String[]) {
0788:                //                String[] source = (String[])o;
0789:                String[] source = getEditableProperties(bean);
0790:                if (source != null) {
0791:                    List<String> names = new ArrayList<String>(source.length);
0792:
0793:                    for (int i = 0; i < source.length; i++) {
0794:                        String name;
0795:                        int index = source[i].indexOf(':');
0796:
0797:                        if (index == -1) {
0798:                            if ((source.length > 0)
0799:                                    && (source[i].charAt(0) == '*')) {
0800:                                name = source[i].substring(1);
0801:                            } else {
0802:                                name = source[i];
0803:                            }
0804:                        } else {
0805:                            int start = 0;
0806:
0807:                            if ((source.length > 0)
0808:                                    && (source[i].charAt(0) == '*')) {
0809:                                start = 1;
0810:                            }
0811:
0812:                            name = source[i].substring(start, index);
0813:                        }
0814:
0815:                        DesignProperty property = bean.getProperty(name);
0816:
0817:                        if ((property != null) && isEditingAllowed(property)) {
0818:                            names.add(name);
0819:                        }
0820:                    }
0821:
0822:                    return names.toArray(new String[names.size()]);
0823:                }
0824:                //        }
0825:
0826:                return new String[0];
0827:            }
0828:
0829:            public String[] getEditableProperties(Element componentRootElement) {
0830:                MarkupDesignBean markupDesignBean = MarkupUnit
0831:                        .getMarkupDesignBeanForElement(componentRootElement);
0832:                if (markupDesignBean == null) {
0833:                    return new String[0];
0834:                }
0835:                return getEditableProperties(markupDesignBean);
0836:            }
0837:
0838:            private static String[] getEditableProperties(DesignBean bean) {
0839:                BeanInfo bi = bean.getBeanInfo();
0840:
0841:                if (bi != null) {
0842:                    BeanDescriptor bd = bi.getBeanDescriptor();
0843:                    Object o = bd
0844:                            .getValue(Constants.BeanDescriptor.INLINE_EDITABLE_PROPERTIES);
0845:
0846:                    if (o instanceof  String[]) {
0847:                        return (String[]) o;
0848:                    }
0849:                }
0850:
0851:                return null;
0852:            }
0853:
0854:            /**
0855:             * Return true if inline editing is allowed for the given property (assuming it
0856:             * has already been marked via metadata for inline editing; -that- is not checked here)
0857:             */
0858:            static boolean isEditingAllowed(DesignProperty property) {
0859:                // TODO: Change types above from DesignProperty to FacesDesignProperty, and
0860:                // call property.isBound() instead of the below!
0861:                if (NO_EDIT_VB_EXPR) {
0862:                    String value = property.getValueSource();
0863:
0864:                    // TODO: Change types above from DesignProperty to FacesDesignProperty, and
0865:                    // call property.isBound() instead of the below!
0866:                    //            if ((value != null) && FacesSupport.isValueBindingExpression(value, false)) {
0867:                    if ((value != null)
0868:                            && DesignBeanNode.isValueBindingExpression(value,
0869:                                    false)) {
0870:                        return false;
0871:                    }
0872:                }
0873:
0874:                return true;
0875:            }
0876:
0877:            static String getSpecialInitValue(DesignProperty designProperty) {
0878:                if (!NO_EDIT_VB_EXPR) {
0879:                    String value = designProperty.getValueSource();
0880:
0881:                    //            if ((value != null) && FacesSupport.isValueBindingExpression(value, false)) {
0882:                    if ((value != null)
0883:                            && DesignBeanNode.isValueBindingExpression(value,
0884:                                    false)) {
0885:                        return value;
0886:                    }
0887:                }
0888:
0889:                return null;
0890:            }
0891:
0892:            public ResizeConstraint[] getResizeConstraintsForComponent(
0893:                    Element componentRootElement) {
0894:                MarkupDesignBean bean = MarkupUnit
0895:                        .getMarkupDesignBeanForElement(componentRootElement);
0896:                int constraints = getResizeConstraintsForMarkupDesignBean(bean);
0897:
0898:                if (constraints == Constants.ResizeConstraints.NONE) {
0899:                    return new ResizeConstraint[0];
0900:                }
0901:
0902:                List<ResizeConstraint> resizeConstraints = new ArrayList<ResizeConstraint>();
0903:                if ((constraints & Constants.ResizeConstraints.TOP) != 0) {
0904:                    resizeConstraints.add(ResizeConstraint.TOP);
0905:                }
0906:                if ((constraints & Constants.ResizeConstraints.LEFT) != 0) {
0907:                    resizeConstraints.add(ResizeConstraint.LEFT);
0908:                }
0909:                if ((constraints & Constants.ResizeConstraints.BOTTOM) != 0) {
0910:                    resizeConstraints.add(ResizeConstraint.BOTTOM);
0911:                }
0912:                if ((constraints & Constants.ResizeConstraints.RIGHT) != 0) {
0913:                    resizeConstraints.add(ResizeConstraint.RIGHT);
0914:                }
0915:                if ((constraints & Constants.ResizeConstraints.MAINTAIN_ASPECT_RATIO) != 0) {
0916:                    resizeConstraints
0917:                            .add(ResizeConstraint.MAINTAIN_ASPECT_RATIO);
0918:                }
0919:                if ((constraints & Constants.ResizeConstraints.VERTICAL) != 0) {
0920:                    resizeConstraints.add(ResizeConstraint.VERTICAL);
0921:                }
0922:                if ((constraints & Constants.ResizeConstraints.HORIZONTAL) != 0) {
0923:                    resizeConstraints.add(ResizeConstraint.HORIZONTAL);
0924:                }
0925:                if ((constraints & Constants.ResizeConstraints.ANY) != 0) {
0926:                    resizeConstraints.add(ResizeConstraint.ANY);
0927:                }
0928:
0929:                return resizeConstraints
0930:                        .toArray(new ResizeConstraint[resizeConstraints.size()]);
0931:            }
0932:
0933:            private static int getResizeConstraintsForMarkupDesignBean(
0934:                    MarkupDesignBean bean) {
0935:                int constraints = Constants.ResizeConstraints.ANY;
0936:                if (bean == null) {
0937:                    return constraints;
0938:                }
0939:
0940:                // Special case: The Jsp Include box is not resizable.
0941:                // If I build a BeanDescriptor for it I can inject
0942:                // this value right on it, but I also want to make it
0943:                // as NOT POSITIONABLE.
0944:                if (bean.getInstance() instanceof  Jsp_Directive_Include) {
0945:                    return Constants.ResizeConstraints.NONE;
0946:                }
0947:
0948:                BeanInfo bi = bean.getBeanInfo();
0949:                if (bi != null) {
0950:                    BeanDescriptor bd = bi.getBeanDescriptor();
0951:                    Object o = bd
0952:                            .getValue(Constants.BeanDescriptor.RESIZE_CONSTRAINTS);
0953:
0954:                    if ((o != null) && o instanceof  Integer) {
0955:                        constraints = ((Integer) o).intValue();
0956:                    }
0957:                }
0958:
0959:                return constraints;
0960:            }
0961:
0962:            public boolean isRootContainerComponent(Element componentRootElement) {
0963:                MarkupDesignBean markupDesignBean = MarkupUnit
0964:                        .getMarkupDesignBeanForElement(componentRootElement);
0965:                if (markupDesignBean == null) {
0966:                    return false;
0967:                }
0968:
0969:                DesignContext designContext = markupDesignBean
0970:                        .getDesignContext();
0971:                if (designContext == null) {
0972:                    return false;
0973:                }
0974:
0975:                return markupDesignBean == designContext.getRootContainer();
0976:            }
0977:
0978:            public boolean hasDefaultProperty(Element componentRootElement) {
0979:                MarkupDesignBean lb = MarkupUnit
0980:                        .getMarkupDesignBeanForElement(componentRootElement);
0981:                BeanInfo bi = lb.getBeanInfo();
0982:                if (bi != null) {
0983:                    int defaultProp = bi.getDefaultPropertyIndex();
0984:
0985:                    if (defaultProp != -1) {
0986:                        return true;
0987:                    }
0988:                }
0989:                return false;
0990:            }
0991:
0992:            public boolean focusDefaultProperty(Element componentRootElement,
0993:                    final String content) {
0994:                MarkupDesignBean lb = MarkupUnit
0995:                        .getMarkupDesignBeanForElement(componentRootElement);
0996:                BeanInfo bi = lb.getBeanInfo();
0997:                int defaultProp;
0998:                if (bi != null) {
0999:                    defaultProp = bi.getDefaultPropertyIndex();
1000:                    if (defaultProp == -1) {
1001:                        return false;
1002:                    }
1003:                } else {
1004:                    return false;
1005:                }
1006:
1007:                FeatureDescriptor defProp = bi.getPropertyDescriptors()[defaultProp];
1008:
1009:                // How do we launch the property sheet editing a
1010:                // particular property?
1011:                final JTable jt =
1012:                //                            org.netbeans.modules.visualweb.designer.DesignerUtils.findPropSheetTable(true, true);
1013:                findPropSheetTable(true, true);
1014:
1015:                if (jt == null) {
1016:                    return false;
1017:                }
1018:
1019:                TableModel model = jt.getModel();
1020:
1021:                // Set focus of jt?
1022:                for (int row = 0, n = model.getRowCount(); row < n; row++) {
1023:                    Object o = model.getValueAt(row, 0);
1024:
1025:                    if (!(o instanceof  FeatureDescriptor)) {
1026:                        continue;
1027:                    }
1028:
1029:                    FeatureDescriptor desc = (FeatureDescriptor) o;
1030:
1031:                    if (defProp.getName().equals(desc.getName())) {
1032:                        // Edit the cell XXX only if readonly!
1033:                        if (desc instanceof  org.openide.nodes.Node.Property) {
1034:                            org.openide.nodes.Node.Property prop = (org.openide.nodes.Node.Property) desc;
1035:
1036:                            if (!prop.canWrite()) {
1037:                                return false;
1038:                            }
1039:                        }
1040:
1041:                        final int r = row;
1042:                        //                final String content = event.getActionCommand();
1043:                        SwingUtilities.invokeLater(new Runnable() {
1044:                            public void run() {
1045:                                jt.editCellAt(r, 1, null);
1046:                                jt.requestFocus();
1047:
1048:                                Object ce = jt.getCellEditor(r, 1);
1049:
1050:                                // Hack Alert: try to transfer the
1051:                                // original keypress into the text field
1052:                                Component comp = getInplaceEditorComponentForSheetCellEditor(ce);
1053:
1054:                                if (comp instanceof  javax.swing.text.JTextComponent) {
1055:                                    javax.swing.text.JTextComponent jtc = (javax.swing.text.JTextComponent) comp;
1056:                                    jtc.replaceSelection(content);
1057:                                }
1058:                            }
1059:                        });
1060:
1061:                        return true;
1062:                    }
1063:                }
1064:                return false;
1065:            }
1066:
1067:            // XXX Moved from DesignerUtils.
1068:            /** Locate the JTable within the property sheet in the IDE.
1069:             * WARNING: Implementation hacks!
1070:             * @param focus If set, focus the top component
1071:             * @param visible If set, ensure the top component is fronted
1072:             */
1073:            private static JTable findPropSheetTable(boolean focus,
1074:                    boolean visible) {
1075:                WindowManager mgr = WindowManager.getDefault();
1076:                TopComponent properties = mgr.findTopComponent("properties"); // NOI18N
1077:
1078:                if ((properties != null) && (visible || properties.isShowing())) {
1079:                    if (focus) {
1080:                        properties.requestActive();
1081:                    }
1082:
1083:                    if (visible) {
1084:                        properties.requestVisible();
1085:                    }
1086:
1087:                    return findTable(properties);
1088:                }
1089:
1090:                return null;
1091:            }
1092:
1093:            /** Fish the given Container hierarchy for a JTable */
1094:            private static JTable findTable(Container c) {
1095:                //        if(DEBUG) {
1096:                //            debugLog(DesignerUtils.class.getName() + ".findTable(Container)");
1097:                //        }
1098:                if (c == null) {
1099:                    return (null);
1100:                }
1101:                if (c instanceof  JTable) {
1102:                    return (JTable) c;
1103:                }
1104:
1105:                int n = c.getComponentCount();
1106:
1107:                for (int i = 0; i < n; i++) {
1108:                    Component comp = c.getComponent(i);
1109:
1110:                    if (comp instanceof  JTable) {
1111:                        return (JTable) comp;
1112:                    }
1113:
1114:                    if (comp instanceof  Container) {
1115:                        JTable table = findTable((Container) comp);
1116:
1117:                        if (table != null) {
1118:                            return table;
1119:                        }
1120:                    }
1121:                }
1122:
1123:                return null;
1124:            }
1125:
1126:            // XXX Using reflection, But it is still better than changing NB code
1127:            // The task from UI point of view looks very strange... why the text isn't inserted into the component, as user expect,
1128:            // but surprisinlgy the focus is moved into property sheet? That kind of solutions cause problems like this.
1129:            private static Component getInplaceEditorComponentForSheetCellEditor(
1130:                    Object ce) {
1131:                if (ce == null) {
1132:                    return null;
1133:                }
1134:
1135:                Object inplaceEditor;
1136:
1137:                try {
1138:                    ClassLoader cl = org.openide.explorer.propertysheet.PropertySheet.class
1139:                            .getClassLoader();
1140:                    Class sheetCellEditorClass = Class
1141:                            .forName(
1142:                                    "org.openide.explorer.propertysheet.SheetCellEditor",
1143:                                    true, cl); // NOI18N
1144:                    java.lang.reflect.Method getInplaceEditorMethod = sheetCellEditorClass
1145:                            .getDeclaredMethod("getInplaceEditor", new Class[0]); // NOI18N
1146:                    getInplaceEditorMethod.setAccessible(true);
1147:                    inplaceEditor = getInplaceEditorMethod.invoke(ce,
1148:                            new Object[0]);
1149:                } catch (ClassNotFoundException cnfe) {
1150:                    ErrorManager.getDefault().notify(
1151:                            ErrorManager.INFORMATIONAL, cnfe);
1152:                    inplaceEditor = null;
1153:                } catch (NoSuchMethodException nsme) {
1154:                    ErrorManager.getDefault().notify(
1155:                            ErrorManager.INFORMATIONAL, nsme);
1156:                    inplaceEditor = null;
1157:                } catch (IllegalAccessException iae) {
1158:                    ErrorManager.getDefault().notify(
1159:                            ErrorManager.INFORMATIONAL, iae);
1160:                    inplaceEditor = null;
1161:                } catch (java.lang.reflect.InvocationTargetException ite) {
1162:                    ErrorManager.getDefault().notify(
1163:                            ErrorManager.INFORMATIONAL, ite);
1164:                    inplaceEditor = null;
1165:                }
1166:
1167:                if (inplaceEditor instanceof  org.openide.explorer.propertysheet.InplaceEditor) {
1168:                    return ((org.openide.explorer.propertysheet.InplaceEditor) inplaceEditor)
1169:                            .getComponent();
1170:                } else {
1171:                    return null;
1172:                }
1173:            }
1174:
1175:            public Image getIcon(Element componentRootElement) {
1176:                MarkupDesignBean bean = MarkupUnit
1177:                        .getMarkupDesignBeanForElement(componentRootElement);
1178:                if (bean == null) {
1179:                    return null;
1180:                }
1181:
1182:                BeanInfo bi = bean.getBeanInfo();
1183:                if (bi != null) {
1184:                    return bi.getIcon(BeanInfo.ICON_COLOR_16x16);
1185:                }
1186:                return null;
1187:            }
1188:
1189:            //    public org.openide.nodes.Node getNodeRepresentation(Element componentRootElement) {
1190:            ////        MarkupDesignBean markupDesignBean = MarkupUnit.getMarkupDesignBeanForElement(componentRootElement);
1191:            ////        return DesigntimeIdeBridgeProvider.getDefault().getNodeRepresentation(markupDesignBean);
1192:            //        return JsfSupportUtilities.getNodeRepresentation(componentRootElement);
1193:            //    }
1194:
1195:            public Element getComponentRootElementFromNode(
1196:                    org.openide.nodes.Node node) {
1197:                //        DesignBean bean = (DesignBean)node.getLookup().lookup(DesignBean.class);
1198:                //        if (bean == null) {
1199:                //            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
1200:                //                new NullPointerException("No DesignBean for node=" + node)); // NOI18N
1201:                //            return null;
1202:                //        }
1203:                //
1204:                //        return bean instanceof MarkupDesignBean ? getComponentRootElementForMarkupDesignBean((MarkupDesignBean)bean) : null;
1205:                return JsfSupportUtilities
1206:                        .getComponentRootElementFromNode(node);
1207:            }
1208:
1209:            //    public MarkupPosition getDefaultMarkupPositionUnderParent(DesignBean parent) {
1210:            //        return parent instanceof MarkupDesignBean ? FacesDndSupport.getDefaultMarkupPositionUnderParent(parent) : null;
1211:            //    }
1212:
1213:            //    public DomProvider.Location computeLocationForPositions(String facet, Point canvasPos, Node documentPosNode, int documentPosOffset, Dimension dimension, boolean isGrid, Element droppeeElement, Element dropeeComponentRootElement, Element defaultParentComponentRootElement) {
1214:            //        MarkupDesignBean droppeeBean = MarkupUnit.getMarkupDesignBeanForElement(dropeeComponentRootElement);
1215:            //        MarkupDesignBean defaultParentBean = MarkupUnit.getMarkupDesignBeanForElement(defaultParentComponentRootElement);
1216:            //        FacesDndSupport.Location location = FacesDndSupport.computeLocationForPositions(facet, canvasPos, documentPosNode, documentPosOffset, dimension, isGrid, droppeeElement, droppeeBean, defaultParentBean);
1217:            //        DomProvider.Location l = new DomProvider.Location();
1218:            //        l.coordinates = location.getCoordinates();
1219:            //        l.droppee = location.getDroppee();
1220:            //        l.droppeeElement = location.getDroppeeElement();
1221:            //        l.facet = location.getFacet();
1222:            //        l.pos = location.getPos();
1223:            //        l.size = location.getSize();
1224:            //        return l;
1225:            //    }
1226:
1227:            private static final Map<MarkupDesignBean, MarkupTableDesignInfo> markupDesignBean2markupTableDesignInfo = new WeakHashMap<MarkupDesignBean, MarkupTableDesignInfo>();
1228:
1229:            private static MarkupTableDesignInfo getMarkupTableDesignInfo(
1230:                    MarkupDesignBean markupDesignBean) {
1231:                if (markupDesignBean == null) {
1232:                    return null;
1233:                }
1234:
1235:                MarkupTableDesignInfo markupTableDesignInfo;
1236:                synchronized (markupDesignBean2markupTableDesignInfo) {
1237:                    markupTableDesignInfo = markupDesignBean2markupTableDesignInfo
1238:                            .get(markupDesignBean);
1239:                }
1240:                if (markupTableDesignInfo != null) {
1241:                    return markupTableDesignInfo;
1242:                }
1243:
1244:                DesignInfo info = markupDesignBean.getDesignInfo();
1245:                if (info instanceof  MarkupTableDesignInfo) {
1246:                    markupTableDesignInfo = (MarkupTableDesignInfo) info;
1247:                }
1248:                if (markupTableDesignInfo == null) {
1249:                    return null;
1250:                }
1251:
1252:                synchronized (markupDesignBean2markupTableDesignInfo) {
1253:                    markupDesignBean2markupTableDesignInfo.put(
1254:                            markupDesignBean, markupTableDesignInfo);
1255:                }
1256:                return markupTableDesignInfo;
1257:            }
1258:
1259:            public boolean hasTableResizeSupport(
1260:                    Element tableComponentRootElement) {
1261:                MarkupDesignBean markupDesignBean = MarkupUnit
1262:                        .getMarkupDesignBeanForElement(tableComponentRootElement);
1263:                return getMarkupTableDesignInfo(markupDesignBean) != null;
1264:            }
1265:
1266:            public int testResizeColumn(Element tableComponentRootElement,
1267:                    int row, int column, int width) {
1268:                MarkupDesignBean markupDesignBean = MarkupUnit
1269:                        .getMarkupDesignBeanForElement(tableComponentRootElement);
1270:                MarkupTableDesignInfo markupTableDesignInfo = getMarkupTableDesignInfo(markupDesignBean);
1271:                if (markupTableDesignInfo == null) {
1272:                    return 0;
1273:                }
1274:
1275:                return markupTableDesignInfo.testResizeColumn(markupDesignBean,
1276:                        row, column, width);
1277:            }
1278:
1279:            public int testResizeRow(Element tableComponentRootElement,
1280:                    int row, int column, int height) {
1281:                MarkupDesignBean markupDesignBean = MarkupUnit
1282:                        .getMarkupDesignBeanForElement(tableComponentRootElement);
1283:                MarkupTableDesignInfo markupTableDesignInfo = getMarkupTableDesignInfo(markupDesignBean);
1284:                if (markupTableDesignInfo == null) {
1285:                    return 0;
1286:                }
1287:
1288:                return markupTableDesignInfo.testResizeRow(markupDesignBean,
1289:                        row, column, height);
1290:            }
1291:
1292:            public void resizeColumn(Element tableComponentRootElement,
1293:                    int column, int width) {
1294:                MarkupDesignBean markupDesignBean = MarkupUnit
1295:                        .getMarkupDesignBeanForElement(tableComponentRootElement);
1296:                MarkupTableDesignInfo markupTableDesignInfo = getMarkupTableDesignInfo(markupDesignBean);
1297:                if (markupTableDesignInfo == null) {
1298:                    return;
1299:                }
1300:
1301:                markupTableDesignInfo.resizeColumn(markupDesignBean, column,
1302:                        width);
1303:            }
1304:
1305:            public void resizeRow(Element tableComponentRootElement, int row,
1306:                    int height) {
1307:                MarkupDesignBean markupDesignBean = MarkupUnit
1308:                        .getMarkupDesignBeanForElement(tableComponentRootElement);
1309:                MarkupTableDesignInfo markupTableDesignInfo = getMarkupTableDesignInfo(markupDesignBean);
1310:                if (markupTableDesignInfo == null) {
1311:                    return;
1312:                }
1313:
1314:                markupTableDesignInfo.resizeRow(markupDesignBean, row, height);
1315:            }
1316:
1317:            public boolean areLinkedToSameBean(Element oneElement,
1318:                    Element otherElement) {
1319:                MarkupDesignBean oneMarkupDesignBean = MarkupUnit
1320:                        .getMarkupDesignBeanForElement(oneElement);
1321:                if (oneMarkupDesignBean == null) {
1322:                    return false;
1323:                }
1324:                return oneMarkupDesignBean == MarkupUnit
1325:                        .getMarkupDesignBeanForElement(otherElement);
1326:            }
1327:
1328:            public Node findPropertyNode(Node root, String xpaths) {
1329:                return JsfSupportUtilities.findPropertyNode(root, xpaths);
1330:            }
1331:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.