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.xhtml;
042:
043: import org.w3c.dom.Document;
044: import org.w3c.dom.Element;
045: import org.w3c.dom.Node;
046:
047: import com.sun.rave.designtime.Customizer2;
048: import com.sun.rave.designtime.DesignBean;
049: import com.sun.rave.designtime.DesignEvent;
050: import com.sun.rave.designtime.DesignInfo;
051: import com.sun.rave.designtime.DesignProperty;
052: import com.sun.rave.designtime.DisplayAction;
053: import com.sun.rave.designtime.Result;
054: import com.sun.rave.designtime.markup.MarkupDesignBean;
055:
056: import javax.faces.component.UIComponent;
057:
058: /** DesignInfo ancestor for the various xhtml components
059: *
060: * @author Tor Norbye
061: */
062: public abstract class XhtmlDesignInfo implements DesignInfo {
063: public boolean acceptParent(DesignBean parentBean,
064: DesignBean childBean, Class childClass) {
065: // f: beans (such as F_Verbatim) can be dropped anywhere
066: Class clz = getBeanClass();
067: if (clz.getName().startsWith("F_")) {
068: return true;
069: }
070:
071: // Refuse drops into JSF components that renders their own children, such as
072: // grid panels -- you can't drop HTML components into these
073: if (parentBean != null) {
074: java.lang.Object o = parentBean.getInstance();
075:
076: if (o instanceof UIComponent) {
077: UIComponent uic = (UIComponent) o;
078: if (uic.getRendersChildren()) {
079: return false;
080: }
081: }
082: }
083:
084: return true;
085: }
086:
087: public boolean acceptChild(DesignBean parentBean,
088: DesignBean childBean, Class childClass) {
089: return true;
090: }
091:
092: public Result beanCreatedSetup(DesignBean bean) {
093: // Many tags are simply style tags that when inserted should
094: // have a sample string inside - for example <a> or <h1>.
095: // Children of this DesignInfo simply need to return a
096: // String instead of null and not override beanCreated
097: // to get this behavior.
098: String s = getText();
099:
100: if (s != null) {
101: try {
102: addTextChild(bean, getText());
103: } catch (Exception x) {
104: x.printStackTrace();
105: }
106: }
107:
108: return Result.SUCCESS;
109: }
110:
111: public Result beanPastedSetup(DesignBean bean) {
112: return Result.SUCCESS;
113: }
114:
115: public Result beanDeletedCleanup(DesignBean bean) {
116: return Result.SUCCESS;
117: }
118:
119: /**
120: * Override this method to return a string to have beanCreated create a single text node
121: * child of the element when inserted.
122: */
123: protected String getText() {
124: return null;
125: }
126:
127: public DisplayAction[] getContextItems(DesignBean bean) {
128: return DisplayAction.EMPTY_ARRAY;
129: }
130:
131: public boolean acceptLink(DesignBean targetBean,
132: DesignBean sourceBean, Class sourceClass) {
133: return false;
134: }
135:
136: public Result linkBeans(DesignBean targetBean, DesignBean sourceBean) {
137: return Result.SUCCESS;
138: }
139:
140: public void beanContextActivated(DesignBean bean) {
141: }
142:
143: public void beanContextDeactivated(DesignBean bean) {
144: }
145:
146: public void instanceNameChanged(DesignBean bean,
147: String oldInstanceName) {
148: }
149:
150: public void beanChanged(DesignBean bean) {
151: }
152:
153: public void propertyChanged(
154: com.sun.rave.designtime.DesignProperty prop,
155: java.lang.Object oldValue) {
156: }
157:
158: public void eventChanged(DesignEvent event) {
159: }
160:
161: // Utility methods
162:
163: /** Look up the element for a given bean */
164: protected Element getElement(DesignBean bean) {
165: if (bean instanceof MarkupDesignBean) {
166: MarkupDesignBean mlb = (MarkupDesignBean) bean;
167:
168: return mlb.getElement();
169: }
170:
171: return null;
172: }
173:
174: /** Add a text node child below the given tag's element */
175: protected void addTextChild(DesignBean bean, String text) {
176: // Don't look, Joe!
177: // I need to access the actual Elements created by the
178: // <h1>, so I can insert text inside of it
179: Element element = getElement(bean);
180:
181: if (element != null) {
182: addTextChild(element, text);
183: }
184: }
185:
186: protected void addTextChild(Element element, String text) {
187: Document doc = element.getOwnerDocument();
188: Node node;
189:
190: // XXX Commented out, seems to be a dummy code (see the next line).
191: // if (doc instanceof RaveDocument) {
192: // node = ((RaveDocument)doc).createJspxTextNode(text);
193: // } else {
194: // node = doc.createTextNode(text);
195: // }
196: node = doc.createTextNode(text);
197:
198: element.appendChild(node);
199: }
200: }
|