~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to j2ee/archiveproject/src/org/netbeans/modules/j2ee/archive/ui/RootNode.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
 
 
43
package org.netbeans.modules.j2ee.archive.ui;
 
44
 
 
45
import java.util.ArrayList;
 
46
import java.util.Collections;
 
47
import java.util.Iterator;
 
48
import java.util.List;
 
49
import java.util.ResourceBundle;
 
50
import javax.swing.Action;
 
51
import javax.swing.JSeparator;
 
52
import org.netbeans.api.project.Project;
 
53
import org.netbeans.api.project.ProjectUtils;
 
54
import org.netbeans.modules.j2ee.archive.project.ArchiveProject;
 
55
import org.netbeans.modules.j2ee.archive.project.ArchiveProjectProperties;
 
56
import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView;
 
57
import org.netbeans.spi.project.ActionProvider;
 
58
import org.netbeans.spi.project.ui.support.CommonProjectActions;
 
59
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
 
60
import org.openide.filesystems.FileChangeListener;
 
61
import org.openide.filesystems.FileObject;
 
62
import org.openide.loaders.DataFolder;
 
63
import org.openide.nodes.Children;
 
64
import org.openide.nodes.Node;
 
65
//import org.openide.util.HelpCtx;
 
66
import org.openide.util.Lookup;
 
67
import org.openide.util.NbBundle;
 
68
import org.openide.util.actions.SystemAction;
 
69
import org.openide.util.lookup.Lookups;
 
