001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.faces.dt.component.html;
042:
043: import com.sun.rave.designtime.markup.*;
044: import org.netbeans.modules.visualweb.faces.dt.HtmlDesignInfoBase;
045: import javax.faces.component.html.HtmlPanelGroup;
046: import org.w3c.dom.*;
047:
048: public class HtmlPanelGroupDesignInfo extends HtmlDesignInfoBase
049: implements MarkupDesignInfo {
050: public Class getBeanClass() {
051: return HtmlPanelGroup.class;
052: }
053:
054: public void customizeRender(MarkupDesignBean bean,
055: MarkupRenderContext renderContext) {
056: DocumentFragment documentFragment = renderContext
057: .getDocumentFragment();
058: MarkupPosition begin = renderContext.getBeginPosition();
059: MarkupPosition end = renderContext.getEndPosition();
060:
061: if (bean.isContainer() && bean.getChildBeanCount() > 0) {
062: return;
063: }
064: if (begin == end) { // table didn't render anything.... that's not right! Insert one? TODO
065: return;
066: }
067: assert begin.getUnderParent() == end.getUnderParent();
068: Node child = begin.getBeforeSibling();
069: Node stop = end.getBeforeSibling();
070: for (child = begin.getBeforeSibling(); child != stop; child = child
071: .getNextSibling()) {
072: if (child instanceof Element) {
073: Element e = (Element) child;
074: String style = e.getAttribute("style"); //NOI18N
075: if (style == null) {
076: style = ""; //NOI18N
077: }
078: // This is wrong because "font-height" will be a match for
079: // example
080: if (e.getChildNodes().getLength() == 0
081: && style.indexOf("position:") == -1) { // NOI18N
082: // An empty group panel in flow formatting context -- it will render
083: // to absolutely nothing visible, so put its bean name in here as a help
084: e.appendChild(e.getOwnerDocument().createTextNode(
085: bean.getInstanceName()));
086: e.setAttribute("class", "rave-uninitialized-text"); // NOI18N
087: break;
088: } else if (style.indexOf("width") < 0
089: || style.indexOf("height") < 0) { //NOI18N
090: StringBuffer sb = new StringBuffer(
091: style.length() + 30);
092: sb.append(style);
093: if (!style.endsWith(";")) { //NOI18N
094: sb.append(';');
095: }
096: // Set display: block - work around the fact that
097: // the group panel uses a <span> which of course
098: // is an inline tag and therefore ignores our width
099: // and height settings.
100: sb.append("display:block;"); // NOI18N
101: if (style.indexOf("width") < 0) { //NOI18N
102: sb.append(" width: 96px;"); //NOI18N
103: }
104: if (style.indexOf("height") < 0) { //NOI18N
105: sb.append(" height: 96px;"); //NOI18N
106: }
107: style = sb.toString();
108: e.setAttribute("style", style); //NOI18N
109: }
110: // Ensure that we show a border
111: e.setAttribute("class", "rave-design-border"); // NOI18N
112: break;
113: }
114: }
115: }
116:
117: }
|