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.compapp.projects.jbi.ui;
043:
044: import javax.swing.Action;
045: import org.netbeans.modules.compapp.projects.jbi.JbiProject;
046: import org.netbeans.spi.project.ui.support.CommonProjectActions; //import org.netbeans.modules.j2ee.ejbjar.project.ui.ServerResourceNode;
047: import org.netbeans.modules.compapp.projects.jbi.ui.customizer.JbiProjectProperties;
048:
049: import org.netbeans.api.java.project.JavaProjectConstants;
050: import org.netbeans.api.project.FileOwnerQuery;
051: import org.netbeans.api.project.Project;
052: import org.netbeans.api.project.ProjectUtils;
053: import org.netbeans.api.project.SourceGroup;
054: import org.netbeans.spi.project.support.ant.AntProjectHelper;
055: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
056:
057: // import org.netbeans.modules.websvc.api.webservices.WebServicesView;
058: import org.openide.filesystems.FileChangeListener;
059:
060: //import org.netbeans.modules.j2ee.common.ui.ServerResourceNode;
061: import org.openide.filesystems.FileObject;
062:
063: import org.openide.loaders.DataFolder;
064: import org.openide.loaders.DataObject;
065: import org.openide.loaders.DataObjectNotFoundException;
066:
067: import org.openide.nodes.Children;
068: import org.openide.nodes.FilterNode;
069: import org.openide.nodes.Node;
070:
071: import org.openide.nodes.NodeAdapter;
072: import org.openide.nodes.NodeEvent;
073: import org.openide.util.NbBundle;
074:
075: import java.util.ArrayList;
076: import java.util.Collections;
077: import java.util.List;
078: import javax.swing.event.ChangeEvent;
079: import javax.swing.event.ChangeListener;
080: import javax.swing.event.EventListenerList;
081: import org.netbeans.api.queries.VisibilityQuery;
082: import org.openide.loaders.ChangeableDataFilter;
083: import org.openide.loaders.DataFilter;
084:
085: /**
086: * DOCUMENT ME!
087: *
088: * @author
089: * @version
090: */
091: class JbiViews {
092: private JbiViews() {
093: }
094:
095: /**
096: * DOCUMENT ME!
097: *
098: * @author
099: * @version
100: */
101: static final class LogicalViewChildren extends Children.Keys
102: implements FileChangeListener {
103: private static final String KEY_SVC_COMP_NODE = "SvcCompNode"; // NOI18N
104: private static final String KEY_SOURCE_DIR = "srcDir"; // NOI18N
105: private static final String KEY_DOC_BASE = "docBase"; // NOI18N
106: private static final String KEY_JBIS = "jbiKey"; // NOI18N
107: // private static final String WEBSERVICES_DIR = "webservicesDir"; // NOI18N
108: private static final String KEY_SETUP_DIR = "setupDir"; // NOI18N
109: private AntProjectHelper helper;
110: private final PropertyEvaluator evaluator;
111: private FileObject projectDir;
112: private Project project;
113:
114: /**
115: * Creates a new LogicalViewChildren object.
116: *
117: * @param helper DOCUMENT ME!
118: * @param evaluator DOCUMENT ME!
119: * @param project DOCUMENT ME!
120: */
121: public LogicalViewChildren(AntProjectHelper helper,
122: PropertyEvaluator evaluator, Project project) {
123: assert helper != null;
124: this .helper = helper;
125: projectDir = helper.getProjectDirectory();
126: this .evaluator = evaluator;
127: this .project = project;
128: }
129:
130: /**
131: * DOCUMENT ME!
132: */
133: protected void addNotify() {
134: super .addNotify();
135: projectDir.addFileChangeListener(this );
136: createNodes();
137: }
138:
139: private void createNodes() {
140: List l = new ArrayList();
141:
142: // DataFolder docBaseDir = getFolder(JbiProjectProperties.META_INF);
143: //
144: // if (docBaseDir != null) {
145: // l.add(KEY_DOC_BASE);
146: // }
147: l.add(KEY_SVC_COMP_NODE);
148: DataFolder srcDir = getFolder(JbiProjectProperties.SRC_DIR);
149:
150: if (srcDir != null) {
151: l.add(KEY_SOURCE_DIR);
152: }
153:
154: FileObject setupFolder = getSetupFolder();
155:
156: if ((setupFolder != null) && setupFolder.isFolder()) {
157: l.add(KEY_SETUP_DIR);
158: }
159:
160: /*
161: l.add(WEBSERVICES_DIR);
162: */
163: setKeys(l);
164: }
165:
166: private FileObject getSetupFolder() {
167: return projectDir.getFileObject("setup"); // NOI18N
168: }
169:
170: /**
171: * DOCUMENT ME!
172: */
173: protected void removeNotify() {
174: setKeys(Collections.EMPTY_SET);
175: projectDir.removeFileChangeListener(this );
176: super .removeNotify();
177: }
178:
179: /**
180: * DOCUMENT ME!
181: *
182: * @param key DOCUMENT ME!
183: *
184: * @return DOCUMENT ME!
185: */
186: protected Node[] createNodes(Object key) {
187: Node n = null;
188:
189: if (key == KEY_SOURCE_DIR) {
190: FileObject srcRoot = helper.resolveFileObject(evaluator
191: .getProperty(JbiProjectProperties.SRC_DIR));
192: Project p = FileOwnerQuery.getOwner(srcRoot);
193: SourceGroup[] sgs = ProjectUtils.getSources(p)
194: .getSourceGroups(
195: JavaProjectConstants.SOURCES_TYPE_JAVA);
196:
197: for (int i = 0; i < sgs.length; i++) {
198: if (sgs[i].contains(srcRoot)) {
199: // n = PackageView.createPackageView(sgs[i]);
200: try {
201: DataObject dobj = DataObject.find(sgs[i]
202: .getRootFolder());
203: n = new RootNode(DataFolder
204: .findFolder(sgs[i].getRootFolder()));
205: } catch (DataObjectNotFoundException ex) {
206: }
207: break;
208: }
209: }
210: // } else if (key == KEY_DOC_BASE) {
211: // n = new DocBaseNode(getFolder(JbiProjectProperties.META_INF).getNodeDelegate());
212:
213: /*
214: } else if (key == KEY_EJBS) {
215: FileObject srcRoot = helper.resolveFileObject(evaluator.getProperty (JbiProjectProperties.SRC_DIR));
216: Project project = FileOwnerQuery.getOwner (srcRoot);
217: DDProvider provider = DDProvider.getDefault();
218: EjbJarImplementation jp = (EjbJarImplementation) project.getLookup().lookup(EjbJarImplementation.class);
219: org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = null;
220: try {
221: ejbJar = provider.getDDRoot(jp.getDeploymentDescriptor());
222: } catch (IOException ioe) {
223: ErrorManager.getDefault().notify(ioe);
224: }
225: ClassPathProvider cpp = (ClassPathProvider)
226: project.getLookup().lookup(ClassPathProvider.class);
227: assert cpp != null;
228: ClassPath classPath = cpp.findClassPath(srcRoot, ClassPath.SOURCE);
229: n = new EjbContainerNode(ejbJar, classPath);
230: //Node nws = new WebServicesNode(ejbJar, classPath);
231: return n == null ? new Node[0] : new Node[] {n};
232: } else if (key == WEBSERVICES_DIR){
233: FileObject srcRoot = helper.resolveFileObject(evaluator.getProperty (JbiProjectProperties.SRC_DIR));
234: WebServicesView webServicesView = WebServicesView.getWebServicesView(srcRoot);
235: if(webServicesView != null)
236: {
237: n = webServicesView.createWebServicesView(srcRoot);
238: }
239: */
240: } else if (key == KEY_SETUP_DIR) {
241: try {
242: DataObject sdo = DataObject.find(getSetupFolder());
243: n = null; // new ServerResourceNode(project); // sdo.getNodeDelegate());
244: } catch (org.openide.loaders.DataObjectNotFoundException dnfe) {
245: }
246: } else if (key == KEY_SVC_COMP_NODE) {
247: n = ServiceCompositionNode
248: .createServiceCompositionNode((JbiProject) project);
249: n.addNodeListener(new NodeAdapter() {
250:
251: @Override
252: public void nodeDestroyed(NodeEvent ev) {
253: System.err
254: .println("XXXXXXXXXX ServiceCompositionNode getting destroyed");
255: refreshKey(KEY_SVC_COMP_NODE);
256: }
257: });
258: }
259:
260: return (n == null) ? new Node[0] : new Node[] { n };
261: }
262:
263: private DataFolder getFolder(String propName) {
264: String propValue = evaluator.getProperty(propName);
265:
266: if (propValue != null) {
267: FileObject fo = helper.resolveFileObject(propValue);
268:
269: if (fo != null) {
270: DataFolder df = DataFolder.findFolder(fo);
271:
272: return df;
273: }
274: }
275:
276: return null;
277: }
278:
279: // file change events in the project directory
280: public void fileAttributeChanged(
281: org.openide.filesystems.FileAttributeEvent fe) {
282: }
283:
284: /**
285: * DOCUMENT ME!
286: *
287: * @param fe DOCUMENT ME!
288: */
289: public void fileChanged(org.openide.filesystems.FileEvent fe) {
290: }
291:
292: /**
293: * DOCUMENT ME!
294: *
295: * @param fe DOCUMENT ME!
296: */
297: public void fileDataCreated(org.openide.filesystems.FileEvent fe) {
298: }
299:
300: /**
301: * DOCUMENT ME!
302: *
303: * @param fe DOCUMENT ME!
304: */
305: public void fileDeleted(org.openide.filesystems.FileEvent fe) {
306: // setup folder deleted
307: createNodes();
308: }
309:
310: /**
311: * DOCUMENT ME!
312: *
313: * @param fe DOCUMENT ME!
314: */
315: public void fileFolderCreated(
316: org.openide.filesystems.FileEvent fe) {
317: // setup folder could be created
318: createNodes();
319: }
320:
321: /**
322: * DOCUMENT ME!
323: *
324: * @param fe DOCUMENT ME!
325: */
326: public void fileRenamed(
327: org.openide.filesystems.FileRenameEvent fe) {
328: // setup folder could be renamed
329: createNodes();
330: }
331: }
332:
333: private static class DocBaseChildren extends FilterNode.Children {
334: DocBaseChildren(Node orig) {
335: super (orig);
336: }
337:
338: protected Node[] createNodes(org.openide.nodes.Node key) {
339: if (key instanceof FilterNode) {
340: String name = ((FilterNode) key).getDisplayName();
341: if ((name != null) && (name.equalsIgnoreCase("CVS"))) { // NOI18N
342: return new Node[] {};
343: }
344: }
345: return super .createNodes(key);
346: }
347: }
348:
349: private static final DataFilter VISIBILITY_QUERY_FILTER = new VisibilityQueryDataFilter();
350:
351: private static final class RootNode extends FilterNode {
352: public RootNode(DataFolder folder) {
353: super (folder.getNodeDelegate(), folder
354: .createNodeChildren(VISIBILITY_QUERY_FILTER));
355:
356: disableDelegation(DELEGATE_GET_DISPLAY_NAME
357: | DELEGATE_SET_DISPLAY_NAME
358: | DELEGATE_GET_SHORT_DESCRIPTION
359: | DELEGATE_GET_ACTIONS);
360: setDisplayName(NbBundle.getMessage(RootNode.class,
361: "LBL_ProcessFiles")); // NOI18N
362:
363: }
364:
365: //@Override
366: public Action[] getActions(boolean context) {
367: return new Action[] {
368: CommonProjectActions.newFileAction(),
369: null,
370: org.openide.util.actions.SystemAction
371: .get(org.openide.actions.FileSystemAction.class),
372: null,
373: org.openide.util.actions.SystemAction
374: .get(org.openide.actions.FindAction.class),
375: null,
376: org.openide.util.actions.SystemAction
377: .get(org.openide.actions.PasteAction.class),
378: null,
379: org.openide.util.actions.SystemAction
380: .get(org.openide.actions.ToolsAction.class), };
381: }
382:
383: //@Override
384: public boolean canRename() {
385: return false;
386: }
387:
388: //@Override
389: public boolean canCopy() {
390: return false;
391: }
392:
393: //@Override
394: public boolean canCut() {
395: return false;
396: }
397:
398: //@Override
399: public boolean canDestroy() {
400: return false;
401: }
402:
403: }
404:
405: static final class VisibilityQueryDataFilter implements
406: ChangeListener, ChangeableDataFilter {
407:
408: EventListenerList ell = new EventListenerList();
409:
410: public VisibilityQueryDataFilter() {
411: VisibilityQuery.getDefault().addChangeListener(this );
412: }
413:
414: public boolean acceptDataObject(DataObject obj) {
415: FileObject fileObject = obj.getPrimaryFile();
416: return VisibilityQuery.getDefault().isVisible(fileObject);
417: }
418:
419: public void stateChanged(ChangeEvent e) {
420: Object[] listeners = ell.getListenerList();
421: ChangeEvent event = null;
422: for (int i = listeners.length - 2; i >= 0; i -= 2) {
423: if (listeners[i] == ChangeListener.class) {
424: if (event == null) {
425: event = new ChangeEvent(this );
426: }
427: ((ChangeListener) listeners[i + 1])
428: .stateChanged(event);
429: }
430: }
431: }
432:
433: public void addChangeListener(ChangeListener listener) {
434: ell.add(ChangeListener.class, listener);
435: }
436:
437: public void removeChangeListener(ChangeListener listener) {
438: ell.remove(ChangeListener.class, listener);
439: }
440:
441: }
442:
443: // private static final class DocBaseNode extends FilterNode {
444: // private static Image CONFIGURATION_FILES_BADGE = Utilities.loadImage(
445: // "org/netbeans/modules/compapp/projects/jbi/ui/resources/configbadge.gif", true ); // NOI18N
446: //
447: // /**
448: // * Creates a new DocBaseNode object.
449: // *
450: // * @param orig DOCUMENT ME!
451: // */
452: // DocBaseNode(Node orig) {
453: // super(orig, new DocBaseChildren(orig));
454: // }
455: //
456: // /**
457: // * DOCUMENT ME!
458: // *
459: // * @param type DOCUMENT ME!
460: // *
461: // * @return DOCUMENT ME!
462: // */
463: // public Image getIcon(int type) {
464: // return computeIcon(false, type);
465: // }
466: //
467: // /**
468: // * DOCUMENT ME!
469: // *
470: // * @param type DOCUMENT ME!
471: // *
472: // * @return DOCUMENT ME!
473: // */
474: // public Image getOpenedIcon(int type) {
475: // return computeIcon(true, type);
476: // }
477: //
478: // private Image computeIcon(boolean opened, int type) {
479: // Node folderNode = getOriginal();
480: // Image image = opened ? folderNode.getOpenedIcon(type) : folderNode.getIcon(type);
481: //
482: // return Utilities.mergeImages(image, CONFIGURATION_FILES_BADGE, 7, 7);
483: // }
484: //
485: // /**
486: // * DOCUMENT ME!
487: // *
488: // * @return DOCUMENT ME!
489: // */
490: // public String getDisplayName() {
491: // return NbBundle.getMessage(JbiViews.class, "LBL_Node_DocBase"); // NOI18N
492: // }
493: // }
494: }
|