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.web.ui.dt.component;
042:
043: import com.sun.rave.designtime.DesignBean;
044: import com.sun.rave.designtime.DesignContext;
045: import com.sun.rave.designtime.DesignProject;
046: import com.sun.rave.designtime.DesignProperty;
047: import com.sun.rave.designtime.Result;
048: import com.sun.rave.designtime.faces.FacesDesignContext;
049: import com.sun.rave.designtime.faces.FacesDesignProject;
050: import com.sun.rave.web.ui.component.Breadcrumbs;
051: import com.sun.rave.web.ui.component.Hyperlink;
052: import com.sun.rave.web.ui.component.ImageHyperlink;
053: import com.sun.rave.web.ui.component.Page;
054: import org.netbeans.modules.visualweb.web.ui.dt.AbstractDesignInfo;
055: import java.net.URI;
056: import java.net.URISyntaxException;
057: import javax.faces.component.UIComponent;
058: import javax.faces.component.UIViewRoot;
059:
060: /**
061: * DesignInfo for the {@link org.netbeans.modules.visualweb.web.ui.dt.component.Breadcrumbs} component.
062: * The following behaviors are implemented:
063: * <ul>
064: * <li>Upon creation, populate breadcrumbs with two hyperlink components, one
065: * for the web application, and one for the current page
066: * ({@link org.netbeans.modules.visualweb.web.ui.dt.component.Hyperlink} is used, since that is
067: * the only hyperlink used by Creator).</li>
068: * </ul>
069: *
070: * @author gjmurphy
071: */
072: public class BreadcrumbsDesignInfo extends AbstractDesignInfo {
073:
074: public BreadcrumbsDesignInfo() {
075: super (Breadcrumbs.class);
076: }
077:
078: // For performance improvement. No need to get all the contexts in the project
079: private DesignContext[] getDesignContexts(DesignBean designBean) {
080: DesignProject designProject = designBean.getDesignContext()
081: .getProject();
082: DesignContext[] contexts;
083: if (designProject instanceof FacesDesignProject) {
084: contexts = ((FacesDesignProject) designProject)
085: .findDesignContexts(new String[] { "request",
086: "session", "application" });
087: } else {
088: contexts = new DesignContext[0];
089: }
090: DesignContext[] designContexts = new DesignContext[contexts.length + 1];
091: designContexts[0] = designBean.getDesignContext();
092: System.arraycopy(contexts, 0, designContexts, 1,
093: contexts.length);
094: return designContexts;
095: }
096:
097: public Result beanCreatedSetup(DesignBean bean) {
098: DesignContext context = bean.getDesignContext();
099: UIComponent component = (UIComponent) bean.getInstance();
100: if (context
101: .canCreateBean(Hyperlink.class.getName(), bean, null)) {
102: // Add an initial hyperlink for every page in the project
103: try {
104: DesignContext[] contexts = bean.getDesignContext()
105: .getProject().getDesignContexts();
106: //DesignContext[] contexts = getDesignContexts(bean);
107:
108: URI rootURI = context.getProject().getResourceFile(
109: new URI("./web")).toURI(); //NOI18N
110: for (int i = 0; i < contexts.length; i++) {
111: DesignBean rootBean = contexts[i]
112: .getRootContainer();
113: if (rootBean.getInstance() != null
114: && UIViewRoot.class
115: .isAssignableFrom(rootBean
116: .getInstance().getClass())
117: && rootBean.getChildBean(0).getInstance() instanceof Page) {
118: DesignBean hyperlinkBean = context.createBean(
119: Hyperlink.class.getName(), bean, null);
120: URI pageURI = new URI(contexts[i]
121: .resolveResource(
122: rootBean.getInstanceName()
123: + ".jsp").toString()); //NOI18N
124: URI relativeURI = rootURI.relativize(pageURI);
125: String contextRelativePath = "/faces/"
126: + relativeURI.toString();
127: hyperlinkBean.getProperty("url").setValue(
128: contextRelativePath); //NOI18N
129: hyperlinkBean.getProperty("text").setValue(
130: ((FacesDesignContext) contexts[i])
131: .getDisplayName()); //NOI18N
132: }
133: }
134: } catch (URISyntaxException e) {
135: e.printStackTrace();
136: }
137: }
138: return Result.SUCCESS;
139: }
140:
141: public boolean acceptChild(DesignBean parentBean,
142: DesignBean childBean, Class childClass) {
143: Class parentClass = parentBean.getInstance().getClass();
144: if (Hyperlink.class.equals(childClass)
145: || ImageHyperlink.class.equals(childClass))
146: return true;
147: return super .acceptChild(parentBean, childBean, childClass);
148: }
149:
150: protected DesignProperty getDefaultBindingProperty(
151: DesignBean targetBean) {
152: return targetBean.getProperty("pages"); //NOI18N
153: }
154:
155: }
|