70
 
 
71
public class RootNode extends org.openide.nodes.AbstractNode {
 
72
    
 
73
//    private boolean broken;
 
74
    
 
75
//    private BrokenLinksAction brokenLinksAction;
 
76
//
 
77
//    private BrokenServerAction brokenServerAction;
 
78
    
 
79
    public RootNode(ArchiveProject ap) {
 
80
        super(new LogicalViewChildren(ap), createLookup(ap));
 
81
        super.setName(ProjectUtils.getInformation(ap).getDisplayName());
 
82
        setIconBaseWithExtension("org/netbeans/modules/j2ee/archive/project/resources/packaged_archive_16.png"); // NOI18N
 
83
//        if (hasBrokenLinks()) {
 
84
//            broken = true;
 
85
//        }
 
86
//        brokenLinksAction = new BrokenLinksAction();
 
87
//        brokenServerAction = new BrokenServerAction();
 
88
        
 
89
        ArchiveProjectProperties app = ap.getArchiveProjectProperties();
 
90
        String sourceArchive = ap.getPropertyEvaluator().evaluate((String)app.get(ArchiveProjectProperties.SOURCE_ARCHIVE));
 
91
        setShortDescription(NbBundle.getMessage(RootNode.class,"LBL_ProjectToolTip",        // NOI18N
 
92
                sourceArchive)); 
 
93
    }
 
94
    
 
95
    public Action[] getActions( boolean context ) {
 
96
        Action[] retVal;
 
97
        if ( context ) {
 
98
            retVal = super.getActions( true );
 
99
        } else {
 
100
            retVal = getAdditionalActions();
 
101
        }
 
102
        return retVal;
 
103
    }
 
104
 
 
105
    private Action[] getAdditionalActions() {
 
106
        
 
107
        ResourceBundle bundle = NbBundle.getBundle(RootNode.class);
 
108
        
 
109
        List actions = new ArrayList(30);
 
110
        actions.add(CommonProjectActions.newFileAction());
 
111
        actions.add(null);
 
112
        actions.add(ProjectSensitiveActions.projectCommandAction( 
 
113
                ActionProvider.COMMAND_BUILD, bundle.getString("LBL_BuildAction_Name"), null)); // NOI18N
 
114
        actions.add(ProjectSensitiveActions.projectCommandAction( 
 
115
                "verify", bundle.getString("LBL_VerifyAction_Name"), null)); // NOI18N
 
116
        actions.add(ProjectSensitiveActions.projectCommandAction(
 
117
                ActionProvider.COMMAND_RUN, bundle.getString("LBL_RunAction_Name"), null)); // NOI18N
 
118
        actions.add(null);
 
119
        actions.add(CommonProjectActions.setAsMainProjectAction());
 
120
        actions.add(CommonProjectActions.openSubprojectsAction());
 
121
        actions.add(CommonProjectActions.closeProjectAction());
 
122
        actions.add(null);
 
123
        actions.add(CommonProjectActions.renameProjectAction());
 
124
        actions.add(CommonProjectActions.moveProjectAction());
 
125
        actions.add(CommonProjectActions.copyProjectAction());
 
126
        actions.add(CommonProjectActions.deleteProjectAction());
 
127
        actions.add(null);
 
128
        actions.add(SystemAction.get( org.openide.actions.FindAction.class ));
 
129
        
 
130
        // honor 57874 contact
 
131
        
 
132
 
 
133
        Lookup lookup = Lookups.forPath("Projects/Actions"); // NOI18N
 
134
        Lookup.Template query = new Lookup.Template(Object.class);
 
135
        Iterator it = lookup.lookup(query).allInstances().iterator();
 
136
        if (it.hasNext()) {
 
137
            actions.add(null);
 
138
        }
 
139
        while (it.hasNext()) {
 
140
            Object next = it.next();
 
141
            if (next instanceof Action) {
 
142
                actions.add(next);
 
143
            } else if (next instanceof JSeparator) {
 
144
                actions.add(null);
 
145
            }
 
146
        }
 
147
        
 
148
//        actions.add(null);
 
149
//        if (brokenLinksAction != null && brokenLinksAction.isEnabled()) {
 
150
//            actions.add(brokenLinksAction);
 
151
//        }
 
152
//        if (brokenServerAction.isEnabled()) {
 
153
//            actions.add(brokenServerAction);
 
154
//        }
 
155
        actions.add(null);
 
156
        actions.add(CommonProjectActions.customizeProjectAction());
 
157
        
 
158
        return (Action[])actions.toArray(new Action[actions.size()]);
 
159
    }
 
160
    
 
161
    static final class LogicalViewChildren extends Children.Keys/*<FileObject>*/  implements FileChangeListener {
 
162
        
 
163
        // XXX does not react correctly to addition or removal of src/ subdir
 
164
        
 
165
        private static final String KEY_DOC_BASE = "docBase"; //NOI18N
 
166
        private static final String KEY_SETUP_DIR = "setupDir"; //NOI18N
 
167
        
 
168
        private ArchiveProject project;
 
169
        
 
170
        public LogicalViewChildren(ArchiveProject project) { 
 
171
            assert project != null;
 
172
            this.project = project;
 
173
        }
 
174
        
 
175
        protected void addNotify() {
 
176
            super.addNotify();
 
177
            project.getProjectDirectory().addFileChangeListener(this);
 
178
            createNodes();
 
179
        }
 
180
 
 
181
        private void createNodes() {
 
182
            List l = new ArrayList();            
 
183
            DataFolder docBaseDir = getFolder((String)project.getArchiveProjectProperties().get(ArchiveProjectProperties.PROXY_PROJECT_DIR)); // WEB_CONF);
 
184
            if (docBaseDir != null) {
 
185
                l.add(KEY_DOC_BASE);
 
186
            }
 
187
            l.add(KEY_SETUP_DIR);
 
188
            
 
189
            String dir = (String)project.getArchiveProjectProperties().get(ArchiveProjectProperties.PROXY_PROJECT_DIR);
 
190
            FileObject fo = project.getProjectDirectory().getFileObject("subarchives");     // NOI18N
 
191
            if (null != fo) {
 
192
                FileObject subarchives[] = fo.getChildren();
 
193
                for (FileObject innerFo : subarchives) {
 
194
                    FileObject innerProj = null;
 
195
                    if (null != innerFo) {
 
196
                        innerProj = innerFo.getFileObject("tmpproj");           // NOI18N
 
197
                    }
 
198
                    if (null != innerProj && innerProj.isFolder()) {
 
199
                        DataFolder folder = getFolder("subarchives/"+innerFo.getName()+"/"+dir);        // NOI18N
 
200
                        if (null == folder) {
 
201
                            continue;
 
202
                        }
 
203
                        Node n = new ModuleNode(folder, 
 
204
                                NbBundle.getMessage(RootNode.class,"LBL_ModuleNode",        // NOI18N
 
205
                                project.getEarPath(innerFo.getName())));
 
206
                        l.add(n);
 
207
                    }
 
208
                }
 
209
            }
 
210
            setKeys(l);
 
211
        }
 
212
        
 
213
        protected void removeNotify() {
 
214
            setKeys(Collections.EMPTY_SET);
 
215
            project.getProjectDirectory().removeFileChangeListener(this);
 
216
            super.removeNotify();
 
217
        }
 
218
        
 
219
        protected Node[] createNodes(Object key) {
 
220
            Node n;
 
221
            if (key == KEY_DOC_BASE) {
 
222
                n = new ConfigFilesNode(getFolder((String)project.getArchiveProjectProperties().get(ArchiveProjectProperties.PROXY_PROJECT_DIR)));
 
223
            }  else if (key == KEY_SETUP_DIR) {
 
224
                n = J2eeProjectView.createServerResourcesNode(project);
 
225
            } else {
 
226
                n = (Node) key;
 
227
            }
 
228
            return n == null ? new Node[0] : new Node[] {n};
 
229
        }
 
230
        
 
231
        private DataFolder getFolder(String dir) {
 
232
            FileObject fo = project.getProjectDirectory();
 
233
            if (null == dir) {
 
234
                return null;
 
235
            }
 
236
            if (null != fo) {
 
237
                fo = fo.getFileObject(dir);
 
238
            }
 
239
            if (null == fo) {
 
240
                return null;
 
241
            }
 
242
            
 
243
            // check for a web app
 
244
            fo = fo.getFileObject("web");                                       // NOI18N
 
245
            if (null != fo) {
 
246
                fo = fo.getFileObject("WEB-INF");                               // NOI18N
 
247
                if (fo != null) {
 
248
                    DataFolder df = DataFolder.findFolder(fo);
 
249
                    return df;
 
250
                } else {
 
251
                    return null;
 
252
                }
 
253
            }
 
254
            fo = project.getProjectDirectory().getFileObject(dir);
 
255
            if (null == fo) {
 
256
                return null;
 
257
            }
 
258
            fo = fo.getFileObject("src");                                       // NOI18N
 
259
            if (null == fo) {
 
260
                return null;
 
261
            }
 
262
            fo = fo.getFileObject("conf");                                      // NOI18N
 
263
            if (null == fo) {
 
264
                return null;
 
265
            }
 
266
            return DataFolder.findFolder(fo);
 
267
        }
 
268
        
 
269
        // file change events in the project directory
 
270
        public void fileAttributeChanged(org.openide.filesystems.FileAttributeEvent fe) {
 
271
        }
 
272
        
 
273
        public void fileChanged(org.openide.filesystems.FileEvent fe) {
 
274
        }
 
275
        
 
276
        public void fileDataCreated(org.openide.filesystems.FileEvent fe) {
 
277
        }
 
278
        
 
279
        public void fileDeleted(org.openide.filesystems.FileEvent fe) {
 
280
            // setup folder deleted
 
281
             //this was playing in a deadlock stack of 74613.
 
282
             // This needs to be re-evaluated
 
283
             // Filed as 76844
 
284
             //createNodes();
 
285
        }
 
286
        
 
287
        public void fileFolderCreated(org.openide.filesystems.FileEvent fe) {
 
288
            // setup folder could be created
 
289
            createNodes();
 
290
        }
 
291
        
 
292
        public void fileRenamed(org.openide.filesystems.FileRenameEvent fe) {
 
293
            // setup folder could be renamed
 
294
            createNodes();
 
295
        }
 
296
    }
 
297
    
 
298
    
 
299
    private static Lookup createLookup( Project project ) {
 
300
        DataFolder rootFolder = DataFolder.findFolder( project.getProjectDirectory() );
 
301
        // XXX Remove root folder after FindAction rewrite
 
302
        return Lookups.fixed( new Object[] { project, rootFolder } );
 
303
    }
 
304
    
 
305
//    private static final String[] BREAKABLE_PROPERTIES = new String[] {
 
306
//        ArchiveProjectProperties.SOURCE_ARCHIVE,
 
307
//    };
 
308
    
 
309
//    public boolean hasBrokenLinks() {
 
310
//        return BrokenReferencesSupport.isBroken(helper.getAntProjectHelper(), resolver, getBreakableProperties(),
 
311
//                new String[] {WebProjectProperties.JAVA_PLATFORM});
 
312
//    }
 
313
    
 
314
//    private String[] getBreakableProperties() {
 
315
////        SourceRoots roots = this.project.getSourceRoots();
 
316
////        String[] srcRootProps = roots.getRootProperties();
 
317
////        roots = this.project.getTestSourceRoots();
 
318
////        String[] testRootProps = roots.getRootProperties();
 
319
//        String[] result = new String [BREAKABLE_PROPERTIES.length]; //  + srcRootProps.length + testRootProps.length];
 
320
//        System.arraycopy(BREAKABLE_PROPERTIES, 0, result, 0, BREAKABLE_PROPERTIES.length);
 
321
////        System.arraycopy(srcRootProps, 0, result, BREAKABLE_PROPERTIES.length, srcRootProps.length);
 
322
////        System.arraycopy(testRootProps, 0, result, BREAKABLE_PROPERTIES.length + srcRootProps.length, testRootProps.length);
 
323
//        return result;
 
324
//    }
 
325
    
 
326
//    private static Image brokenProjectBadge = Utilities.loadImage( "org/netbeans/modules/web/project/ui/resources/brokenProjectBadge.gif" ); // NOI18N
 
327
    
 
328
    /** This action is created only when project has broken references.
 
329
     * Once these are resolved the action is disabled.
 
330
     */
 
331
//    private class BrokenLinksAction extends AbstractAction implements PropertyChangeListener, ChangeListener, Runnable {
 
332
//
 
333
//        private RequestProcessor.Task task = null;
 
334
//
 
335
//        private PropertyChangeListener weakPCL;
 
336
//
 
337
//        public BrokenLinksAction() {
 
338
//            putValue(Action.NAME, NbBundle.getMessage(RootNode.class, "LBL_Fix_Broken_Links_Action"));
 
339
//            setEnabled(broken);
 
340
////            evaluator.addPropertyChangeListener( this );
 
341
//            // When evaluator fires changes that platform properties were
 
342
//            // removed the platform still exists in JavaPlatformManager.
 
343
//            // That's why I have to listen here also on JPM:
 
344
//            //weakPCL = WeakListeners.propertyChange( this, JavaPlatformManager.getDefault() );
 
345
//            //JavaPlatformManager.getDefault().addPropertyChangeListener( weakPCL );
 
346
//            RootNode.this.addChangeListener((ChangeListener)WeakListeners.change(this, RootNode.this));
 
347
//        }
 
348
//
 
349
//        public void actionPerformed(ActionEvent e) {
 
350
//            try {
 
351
//                helper.requestSave();
 
352
//                BrokenReferencesSupport.showCustomizer(helper.getAntProjectHelper(), resolver, getBreakableProperties(), new String[]{WebProjectProperties.JAVA_PLATFORM});
 
353
//                run();
 
354
//            } catch (IOException ioe) {
 
355
//                ErrorManager.getDefault().notify(ioe);
 
356
//            }
 
357
//        }
 
358
//
 
359
//        public void propertyChange(PropertyChangeEvent evt) {
 
360
//            refsMayChanged();
 
361
//        }
 
362
//
 
363
//        public void stateChanged(ChangeEvent evt) {
 
364
//            refsMayChanged();
 
365
//        }
 
366
//
 
367
//        public synchronized void run() {
 
368
//            boolean old = broken;
 
369
//            broken = hasBrokenLinks();
 
370
//            if (old != broken) {
 
371
//                setEnabled(broken);
 
372
//                fireIconChange();
 
373
//                fireOpenedIconChange();
 
374
//                fireDisplayNameChange(null, null);
 
375
//                //project.getWebProjectProperties().save();
 
376
//            }
 
377
//        }
 
378
//
 
379
//        public void refsMayChanged() {
 
380
//            // check project state whenever there was a property change
 
381
//            // or change in list of platforms.
 
382
//            // Coalesce changes since they can come quickly:
 
383
//            if (task == null) {
 
384
//                task = BROKEN_LINKS_RP.create(this);
 
385
//            }
 
386
//            task.schedule(100);
 
387
//        }
 
388
//
 
389
//    }
 
390
//
 
391
//    private class BrokenServerAction extends AbstractAction implements
 
392
//            InstanceListener, PropertyChangeListener {
 
393
//
 
394
//        private boolean brokenServer;
 
395
//
 
396
//        public BrokenServerAction() {
 
397
//            putValue(Action.NAME, NbBundle.getMessage(RootNode.class, "LBL_Fix_Missing_Server_Action")); // NOI18N
 
398
//            evaluator.addPropertyChangeListener(this);
 
399
//            checkMissingServer();
 
400
//        }
 
401
//
 
402
//        public boolean isEnabled() {
 
403
//            return brokenServer;
 
404
//        }
 
405
//
 
406
//        public void actionPerformed(ActionEvent e) {
 
407
//            BrokenServerSupport.showCustomizer(project, helper);
 
408
//            checkMissingServer();
 
409
//        }
 
410
//
 
411
//        public void propertyChange(PropertyChangeEvent evt) {
 
412
//            if (ArchiveProjectProperties.J2EE_SERVER_INSTANCE.equals(evt.getPropertyName())) {
 
413
//                checkMissingServer();
 
414
//            }
 
415
//        }
 
416
//
 
417
//        public void changeDefaultInstance(String oldServerInstanceID, String newServerInstanceID) {
 
418
//        }
 
419
//
 
420
//        public void instanceAdded(String serverInstanceID) {
 
421
//            checkMissingServer();
 
422
//        }
 
423
//
 
424
//        public void instanceRemoved(String serverInstanceID) {
 
425
//            checkMissingServer();
 
426
//        }
 
427
//
 
428
//        private void checkMissingServer() {
 
429
//            boolean old = brokenServer;
 
430
//            String servInstID = evaluator.getProperty(ArchiveProjectProperties.J2EE_SERVER_INSTANCE);
 
431
//            brokenServer = BrokenServerSupport.isBroken(servInstID);
 
432
//            if (old != brokenServer) {
 
433
//                fireIconChange();
 
434
//                fireOpenedIconChange();
 
435
//                fireDisplayNameChange(null, null);
 
436
//            }
 
437
//        }
 
438
//    }
 
439
    
 
440
}