Source Code Cross Referenced for DesignBeanNodeHelper.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » insync » live » 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.insync.live 
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.insync.live;
0043:
0044:        import java.beans.PropertyDescriptor;
0045:        import org.netbeans.modules.visualweb.api.designer.cssengine.CssComputedValue;
0046:        import org.netbeans.modules.visualweb.api.designer.cssengine.CssProvider;
0047:        import org.netbeans.modules.visualweb.api.designer.cssengine.CssValue;
0048:        import org.netbeans.modules.visualweb.api.designer.cssengine.XhtmlCss;
0049:        import org.netbeans.modules.visualweb.api.designer.markup.MarkupService;
0050:        import org.netbeans.modules.visualweb.designer.html.HtmlAttribute;
0051:        import org.netbeans.modules.visualweb.designer.html.HtmlTag;
0052:        import com.sun.rave.designtime.DesignBean;
0053:        import com.sun.rave.designtime.DesignContext;
0054:        import com.sun.rave.designtime.DesignProperty;
0055:        import com.sun.rave.designtime.Position;
0056:        import com.sun.rave.designtime.markup.MarkupPosition;
0057:        import org.netbeans.modules.visualweb.insync.InSyncServiceProvider;
0058:        import org.netbeans.modules.visualweb.insync.UndoEvent;
0059:        import org.netbeans.modules.visualweb.insync.Util;
0060:        import org.netbeans.modules.visualweb.insync.faces.FacesPageUnit;
0061:        import org.netbeans.modules.visualweb.insync.faces.MarkupBean;
0062:        import org.netbeans.modules.visualweb.insync.markup.MarkupUnit;
0063:        import org.netbeans.modules.visualweb.insync.models.FacesModel;
0064:        import org.netbeans.modules.visualweb.propertyeditors.StandardUrlPropertyEditor;
0065:        import java.awt.Color;
0066:        import java.beans.PropertyEditor;
0067:        import java.beans.PropertyEditorSupport;
0068:        import javax.faces.component.UIViewRoot;
0069:        import org.openide.ErrorManager;
0070:        import org.openide.filesystems.FileObject;
0071:        import org.openide.loaders.DataObject;
0072:        import org.openide.loaders.DataObjectNotFoundException;
0073:        import org.openide.nodes.PropertySupport;
0074:        import org.openide.nodes.Sheet;
0075:        import org.openide.nodes.Sheet.Set;
0076:        import org.openide.util.NbBundle;
0077:        import org.w3c.dom.Document;
0078:        import org.w3c.dom.Element;
0079:        import org.w3c.dom.Node;
0080:        import org.w3c.dom.NodeList;
0081:
0082:        /**
0083:         * XXX Providing the fake properties for the <code>DesignBeanNode</code>
0084:         * if the one represents the root container of Page design bean context.
0085:         * This is a continuation of hack from the past made in designer using
0086:         * DocumentComp and DocumentCompNode.
0087:         *
0088:         * @author Peter Zavadsky
0089:         * @author Tor Norbye (old code, parts of impl of set/getValue methods)
0090:         */
0091:        final class DesignBeanNodeHelper {
0092:
0093:            /** Creates a new instance of DesignBeanNodeHelper */
0094:            private DesignBeanNodeHelper() {
0095:            }
0096:
0097:            /** XXX Adds additional properties to the specified sheet
0098:             * and for specified <code>DesignBean</code>.
0099:             * @return same sheet with added properties */
0100:            static void addFakePageProperties(Sheet sheet, DesignBean designBean) {
0101:
0102:                Sheet.Set set = addSetIntoSheet(sheet, "Appearance", // NOI18N
0103:                        NbBundle.getMessage(DesignBeanNodeHelper.class,
0104:                                "LBL_Appearance"));
0105:
0106:                boolean isPortlet = isPortlet(designBean);
0107:                boolean isFragment = isFragment(designBean);
0108:
0109:                if (isPortlet || !isFragment) {
0110:                    // Add Background property
0111:                    set.put(new BackgroundProperty(designBean));
0112:                }
0113:                if (!isPortlet && !isFragment) {
0114:                    // Add Background Image property
0115:                    set.put(new BackgroundImageProperty(designBean));
0116:                }
0117:                // Add Page Layout property
0118:                set.put(new LayoutProperty(designBean));
0119:                if (isPortlet || isFragment) {
0120:                    // Add Width property
0121:                    // TODO
0122:                    set.put(new WidthProperty(designBean));
0123:                    // Add Height property
0124:                    // TODO
0125:                    set.put(new HeightProperty(designBean));
0126:                }
0127:                if (!isPortlet && !isFragment) {
0128:                    // Add Style sheet property
0129:                    set.put(new StyleSheetProperty(designBean));
0130:                    // Add Title property
0131:                    set.put(new TitleProperty(designBean));
0132:
0133:                    set = addSetIntoSheet(sheet, "Advanced", // NOI18N
0134:                            NbBundle.getMessage(DesignBeanNodeHelper.class,
0135:                                    "LBL_Advanced"));
0136:                    // Add Response Encoding property
0137:                    set.put(new EncodingProperty(designBean));
0138:                    // Add Language property
0139:                    set.put(new LanguageProperty(designBean));
0140:                }
0141:            }
0142:
0143:            private static Set addSetIntoSheet(Sheet sheet, String name,
0144:                    String displayName) {
0145:                Sheet.Set set = sheet.get(name);
0146:                if (set == null) {
0147:                    set = new Sheet.Set();
0148:                    set.setName(name);
0149:                    set.setDisplayName(displayName);
0150:                    //            //ss.setExpert();
0151:                    //            // would like to set default expanded state too...
0152:                    //            if (descr != null) {
0153:                    //                ss.setShortDescription(descr);
0154:                    //            }
0155:                    sheet.put(set);
0156:                }
0157:
0158:                return set;
0159:            }
0160:
0161:            private static class BackgroundProperty extends
0162:                    PropertySupport.ReadWrite {
0163:                private final DesignBean designBean;
0164:                private Color bgColor;
0165:
0166:                public BackgroundProperty(DesignBean desingBean) {
0167:                    super ("background", // NOI18n
0168:                            Color.class, NbBundle.getMessage(
0169:                                    DesignBeanNodeHelper.class,
0170:                                    "LBL_Background"), NbBundle.getMessage(
0171:                                    DesignBeanNodeHelper.class,
0172:                                    "DESC_Background"));
0173:                    this .designBean = desingBean;
0174:                }
0175:
0176:                public void setValue(Object value)
0177:                        throws IllegalArgumentException {
0178:                    validateValue(value, Color.class);
0179:
0180:                    Color color = (Color) value;
0181:
0182:                    FacesModel facesModel = findFacesModel(designBean);
0183:                    if (facesModel == null) {
0184:                        return;
0185:                    }
0186:
0187:                    Element body = facesModel.getHtmlBody();
0188:                    if (body == null) {
0189:                        return;
0190:                    }
0191:
0192:                    String bga = colorToHex(color); //!CQ or call: colorToRgb(bgcolor);
0193:                    String description = null; // TODO XXX old code
0194:                    UndoEvent event = facesModel.writeLock(description);
0195:                    try {
0196:                        //                CssLookup.setLocalStyleValue(body, XhtmlCss.BACKGROUND_COLOR_INDEX, bga);
0197:                        Util.addLocalStyleValueForElement(body,
0198:                                XhtmlCss.BACKGROUND_COLOR_INDEX, bga);
0199:                        bgColor = color;
0200:                    } finally {
0201:                        facesModel.writeUnlock(event);
0202:                    }
0203:
0204:                    //            CssLookup.refreshEffectiveStyles(webform.getDom());
0205:                    CssProvider.getEngineService().refreshStylesForDocument(
0206:                            facesModel.getJspDom());
0207:                    // XXX Should this be here too (or the above?).
0208:                    CssProvider.getEngineService().refreshStylesForDocument(
0209:                            facesModel.getHtmlDom());
0210:                }
0211:
0212:                public Object getValue() {
0213:                    if (bgColor != null) {
0214:                        return bgColor;
0215:                    }
0216:
0217:                    FacesModel facesModel = findFacesModel(designBean);
0218:                    if (facesModel == null) {
0219:                        bgColor = Color.WHITE;
0220:                        return bgColor;
0221:                    }
0222:
0223:                    Element body = facesModel.getHtmlBody();
0224:                    if (body == null) {
0225:                        bgColor = Color.WHITE;
0226:                        return bgColor;
0227:                    }
0228:
0229:                    if (body != null) {
0230:                        //                bgColor = CssLookup.getColor(body, XhtmlCss.BACKGROUND_COLOR_INDEX);
0231:                        bgColor = CssProvider.getValueService()
0232:                                .getColorForElement(body,
0233:                                        XhtmlCss.BACKGROUND_COLOR_INDEX);
0234:                        if (bgColor == null) {
0235:                            bgColor = Color.WHITE;
0236:                        }
0237:                    }
0238:                    return bgColor;
0239:                }
0240:            } // End of BackgroundProperty.
0241:
0242:            private static class BackgroundImageProperty extends
0243:                    PropertySupport.ReadWrite {
0244:                private final DesignBean designBean;
0245:                private String bgImage;
0246:
0247:                public BackgroundImageProperty(DesignBean desingBean) {
0248:                    super ("backgroundImage", // NOI18N
0249:                            String.class, NbBundle.getMessage(
0250:                                    DesignBeanNodeHelper.class,
0251:                                    "LBL_BackgroundImage"), NbBundle
0252:                                    .getMessage(DesignBeanNodeHelper.class,
0253:                                            "DESC_BackgroundImage"));
0254:                    this .designBean = desingBean;
0255:                    DesignContext designContext = designBean.getDesignContext();
0256:                    FacesModel facesModel = findFacesModel(designBean);
0257:                    FileObject fileObject = facesModel == null ? null
0258:                            : facesModel.getFile();
0259:                    if ((designContext != null) || (fileObject != null)) {
0260:                        setValue(StandardUrlPropertyEditor.PROPERTY_PROPERTY,
0261:                                this );
0262:                        if (designContext == null) {
0263:                            setValue(
0264:                                    StandardUrlPropertyEditor.PROPERTY_FORM_FILE,
0265:                                    fileObject);
0266:                        } else {
0267:                            setValue(
0268:                                    StandardUrlPropertyEditor.PROPERTY_LIVE_CONTEXT,
0269:                                    designContext);
0270:                        }
0271:                    }
0272:                }
0273:
0274:                public PropertyEditor getPropertyEditor() {
0275:                    if (this .designBean.getInstance() instanceof  UIViewRoot) {
0276:                        StandardUrlPropertyEditor editor = new StandardUrlPropertyEditor();
0277:                        return editor;
0278:                    }
0279:                    return super .getPropertyEditor();
0280:                }
0281:
0282:                public Object getValue() {
0283:                    if (bgImage == null) {
0284:                        FacesModel facesModel = findFacesModel(designBean);
0285:                        if (facesModel == null) {
0286:                            return ""; // NOI18N
0287:                        }
0288:
0289:                        Element body = facesModel.getHtmlBody();
0290:
0291:                        if (body != null) {
0292:                            // Prefer to use the body's "background image" property, since
0293:                            // this can properly handle context relative urls etc. (direct CSS properties
0294:                            // can not)
0295:                            //                    DesignBean bodyBean = ((RaveElement)body).getDesignBean();
0296:                            DesignBean bodyBean = InSyncServiceProvider.get()
0297:                                    .getMarkupDesignBeanForElement(body);
0298:                            if (bodyBean != null) {
0299:                                DesignProperty background = bodyBean
0300:                                        .getProperty("imageURL"); // NOI18N
0301:                                if (background != null) {
0302:                                    Object o = background.getValue();
0303:                                    if (o != null) {
0304:                                        return o.toString();
0305:                                    } else {
0306:                                        return "";
0307:                                    }
0308:                                }
0309:                            }
0310:
0311:                            //                    Value value = CssLookup.getValue(body, XhtmlCss.BACKGROUND_IMAGE_INDEX);
0312:                            CssValue cssValue = CssProvider.getEngineService()
0313:                                    .getComputedValueForElement(body,
0314:                                            XhtmlCss.BACKGROUND_IMAGE_INDEX);
0315:
0316:                            //                    if ((value == CssValueConstants.NONE_VALUE) || (value == null)) {
0317:                            if (cssValue == null
0318:                                    || CssProvider.getValueService()
0319:                                            .isNoneValue(cssValue)) {
0320:                                bgImage = ""; // NOI18N
0321:                            } else {
0322:                                bgImage = cssValue.getStringValue();
0323:                            }
0324:                        } else {
0325:                            bgImage = ""; // NOI18N
0326:                        }
0327:                    }
0328:
0329:                    return bgImage;
0330:                }
0331:
0332:                public void setValue(Object value)
0333:                        throws IllegalArgumentException {
0334:                    validateValue(value, String.class);
0335:                    String bgImage = (String) value;
0336:
0337:                    FacesModel facesModel = findFacesModel(designBean);
0338:                    if (facesModel == null) {
0339:                        this .bgImage = null;
0340:                        return;
0341:                    }
0342:
0343:                    Element body = facesModel.getHtmlBody();
0344:
0345:                    if (body != null) {
0346:                        UndoEvent event = null;
0347:
0348:                        try {
0349:                            String description = null; // TODO
0350:                            event = facesModel.writeLock(description);
0351:
0352:                            // Prefer to use the body's "background image" property, since
0353:                            // this can properly handle context relative urls etc. (direct CSS properties
0354:                            // can not)
0355:                            //                    DesignBean bodyBean = ((RaveElement)body).getDesignBean();
0356:                            DesignBean bodyBean = InSyncServiceProvider.get()
0357:                                    .getMarkupDesignBeanForElement(body);
0358:                            if (bodyBean != null) {
0359:                                DesignProperty background = bodyBean
0360:                                        .getProperty("imageURL"); // NOI18N
0361:                                if (background != null) {
0362:                                    if ((bgImage != null)
0363:                                            && (bgImage.length() > 0)) {
0364:                                        background.setValue(bgImage);
0365:                                    } else {
0366:                                        background.unset();
0367:                                    }
0368:
0369:                                    return;
0370:                                }
0371:                            }
0372:
0373:                            if ((bgImage != null) && (bgImage.length() > 0)) {
0374:                                String url = "url(" + bgImage + ")"; // NOI18N
0375:                                //                        CssLookup.setLocalStyleValue(body, XhtmlCss.BACKGROUND_IMAGE_INDEX, url);
0376:                                Util.addLocalStyleValueForElement(body,
0377:                                        XhtmlCss.BACKGROUND_IMAGE_INDEX, url);
0378:                            } else {
0379:                                //                        CssLookup.removeLocalStyleValue(body, XhtmlCss.BACKGROUND_IMAGE_INDEX);
0380:                                Util.removeLocalStyleValueForElement(body,
0381:                                        XhtmlCss.BACKGROUND_IMAGE_INDEX);
0382:                            }
0383:                        } finally {
0384:                            facesModel.writeUnlock(event);
0385:                            this .bgImage = bgImage;
0386:                        }
0387:                    }
0388:                }
0389:
0390:                public boolean supportsDefaultValue() {
0391:                    return true;
0392:                }
0393:
0394:                public void restoreDefaultValue() {
0395:                    setValue(null);
0396:                }
0397:            } // End of BackgroundImageProperty.
0398:
0399:            private static class LayoutProperty extends
0400:                    PropertySupport.ReadWrite {
0401:                private final DesignBean designBean;
0402:                private int layoutMode = -1;
0403:
0404:                public LayoutProperty(DesignBean desingBean) {
0405:                    super (
0406:                            "layout", // NOI18N
0407:                            Integer.class, NbBundle.getMessage(
0408:                                    DesignBeanNodeHelper.class, "LBL_Layout"),
0409:                            NbBundle.getMessage(DesignBeanNodeHelper.class,
0410:                                    "DESC_Layout"));
0411:                    this .designBean = desingBean;
0412:                }
0413:
0414:                public Object getValue() {
0415:                    if (layoutMode < 0) {
0416:                        FacesModel facesModel = findFacesModel(designBean);
0417:                        if (facesModel == null) {
0418:                            return new Integer(0);
0419:                        }
0420:
0421:                        Element body = facesModel.getHtmlBody();
0422:
0423:                        if (body != null) {
0424:                            //                    Value val = CssLookup.getValue(body, XhtmlCss.RAVELAYOUT_INDEX);
0425:                            CssValue cssValue = CssProvider.getEngineService()
0426:                                    .getComputedValueForElement(body,
0427:                                            XhtmlCss.RAVELAYOUT_INDEX);
0428:                            //                    layoutMode = (val == CssValueConstants.GRID_VALUE) ? 0 : 1;
0429:                            layoutMode = (CssProvider.getValueService()
0430:                                    .isGridValue(cssValue) ? 0 : 1);
0431:                        } else {
0432:                            layoutMode = 1; // flow if grid is not known
0433:                        }
0434:                    }
0435:
0436:                    return new Integer(layoutMode);
0437:                }
0438:
0439:                /** XXX */
0440:                public PropertyEditor getPropertyEditor() {
0441:                    return new PageLayoutEditor();
0442:                }
0443:
0444:                public void setValue(Object value)
0445:                        throws IllegalArgumentException {
0446:                    validateValue(value, Integer.class);
0447:                    Integer intValue = (Integer) value;
0448:                    int mode = intValue == null ? 0 : intValue.intValue();
0449:
0450:                    FacesModel facesModel = findFacesModel(designBean);
0451:                    if (facesModel == null) {
0452:                        return;
0453:                    }
0454:
0455:                    Element body = facesModel.getHtmlBody();
0456:
0457:                    if (body != null) {
0458:                        UndoEvent event = null;
0459:
0460:                        try {
0461:                            String description = null; // TODO
0462:                            event = facesModel.writeLock(description);
0463:
0464:                            if (mode == 1) { // flow
0465:                            //                        CssLookup.removeLocalStyleValue(body, XhtmlCss.RAVELAYOUT_INDEX);
0466:                                Util.removeLocalStyleValueForElement(body,
0467:                                        XhtmlCss.RAVELAYOUT_INDEX);
0468:
0469:                                // Ensure that the document has a <br> near the top we
0470:                                // can go back to. This is necessary because the caret can
0471:                                // only be placed in lineboxes, and we need to ensure we have a linebox.
0472:                                // Other HTML editors seem to do this too - Mozilla Composer for example.
0473:                                //                        if (body instanceof RaveElement) {
0474:                                if (body != null) {
0475:                                    //                            DesignBean bean = ((RaveElement)body).getDesignBean();
0476:                                    DesignBean bean = InSyncServiceProvider
0477:                                            .get()
0478:                                            .getMarkupDesignBeanForElement(body);
0479:
0480:                                    LiveUnit lunit = facesModel.getLiveUnit();
0481:                                    if (bean != null) {
0482:                                        if ((bean.getChildBeanCount() == 0)
0483:                                                || !((MarkupDesignBean) bean
0484:                                                        .getChildBean(0))
0485:                                                        .getElement()
0486:                                                        .getTagName()
0487:                                                        .equals(HtmlTag.BR.name)) {
0488:                                            // Add a br
0489:                                            Element parent = ((MarkupDesignBean) bean)
0490:                                                    .getElement();
0491:                                            Node before = parent
0492:                                                    .getFirstChild();
0493:                                            //                                    webform.getDocument().createBean(org.netbeans.modules.visualweb.xhtml.Br.class.getName(), parent, before);
0494:                                            createBean(
0495:                                                    org.netbeans.modules.visualweb.xhtml.Br.class
0496:                                                            .getName(), parent,
0497:                                                    before, lunit);
0498:                                        }
0499:                                    }
0500:
0501:                                    // Add one to form too...
0502:                                    FacesPageUnit facesUnit = facesModel
0503:                                            .getFacesUnit();
0504:
0505:                                    if ((facesUnit != null) && (lunit != null)) {
0506:                                        MarkupBean formBean = facesUnit
0507:                                                .getDefaultParent();
0508:                                        //                                bean = /*FacesSupport*/Util.getDesignBean(formBean.getElement());
0509:                                        bean = InSyncServiceProvider.get()
0510:                                                .getMarkupDesignBeanForElement(
0511:                                                        formBean.getElement());
0512:
0513:                                        if (bean != null) {
0514:                                            int n = bean.getChildBeanCount();
0515:
0516:                                            if ((n == 0)
0517:                                                    || !((MarkupDesignBean) bean
0518:                                                            .getChildBean(n - 1))
0519:                                                            .getElement()
0520:                                                            .getTagName()
0521:                                                            .equals(
0522:                                                                    HtmlTag.BR.name)) {
0523:                                                // Add a br
0524:                                                Element parent = ((MarkupDesignBean) bean)
0525:                                                        .getElement();
0526:                                                //                                        webform.getDocument().createBean(org.netbeans.modules.visualweb.xhtml.Br.class.getName(), parent, null);
0527:                                                createBean(
0528:                                                        org.netbeans.modules.visualweb.xhtml.Br.class
0529:                                                                .getName(),
0530:                                                        parent, null, lunit);
0531:                                            }
0532:                                        }
0533:                                    }
0534:                                }
0535:                            } else {
0536:                                assert mode == 0; // grid
0537:                                //                        CssLookup.setLocalStyleValue(body, XhtmlCss.RAVELAYOUT_INDEX,
0538:                                //                            CssConstants.CSS_GRID_VALUE);
0539:                                Util.addLocalStyleValueForElement(body,
0540:                                        XhtmlCss.RAVELAYOUT_INDEX, CssProvider
0541:                                                .getValueService()
0542:                                                .getGridValue());
0543:                            }
0544:                        } finally {
0545:                            facesModel.writeUnlock(event);
0546:                        }
0547:                    }
0548:
0549:                    this .layoutMode = mode;
0550:                }
0551:
0552:                // XXX Copy from designer/Document.
0553:                private static DesignBean createBean(String className,
0554:                        Node parent, Node before, LiveUnit liveUnit) {
0555:                    MarkupPosition pos = new MarkupPosition(parent, before);
0556:                    DesignBean parentBean = /*FacesSupport.*/Util
0557:                            .findParentBean(parent);
0558:                    //            LiveUnit unit = webform.getModel().getLiveUnit();
0559:                    DesignBean bean = liveUnit.createBean(className,
0560:                            parentBean, pos);
0561:
0562:                    return bean;
0563:                }
0564:
0565:            } // End of LauoutProperty.
0566:
0567:            /**
0568:             * Property editor for editing the "pagelayout" property of a document
0569:             */
0570:            private static class PageLayoutEditor extends PropertyEditorSupport {
0571:                private String[] tags = new String[] {
0572:                        NbBundle.getMessage(DesignBeanNodeHelper.class,
0573:                                "LBL_GridLayout"), // NOI18N
0574:                        NbBundle.getMessage(DesignBeanNodeHelper.class,
0575:                                "LBL_FlowLayout") // NOI18N
0576:                };
0577:
0578:                public String getJavaInitializationString() {
0579:                    return getAsText();
0580:                }
0581:
0582:                public String getAsText() {
0583:                    int val = ((Integer) getValue()).intValue();
0584:
0585:                    return (val == 0) ? tags[0] : tags[1];
0586:                }
0587:
0588:                public void setAsText(String text)
0589:                        throws java.lang.IllegalArgumentException {
0590:                    if (text.equals(tags[0])) {
0591:                        setValue(new Integer(0));
0592:                    } else if (text.equals(tags[1])) {
0593:                        setValue(new Integer(1));
0594:                    } else {
0595:                        throw new java.lang.IllegalArgumentException(text);
0596:                    }
0597:                }
0598:
0599:                public String[] getTags() {
0600:                    return tags;
0601:                }
0602:            } // End of PageLayoutEditor.
0603:
0604:            private static class StyleSheetProperty extends
0605:                    PropertySupport.ReadWrite {
0606:                private final DesignBean designBean;
0607:                private String styleSheet;
0608:
0609:                public StyleSheetProperty(DesignBean desingBean) {
0610:                    super ("styleSheet", // NOI18n
0611:                            String.class, NbBundle.getMessage(
0612:                                    DesignBeanNodeHelper.class,
0613:                                    "LBL_StyleSheet"), NbBundle.getMessage(
0614:                                    DesignBeanNodeHelper.class,
0615:                                    "DESC_StyleSheet"));
0616:                    this .designBean = desingBean;
0617:                    DesignContext designContext = designBean.getDesignContext();
0618:                    FacesModel facesModel = findFacesModel(designBean);
0619:                    FileObject fileObject = facesModel == null ? null
0620:                            : facesModel.getFile();
0621:                    if ((designContext != null) || (fileObject != null)) {
0622:                        setValue(StandardUrlPropertyEditor.PROPERTY_PROPERTY,
0623:                                this );
0624:                        if (designContext == null) {
0625:                            setValue(
0626:                                    StandardUrlPropertyEditor.PROPERTY_FORM_FILE,
0627:                                    fileObject);
0628:                        } else {
0629:                            setValue(
0630:                                    StandardUrlPropertyEditor.PROPERTY_LIVE_CONTEXT,
0631:                                    designContext);
0632:                        }
0633:                    }
0634:                }
0635:
0636:                public PropertyEditor getPropertyEditor() {
0637:                    if (this .designBean.getInstance() instanceof  UIViewRoot) {
0638:                        StandardUrlPropertyEditor editor = new StandardUrlPropertyEditor();
0639:                        return editor;
0640:                    }
0641:                    return super .getPropertyEditor();
0642:                }
0643:
0644:                public Object getValue() {
0645:                    if (styleSheet == null) {
0646:                        styleSheet = getStyleSheetURL();
0647:                    }
0648:
0649:                    return styleSheet;
0650:                }
0651:
0652:                public void setValue(Object value)
0653:                        throws IllegalArgumentException {
0654:                    validateValue(value, String.class);
0655:                    styleSheet = (String) value;
0656:
0657:                    FacesModel facesModel = findFacesModel(designBean);
0658:                    if (facesModel == null) {
0659:                        return;
0660:                    }
0661:
0662:                    if (styleSheet == null) {
0663:                        styleSheet = ""; // NOI18N
0664:                    }
0665:
0666:                    String description = null; // TODO
0667:                    UndoEvent event = facesModel.writeLock(description);
0668:                    try {
0669:                        setStyleSheetURL(styleSheet);
0670:
0671:                        // The value shown in the propertysheet is shown by immediately
0672:                        // calling getStyleSheet() after setStyleSheet(), and at this point we haven't
0673:                        // re-rendered the document (it's delayed by DomSynchronizer) so
0674:                        // just use the expected value directly.
0675:                        this .styleSheet = styleSheet;
0676:                    } finally {
0677:                        facesModel.writeUnlock(event);
0678:                    }
0679:
0680:                    // Apparently we don't need to refresh the styles, the CSS engine
0681:                    // listens to the DOM
0682:                    this .styleSheet = styleSheet;
0683:                }
0684:
0685:                private String getStyleSheetURL() {
0686:                    FacesModel facesModel = findFacesModel(designBean);
0687:                    if (facesModel == null) {
0688:                        return ""; // NOI18N
0689:                    }
0690:
0691:                    //            RaveDocument document = webform.getDom();
0692:                    Document document = facesModel.getJspDom();
0693:                    //            MarkupUnit markup = webform.getMarkup();
0694:                    MarkupUnit markup = facesModel.getMarkupUnit();
0695:                    //            Element root = document.getRoot();
0696:                    Node root = facesModel.getHtmlDomFragment();
0697:                    if (root == null) {
0698:                        return ""; // NOI18N
0699:                    }
0700:
0701:                    // XXX is there a way to get ensureElement to NOT create?
0702:                    Element html = markup.findHtmlTag(root);
0703:
0704:                    if (html == null) {
0705:                        return "";
0706:                    }
0707:
0708:                    Element head = Util.findChild(HtmlTag.HEAD.name, html,
0709:                            false);
0710:
0711:                    if (head == null) {
0712:                        return "";
0713:                    }
0714:
0715:                    NodeList list = head.getChildNodes();
0716:                    int len = list.getLength();
0717:
0718:                    for (int i = 0; i < len; i++) {
0719:                        org.w3c.dom.Node child = list.item(i);
0720:
0721:                        if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
0722:                            Element element = (Element) child;
0723:
0724:                            if (element.getTagName().equals(HtmlTag.LINK.name)) {
0725:                                //                        RaveElement xlink = (RaveElement)element;
0726:
0727:                                //                        if (xlink.isRendered() && (xlink.getSource() == null)) {
0728:                                //                        if (MarkupService.isRenderedNode(element) && MarkupService.getSourceNodeForNode(element) == null) {
0729:                                // It is the rendered node (got from #getHtmlDomFragment).
0730:                                if (MarkupService.getSourceNodeForNode(element) == null) {
0731:                                    // Don't return "derived" links such as theme links
0732:                                    // automatically rendered for themes for example
0733:                                    continue;
0734:                                }
0735:
0736:                                String url = element
0737:                                        .getAttribute(HtmlAttribute.HREF);
0738:
0739:                                if (url != null) {
0740:                                    return url;
0741:                                }
0742:                            }
0743:                        }
0744:                    }
0745:
0746:                    return ""; // NOI18N
0747:                }
0748:
0749:                private void setStyleSheetURL(String url) {
0750:                    // See if we have a Braveheart Link component. If so, just change its
0751:                    // url.
0752:                    boolean add = (url != null) && (url.length() > 0);
0753:
0754:                    FacesModel facesModel = findFacesModel(designBean);
0755:                    if (facesModel == null) {
0756:                        return;
0757:                    }
0758:
0759:                    //            MarkupUnit markup = webform.getMarkup();
0760:                    MarkupUnit markup = facesModel.getMarkupUnit();
0761:                    //            RaveDocument document = webform.getDom();
0762:                    Document document = facesModel.getJspDom();
0763:                    //            LiveUnit lu = webform.getModel().getLiveUnit();
0764:                    LiveUnit lu = facesModel.getLiveUnit();
0765:
0766:                    DataObject markupDO;
0767:                    try {
0768:                        markupDO = DataObject.find(facesModel.getMarkupFile());
0769:                    } catch (DataObjectNotFoundException ex) {
0770:                        ErrorManager.getDefault().notify(
0771:                                ErrorManager.INFORMATIONAL, ex);
0772:                        return;
0773:                    }
0774:
0775:                    DesignBean uihead = null;
0776:                    //            if (DesignerUtils.isBraveheartPage(document)) {
0777:                    if (InSyncServiceProvider.get().isBraveheartPage(document)) {
0778:                        DesignBean[] heads = lu
0779:                                .getBeansOfType(com.sun.rave.web.ui.component.Head.class);
0780:
0781:                        if ((heads != null) && (heads.length > 0)) {
0782:                            uihead = heads[0];
0783:                        }
0784:                    } else if (InSyncServiceProvider.get().isWoodstockPage(
0785:                            document)) {
0786:                        DesignBean[] heads = lu
0787:                                .getBeansOfType(com.sun.webui.jsf.component.Head.class);
0788:
0789:                        if ((heads != null) && (heads.length > 0)) {
0790:                            uihead = heads[0];
0791:                        }
0792:                    }
0793:
0794:                    if (uihead != null) {
0795:                        // Find existing eligible links
0796:                        for (int i = 0, n = uihead.getChildBeanCount(); i < n; i++) {
0797:                            DesignBean child = uihead.getChildBean(i);
0798:
0799:                            if (child.getInstance() instanceof  com.sun.rave.web.ui.component.Link) {
0800:                                // Ensure that this is a stylesheet link
0801:                                String rel = (String) child.getProperty("rel")
0802:                                        .getValue(); // NOI18N
0803:
0804:                                if ((rel != null) && (rel.length() > 0)
0805:                                        && !rel.equalsIgnoreCase("stylesheet")) { // NOI18N
0806:
0807:                                    continue;
0808:                                }
0809:
0810:                                // Use this one
0811:                                if (add) {
0812:                                    child.getProperty("url").setValue(url); // NOI18N
0813:                                    //                            webform.getActions().refresh(false);
0814:                                    //                            DesignerServiceHack.getDefault().refresh(null, markupDO, false);
0815:                                    //                            DesignerServiceHack.getDefault().refreshDataObject(markupDO, false);
0816:                                    fireRefreshNeeded(false);
0817:
0818:                                    return;
0819:                                } else {
0820:                                    lu.deleteBean(child);
0821:                                    //                            webform.getActions().refresh(false);
0822:                                    //                            DesignerServiceHack.getDefault().refresh(null, markupDO, false);
0823:                                    //                            DesignerServiceHack.getDefault().refreshDataObject(markupDO, false);
0824:                                    fireRefreshNeeded(false);
0825:
0826:                                    return;
0827:                                }
0828:                            }
0829:                        }
0830:
0831:                        // No stylesheet link exists - add one
0832:                        //                DesignBean link = lu.createBean("com.sun.rave.web.ui.component.Link", uihead, new Position()); // NOI18N
0833:
0834:                        DesignBean link;
0835:                        if (InSyncServiceProvider.get().isBraveheartPage(
0836:                                document)) {
0837:                            link = lu.createBean(
0838:                                    com.sun.rave.web.ui.component.Link.class
0839:                                            .getName(), uihead, new Position());
0840:                        } else if (InSyncServiceProvider.get().isWoodstockPage(
0841:                                document)) {
0842:                            link = lu.createBean(
0843:                                    com.sun.webui.jsf.component.Link.class
0844:                                            .getName(), uihead, new Position());
0845:                        } else {
0846:                            // XXX Log?
0847:                            link = null;
0848:                        }
0849:
0850:                        if (link != null) {
0851:                            link.getProperty("rel").setValue("stylesheet"); // NOI18N
0852:                            link.getProperty("type").setValue("text/css"); // NOI18N
0853:                            link.getProperty("url").setValue(url); // NOI18N
0854:                            //                    webform.getActions().refresh(false);
0855:                            //                    DesignerServiceHack.getDefault().refresh(null, markupDO, false);
0856:                            //                    DesignerServiceHack.getDefault().refreshDataObject(markupDO, false);
0857:                            fireRefreshNeeded(false);
0858:                        }
0859:                    } else {
0860:                        Element root = document.getDocumentElement();
0861:                        Element html = markup.findHtmlTag(root);
0862:
0863:                        if (html == null) { // We're hosed!!! This shouldn't happen
0864:                            Thread.dumpStack();
0865:
0866:                            return;
0867:                        }
0868:
0869:                        // Gotta replace with HtmlTag.LINK.name
0870:                        Element head = Util.findChild(HtmlTag.HEAD.name, html,
0871:                                true);
0872:                        Element link = Util.findChild(HtmlTag.LINK.name, head,
0873:                                false);
0874:
0875:                        // XXX should iterate over ALL the links until you find one
0876:                        // that has rel="stylesheet" !!
0877:                        if ((url != null) && (url.length() > 0)) {
0878:                            // Add stylesheet reference
0879:                            if (link == null) {
0880:                                // XXX Shouldn't I be using beans2 here?? plus accquiring a writelock?
0881:                                // No stylesheet link exists - add one
0882:                                link = document
0883:                                        .createElement(HtmlTag.LINK.name);
0884:                                link.setAttribute(HtmlAttribute.REL,
0885:                                        "stylesheet");
0886:                                link.setAttribute(HtmlAttribute.TYPE,
0887:                                        "text/css");
0888:                                link.setAttribute(HtmlAttribute.HREF, url);
0889:                                head.appendChild(link);
0890:                            } else {
0891:                                // Existing stylesheet - just change it
0892:                                link.setAttribute(HtmlAttribute.HREF, url);
0893:                            }
0894:                        } else if (link != null) {
0895:                            // Remove stylesheet reference
0896:                            head.removeChild(link);
0897:                        }
0898:
0899:                        //                webform.getActions().refresh(true);
0900:                        //                DesignerServiceHack.getDefault().refresh(null, markupDO, true);
0901:                        //                DesignerServiceHack.getDefault().refreshDataObject(markupDO, true);
0902:                        fireRefreshNeeded(true);
0903:                    }
0904:                }
0905:
0906:                private void fireRefreshNeeded(boolean deep) {
0907:                    FacesModel facesModel = findFacesModel(designBean);
0908:                    if (facesModel != null) {
0909:                        // XXX FacesModel should be able to fire events itself.
0910:                        //                facesModel.getDnDSupport().fireRefreshNeeded(deep);
0911:                        facesModel.getJsfSupport().refresh(deep);
0912:                    }
0913:                }
0914:
0915:                public boolean supportsDefaultValue() {
0916:                    return true;
0917:                }
0918:
0919:                public void restoreDefaultValue() {
0920:                    setValue(null);
0921:                }
0922:            } // End of StyleSheetProperty.
0923:
0924:            private static class TitleProperty extends
0925:                    PropertySupport.ReadWrite {
0926:                private final DesignBean designBean;
0927:                private String title;
0928:
0929:                public TitleProperty(DesignBean desingBean) {
0930:                    super (
0931:                            "title", // NOI18n
0932:                            String.class, NbBundle.getMessage(
0933:                                    DesignBeanNodeHelper.class, "LBL_Title"),
0934:                            NbBundle.getMessage(DesignBeanNodeHelper.class,
0935:                                    "DESC_Title"));
0936:                    this .designBean = desingBean;
0937:                }
0938:
0939:                public Object getValue() {
0940:                    if (title == null) {
0941:                        Element titleElem = findTitle();
0942:
0943:                        if (titleElem != null) {
0944:                            title = MarkupUnit.getElementText(titleElem);
0945:                        }
0946:
0947:                        if (title == null) {
0948:                            title = ""; // NOI18N
0949:                        } else {
0950:                            // Swing labels like to interpret String that start with <html>
0951:                            // as actual HTML to be rendered. That happens for some weird
0952:                            // titles (like the one in 6316218) - so prevent this scenario
0953:                            if (title.startsWith("<html>")) { // NOI18N
0954:                                title = " " + title;
0955:                            }
0956:                        }
0957:                    }
0958:
0959:                    return title;
0960:                }
0961:
0962:                public void setValue(Object value)
0963:                        throws IllegalArgumentException {
0964:                    validateValue(value, String.class);
0965:                    String title = (String) value;
0966:
0967:                    Element head = findHead();
0968:
0969:                    if (head != null) {
0970:                        //                RaveElement h = (RaveElement)head;
0971:
0972:                        //                if (h.isRendered() && (h.getDesignBean() != null)) {
0973:                        // It is the rendered node.
0974:                        //                if (MarkupService.isRenderedNode(head)) {
0975:                        //                    MarkupDesignBean b = h.getDesignBean();
0976:                        com.sun.rave.designtime.markup.MarkupDesignBean b = InSyncServiceProvider
0977:                                .get().getMarkupDesignBeanForElement(head);
0978:                        if (b != null) {
0979:                            DesignProperty prop = b.getProperty("title"); // NOI18N
0980:
0981:                            if (prop != null) {
0982:                                prop.setValue(title);
0983:
0984:                                // The value shown in the propertysheet is shown by immediately
0985:                                // calling getTitle() after setTitle(), and at this point we haven't
0986:                                // re-rendered the document (it's delayed by DomSynchronizer) so
0987:                                // just use the expected value directly.
0988:                                this .title = title;
0989:
0990:                                return;
0991:                            }
0992:                        }
0993:                        //                }
0994:                    }
0995:
0996:                    FacesModel facesModel = findFacesModel(designBean);
0997:                    if (facesModel == null) {
0998:                        return;
0999:                    }
1000:                    Document doc = facesModel.getJspDom();
1001:                    String description = null; // TODO
1002:                    UndoEvent event = facesModel.writeLock(description);
1003:                    try {
1004:                        head = MarkupUnit.ensureElement(doc
1005:                                .getDocumentElement(), HtmlTag.HEAD.name, null);
1006:
1007:                        //Element head = MarkupUnit.getFirstDescendantElement(doc.getDocumentElement(), "head");
1008:                        Element titleElem = MarkupUnit.ensureElement(head,
1009:                                HtmlTag.TITLE.name, null);
1010:                        MarkupUnit.setElementText(titleElem, title);
1011:                    } finally {
1012:                        facesModel.writeUnlock(event);
1013:                    }
1014:
1015:                    this .title = title;
1016:                }
1017:
1018:                public boolean supportsDefaultValue() {
1019:                    return true;
1020:                }
1021:
1022:                public void restoreDefaultValue() {
1023:                    setValue(null);
1024:                }
1025:
1026:                private Element findHead() {
1027:                    FacesModel facesModel = findFacesModel(designBean);
1028:                    if (facesModel == null) {
1029:                        return null;
1030:                    }
1031:
1032:                    //            Document doc = facesModel.getMarkupUnit().getSourceDom();
1033:                    //            Element head =
1034:                    //                MarkupUnit.getFirstDescendantElement(((RaveDocument)doc).getRoot(), HtmlTag.HEAD.name);
1035:                    Node root = facesModel.getHtmlDomFragment();
1036:                    if (root == null) {
1037:                        return null;
1038:                    }
1039:                    MarkupUnit markup = facesModel.getMarkupUnit();
1040:                    Element html = markup.findHtmlTag(root);
1041:                    if (html == null) {
1042:                        return null;
1043:                    }
1044:
1045:                    return MarkupUnit.getFirstDescendantElement(html,
1046:                            HtmlTag.HEAD.name);
1047:                }
1048:
1049:                private Element findTitle() {
1050:                    Element head = findHead();
1051:
1052:                    if (head != null) {
1053:                        Element titleElem = MarkupUnit
1054:                                .getFirstDescendantElement(head,
1055:                                        HtmlTag.TITLE.name);
1056:
1057:                        if (titleElem != null) {
1058:                            return titleElem;
1059:                        }
1060:                    }
1061:
1062:                    return null;
1063:                }
1064:            } // End of TitleProperty.
1065:
1066:            private static class EncodingProperty extends
1067:                    PropertySupport.ReadWrite {
1068:                private final DesignBean designBean;
1069:
1070:                public EncodingProperty(DesignBean desingBean) {
1071:                    super (
1072:                            "encoding", // NOI18n
1073:                            String.class,
1074:                            NbBundle.getMessage(DesignBeanNodeHelper.class,
1075:                                    "LBL_Encoding"), NbBundle
1076:                                    .getMessage(DesignBeanNodeHelper.class,
1077:                                            "DESC_Encoding"));
1078:                    this .designBean = desingBean;
1079:                }
1080:
1081:                public Object getValue() {
1082:                    FacesModel facesModel = findFacesModel(designBean);
1083:                    if (facesModel == null) {
1084:                        return null;
1085:                    }
1086:                    if (facesModel.getFacesUnit() != null) {
1087:                        return facesModel.getFacesUnit().getEncoding();
1088:                    } else {
1089:                        return null;
1090:                    }
1091:                }
1092:
1093:                public void setValue(Object value)
1094:                        throws IllegalArgumentException {
1095:                    validateValue(value, String.class);
1096:                    String encoding = (String) value;
1097:
1098:                    FacesModel facesModel = findFacesModel(designBean);
1099:                    if (facesModel == null) {
1100:                        return;
1101:                    }
1102:                    if (facesModel.getFacesUnit() != null) {
1103:                        String description = null; // TODO
1104:                        UndoEvent event = facesModel.writeLock(description);
1105:                        try {
1106:                            facesModel.getFacesUnit().setEncoding(encoding);
1107:                        } finally {
1108:                            facesModel.writeUnlock(event);
1109:                        }
1110:                    }
1111:                }
1112:
1113:                public boolean supportsDefaultValue() {
1114:                    return true;
1115:                }
1116:
1117:                public void restoreDefaultValue() {
1118:                    setValue(null);
1119:                }
1120:            } // End of EncodingProperty.
1121:
1122:            private static class LanguageProperty extends
1123:                    PropertySupport.ReadWrite {
1124:                private final DesignBean designBean;
1125:
1126:                public LanguageProperty(DesignBean desingBean) {
1127:                    super (
1128:                            "language", // NOI18n
1129:                            String.class,
1130:                            NbBundle.getMessage(DesignBeanNodeHelper.class,
1131:                                    "LBL_Language"), NbBundle
1132:                                    .getMessage(DesignBeanNodeHelper.class,
1133:                                            "DESC_Language"));
1134:                    this .designBean = desingBean;
1135:
1136:                    // EATTODO: Take the setting of property editor out until I can get someone to help me
1137:                    // liveProperty not getting set on this editor.  I assume its due to this not being a DesignProperty :)
1138:                    // Never the less, I want a solution, maybe I do one where the property editor can work with no liveProperty
1139:                    //            p.setPropertyEditorClass(com.sun.jsfcl.std.property.SingleChoiceReferenceDataPropertyEditor.class);
1140:                    //            setValue(ChooseOneReferenceDataPropertyEditor.REFERENCE_DATA_NAME,
1141:                    //                ReferenceDataManager.LANGUAGE_CODES);
1142:                }
1143:
1144:                public Object getValue() {
1145:                    FacesModel facesModel = findFacesModel(designBean);
1146:                    if (facesModel == null) {
1147:                        return ""; // NOI18N
1148:                    }
1149:                    Document doc = facesModel.getJspDom();
1150:
1151:                    if (InSyncServiceProvider.get().isBraveheartPage(doc)
1152:                            || InSyncServiceProvider.get().isWoodstockPage(doc)) {
1153:                        DesignProperty property = findLanguageProperty();
1154:
1155:                        if (property != null) {
1156:                            String lang = property.getValueSource();
1157:
1158:                            if (lang != null) {
1159:                                return lang;
1160:                            }
1161:                        }
1162:
1163:                        // Just return empty string
1164:                    } else {
1165:                        Element html = MarkupUnit.getFirstDescendantElement(doc
1166:                                .getDocumentElement(), HtmlTag.HTML.name);
1167:
1168:                        if (html != null) {
1169:                            return html.getAttribute(HtmlAttribute.LANG);
1170:                        }
1171:                    }
1172:
1173:                    return ""; // NOI18N
1174:                }
1175:
1176:                public void setValue(Object value)
1177:                        throws IllegalArgumentException {
1178:                    validateValue(value, String.class);
1179:                    String language = (String) value;
1180:
1181:                    FacesModel facesModel = findFacesModel(designBean);
1182:                    if (facesModel == null) {
1183:                        return;
1184:                    }
1185:                    Document doc = facesModel.getJspDom();
1186:                    if (InSyncServiceProvider.get().isBraveheartPage(doc)
1187:                            || InSyncServiceProvider.get().isWoodstockPage(doc)) {
1188:                        DesignProperty property = findLanguageProperty();
1189:
1190:                        if (property != null) {
1191:                            property.setValue(language);
1192:                        }
1193:                    } else {
1194:                        if ((language == null)
1195:                                && (facesModel.getFacesUnit() != null)) {
1196:                            language = facesModel.getFacesUnit()
1197:                                    .getDefaultLanguage();
1198:                        }
1199:
1200:                        String description = null; // TODO
1201:                        UndoEvent event = facesModel.writeLock(description);
1202:                        try {
1203:
1204:                            Element html = MarkupUnit
1205:                                    .getFirstDescendantElement(doc
1206:                                            .getDocumentElement(),
1207:                                            HtmlTag.HTML.name);
1208:
1209:                            if (html != null) {
1210:                                MarkupUnit pgunit = facesModel.getMarkupUnit();
1211:                                pgunit.ensureAttributeValue(html,
1212:                                        HtmlAttribute.LANG, language);
1213:                                pgunit.ensureAttributeValue(html, "xml:lang",
1214:                                        language);
1215:                            }
1216:                        } finally {
1217:                            facesModel.writeUnlock(event);
1218:                        }
1219:                    }
1220:                }
1221:
1222:                public boolean supportsDefaultValue() {
1223:                    return true;
1224:                }
1225:
1226:                public void restoreDefaultValue() {
1227:                    setValue(null);
1228:                }
1229:
1230:                private DesignProperty findLanguageProperty() {
1231:                    //            assert !webform.isPortlet();
1232:                    //            assert !webform.isFragment();
1233:
1234:                    //            RaveElement body = webform.getBody();
1235:                    FacesModel facesModel = findFacesModel(designBean);
1236:                    if (facesModel == null) {
1237:                        return null; // NOI18N
1238:                    }
1239:
1240:                    Element body = facesModel.getHtmlBody();
1241:
1242:                    if (body == null) {
1243:                        return null;
1244:                    }
1245:
1246:                    //            DesignBean bodyBean = body.getDesignBean();
1247:                    DesignBean bodyBean = InSyncServiceProvider.get()
1248:                            .getMarkupDesignBeanForElement(body);
1249:                    DesignBean parent = bodyBean.getBeanParent();
1250:
1251:                    if (parent != null) {
1252:                        // TODO - check if this is really an Html component?
1253:                        // It doesn't really matter... if it has a "lang" property we'll
1254:                        // be happy with third party containers too!
1255:                        DesignProperty property = parent.getProperty("lang"); // NOI18N
1256:
1257:                        return property;
1258:                    }
1259:
1260:                    return null;
1261:                }
1262:
1263:            } // End of LanguageProperty.
1264:
1265:            private static class WidthProperty extends
1266:                    PropertySupport.ReadWrite {
1267:                private final DesignBean designBean;
1268:
1269:                public WidthProperty(DesignBean desingBean) {
1270:                    super (
1271:                            "width", // NOI18N
1272:                            String.class, NbBundle.getMessage(
1273:                                    DesignBeanNodeHelper.class, "LBL_Width"),
1274:                            NbBundle.getMessage(DesignBeanNodeHelper.class,
1275:                                    "DESC_Width"));
1276:                    this .designBean = desingBean;
1277:                }
1278:
1279:                public Object getValue() {
1280:                    return getSize(designBean, XhtmlCss.WIDTH_INDEX);
1281:                }
1282:
1283:                public void setValue(Object value)
1284:                        throws IllegalArgumentException {
1285:                    validateValue(value, String.class);
1286:                    String size = (String) value;
1287:                    setSize(designBean, XhtmlCss.WIDTH_INDEX, size);
1288:                }
1289:
1290:                public boolean supportsDefaultValue() {
1291:                    return true;
1292:                }
1293:
1294:                public void restoreDefaultValue() {
1295:                    setValue(null);
1296:                }
1297:            } // End of WidthProperty.
1298:
1299:            private static class HeightProperty extends
1300:                    PropertySupport.ReadWrite {
1301:                private final DesignBean designBean;
1302:
1303:                public HeightProperty(DesignBean desingBean) {
1304:                    super (
1305:                            "height", // NOI18N
1306:                            String.class, NbBundle.getMessage(
1307:                                    DesignBeanNodeHelper.class, "LBL_Height"),
1308:                            NbBundle.getMessage(DesignBeanNodeHelper.class,
1309:                                    "DESC_Height"));
1310:                    this .designBean = desingBean;
1311:                }
1312:
1313:                public Object getValue() {
1314:                    return getSize(designBean, XhtmlCss.HEIGHT_INDEX);
1315:                }
1316:
1317:                public void setValue(Object value)
1318:                        throws IllegalArgumentException {
1319:                    validateValue(value, String.class);
1320:                    String size = (String) value;
1321:                    setSize(designBean, XhtmlCss.HEIGHT_INDEX, size);
1322:                }
1323:
1324:                public boolean supportsDefaultValue() {
1325:                    return true;
1326:                }
1327:
1328:                public void restoreDefaultValue() {
1329:                    setValue(null);
1330:                }
1331:            } // End of HeightProperty.
1332:
1333:            private static void validateValue(Object value, Class type)
1334:                    throws IllegalArgumentException {
1335:                if (value != null && !type.isAssignableFrom(value.getClass())) {
1336:                    throw new IllegalArgumentException("Value is not of "
1337:                            + type + ", value class=" + value.getClass()); // NOI18N
1338:                }
1339:            }
1340:
1341:            private static FacesModel findFacesModel(DesignBean designBean) {
1342:                DesignContext designContext = designBean.getDesignContext();
1343:                if (!(designContext instanceof  LiveUnit)) {
1344:                    return null;
1345:                }
1346:                return ((LiveUnit) designContext).getModel();
1347:            }
1348:
1349:            private static void setSize(DesignBean designBean, int property,
1350:                    String size) {
1351:                FacesModel facesModel = findFacesModel(designBean);
1352:                if (facesModel == null) {
1353:                    return;
1354:                }
1355:
1356:                Element body = facesModel.getHtmlBody();
1357:                if (body == null) {
1358:                    return;
1359:                }
1360:
1361:                UndoEvent undoEvent = facesModel.writeLock(NbBundle.getMessage(
1362:                        DesignBeanNodeHelper.class, "LBL_SetSize")); // NOI18N
1363:                try {
1364:                    if (size != null) {
1365:                        size = size.trim();
1366:                    }
1367:
1368:                    //            if ((size == null) || (size.length() == 0) || CssConstants.CSS_AUTO_VALUE.equals(size)) {
1369:                    if (size == null || size.length() == 0
1370:                            || CssProvider.getValueService().isAutoValue(size)) {
1371:                        //                CssLookup.removeLocalStyleValue(body, property);
1372:                        Util.removeLocalStyleValueForElement(body, property);
1373:                    } else {
1374:                        //                if (XhtmlCssEngine.hasNoUnits(size)) {
1375:                        if (CssProvider.getValueService().hasNoUnits(size)) {
1376:                            size = size + "px"; // NOI18N
1377:                        }
1378:
1379:                        //                CssLookup.setLocalStyleValue(body, property, size);
1380:                        Util.addLocalStyleValueForElement(body, property, size);
1381:                    }
1382:                } finally {
1383:                    facesModel.writeUnlock(undoEvent);
1384:                }
1385:            }
1386:
1387:            private static String getSize(DesignBean designBean, int property) {
1388:                FacesModel facesModel = findFacesModel(designBean);
1389:                if (facesModel == null) {
1390:                    return ""; // NOI18N
1391:                }
1392:
1393:                Element body = facesModel.getHtmlBody();
1394:                if (body == null) {
1395:                    return ""; // NOI18N
1396:                }
1397:
1398:                if (body != null) {
1399:                    //            Value v = CssLookup.getValue(body, property);
1400:                    CssValue cssValue = CssProvider.getEngineService()
1401:                            .getComputedValueForElement(body, property);
1402:
1403:                    //            if ((v == null) || (v == CssValueConstants.AUTO_VALUE)) {
1404:                    if (cssValue == null
1405:                            || CssProvider.getValueService().isAutoValue(
1406:                                    cssValue)) {
1407:                        return ""; // NOI18N
1408:                    }
1409:
1410:                    //            if (v instanceof ComputedValue) {
1411:                    //                return ((ComputedValue)v).getCascadedValue().getCssText();
1412:                    //            }
1413:                    if (cssValue instanceof  CssComputedValue) {
1414:                        return ((CssComputedValue) cssValue).getCascadedValue()
1415:                                .getCssText();
1416:                    }
1417:
1418:                    //            return v.toString(); // Do I need to add in the percent?
1419:                    return cssValue.getCssText();
1420:                }
1421:
1422:                return ""; // NOI18N
1423:            }
1424:
1425:            /** XXX Moved from designer/DesignerUtils. */
1426:            private static char[] hexdigits = { '0', '1', '2', '3', '4', '5',
1427:                    '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
1428:
1429:            private static String colorToHex(Color c) {
1430:                if (c == null) {
1431:                    return null;
1432:                }
1433:
1434:                int r = c.getRed();
1435:                int g = c.getGreen();
1436:                int b = c.getBlue();
1437:
1438:                return "#" + hexdigits[(r & 0xF0) >> 4] + hexdigits[r & 0x0F]
1439:                        + hexdigits[(g & 0xF0) >> 4] + hexdigits[g & 0x0F]
1440:                        + hexdigits[(b & 0xF0) >> 4] + hexdigits[b & 0x0F];
1441:            }
1442:
1443:            private static boolean isPortlet(DesignBean designBean) {
1444:                DesignContext designContext = designBean.getDesignContext();
1445:                if (designContext instanceof  LiveUnit) {
1446:                    LiveUnit liveUnit = (LiveUnit) designContext;
1447:                    FileObject markupFile = liveUnit.getModel().getMarkupFile();
1448:                    if (markupFile != null
1449:                            && "jspf".equals(markupFile.getExt())) { // NOI18N
1450:                        return true;
1451:                    }
1452:                }
1453:                return false;
1454:            }
1455:
1456:            private static boolean isFragment(DesignBean designBean) {
1457:                DesignContext designContext = designBean.getDesignContext();
1458:                if (designContext instanceof  LiveUnit) {
1459:                    LiveUnit liveUnit = (LiveUnit) designContext;
1460:                    if (liveUnit.getModel().getFacesModelSet()
1461:                            .getFacesContainer().isPortletContainer()) {
1462:                        return true;
1463:                    }
1464:                }
1465:                return false;
1466:            }
1467:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.