001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: * Sun Public License Notice
022: *
023: * The contents of this file are subject to the Sun Public License
024: * Version 1.0 (the "License"). You may not use this file except in
025: * compliance with the License. A copy of the License is available at
026: * http://www.sun.com/
027: *
028: * The Original Code is NetBeans. The Initial Developer of the Original
029: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
030: * Microsystems, Inc. All Rights Reserved.
031: */
032:
033: package org.netbeans.modules.sql.project.ui;
034:
035: import java.awt.Image;
036: import java.util.ArrayList;
037: import java.util.Collections;
038: import java.util.List;
039: import java.util.logging.Logger;
040: import org.netbeans.api.java.project.JavaProjectConstants;
041: import org.netbeans.api.project.FileOwnerQuery;
042: import org.netbeans.api.project.Project;
043: import org.netbeans.api.project.ProjectUtils;
044: import org.netbeans.api.project.SourceGroup;
045:
046: import org.openide.filesystems.FileObject;
047: import org.openide.loaders.DataFolder;
048: import org.openide.nodes.Children;
049: import org.openide.nodes.FilterNode;
050: import org.openide.nodes.Node;
051: import org.openide.util.NbBundle;
052: import org.openide.util.Utilities;
053:
054: import org.netbeans.spi.java.project.support.ui.PackageView;
055: import org.netbeans.spi.project.support.ant.AntProjectHelper;
056: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
057:
058: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
059: import org.netbeans.modules.compapp.projects.base.ui.IcanproLogicalViewProvider; // import org.netbeans.modules.websvc.api.webservices.WebServicesView;
060: import org.openide.filesystems.FileChangeListener;
061:
062: class SQLproViews {
063:
064: private static Logger logger = Logger.getLogger(SQLproViews.class
065: .getName());
066:
067: private SQLproViews() {
068: }
069:
070: static final class LogicalViewChildren extends Children.Keys
071: implements FileChangeListener {
072:
073: private static final String KEY_SOURCE_DIR = "srcDir"; // NOI18N
074: private static final String KEY_DOC_BASE = "docBase"; //NOI18N
075: private static final String KEY_EJBS = "ejbKey"; //NOI18N
076: private static final String WEBSERVICES_DIR = "webservicesDir"; // NOI18N
077: private static final String KEY_SETUP_DIR = "setupDir"; //NOI18N
078:
079: private AntProjectHelper helper;
080: private final PropertyEvaluator evaluator;
081: private FileObject projectDir;
082: private Project project;
083:
084: public LogicalViewChildren(AntProjectHelper helper,
085: PropertyEvaluator evaluator, Project project) {
086: assert helper != null;
087: this .helper = helper;
088: projectDir = helper.getProjectDirectory();
089: this .evaluator = evaluator;
090: this .project = project;
091: }
092:
093: public LogicalViewChildren(AntProjectHelper helper,
094: PropertyEvaluator evaluator) {
095: assert helper != null;
096: this .helper = helper;
097: projectDir = helper.getProjectDirectory();
098: this .evaluator = evaluator;
099: }
100:
101: protected void addNotify() {
102: super .addNotify();
103: projectDir.addFileChangeListener(this );
104: createNodes();
105: }
106:
107: private void createNodes() {
108: List l = new ArrayList();
109: /*
110: l.add(KEY_EJBS);
111: */
112:
113: DataFolder docBaseDir = getFolder(IcanproProjectProperties.META_INF);
114: if (docBaseDir != null) {
115: /*
116: l.add(KEY_DOC_BASE);
117: */
118: }
119:
120: DataFolder srcDir = getFolder(IcanproProjectProperties.SRC_DIR);
121: if (srcDir != null) {
122: l.add(KEY_SOURCE_DIR);
123: }
124:
125: FileObject setupFolder = getSetupFolder();
126: if (setupFolder != null && setupFolder.isFolder()) {
127: l.add(KEY_SETUP_DIR);
128: }
129: /*
130: l.add(WEBSERVICES_DIR);
131: */
132: setKeys(l);
133: }
134:
135: private FileObject getSetupFolder() {
136: return projectDir.getFileObject("setup"); //NOI18N
137: }
138:
139: protected void removeNotify() {
140: setKeys(Collections.EMPTY_SET);
141: projectDir.removeFileChangeListener(this );
142: super .removeNotify();
143: }
144:
145: protected Node[] createNodes(Object key) {
146: Node n = null;
147: if (key == KEY_SOURCE_DIR) {
148: FileObject srcRoot = helper.resolveFileObject(evaluator
149: .getProperty(IcanproProjectProperties.SRC_DIR));
150: Project p = FileOwnerQuery.getOwner(srcRoot);
151: SourceGroup sgs[] = ProjectUtils.getSources(p)
152: .getSourceGroups(
153: JavaProjectConstants.SOURCES_TYPE_JAVA);
154: for (int i = 0; i < sgs.length; i++) {
155: if (sgs[i].contains(srcRoot)) {
156: n = PackageView.createPackageView(sgs[i]);
157: break;
158: }
159: }
160: /*
161: } else if (key == KEY_DOC_BASE) {
162: n = new DocBaseNode (getFolder(IcanproProjectProperties.META_INF).getNodeDelegate());
163: } else if (key == KEY_EJBS) {
164: FileObject srcRoot = helper.resolveFileObject(evaluator.getProperty (IcanproProjectProperties.SRC_DIR));
165: Project project = FileOwnerQuery.getOwner (srcRoot);
166: DDProvider provider = DDProvider.getDefault();
167: EjbJarImplementation jp = (EjbJarImplementation) project.getLookup().lookup(EjbJarImplementation.class);
168: org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = null;
169: try {
170: ejbJar = provider.getDDRoot(jp.getDeploymentDescriptor());
171: } catch (IOException ioe) {
172: ErrorManager.getDefault().notify(ioe);
173: }
174: ClassPathProvider cpp = (ClassPathProvider)
175: project.getLookup().lookup(ClassPathProvider.class);
176: assert cpp != null;
177: ClassPath classPath = cpp.findClassPath(srcRoot, ClassPath.SOURCE);
178: n = new EjbContainerNode(ejbJar, classPath);
179: //Node nws = new WebServicesNode(ejbJar, classPath);
180: return n == null ? new Node[0] : new Node[] {n};
181: } else if (key == WEBSERVICES_DIR){
182: FileObject srcRoot = helper.resolveFileObject(evaluator.getProperty (IcanproProjectProperties.SRC_DIR));
183: WebServicesView webServicesView = WebServicesView.getWebServicesView(srcRoot);
184: if(webServicesView != null)
185: {
186: n = webServicesView.createWebServicesView(srcRoot);
187: }
188: } else if (key == KEY_SETUP_DIR) {
189: try {
190: DataObject sdo = DataObject.find(getSetupFolder());
191: n = new ServerResourceNode(project); // sdo.getNodeDelegate());
192: } catch (org.openide.loaders.DataObjectNotFoundException dnfe) {}
193: */
194: }
195:
196: return n == null ? new Node[0] : new Node[] { n };
197: }
198:
199: private DataFolder getFolder(String propName) {
200: String propertyValue = evaluator.getProperty(propName);
201: if (propertyValue != null) {
202: FileObject fo = helper.resolveFileObject(evaluator
203: .getProperty(propName));
204: if (fo != null && fo.isValid()) {
205: try {
206: DataFolder df = DataFolder.findFolder(fo);
207: return df;
208: } catch (Exception ex) {
209: logger.info(ex.getMessage());
210: }
211: }
212: }
213: return null;
214: }
215:
216: // file change events in the project directory
217: public void fileAttributeChanged(
218: org.openide.filesystems.FileAttributeEvent fe) {
219: }
220:
221: public void fileChanged(org.openide.filesystems.FileEvent fe) {
222: }
223:
224: public void fileDataCreated(org.openide.filesystems.FileEvent fe) {
225: }
226:
227: public void fileDeleted(org.openide.filesystems.FileEvent fe) {
228: // setup folder deleted
229: createNodes();
230: }
231:
232: public void fileFolderCreated(
233: org.openide.filesystems.FileEvent fe) {
234: // setup folder could be created
235: createNodes();
236: }
237:
238: public void fileRenamed(
239: org.openide.filesystems.FileRenameEvent fe) {
240: // setup folder could be renamed
241: createNodes();
242: }
243: }
244:
245: private static final class DocBaseNode extends FilterNode {
246: private static Image CONFIGURATION_FILES_BADGE = Utilities
247: .loadImage(
248: "org/netbeans/modules/sql/projects/ui/resources/docjar.gif",
249: true); // NOI18N
250:
251: DocBaseNode(Node orig) {
252: super (orig);
253: }
254:
255: public Image getIcon(int type) {
256: return computeIcon(false, type);
257: }
258:
259: public Image getOpenedIcon(int type) {
260: return computeIcon(true, type);
261: }
262:
263: private Image computeIcon(boolean opened, int type) {
264: Node folderNode = getOriginal();
265: Image image = opened ? folderNode.getOpenedIcon(type)
266: : folderNode.getIcon(type);
267: return Utilities.mergeImages(image,
268: CONFIGURATION_FILES_BADGE, 7, 7);
269: }
270:
271: public String getDisplayName() {
272: return NbBundle.getMessage(
273: IcanproLogicalViewProvider.class,
274: "LBL_Node_DocBase"); //NOI18N
275: }
276: }
277: }
|