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.sql.project;
043:
044: import java.awt.Image;
045: import java.util.ArrayList;
046: import java.util.Collections;
047: import java.util.List;
048:
049: import org.netbeans.api.project.*;
050:
051: import org.openide.filesystems.FileObject;
052: import org.openide.loaders.DataFolder;
053: import org.openide.nodes.Children;
054: import org.openide.nodes.FilterNode;
055: import org.openide.nodes.Node;
056: import org.openide.util.NbBundle;
057: import org.openide.util.Utilities;
058:
059: import org.netbeans.spi.project.support.ant.AntProjectHelper;
060: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
061:
062: import org.netbeans.modules.sql.project.IcanproProject;
063: import org.netbeans.modules.sql.project.ui.PackageView; //import org.netbeans.modules.sql.project.ui.customizer.IcanproProjectProperties;
064: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
065: import org.openide.filesystems.FileChangeListener;
066:
067: public class IcanproViews {
068:
069: private IcanproViews() {
070: }
071:
072: static final class LogicalViewChildren extends Children.Keys
073: implements FileChangeListener {
074:
075: private static final String KEY_SOURCE_DIR = "srcDir"; // NOI18N
076: private static final String KEY_DOC_BASE = "docBase"; //NOI18N
077: private static final String KEY_EJBS = "ejbKey"; //NOI18N
078: private static final String WEBSERVICES_DIR = "webservicesDir"; // NOI18N
079: private static final String KEY_SETUP_DIR = "setupDir"; //NOI18N
080:
081: private AntProjectHelper helper;
082: private final PropertyEvaluator evaluator;
083: private FileObject projectDir;
084: private Project project;
085:
086: public LogicalViewChildren(AntProjectHelper helper,
087: PropertyEvaluator evaluator, Project project) {
088: assert helper != null;
089: this .helper = helper;
090: projectDir = helper.getProjectDirectory();
091: this .evaluator = evaluator;
092: this .project = project;
093: }
094:
095: protected void addNotify() {
096: super .addNotify();
097: projectDir.addFileChangeListener(this );
098: createNodes();
099: }
100:
101: private void createNodes() {
102: List l = new ArrayList();
103: /*
104: l.add(KEY_EJBS);
105: */
106:
107: DataFolder docBaseDir = getFolder(IcanproProjectProperties.META_INF);
108: if (docBaseDir != null) {
109: /*
110: l.add(KEY_DOC_BASE);
111: */
112: }
113:
114: DataFolder srcDir = getFolder(IcanproProjectProperties.SRC_DIR);
115: if (srcDir != null) {
116: l.add(KEY_SOURCE_DIR);
117: }
118:
119: FileObject setupFolder = getSetupFolder();
120: if (setupFolder != null && setupFolder.isFolder()) {
121: l.add(KEY_SETUP_DIR);
122: }
123: /*
124: l.add(WEBSERVICES_DIR);
125: */
126: setKeys(l);
127: }
128:
129: private FileObject getSetupFolder() {
130: return projectDir.getFileObject("setup"); //NOI18N
131: }
132:
133: protected void removeNotify() {
134: setKeys(Collections.EMPTY_SET);
135: projectDir.removeFileChangeListener(this );
136: super .removeNotify();
137: }
138:
139: protected Node[] createNodes(Object key) {
140: Node n = null;
141: if (key == KEY_SOURCE_DIR) {
142: FileObject srcRoot = helper.resolveFileObject(evaluator
143: .getProperty(IcanproProjectProperties.SRC_DIR));
144: Project p = FileOwnerQuery.getOwner(srcRoot);
145: Sources s = ProjectUtils.getSources(p);
146: SourceGroup sgs[] = ProjectUtils.getSources(p)
147: .getSourceGroups(
148: IcanproProject.SOURCES_TYPE_ICANPRO);
149: for (int i = 0; i < sgs.length; i++) {
150: if (sgs[i].contains(srcRoot)) {
151: n = PackageView.createPackageView(sgs[i]);
152: break;
153: }
154: }
155: /*
156: } else if (key == KEY_DOC_BASE) {
157: n = new DocBaseNode (getFolder(IcanproProjectProperties.META_INF).getNodeDelegate());
158: } else if (key == KEY_EJBS) {
159: FileObject srcRoot = helper.resolveFileObject(evaluator.getProperty (IcanproProjectProperties.SRC_DIR));
160: Project project = FileOwnerQuery.getOwner (srcRoot);
161: DDProvider provider = DDProvider.getDefault();
162: EjbJarImplementation jp = (EjbJarImplementation) project.getLookup().lookup(EjbJarImplementation.class);
163: org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = null;
164: try {
165: ejbJar = provider.getDDRoot(jp.getDeploymentDescriptor());
166: } catch (IOException ioe) {
167: ErrorManager.getDefault().notify(ioe);
168: }
169: ClassPathProvider cpp = (ClassPathProvider)
170: project.getLookup().lookup(ClassPathProvider.class);
171: assert cpp != null;
172: ClassPath classPath = cpp.findClassPath(srcRoot, ClassPath.SOURCE);
173: n = new EjbContainerNode(ejbJar, classPath);
174: //Node nws = new WebServicesNode(ejbJar, classPath);
175: return n == null ? new Node[0] : new Node[] {n};
176: } else if (key == WEBSERVICES_DIR){
177: FileObject srcRoot = helper.resolveFileObject(evaluator.getProperty (IcanproProjectProperties.SRC_DIR));
178: WebServicesView webServicesView = WebServicesView.getWebServicesView(srcRoot);
179: if(webServicesView != null)
180: {
181: n = webServicesView.createWebServicesView(srcRoot);
182: }
183: } else if (key == KEY_SETUP_DIR) {
184: try {
185: DataObject sdo = DataObject.find(getSetupFolder());
186: n = new ServerResourceNode(project); // sdo.getNodeDelegate());
187: } catch (org.openide.loaders.DataObjectNotFoundException dnfe) {}
188: */
189: }
190:
191: return n == null ? new Node[0] : new Node[] { n };
192: }
193:
194: private DataFolder getFolder(String propName) {
195: FileObject fo = helper.resolveFileObject(evaluator
196: .getProperty(propName));
197: if (fo != null) {
198: DataFolder df = DataFolder.findFolder(fo);
199: return df;
200: }
201: return null;
202: }
203:
204: // file change events in the project directory
205: public void fileAttributeChanged(
206: org.openide.filesystems.FileAttributeEvent fe) {
207: }
208:
209: public void fileChanged(org.openide.filesystems.FileEvent fe) {
210: }
211:
212: public void fileDataCreated(org.openide.filesystems.FileEvent fe) {
213: }
214:
215: public void fileDeleted(org.openide.filesystems.FileEvent fe) {
216: // setup folder deleted
217: createNodes();
218: }
219:
220: public void fileFolderCreated(
221: org.openide.filesystems.FileEvent fe) {
222: // setup folder could be created
223: createNodes();
224: }
225:
226: public void fileRenamed(
227: org.openide.filesystems.FileRenameEvent fe) {
228: // setup folder could be renamed
229: createNodes();
230: }
231: }
232:
233: private static final class DocBaseNode extends FilterNode {
234: private static Image CONFIGURATION_FILES_BADGE = Utilities
235: .loadImage(
236: "org/netbeans/modules/sql/project/ui/resources/docjar.gif",
237: true); // NOI18N
238:
239: DocBaseNode(Node orig) {
240: super (orig);
241: }
242:
243: public Image getIcon(int type) {
244: return computeIcon(false, type);
245: }
246:
247: public Image getOpenedIcon(int type) {
248: return computeIcon(true, type);
249: }
250:
251: private Image computeIcon(boolean opened, int type) {
252: Node folderNode = getOriginal();
253: Image image = opened ? folderNode.getOpenedIcon(type)
254: : folderNode.getIcon(type);
255: return Utilities.mergeImages(image,
256: CONFIGURATION_FILES_BADGE, 7, 7);
257: }
258:
259: public String getDisplayName() {
260: return NbBundle.getMessage(IcanproViews.class,
261: "LBL_Node_DocBase"); //NOI18N
262: }
263: }
264: }
|