KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > LogicalViewChildren


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.earproject.ui;
21
22 import java.util.Collections JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.api.project.FileOwnerQuery;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.api.project.ant.AntArtifact;
28 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
29 import org.netbeans.modules.j2ee.earproject.EarProject;
30 import org.netbeans.modules.j2ee.earproject.ui.customizer.VisualClassPathItem;
31 import org.netbeans.spi.project.support.ant.AntProjectEvent;
32 import org.netbeans.spi.project.support.ant.AntProjectHelper;
33 import org.netbeans.spi.project.support.ant.AntProjectListener;
34 import org.openide.ErrorManager;
35 import org.openide.nodes.Children;
36 import org.openide.nodes.Node;
37 import org.openide.util.RequestProcessor;
38
39 /**
40  * List of children of a containing node.
41  * Each child node is represented by one key from some data model.
42  * Remember to document what your permitted keys are!
43  * Edit this template to work with the classes and logic of your data model.
44  * @author vkraemer
45  */

46 public class LogicalViewChildren extends Children.Keys implements AntProjectListener {
47     
48     private final AntProjectHelper model;
49     private java.util.Map JavaDoc<String JavaDoc, VisualClassPathItem> vcpItems;
50     
51     public LogicalViewChildren(AntProjectHelper model) {
52         if (null == model) {
53             throw new IllegalArgumentException JavaDoc("model cannot be null"); // NOI18N
54
}
55         this.model = model;
56     }
57     
58     protected void addNotify() {
59         super.addNotify();
60         // set the children to use:
61
updateKeys();
62         // and listen to changes in the model too:
63
model.addAntProjectListener(this);
64     }
65     
66     private void updateKeys() {
67         Project p = FileOwnerQuery.getOwner(model.getProjectDirectory());
68         //#62823 debug
69
if(p == null) {
70             ErrorManager.getDefault().notify(ErrorManager.WARNING,
71                     new IllegalStateException JavaDoc("FileOwnerQuery.getOwner("+ model.getProjectDirectory() + ") returned null. " + // NOI18N
72
"Please report this with the situation description to issue #62823 " + // NOI18N
73
"(http://www.netbeans.org/issues/show_bug.cgi?id=62823)."));
74             return ;
75         }
76         
77         EarProject earProject = (EarProject) p.getLookup().lookup(EarProject.class);
78         List JavaDoc<VisualClassPathItem> vcpis = earProject.getProjectProperties().getJarContentAdditional();
79         vcpItems = new HashMap JavaDoc<String JavaDoc, VisualClassPathItem>();
80         for (VisualClassPathItem vcpi : vcpis) {
81             Object JavaDoc obj = vcpi.getObject();
82             if (!(obj instanceof AntArtifact)) {
83                 continue;
84             }
85             AntArtifact aa = (AntArtifact) obj;
86             Project vcpiProject = aa.getProject();
87             J2eeModuleProvider jmp = (J2eeModuleProvider) vcpiProject.getLookup().lookup(J2eeModuleProvider.class);
88             if (null != jmp) {
89                 vcpItems.put(vcpi.getRaw(), vcpi);
90             }
91         }
92         setKeys(vcpItems.keySet());
93     }
94     
95     protected void removeNotify() {
96         model.removeAntProjectListener(this);
97         setKeys(Collections.EMPTY_SET);
98         super.removeNotify();
99     }
100     
101     protected Node[] createNodes(Object JavaDoc key) {
102         VisualClassPathItem vcpItem = vcpItems.get((String JavaDoc) key);
103         return new Node[] { new ModuleNode(vcpItem, model.getProjectDirectory() ) };
104     }
105     
106     public void modelChanged(Object JavaDoc ev) {
107         // your data model changed, so update the children to match:
108
updateKeys();
109     }
110     
111     public void configurationXmlChanged(AntProjectEvent ape) {
112         // unsafe to call Children.setKeys() while holding a mutext
113
// here the caller holds ProjectManager.mutex() read access
114
RequestProcessor.getDefault().post(new Runnable JavaDoc() {
115             public void run() {
116                 updateKeys();
117             }
118         });
119     }
120  
121     public void propertiesChanged(final AntProjectEvent ape) {
122         // unsafe to call Children.setKeys() while holding a mutext
123
// here the caller holds ProjectManager.mutex() read access
124
RequestProcessor.getDefault().post(new Runnable JavaDoc() {
125             public void run() {
126                 updateKeys();
127             }
128         });
129     }
130
131 }
132
Popular Tags