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:
042: package org.netbeans.modules.visualweb.designer.jsf;
043:
044: import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectUtils;
045: import javax.faces.context.ExternalContext;
046: import javax.faces.context.FacesContext;
047:
048: import org.netbeans.api.project.Project;
049:
050: import org.netbeans.modules.visualweb.project.jsf.services.RefreshService;
051: import org.netbeans.modules.visualweb.insync.models.FacesModelSet;
052: import org.openide.ErrorManager;
053: import org.openide.filesystems.FileObject;
054: import org.openide.loaders.DataObject;
055: import org.openide.loaders.DataObjectNotFoundException;
056:
057: // XXX Copied from designer/RefreshServiceProvider.
058: /**
059: * Actual implementation of web/project's org.netbeans.modules.visualweb.jsf.project.services.RefreshService.
060: * Provides designer refresh service. This is not part of the general DesignerService
061: * API because web/project is in a different cluster which cannot access the rave
062: * modules - the dependency goes the other way.
063: *
064: * @author Tor Norbye (the original code)
065: * @author Peter Zavadsky (the new changes after the move)
066: */
067: public class RefreshServiceImpl extends RefreshService {
068: /** Creates a new instance of RefreshServiceProvider */
069: public RefreshServiceImpl() {
070: }
071:
072: public void refresh(Project project) {
073: // Purge cached theme info from design container
074: FacesModelSet fms = FacesModelSet.getInstance(project);
075:
076: if (fms != null) {
077: FacesContext context = fms.getFacesContainer()
078: .getFacesContext();
079: ExternalContext appContext = context.getExternalContext();
080:
081: if (JsfProjectUtils.JAVA_EE_5.equals(JsfProjectUtils
082: .getJ2eePlatformVersion(project))) {
083: // XXX Woodstock
084: appContext.getApplicationMap().remove(
085: com.sun.webui.theme.ThemeManager.THEME_MANAGER);
086:
087: //appContext.getInitParameterMap().put(ThemeFactory.DEFAULT_THEME, "defaulttheme");
088: appContext.getSessionMap().remove(
089: com.sun.webui.theme.Theme.THEME_ATTR);
090: } else {
091: appContext
092: .getApplicationMap()
093: .remove(
094: com.sun.rave.web.ui.theme.ThemeManager.THEME_MANAGER);
095:
096: //appContext.getInitParameterMap().put(ThemeFactory.DEFAULT_THEME, "defaulttheme");
097: appContext.getSessionMap().remove(
098: com.sun.rave.web.ui.theme.Theme.THEME_ATTR);
099: }
100: }
101:
102: // WebForm.refreshAll(project, false);
103: refreshProject(project, false);
104: }
105:
106: /** Refresh all forms in the project */
107: static void refreshProject(Project project, boolean deep) {
108: FileObject fobj = JsfProjectUtils.getDocumentRoot(project);
109: refreshFolder(fobj, deep);
110: }
111:
112: /** Refresh the given DataObject, if it's a webform */
113: private static void refreshDataObject(DataObject dobj, boolean deep) {
114: // if (hasWebFormForDataObject(dobj)) {
115: //// WebForm webform = WebForm.getWebFormForDataObject(WebForm.findDomProvider(dobj), dobj);
116: //// webform.getActions().refresh(deep);
117: //// WebForm webform = WebForm.findWebForm(dobj);
118: // // XXX Really get, not find only? Revise.
119: // WebForm webform = getWebFormForDataObject(dobj);
120: // if (webform != null) {
121: //// webform.refresh(deep);
122: // webform.refreshModel(deep);
123: // }
124: // }
125: JsfForm jsfForm = JsfForm.findJsfForm(dobj);
126: if (jsfForm != null) {
127: jsfForm.refreshModel(deep);
128: }
129: }
130:
131: private static void refreshFolder(FileObject folder, boolean deep) {
132: FileObject[] children = folder.getChildren();
133:
134: for (int i = 0; i < children.length; i++) {
135: FileObject fo = children[i];
136:
137: if (fo.isFolder()) {
138: refreshFolder(fo, deep);
139: } else {
140: try {
141: DataObject dobj = DataObject.find(fo);
142: // refresh(dobj, deep);
143: refreshDataObject(dobj, deep);
144: } catch (DataObjectNotFoundException ex) {
145: ErrorManager.getDefault().notify(
146: ErrorManager.INFORMATIONAL, ex);
147: }
148: }
149: }
150: }
151:
152: }
|