Source Code Cross Referenced for DomInspector.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » css2 » 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.css2 
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:         * BoxTreeComponent.java
0043:         *
0044:         * Created on September 1, 2005, 9:49 PM
0045:         *
0046:         * To change this template, choose Tools | Options and locate the template under
0047:         * the Source Creation and Management node. Right-click the template and choose
0048:         * Open. You can then make changes to the template in the Source Editor.
0049:         */
0050:
0051:        package org.netbeans.modules.visualweb.css2;
0052:
0053:        import java.awt.BorderLayout;
0054:        import java.awt.Color;
0055:        import java.awt.Dimension;
0056:        import java.awt.Point;
0057:        import java.awt.Rectangle;
0058:        import java.awt.datatransfer.Transferable;
0059:        import java.util.ArrayList;
0060:        import java.util.Collections;
0061:        import java.util.Iterator;
0062:        import java.util.LinkedList;
0063:        import java.util.List;
0064:        import java.util.Set;
0065:
0066:        import javax.swing.Action;
0067:        import javax.swing.JScrollPane;
0068:        import javax.swing.JTree;
0069:        import javax.swing.event.TreeSelectionEvent;
0070:        import javax.swing.event.TreeSelectionListener;
0071:        import javax.swing.tree.DefaultTreeModel;
0072:        import javax.swing.tree.DefaultTreeSelectionModel;
0073:        import javax.swing.tree.TreeNode;
0074:        import javax.swing.tree.TreePath;
0075:
0076:        import org.openide.ErrorManager;
0077:        import org.openide.actions.PropertiesAction;
0078:        import org.openide.nodes.AbstractNode;
0079:        import org.openide.nodes.Children;
0080:        import org.openide.nodes.Node;
0081:        import org.openide.nodes.PropertySupport;
0082:        import org.openide.nodes.PropertySupport.Reflection;
0083:        import org.openide.nodes.Sheet;
0084:        import org.openide.util.NbBundle;
0085:        import org.openide.util.actions.SystemAction;
0086:        import org.openide.windows.Mode;
0087:        import org.openide.windows.TopComponent;
0088:        import org.openide.windows.WindowManager;
0089:
0090:        import org.w3c.dom.Element;
0091:
0092:        import org.netbeans.modules.visualweb.designer.DesignerUtils;
0093:        import org.netbeans.modules.visualweb.designer.SelectionManager;
0094:        import org.netbeans.modules.visualweb.designer.WebForm;
0095:        import org.netbeans.modules.visualweb.css2.BoxType;
0096:        import org.netbeans.modules.visualweb.css2.CssBox;
0097:        import org.netbeans.modules.visualweb.css2.LineBoxGroup;
0098:        import org.netbeans.modules.visualweb.css2.PageBox;
0099:        import org.netbeans.modules.visualweb.css2.TextBox;
0100:        import org.netbeans.modules.visualweb.designer.html.HtmlAttribute;
0101:
0102:        // Originally in org/netbeans/modules/visualweb/designer package, but moved here to have better access to package private data.
0103:        /**
0104:         * TopComponent displaying the box tree - used for debugging only via the DOM inspector
0105:         *
0106:         *
0107:         * @author Tor Norbye
0108:         */
0109:        public class DomInspector extends TopComponent implements 
0110:                TreeSelectionListener {
0111:            private WebForm webform;
0112:            private JTree tree;
0113:            private JScrollPane scrollPane;
0114:            private DefaultTreeModel treeModel;
0115:            protected DefaultTreeSelectionModel treeSelectionModel;
0116:            private boolean ignoreSelectionEvents;
0117:
0118:            /**
0119:             * Creates a new instance of DomInspector
0120:             */
0121:            public DomInspector(WebForm webform) {
0122:                this .webform = webform;
0123:
0124:                setName("LayoutInspector"); // NOI18N
0125:                setDisplayName(getBundleString("LBL_DomInspector"));
0126:                // XXX
0127:                setToolTipText(getDisplayName());
0128:            }
0129:
0130:            /** Make sure we have a window showing the boxes for the given webform */
0131:            public static void show(CssBox box) {
0132:                WebForm webform = box.getWebForm();
0133:
0134:                DomInspector btc = createWindowIfNecessary(webform);
0135:                //btc.requestActive();
0136:
0137:                // Select box
0138:                btc.selectBox(box);
0139:
0140:                // XXX Copied from InteractionManager and refined to select the activated nodes initially.
0141:                // Also set nodes locally such that if this top component
0142:                // retains focus the node selection reflects the selected box
0143:                SelectionManager sm = webform.getSelection();
0144:                List<Node> nodes = new ArrayList<Node>(sm.getNumSelected());
0145:                //        DataObject dobj = webform.getDataObject();
0146:                //        DataObject dobj = webform.getJspDataObject();
0147:                Node n = new BoxNode(box/*, dobj*/);
0148:
0149:                //n.setDataObject(dobj);
0150:                nodes.add(n);
0151:                Node[] nds = nodes.toArray(new Node[nodes.size()]);
0152:
0153:                DesignerUtils.setActivatedNodes(btc, nds);
0154:            }
0155:
0156:            private void selectBox(CssBox box) {
0157:                TreePath path = getPath(box);
0158:
0159:                if (path != null) {
0160:                    ignoreSelectionEvents = true;
0161:
0162:                    try {
0163:                        //TreeSelectionModel model = tree.getSelectionModel();
0164:                        //TreePath[] paths = new TreePath[] { path };
0165:                        //model.setSelectionPaths(paths);
0166:                        tree.setSelectionPath(path);
0167:
0168:                        //tree.expandPath(path);
0169:                        tree.makeVisible(path);
0170:                        tree.scrollPathToVisible(path);
0171:                    } finally {
0172:                        ignoreSelectionEvents = false;
0173:                    }
0174:                }
0175:            }
0176:
0177:            private static DomInspector createWindowIfNecessary(WebForm webform) {
0178:                // Search editor modes
0179:                // Search through workspaces, then modes, then topcomponents
0180:                Set modes = WindowManager.getDefault().getModes();
0181:                Iterator it2 = modes.iterator();
0182:
0183:                while (it2.hasNext()) {
0184:                    Mode m = (Mode) it2.next();
0185:                    TopComponent[] tcs = m.getTopComponents();
0186:
0187:                    if (tcs != null) {
0188:                        for (int i = 0; i < tcs.length; i++) {
0189:                            if (tcs[i] instanceof  DomInspector) {
0190:                                DomInspector btc = (DomInspector) tcs[i];
0191:
0192:                                if (btc.webform == webform) {
0193:                                    // Force refresh if the box tree has changed
0194:                                    //                            if (((BoxTreeNode)btc.treeModel.getRoot()).getBox() != webform.getPane()
0195:                                    //                                                                                              .getPageBox()) {
0196:                                    // XXX #121239 Avoiding possible NPE.
0197:                                    if (btc.treeModel != null
0198:                                            && btc.treeModel.getRoot() instanceof  BoxTreeNode
0199:                                            && webform.getPane() != null
0200:                                            && ((BoxTreeNode) btc.treeModel
0201:                                                    .getRoot()).getBox() != webform
0202:                                                    .getPane().getPageBox()) {
0203:                                        btc.refresh();
0204:                                    }
0205:
0206:                                    // PENDING: refresh();
0207:                                    if (!btc.isShowing()) {
0208:                                        btc.requestVisible();
0209:                                    }
0210:
0211:                                    return btc;
0212:                                }
0213:                            }
0214:                        }
0215:                    }
0216:                }
0217:
0218:                DomInspector btc = new DomInspector(webform);
0219:
0220:                // TODO - pick a mode?
0221:                Mode mode = WindowManager.getDefault().findMode("explorer"); // NOI18N
0222:
0223:                if (mode != null) {
0224:                    mode.dockInto(btc);
0225:                }
0226:
0227:                btc.open();
0228:                btc.requestActive();
0229:
0230:                return btc;
0231:            }
0232:
0233:            private TreePath getPath(CssBox box) {
0234:                LinkedList<Object> pathList = new LinkedList<Object>();
0235:                // #123989 possible NPE.
0236:                if (treeModel == null) {
0237:                    return null;
0238:                }
0239:                BoxTreeNode root = (BoxTreeNode) treeModel.getRoot();
0240:                boolean found = findBox(box, root, pathList);
0241:
0242:                if (found) {
0243:                    //pathList.removeFirst();
0244:                    if (pathList.size() > 0) {
0245:                        return new TreePath(pathList
0246:                                .toArray(new Object[pathList.size()]));
0247:                    }
0248:                }
0249:
0250:                return null;
0251:            }
0252:
0253:            // SUPER INEFFICIENT!
0254:            private boolean findBox(CssBox box, BoxTreeNode node,
0255:                    LinkedList<Object> path) {
0256:                boolean containsBox = false;
0257:
0258:                for (int k = 0; k < node.getChildCount(); k++) {
0259:                    BoxTreeNode child = (BoxTreeNode) node.getChildAt(k);
0260:
0261:                    containsBox |= findBox(box, child, path);
0262:                }
0263:
0264:                if (containsBox || (node.getBox() == box)) {
0265:                    path.addFirst(node);
0266:
0267:                    return true;
0268:                }
0269:
0270:                return false;
0271:            }
0272:
0273:            public void refresh() {
0274:                PageBox pageBox = webform.getPane().getPageBox();
0275:                TreeNode root = new BoxTreeNode(pageBox, null);
0276:                treeModel = new DefaultTreeModel(root);
0277:                treeSelectionModel = new DefaultTreeSelectionModel();
0278:                treeSelectionModel.addTreeSelectionListener(this );
0279:                tree.setSelectionModel(treeSelectionModel);
0280:                tree.setModel(treeModel);
0281:            }
0282:
0283:            //    public String getName() {
0284:            //        // Not internationalized - not part of the product
0285:            //        return "Layout Inspector";
0286:            //    }
0287:
0288:            protected void componentClosed() {
0289:                remove(scrollPane);
0290:                scrollPane = null;
0291:                tree = null;
0292:                treeModel = null;
0293:                treeSelectionModel = null;
0294:
0295:                super .componentClosed();
0296:            }
0297:
0298:            protected void componentOpened() {
0299:                super .componentOpened();
0300:
0301:                tree = new JTree();
0302:                tree.setRootVisible(true);
0303:                scrollPane = new JScrollPane(tree);
0304:                refresh();
0305:
0306:                setLayout(new BorderLayout());
0307:                add(scrollPane, BorderLayout.CENTER);
0308:            }
0309:
0310:            /** Never preserve these windows across sessions etc. */
0311:            public int getPersistenceType() {
0312:                return TopComponent.PERSISTENCE_NEVER;
0313:            }
0314:
0315:            public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
0316:                if (ignoreSelectionEvents) {
0317:                    return;
0318:                }
0319:
0320:                try {
0321:                    ignoreSelectionEvents = true;
0322:
0323:                    TreePath[] paths = tree.getSelectionPaths();
0324:
0325:                    if ((paths == null) || (paths.length == 0)) {
0326:                        return;
0327:                    }
0328:
0329:                    for (int i = 0; i < paths.length; i++) {
0330:                        TreePath p = paths[i];
0331:                        Object o = p.getLastPathComponent();
0332:
0333:                        if (o instanceof  BoxTreeNode) {
0334:                            BoxTreeNode btn = (BoxTreeNode) o;
0335:                            CssBox box = btn.getBox();
0336:
0337:                            SelectionManager sm = webform.getSelection();
0338:                            List<Node> nodes = new ArrayList<Node>(sm
0339:                                    .getNumSelected());
0340:                            //                    DataObject dobj = webform.getDataObject();
0341:                            //                    DataObject dobj = webform.getJspDataObject();
0342:                            Node n = new BoxNode(box/*, dobj*/);
0343:
0344:                            //n.setDataObject(dobj);
0345:                            nodes.add(n);
0346:
0347:                            Node[] nds = nodes.toArray(new Node[nodes.size()]);
0348:                            requestActive();
0349:                            DesignerUtils.setActivatedNodes(this , nds);
0350:                            webform.getPane().getPageBox().setSelected(box);
0351:
0352:                            break;
0353:                        }
0354:                    }
0355:                } finally {
0356:                    ignoreSelectionEvents = false;
0357:                }
0358:            }
0359:
0360:            protected String preferredID() {
0361:                return "dom-inspector";
0362:            }
0363:
0364:            private static class BoxTreeNode implements  TreeNode {
0365:                private CssBox box;
0366:                private BoxTreeNode parent;
0367:                private List<TreeNode> children;
0368:
0369:                private BoxTreeNode(CssBox box, BoxTreeNode parent) {
0370:                    this .box = box;
0371:                    this .parent = parent;
0372:                }
0373:
0374:                public TreeNode getChildAt(int i) {
0375:                    initializeChildren();
0376:
0377:                    return children.get(i);
0378:                }
0379:
0380:                public int getIndex(TreeNode treeNode) {
0381:                    initializeChildren();
0382:
0383:                    for (int i = 0, n = children.size(); i < n; i++) {
0384:                        if (children.get(i) == treeNode) {
0385:                            return i;
0386:                        }
0387:                    }
0388:
0389:                    return -1;
0390:                }
0391:
0392:                public boolean isLeaf() {
0393:                    return box.getBoxCount() == 0;
0394:                }
0395:
0396:                public TreeNode getParent() {
0397:                    return parent;
0398:                }
0399:
0400:                public int getChildCount() {
0401:                    initializeChildren();
0402:
0403:                    return children.size();
0404:                }
0405:
0406:                public boolean getAllowsChildren() {
0407:                    return isLeaf();
0408:                }
0409:
0410:                public java.util.Enumeration<TreeNode> children() {
0411:                    initializeChildren();
0412:
0413:                    return Collections.enumeration(children);
0414:                }
0415:
0416:                private void initializeChildren() {
0417:                    if (children != null) {
0418:                        return;
0419:                    }
0420:
0421:                    int n = box.getBoxCount();
0422:                    children = new ArrayList<TreeNode>(n);
0423:
0424:                    for (int i = 0; i < n; i++) {
0425:                        children.add(new BoxTreeNode(box.getBox(i), this ));
0426:                    }
0427:                }
0428:
0429:                public String toString() {
0430:                    StringBuffer sb = new StringBuffer(40);
0431:                    sb.append("<html>"); // NOI18N
0432:
0433:                    //            RaveElement element = (RaveElement)box.getElement();
0434:                    Element element = box.getElement();
0435:
0436:                    if (box instanceof  LineBoxGroup) {
0437:                        sb.append("<i>" + getBundleString("TXT_LineboxGroup")
0438:                                + "</i>"); // NOI18N
0439:                    } else if (box.getBoxType() == BoxType.LINEBOX) {
0440:                        sb.append("<i>" + getBundleString("TXT_Linebox")
0441:                                + "</i>"); // NOI18N
0442:                    } else if (box.getBoxType() == BoxType.TEXT) {
0443:                        sb.append("<b>"); // NOI18N
0444:                        sb.append(((TextBox) box).getText());
0445:                        sb.append("</b>"); // NOI18N
0446:                    } else if (box.getBoxType() == BoxType.SPACE) {
0447:                        sb.append(getBundleString("TXT_Space"));
0448:                    } else if (element != null) {
0449:                        sb.append("&lt;"); // NOI18N
0450:                        sb.append(element.getTagName());
0451:                        sb.append("&gt;"); // NOI18N
0452:                        sb.append(' '); // NOI18N
0453:
0454:                        WebForm webForm = box.getWebForm();
0455:                        //                if (element.getDesignBean() != null && (box.getParent() == null ||
0456:                        //                        element.getDesignBean() != box.getParent().getDesignBean())) {
0457:                        //                MarkupDesignBean markupDesignBean = InSyncService.getProvider().getMarkupDesignBeanForElement(element);
0458:                        //                MarkupDesignBean markupDesignBean = WebForm.getDomProviderService().getMarkupDesignBeanForElement(element);
0459:                        //                if (markupDesignBean != null
0460:                        if (element != null
0461:                        //                && (box.getParent() == null || markupDesignBean != box.getParent().getDesignBean())) {
0462:                                //                && (box.getParent() == null || markupDesignBean != CssBox.getMarkupDesignBeanForCssBox(box))) {
0463:                                && (box.getParent() == null || element != CssBox
0464:                                        .getElementForComponentRootCssBox(box))) {
0465:                            // TODO - filter out XHTML beans
0466:                            sb.append("<i>"); // NOI18N
0467:                            //                    sb.append(element.getDesignBean().getInstanceName());
0468:                            //                    sb.append(markupDesignBean.getInstanceName());
0469:                            sb.append(webForm.getDomProviderService()
0470:                                    .getInstanceName(element));
0471:                            sb.append("</i>"); // NOI18N
0472:                        }
0473:                    }
0474:
0475:                    sb.append("</html>"); // NOI18N
0476:
0477:                    return sb.toString();
0478:                }
0479:
0480:                public CssBox getBox() {
0481:                    return box;
0482:                }
0483:            }
0484:
0485:            private static class BoxNode extends AbstractNode {
0486:                /** Name of property set for general properties */
0487:                public static final String GENERAL = "general"; // NOI18N
0488:                private CssBox box;
0489:
0490:                //        protected DataObject dobj;
0491:
0492:                public BoxNode(CssBox box/*, DataObject dobj*/) {
0493:                    super (Children.LEAF);
0494:                    this .box = box;
0495:                    //            this.dobj = dobj;
0496:                }
0497:
0498:                public Action[] getActions(boolean context) {
0499:                    return new Action[] { SystemAction
0500:                            .get(PropertiesAction.class) };
0501:                }
0502:
0503:                protected Sheet createSheet() {
0504:                    Sheet s = Sheet.createDefault();
0505:                    Sheet.Set ss = s.get("general"); // NOI18N
0506:
0507:                    if (ss == null) {
0508:                        ss = new Sheet.Set();
0509:                        ss.setName("general"); // NOI18N
0510:                        ss.setDisplayName(getBundleString("LBL_General")); // NOI18N
0511:                        ss.setShortDescription(getBundleString("HINT_General")); // NOI18N
0512:                        s.put(ss);
0513:                    }
0514:
0515:                    // Element name
0516:                    Node.Property p;
0517:
0518:                    if (box instanceof  TextBox) {
0519:                        p = getElementNameProperty(box);
0520:                        p.setName("Text"); // NOI18N
0521:                        p.setDisplayName(getBundleString("LBL_Text")); // parens: ensure first
0522:                        ss.put(p);
0523:                    } else {
0524:                        p = getElementNameProperty(box);
0525:                        p.setName("ElementName"); // NOI18N
0526:                        p.setDisplayName(getBundleString("LBL_Element")); // parens: ensure first
0527:
0528:                        //p.setShortDescription(NbBundle.getMessage(BoxNode.class, "ComponentIdHint")); // NOI18N
0529:                        ss.put(p);
0530:
0531:                        p = getElementIdProperty(box);
0532:                        p.setName("ElementId"); // NOI18N
0533:                        p.setDisplayName(getBundleString("LBL_Id"));
0534:                        ss.put(p);
0535:
0536:                        p = getAttributesProperty(box);
0537:                        p.setName("attributes"); // NOI18N
0538:                        p.setDisplayName(getBundleString("LBL_Attributes"));
0539:                        ss.put(p);
0540:
0541:                        p = getBeanNameDebugProperty(box);
0542:                        p.setName("BeanName"); // NOI18N
0543:                        p.setDisplayName(getBundleString("LBL_BeanName"));
0544:                        ss.put(p);
0545:                    }
0546:
0547:                    //            if (box.getDesignBean() != null) {
0548:                    //            if (CssBox.getMarkupDesignBeanForCssBox(box) != null) {
0549:                    if (CssBox.getElementForComponentRootCssBox(box) != null) {
0550:                        ss = s.get("jsf"); // NOI18N
0551:
0552:                        if (ss == null) {
0553:                            ss = new Sheet.Set();
0554:                            ss.setName("jsf"); // NOI18N
0555:                            ss.setDisplayName(getBundleString("LBL_Jsf")); // NOI18N
0556:                            s.put(ss);
0557:                        }
0558:
0559:                        p = getRenderStreamProperty(box);
0560:                        p.setName("renderStream"); // NOI18N
0561:                        p.setDisplayName(getBundleString("LBL_RenderedHtml")); // NOI18N
0562:                        ss.put(p);
0563:                    }
0564:
0565:                    ss = s.get("css"); // NOI18N
0566:
0567:                    if (ss == null) {
0568:                        ss = new Sheet.Set();
0569:                        ss.setName("css"); // NOI18N
0570:                        ss.setDisplayName(getBundleString("LBL_CssStyles"));
0571:                        s.put(ss);
0572:                    }
0573:
0574:                    try {
0575:                        p = getLocalStylesProperty(box);
0576:                        p.setName("localStyles"); // NOI18N
0577:                        p.setDisplayName(getBundleString("LBL_LocalStyles"));
0578:                        ss.put(p);
0579:
0580:                        p = new Reflection<String>(box, String.class,
0581:                                "getStyles", null); // NOI18N
0582:                        p.setName("styles"); // NOI18N
0583:                        p.setDisplayName(getBundleString("LBL_Styles"));
0584:                        ss.put(p);
0585:
0586:                        p = new Reflection<String>(box, String.class,
0587:                                "getComputedStyles", null); // NOI18N
0588:                        p.setName("compstyles"); // NOI18N
0589:                        p.setDisplayName(getBundleString("LBL_ComputedStyles"));
0590:                        ss.put(p);
0591:
0592:                        p = new Reflection<String>(box, String.class,
0593:                                "getRules", null); // NOI18N
0594:                        p.setName("rules"); // NOI18N
0595:                        p.setDisplayName(getBundleString("LBL_Rules"));
0596:                        ss.put(p);
0597:
0598:                        p = new Reflection<Color>(box, Color.class, "getBg",
0599:                                null); // NOI18N
0600:                        p.setName("bg"); // NOI18N
0601:                        p.setDisplayName(getBundleString("LBL_Background"));
0602:                        ss.put(p);
0603:                    } catch (NoSuchMethodException nsme) {
0604:                        nsme.printStackTrace();
0605:                    }
0606:
0607:                    ss = s.get("boxmodel"); // NOI18N
0608:
0609:                    if (ss == null) {
0610:                        ss = new Sheet.Set();
0611:                        ss.setName("boxmodel"); // NOI18N
0612:                        ss.setDisplayName(getBundleString("LBL_BoxModel"));
0613:
0614:                        //ss.setShortDescription(NbBundle.getMessage(BoxNode.class, "FormatHint")); // NOI18N
0615:                        s.put(ss);
0616:                    }
0617:
0618:                    try {
0619:                        //containing block, extents
0620:                        p = new Reflection<Point>(box, Point.class,
0621:                                "getPosition", null); // NOI18N
0622:                        p.setName("position"); // NOI18N
0623:                        p.setDisplayName(getBundleString("LBL_Position"));
0624:                        ss.put(p);
0625:
0626:                        p = new Reflection<Point>(box, Point.class,
0627:                                "getRelPosition", null); // NOI18N
0628:                        p.setName("relposition"); // NOI18N
0629:                        p.setDisplayName(getBundleString("LBL_RelPosition"));
0630:                        ss.put(p);
0631:
0632:                        p = new Reflection<Dimension>(box, Dimension.class,
0633:                                "getSize", null); // NOI18N
0634:                        p.setName("size"); // NOI18N
0635:                        p.setDisplayName(getBundleString("LBL_Size"));
0636:                        ss.put(p);
0637:
0638:                        p = new Reflection<Dimension>(box, Dimension.class,
0639:                                "getContentSize", null); // NOI18N
0640:                        p.setName("contentsize"); // NOI18N
0641:                        p.setDisplayName(getBundleString("LBL_ContentSize"));
0642:                        ss.put(p);
0643:
0644:                        p = new Reflection<String>(box, String.class,
0645:                                "getBoxTypeName", null); // NOI18N
0646:                        p.setName("boxtype"); // NOI18N
0647:                        p.setDisplayName(getBundleString("LBL_Positioning"));
0648:                        ss.put(p);
0649:
0650:                        p = new Reflection<Rectangle>(box, Rectangle.class,
0651:                                "getPositionRect", null); // NOI18N
0652:                        p.setName("positionrect"); // NOI18N
0653:                        p.setDisplayName(getBundleString("LBL_PosConstraints"));
0654:                        ss.put(p);
0655:
0656:                        p = new Reflection<Rectangle>(box, Rectangle.class,
0657:                                "getMarginRectangle", null); // NOI18N
0658:                        p.setName("marginrectangle"); // NOI18N
0659:                        p.setDisplayName(getBundleString("LBL_Margins"));
0660:                        ss.put(p);
0661:
0662:                        p = new Reflection<Rectangle>(box, Rectangle.class,
0663:                                "getCBRectangle", null); // NOI18N
0664:                        p.setName("cbrectangle"); // NOI18N
0665:                        p
0666:                                .setDisplayName(getBundleString("LBL_ContainingBlock"));
0667:                        ss.put(p);
0668:
0669:                        p = new Reflection<Rectangle>(box, Rectangle.class,
0670:                                "getExtentsRectangle", null); // NOI18N
0671:                        p.setName("extentsrectangle"); // NOI18N
0672:                        p.setDisplayName(getBundleString("LBL_Extents"));
0673:                        ss.put(p);
0674:
0675:                        p = new Reflection<Rectangle>(box, Rectangle.class,
0676:                                "getPaddingRectangle", null); // NOI18N
0677:                        p.setName("paddingrectangle"); // NOI18N
0678:                        p.setDisplayName(getBundleString("LBL_Padding"));
0679:                        ss.put(p);
0680:
0681:                        p = new Reflection<Rectangle>(box, Rectangle.class,
0682:                                "getBorderWidthRectangle", null); // NOI18N
0683:                        p.setName("borderWidthrectangle"); // NOI18N
0684:                        p.setDisplayName(getBundleString("LBL_BorderWidths"));
0685:                        ss.put(p);
0686:
0687:                        p = new Reflection<Boolean>(box, Boolean.TYPE,
0688:                                "isInlineBox", null); // NOI18N
0689:                        p.setName("inline"); // NOI18N
0690:                        p.setDisplayName(getBundleString("LBL_Inline"));
0691:                        ss.put(p);
0692:
0693:                        p = new Reflection<Boolean>(box, Boolean.TYPE,
0694:                                "isReplacedBox", null); // NOI18N
0695:                        p.setName("replaced"); // NOI18N
0696:                        p.setDisplayName(getBundleString("LBL_Replaced"));
0697:                        ss.put(p);
0698:
0699:                        p = new Reflection<Integer>(box, Integer.TYPE,
0700:                                "getBoxCount", null); // NOI18N
0701:                        p.setName("boxcount"); // NOI18N
0702:                        p.setDisplayName(getBundleString("LBL_Children"));
0703:                        ss.put(p);
0704:                    } catch (NoSuchMethodException nsme) {
0705:                        ErrorManager.getDefault().notify(nsme);
0706:                    }
0707:
0708:                    ss = s.get("csspainting"); // NOI18N
0709:
0710:                    if (ss == null) {
0711:                        ss = new Sheet.Set();
0712:                        ss.setName("csspainting"); // NOI18N
0713:                        ss.setDisplayName(getBundleString("LBL_BoxPainting"));
0714:                        s.put(ss);
0715:                    }
0716:
0717:                    try {
0718:                        p = new Reflection<Boolean>(box, Boolean.TYPE,
0719:                                "getPaintPositions", "setPaintPositions"); // NOI18N
0720:                        p.setName("paintpos"); // NOI18N
0721:                        p
0722:                                .setDisplayName(getBundleString("LBL_PaintPositioning"));
0723:                        ss.put(p);
0724:
0725:                        p = new Reflection<Boolean>(box, Boolean.TYPE,
0726:                                "getPaintText", "setPaintText"); // NOI18N
0727:                        p.setName("painttext"); // NOI18N
0728:                        p.setDisplayName(getBundleString("LBL_PaintText"));
0729:                        ss.put(p);
0730:
0731:                        p = new Reflection<Boolean>(box, Boolean.TYPE,
0732:                                "getPaintSpaces", "setPaintSpaces"); // NOI18N
0733:                        p.setName("paintspaces"); // NOI18N
0734:                        p.setDisplayName(getBundleString("LBL_PaintSpaces"));
0735:                        ss.put(p);
0736:
0737:                    } catch (NoSuchMethodException nsme) {
0738:                        ErrorManager.getDefault().notify(nsme);
0739:                    }
0740:
0741:                    return s;
0742:                }
0743:
0744:                //        /**
0745:                //         * Set the data object this component is associated with (if any).
0746:                //         * When set, this node will return the cookies of the data object as well.
0747:                //         * Therefore, as an example, if you select an image component in a page,
0748:                //         * the
0749:                //         */
0750:                //        public void setDataObject(DataObject dobj) {
0751:                //            this.dobj = dobj;
0752:                //        }
0753:
0754:                /** Get a cookie. Call super first, but if null, also check the
0755:                 * associated data object.
0756:                 */
0757:                public <T extends Node.Cookie> T getCookie(Class<T> cl) {
0758:                    T cookie = super .getCookie(cl);
0759:
0760:                    if (cookie != null) {
0761:                        return cookie;
0762:                    }
0763:
0764:                    //            if (dobj != null) {
0765:                    //                return dobj.getCookie(cl);
0766:                    //            }
0767:
0768:                    return null;
0769:                }
0770:
0771:                public boolean canRename() {
0772:                    return false;
0773:                }
0774:
0775:                public boolean canDestroy() {
0776:                    // No point since it gets recreated after every edit
0777:                    return false;
0778:                }
0779:
0780:                /** Can this node be copied?
0781:                 * @return <code>true</code>
0782:                 */
0783:                public boolean canCopy() {
0784:                    return false;
0785:                }
0786:
0787:                /** Can this node be cut?
0788:                 * @return <code>false</code>
0789:                 */
0790:                public boolean canCut() {
0791:                    // No point since it gets recreated after every edit
0792:                    return false;
0793:                }
0794:
0795:                /** Don't allow pastes */
0796:                protected void createPasteTypes(Transferable t, List s) {
0797:                }
0798:
0799:                /*
0800:                public Image getIcon(int type) {
0801:                    // set icon base lazily. The icon should only be needed by nodes
0802:                    // displayed in for example the nonvisual gutter
0803:                    if (iconbase != null) {
0804:                        setIconBase(iconbase);
0805:                        iconbase = null;
0806:                    }
0807:                    return super.getIcon(type);
0808:                }
0809:                 */
0810:
0811:                /** The nodes should display the component name. This ensures
0812:                 * that when you're looking at the node in the tray for example
0813:                 * (an explorer which shows the node names) you see the component
0814:                 * id.)
0815:                 */
0816:                public final String getDisplayName() {
0817:                    return getBundleString("LBL_SelectedBox"); // What do we put here?
0818:                }
0819:            }
0820:
0821:            /////////////
0822:            // Properties 
0823:
0824:            private static Node.Property getElementNameProperty(final CssBox box) {
0825:                return new PropertySupport.ReadOnly<String>("elementName",
0826:                        String.class, "elementName",
0827:                        getBundleString("LBL_NameElement")) {
0828:                    public String getValue() {
0829:                        Element element = box.getElement();
0830:                        if (element != null) {
0831:                            return element.getTagName();
0832:                        } else if (box.getBoxType() == BoxType.TEXT) {
0833:                            return ((TextBox) box).getText();
0834:                        } else if (box.getBoxType() == BoxType.SPACE) {
0835:                            return getBundleString("TXT_Whitespace");
0836:                        } else {
0837:                            return getBundleString("TXT_NotElement");
0838:                        }
0839:                    }
0840:                };
0841:            }
0842:
0843:            private static Node.Property getElementIdProperty(final CssBox box) {
0844:                return new PropertySupport.ReadOnly<String>("elementId",
0845:                        String.class, "elementId",
0846:                        getBundleString("LBL_IdElement")) {
0847:                    public String getValue() {
0848:                        Element element = box.getElement();
0849:                        if (element != null) {
0850:                            String id = element.getAttribute("id"); // NOI18N
0851:
0852:                            if (id != null) {
0853:                                return id;
0854:                            }
0855:
0856:                            id = element.getAttribute("name"); // NOI18N
0857:
0858:                            if (id != null) {
0859:                                return id;
0860:                            }
0861:                        }
0862:
0863:                        return ""; // NOI18N
0864:                    }
0865:                };
0866:            }
0867:
0868:            private static Node.Property getAttributesProperty(final CssBox box) {
0869:                return new PropertySupport.ReadOnly<String>("attributes",
0870:                        String.class, "attributes",
0871:                        getBundleString("LBL_AttributesElement")) {
0872:                    public String getValue() {
0873:                        Element element = box.getElement();
0874:                        if (element != null) {
0875:                            //return element.getAttributes().toString();
0876:                            org.w3c.dom.NamedNodeMap map = element
0877:                                    .getAttributes();
0878:                            StringBuffer sb = new StringBuffer(200);
0879:
0880:                            for (int i = 0, n = map.getLength(); i < n; i++) {
0881:                                if (i > 0) {
0882:                                    sb.append(','); // NOI18N
0883:                                    sb.append(' '); // NOI18N
0884:                                }
0885:
0886:                                org.w3c.dom.Node node = map.item(i);
0887:                                sb.append(node.getNodeName());
0888:                                sb.append('='); // NOI18N
0889:                                sb.append('\"'); // NOI18N
0890:                                sb.append(node.getNodeValue());
0891:                                sb.append('\"'); // NOI18N
0892:                            }
0893:
0894:                            return sb.toString();
0895:                        } else {
0896:                            return ""; // NOI18N
0897:                        }
0898:                    }
0899:                };
0900:            }
0901:
0902:            private static Node.Property getBeanNameDebugProperty(
0903:                    final CssBox box) {
0904:                return new PropertySupport.ReadOnly<String>("beanNameDebug",
0905:                        String.class, "beanNameDebug",
0906:                        getBundleString("LBL_BeanNameDebug")) {
0907:                    public String getValue() {
0908:                        //		MarkupDesignBean bean = box.getDesignBean();
0909:                        //                MarkupDesignBean bean = CssBox.getMarkupDesignBeanForCssBox(box);
0910:                        Element componentRootElement = CssBox
0911:                                .getElementForComponentRootCssBox(box);
0912:                        //		String s = DesignerUtils.getBeanName(bean);
0913:                        //                String s = getBeanName(bean);
0914:                        WebForm webForm = box == null ? null : box.getWebForm();
0915:                        String s = getComponentName(webForm,
0916:                                componentRootElement);
0917:
0918:                        if (s == null) {
0919:                            return ""; // NOI18N
0920:                        }
0921:
0922:                        return s;
0923:                    }
0924:                };
0925:            }
0926:
0927:            // XXX Moved from DesignerUtils.
0928:            /**
0929:             * Get the name of the given bean, e.g. "button1", "textField5", etc.
0930:             *
0931:             * @return the name of the bean, or null if a bean can not be found for this view's element
0932:             */
0933:            //    private static String getBeanName(DesignBean bean) {
0934:            private static String getComponentName(WebForm webForm,
0935:                    Element componentRootElement) {
0936:                if (webForm == null) {
0937:                    return null;
0938:                }
0939:                //        if (bean != null) {
0940:                if (componentRootElement != null) {
0941:                    //            return "<" + bean.getInstanceName() + ">";
0942:                    return "<"
0943:                            + webForm.getDomProviderService().getInstanceName(
0944:                                    componentRootElement) + ">";
0945:                }
0946:
0947:                return null;
0948:            }
0949:
0950:            private static Node.Property getRenderStreamProperty(
0951:                    final CssBox box) {
0952:                return new PropertySupport.ReadOnly<String>("renderStream",
0953:                        String.class, "renderStream",
0954:                        getBundleString("LBL_RenderStream")) {
0955:                    public String getValue() {
0956:                        //		MarkupDesignBean bean = box.getDesignBean();
0957:                        //                MarkupDesignBean bean = CssBox.getMarkupDesignBeanForCssBox(box);
0958:                        Element componentRootElement = CssBox
0959:                                .getElementForComponentRootCssBox(box);
0960:                        //		if (bean == null) {
0961:                        if (componentRootElement == null) {
0962:                            return ""; // NOI18N
0963:                        }
0964:
0965:                        //		FacesModel model = box.getWebForm().getModel();
0966:                        //
0967:                        //		if (model == null) { // testsuite
0968:                        //
0969:                        //		    return ""; // NOI18N
0970:                        //		}
0971:
0972:                        //		if (bean == null) {
0973:                        //		    return ""; // NOI18N
0974:                        //		}
0975:
0976:                        //		FacesPageUnit facesunit = model.getFacesUnit();
0977:                        //		DocumentFragment df = facesunit.getFacesRenderTree(bean, model.getLiveUnit());
0978:                        //
0979:                        //		// TODO - strip out designtime attributes
0980:                        //		if (df == null) {
0981:                        //		    return ""; // NOI18N
0982:                        //		}
0983:
0984:                        //                Element element = bean.getElement();
0985:
0986:                        //		return InSyncService.getProvider().getHtmlStream(df);
0987:                        //                return WebForm.getDomProviderService().getHtmlStream(df);
0988:                        WebForm webForm = box == null ? null : box.getWebForm();
0989:                        if (webForm == null) {
0990:                            return ""; // NOI18N
0991:                        }
0992:                        return webForm.getDomProviderService().getHtmlStream(
0993:                                componentRootElement);
0994:                    }
0995:                };
0996:            }
0997:
0998:            private static Node.Property getLocalStylesProperty(final CssBox box) {
0999:                return new PropertySupport.ReadOnly<String>("localStyles",
1000:                        String.class, "localStyles",
1001:                        getBundleString("LBL_LocalStyles")) {
1002:                    public String getValue() {
1003:                        Element element = box.getElement();
1004:                        if (element != null) {
1005:                            String style = element
1006:                                    .getAttribute(HtmlAttribute.STYLE);
1007:
1008:                            if (style != null) {
1009:                                return style;
1010:                            }
1011:                        }
1012:
1013:                        return ""; // NOI18N
1014:                    }
1015:                };
1016:            }
1017:
1018:            private static String getBundleString(String key) {
1019:                return NbBundle.getMessage(DomInspector.class, key);
1020:            }
1021:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.