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.loaders.DataShadow;
045: import org.openide.nodes.*;
046: import org.openide.util.NbBundle;
047: import org.openide.util.Utilities;
048: import org.openide.util.actions.SystemAction;
049: import org.openide.util.datatransfer.*;
050:
051: import java.awt.Image;
052: import java.awt.datatransfer.*;
053:
054: import java.util.ArrayList;
055: import java.util.List;
056:
057: import javax.swing.Action;
058:
059: import org.netbeans.modules.collab.channel.filesharing.FilesharingConstants;
060: import org.netbeans.modules.collab.channel.filesharing.FilesharingContext;
061: import org.netbeans.modules.collab.channel.filesharing.ui.actions.UnShareFileAction;
062: import org.netbeans.modules.collab.core.Debug;
063:
064: /**
065: *
066: * @author Todd Fast, todd.fast@sun.com
067: */
068: public class SharedProjectNode extends FilterNode implements
069: FilesharingConstants {
070: ////////////////////////////////////////////////////////////////////////////
071: // Instance variables
072: ////////////////////////////////////////////////////////////////////////////
073: private Node originalNode;
074: private boolean isLocal = false;
075: private boolean isFolder = true;
076: private FilesharingContext context = null;
077: private String displayName = null;
078: private Image badge;
079:
080: /**
081: *
082: *
083: */
084: public SharedProjectNode(Node node, boolean isLocal,
085: FilesharingContext context) {
086: this (node.getName(), node, isLocal, context);
087: }
088:
089: /**
090: *
091: *
092: */
093: public SharedProjectNode(String displayName, Node node,
094: boolean isLocal, FilesharingContext context) {
095: super (node, new SharedProjectNodeChildren(node, isLocal,
096: context));
097: this .originalNode = node;
098: this .isLocal = isLocal;
099: this .context = context;
100: init(displayName, node);
101: }
102:
103: /**
104: *
105: *
106: */
107: public SharedProjectNode(Node node, boolean isLocal,
108: FilesharingContext context, boolean canHaveChild) {
109: super (node);
110: this .originalNode = node;
111: this .isLocal = isLocal;
112: this .context = context;
113: init(node.getName(), node);
114: }
115:
116: private void init(String displayName, Node node) {
117: DataObject d = (DataObject) node.getCookie(DataObject.class);
118: if (d != null && d.getPrimaryFile() != null
119: && d.getPrimaryFile().isData())
120: this .isFolder = false;
121: setDisplayName(displayName, node);
122: }
123:
124: private void setDisplayName(String name, Node node) {
125: this .displayName = name;
126:
127: if (displayName.equals(WEB_FOLDER_NAME)) {
128: badge = Utilities
129: .loadImage("org/netbeans/modules/web/project/ui/resources/webPagesBadge.gif"); //NOI18N
130: }
131:
132: DataObject d = (DataObject) node.getCookie(DataObject.class);
133:
134: if (!this .isFolder) {
135: displayName = d.getPrimaryFile().getNameExt();
136: }
137:
138: try { //if lnk change displayName
139:
140: DataShadow lnk = (DataShadow) node
141: .getCookie(DataShadow.class);
142:
143: if (lnk != null) {
144: Debug.out.println("SPN Original node path: "
145: + lnk.getOriginal().getPrimaryFile().getPath());
146: displayName = lnk.getOriginal().getPrimaryFile()
147: .getNameExt();
148: }
149: } catch (Throwable th) {
150: th.printStackTrace(Debug.out);
151: }
152: }
153:
154: /**
155: *
156: *
157: */
158: public String getDisplayName() {
159: return NbBundle.getMessage(SharedProjectNode.class,
160: "LBL_SharedFileNode_FileAnnotation",
161: (this .displayName != null) ? this .displayName : super
162: .getDisplayName());
163: }
164:
165: public Image getIcon(int type) {
166: return computeIcon(false, type);
167: }
168:
169: public Image getOpenedIcon(int type) {
170: return computeIcon(true, type);
171: }
172:
173: private Image computeIcon(boolean opened, int type) {
174: Image image = opened ? originalNode.getOpenedIcon(type)
175: : originalNode.getIcon(type);
176:
177: if (this .badge != null) {
178: image = Utilities.mergeImages(image, this .badge, 7, 7);
179: }
180:
181: return image;
182: }
183:
184: /**
185: *
186: *
187: */
188: public PasteType getDropType(Transferable transferable, int action,
189: int index) {
190: // We need to filter out "move" as an option, lest the user
191: // accidentally move their original file to the conversation
192:
193: /*if (action!=DnDConstants.ACTION_COPY)
194: {
195: return null;
196: }
197: return super.getDropType(transferable,action,index);*/
198: return null;
199: }
200:
201: public PasteType[] getPasteTypes(Transferable t) {
202: return new PasteType[] {};
203: }
204:
205: public NewType[] getNewTypes() {
206: return new NewType[] {};
207: }
208:
209: public Action[] getActions(boolean ctx) {
210: Debug.out.println("SPN getActions: ");
211:
212: SystemAction[] actions = super .getActions();
213: Debug.out.println("SPN getActions: " + actions);
214:
215: List newActions = new ArrayList();
216:
217: for (int i = 0; i < actions.length; i++) {
218: Action action = actions[i];
219:
220: if (action != null) {
221: String displayName = (String) action
222: .getValue(Action.NAME);
223: Debug.out.println("action displayName: " + displayName);
224:
225: if (displayName.equals("Edit")) //NoI18n
226: {
227: newActions.add(actions[i]);
228: }
229: }
230: }
231:
232: if (isLocal && !isFolder) {
233: newActions.add(new UnShareFileAction(this .context, this ));
234: }
235:
236: return (SystemAction[]) newActions.toArray(new SystemAction[0]);
237: }
238:
239: public boolean canCopy() {
240: return true;
241: }
242:
243: public boolean canCut() {
244: return false;
245: }
246:
247: public boolean canDestroy() {
248: return false;
249: }
250:
251: public boolean canRename() {
252: return false;
253: }
254:
255: public Transferable clipboardCut() {
256: return null;
257: }
258:
259: /** Represents children of SharedProjectNode
260: *
261: */
262: private static class SharedProjectNodeChildren extends
263: FilterNode.Children {
264: private boolean isLocal;
265: private FilesharingContext context = null;
266:
267: /**
268: *
269: *
270: */
271: public SharedProjectNodeChildren(Node node, boolean isLocal,
272: FilesharingContext context) {
273: super (node);
274: this .isLocal = isLocal;
275: this .context = context;
276: }
277:
278: /**
279: *
280: *
281: */
282: public boolean add(Node[] nodes) {
283: Debug.out.println("SPN add: " + nodes.length);
284:
285: for (int i = 0; i < nodes.length; i++) {
286: if (super .findChild(nodes[i].getName()) == null) {
287: super .add(createNodes(nodes[i]));
288: }
289: }
290:
291: return true;
292: }
293:
294: /**
295: *
296: *
297: */
298: protected Node[] createNodes(Node node) {
299: Debug.out.println("In SPN: createNodes");
300:
301: Node[] result = null;
302:
303: try {
304: DataObject d = (DataObject) node
305: .getCookie(DataObject.class);
306:
307: if (d != null) {
308: if (d.getPrimaryFile().isData()) {
309: String fileName = d.getPrimaryFile()
310: .getNameExt();
311:
312: if (fileName.equals(".nbattrs")) {
313: return new Node[] {};
314: }
315:
316: result = new Node[] { new SharedProjectNode(d
317: .getNodeDelegate(), isLocal, context,
318: false) };
319: } else {
320: result = new Node[] { new SharedProjectNode(d
321: .getNodeDelegate(), isLocal, context) };
322: }
323: }
324: } catch (Exception e) {
325: Debug.debugNotify(e);
326: }
327:
328: return result;
329: }
330: }
331: }
|