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-2006 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: package org.netbeans.modules.collab.channel.filesharing.ui;
042:
043: import org.openide.loaders.DataObject;
044: import org.openide.nodes.*;
045: import org.openide.util.*;
046: import org.openide.util.actions.*;
047:
048: import java.awt.*;
049:
050: import java.beans.*;
051:
052: import java.io.*;
053:
054: import java.util.*;
055:
056: import org.netbeans.modules.collab.channel.filesharing.FilesharingConstants;
057: import org.netbeans.modules.collab.channel.filesharing.FilesharingContext;
058: import org.netbeans.modules.collab.core.Debug;
059:
060: /**
061: *
062: *
063: * @author Todd Fast, todd.fast@sun.com
064: */
065: public class PackagesNode extends AbstractNode implements
066: FilesharingConstants {
067: ////////////////////////////////////////////////////////////////////////////
068: // Class variables
069: ////////////////////////////////////////////////////////////////////////////
070: public static final String ICON_BASE = "org/netbeans/modules/collab/ui/resources/group_png"; // NOI18N
071: private static final SystemAction[] DEFAULT_ACTIONS = new SystemAction[] {};
072: public static final Image PACKAGE_BADGE = Utilities
073: .loadImage(
074: "org/netbeans/modules/collab/channel/filesharing/resources/packageBadge.gif",
075: true); // NOI18N
076:
077: ////////////////////////////////////////////////////////////////////////////
078: // Instance variables
079: ////////////////////////////////////////////////////////////////////////////
080: private static String packageRootPath;
081: private Node originalNode;
082: private boolean isLocal = false;
083: private FilesharingContext context = null;
084:
085: /**
086: *
087: *
088: */
089: public PackagesNode(String displayName, String packageRootPath,
090: Node originalNode, boolean isLocal,
091: FilesharingContext context) {
092: super (new PackagesNodeChildren(originalNode, isLocal, context));
093: this .isLocal = isLocal;
094: this .context = context;
095: Debug.out.println("In PackagesNode ");
096: setName(originalNode.getName());
097:
098: if (displayName != null) {
099: setDisplayName(displayName);
100: } else {
101: setDisplayName(originalNode.getDisplayName());
102: }
103:
104: //setIcon(originalNode.getIcon(0));
105: systemActions = DEFAULT_ACTIONS;
106: this .packageRootPath = packageRootPath;
107: this .originalNode = originalNode;
108: }
109:
110: public String getName(int type) {
111: Debug.out.println("In PackagesNode getName");
112:
113: return originalNode.getName();
114: }
115:
116: public Image getIcon(int type) {
117: return computeIcon(false, type);
118: }
119:
120: public Image getOpenedIcon(int type) {
121: return computeIcon(true, type);
122: }
123:
124: private Image computeIcon(boolean opened, int type) {
125: Image icon = opened ? originalNode
126: .getOpenedIcon(BeanInfo.ICON_COLOR_16x16)
127: : originalNode.getIcon(BeanInfo.ICON_COLOR_16x16);
128:
129: return Utilities.mergeImages(icon, PACKAGE_BADGE, 7, 7);
130: }
131:
132: /**
133: *
134: *
135: */
136: public HelpCtx getHelpCtx() {
137: return new HelpCtx(PackageNode.class);
138: }
139:
140: /**
141: *
142: *
143: */
144: public boolean canCut() {
145: return false;
146: }
147:
148: /**
149: *
150: *
151: */
152: public boolean canCopy() {
153: return false;
154: }
155:
156: /**
157: *
158: *
159: */
160: public boolean canDestroy() {
161: return false;
162: }
163:
164: /**
165: *
166: *
167: */
168: public boolean canRename() {
169: return false;
170: }
171:
172: /**
173: *
174: *
175: */
176: public void destroy() throws IOException {
177: super .destroy();
178: }
179:
180: /**
181: *
182: *
183: */
184: public PackagesNodeChildren getPackagesNodeChildren() {
185: return (PackagesNodeChildren) getChildren();
186: }
187:
188: public static class PackagesNodeChildren extends Children.Keys
189: implements NodeListener, PropertyChangeListener {
190: ////////////////////////////////////////////////////////////////////////////
191: // Instance variables
192: ////////////////////////////////////////////////////////////////////////////
193: private Collection keys;
194: private Node originalNode;
195: private boolean isLocal;
196: private FilesharingContext context = null;
197:
198: /**
199: *
200: *
201: */
202: public PackagesNodeChildren(Node originalNode, boolean isLocal,
203: FilesharingContext context) {
204: super ();
205: Debug.out.println("In PackagesNodeChildren ");
206: this .originalNode = originalNode;
207: this .isLocal = isLocal;
208: this .context = context;
209: }
210:
211: /**
212: *
213: *
214: */
215: public boolean add(Node[] nodes) {
216: Debug.out.println("PSN add: " + nodes.length);
217:
218: for (int i = 0; i < nodes.length; i++) {
219: super .add(createNodes(nodes[i]));
220: }
221:
222: return true;
223: }
224:
225: /**
226: *
227: *
228: */
229: public boolean add(String name, Node[] nodes) {
230: Debug.out.println("PSN add: " + nodes.length);
231:
232: for (int i = 0; i < nodes.length; i++) {
233: super .add(createNodes(name, nodes[i]));
234: }
235:
236: return true;
237: }
238:
239: /**
240: *
241: *
242: */
243: protected void addNotify() {
244: refreshChildren();
245: }
246:
247: /**
248: *
249: *
250: */
251: protected void removeNotify() {
252: _setKeys(Collections.EMPTY_SET);
253: }
254:
255: /**
256: *
257: *
258: */
259: protected Node[] createNodes(Object key) {
260: Node[] result = null;
261:
262: try {
263: Node node = (Node) key;
264: DataObject d = (DataObject) node
265: .getCookie(DataObject.class);
266: String name = DEFAULT_PKG;
267:
268: if (d != null) {
269: name = d.getPrimaryFile().getPath();
270: Debug.out.println("PSN createNode full: " + name);
271: }
272:
273: int lastIndex = name.lastIndexOf(FILE_SEPERATOR);
274:
275: //uri="src/japp/Main.java" if dragNodePath is "C:/test/javaapp/src/japp/Main.java",
276: //project path is "C:/test/javaapp"
277: //"japp"
278: Debug.out.println("PSN createNode projectPath: "
279: + packageRootPath);
280:
281: if (lastIndex > (packageRootPath.length() + 1)) {
282: name = name.substring(packageRootPath.length() + 1,
283: lastIndex);
284: } else {
285: name = DEFAULT_PKG;
286: }
287:
288: Debug.out.println("PSN createNode short: " + name);
289: result = createNodes(name, key);
290: } catch (Exception e) {
291: Debug.debugNotify(e);
292: }
293:
294: return result;
295: }
296:
297: /**
298: *
299: *
300: */
301: protected Node[] createNodes(String name, Object key) {
302: Node[] result = null;
303:
304: try {
305: Node node = (Node) key;
306: DataObject d = (DataObject) node
307: .getCookie(DataObject.class);
308:
309: if ((name == null) || name.equals("")) {
310: name = DEFAULT_PKG;
311: }
312:
313: Node pkg = new PackageNode(name, isLocal, context);
314: pkg.getChildren().add(new Node[] { (Node) key });
315: result = new Node[] { pkg };
316: } catch (Exception e) {
317: Debug.debugNotify(e);
318: }
319:
320: return result;
321: }
322:
323: /**
324: *
325: *
326: */
327: public Collection getKeys() {
328: return keys;
329: }
330:
331: /**
332: *
333: *
334: */
335: public void _setKeys(Collection value) {
336: keys = value;
337: super .setKeys(value);
338: }
339:
340: /**
341: *
342: *
343: */
344: public void refreshChildren() {
345: java.util.List keys = new ArrayList();
346:
347: try {
348: _setKeys(keys);
349: } catch (Exception e) {
350: Debug.errorManager.notify(e);
351: }
352: }
353:
354: /**
355: *
356: *
357: */
358: public void propertyChange(PropertyChangeEvent event) {
359: }
360:
361: /**
362: *
363: *
364: */
365: public void childrenAdded(NodeMemberEvent ev) {
366: // Ignore
367: }
368:
369: /**
370: *
371: *
372: */
373: public void childrenRemoved(NodeMemberEvent ev) {
374: // Ignore
375: }
376:
377: /**
378: *
379: *
380: */
381: public void childrenReordered(NodeReorderEvent ev) {
382: // Ignore
383: }
384:
385: /**
386: *
387: *
388: */
389: public void nodeDestroyed(NodeEvent ev) {
390: refreshChildren();
391: }
392: }
393: }
|