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 org.netbeans.modules.compapp.projects.jbi.JbiProject;
045: import org.netbeans.modules.compapp.projects.jbi.ui.customizer.JbiProjectProperties;
046: import org.netbeans.modules.compapp.projects.jbi.ui.customizer.VisualClassPathItem;
047: import org.netbeans.api.project.ant.AntArtifact;
048:
049: import org.openide.nodes.Children;
050: import org.openide.nodes.Node;
051:
052: import java.beans.PropertyChangeEvent;
053: import java.beans.PropertyChangeListener;
054: import java.util.*;
055: import org.netbeans.modules.compapp.projects.jbi.api.JbiProjectConstants;
056: import org.netbeans.modules.compapp.projects.jbi.jeese.ui.JavaEEModuleNode;
057:
058: /**
059: * DOCUMENT ME!
060: *
061: * @author
062: * @version
063: */
064: public class JbiModuleViewChildren extends Children.Keys implements
065: PropertyChangeListener {
066: private final JbiProject project;
067:
068: /**
069: * Creates a new JbiModuleViewChildren object.
070: *
071: * @param project DOCUMENT ME!
072: */
073: public JbiModuleViewChildren(JbiProject project) {
074: this .project = project;
075: }
076:
077: /**
078: * DOCUMENT ME!
079: */
080: protected void addNotify() {
081: super .addNotify();
082: updateKeys();
083:
084: // and listen to changes in the model too:
085: //model.addPropertyChangeListener(this);
086: }
087:
088: private void updateKeys() {
089: JbiProjectProperties epp = project.getProjectProperties();
090: List keys = Collections.EMPTY_LIST;
091: Object t = epp.get(JbiProjectProperties.JBI_CONTENT_ADDITIONAL);
092:
093: if (!(t instanceof List)) {
094: assert false : "JBI content isn't a List???"; // NOI18N
095:
096: return;
097: }
098:
099: List vcpis = (List) t;
100: Iterator iter = vcpis.iterator();
101: keys = new ArrayList();
102:
103: while (iter.hasNext()) {
104: t = iter.next();
105:
106: if (!(t instanceof VisualClassPathItem)) {
107: assert false : "JBI content element isn't a VCPI?????"; // NOI18N
108:
109: continue;
110: }
111:
112: VisualClassPathItem vcpi = (VisualClassPathItem) t;
113: Object obj = vcpi.getObject();
114: AntArtifact aa;
115:
116: if (obj instanceof AntArtifact) {
117: // aa = (AntArtifact) obj;
118: // if (this.jeeTypes.contains(aa.getType())){
119: // continue;
120: // }
121: } else {
122: continue;
123: }
124:
125: keys.add(vcpi);
126: }
127:
128: setKeys(keys);
129: }
130:
131: /**
132: * DOCUMENT ME!
133: */
134: protected void removeNotify() {
135: //epp.removePropertyChangeListener(this);
136: setKeys(Collections.EMPTY_SET);
137: super .removeNotify();
138: }
139:
140: /**
141: * DOCUMENT ME!
142: *
143: * @param key DOCUMENT ME!
144: * @return DOCUMENT ME!
145: */
146: protected Node[] createNodes(Object key) {
147: // interpret your key here...usually one node generated, but could be zero or more
148: VisualClassPathItem vcpi = (VisualClassPathItem) key;
149: Object obj = vcpi.getObject();
150: AntArtifact aa;
151: Node[] ret = null;
152: if (obj instanceof AntArtifact) {
153: aa = (AntArtifact) obj;
154: if (JbiProjectConstants.JAVA_EE_AA_TYPES.contains(aa
155: .getType())) {
156: ret = new Node[] { new JavaEEModuleNode(vcpi,
157: this .project) };
158: } else {
159: ret = new Node[] { new JbiModuleNode(vcpi) };
160: }
161: }
162:
163: return ret;
164: }
165:
166: //
167: // public void update() {
168: // Node[] nodes = getNodes();
169: // updateKeys();
170: // setKeys(nodes);
171: //
172: // }
173:
174: /**
175: * DOCUMENT ME!
176: *
177: * @param ev DOCUMENT ME!
178: */
179: public void modelChanged(Object ev) {
180: // your data model changed, so update the children to match:
181: updateKeys();
182: }
183:
184: /**
185: * DOCUMENT ME!
186: *
187: * @param pce DOCUMENT ME!
188: */
189: public void propertyChange(PropertyChangeEvent pce) {
190: updateKeys();
191: }
192: }
|