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.explorer.*;
044: import org.openide.explorer.view.*;
045: import org.openide.filesystems.*;
046: import org.openide.loaders.*;
047: import org.openide.nodes.*;
048: import org.openide.util.*;
049:
050: import java.awt.*;
051: import java.awt.dnd.*;
052:
053: import java.beans.*;
054:
055: import java.io.*;
056:
057: import java.util.*;
058:
059: import javax.swing.*;
060: import javax.swing.text.*;
061: import javax.swing.tree.TreeCellRenderer;
062:
063: import org.netbeans.modules.collab.channel.filesharing.FilesharingCollablet;
064: import org.netbeans.modules.collab.channel.filesharing.FilesharingConstants;
065: import org.netbeans.modules.collab.channel.filesharing.FilesharingContext;
066: import org.netbeans.modules.collab.channel.filesharing.eventhandler.SyncWaitPanel;
067: import org.netbeans.modules.collab.core.Debug;
068:
069: /**
070: * Panel for FilesharingCollablet Filesystem Explorer
071: *
072: * @author Todd Fast <todd.fast@sun.com>
073: * @version 1.0
074: */
075: public class FilesystemExplorerPanel extends JPanel implements
076: ExplorerManager.Provider, Lookup.Provider,
077: PropertyChangeListener, FilesharingConstants {
078: ////////////////////////////////////////////////////////////////////////////
079: // Class variables
080: ////////////////////////////////////////////////////////////////////////////
081: private static final long serialVersionUID = 1L; // DO NOT CHANGE!
082:
083: ////////////////////////////////////////////////////////////////////////////
084: // Instance variables
085: ////////////////////////////////////////////////////////////////////////////
086: private BeanTreeView treeView;
087: private JLabel statusLine = new JLabel(" ");
088: private FilesharingContext context;
089: private ExplorerManager explorerManager;
090: private Lookup lookup;
091: private DataObject dataObject = null;
092: private FileObject file = null;
093: private HashMap someMap = new HashMap();
094: private int number = 0;
095: private ProjectsRootNode rootNode = null;
096: private Node expandTreeNode;
097: private int fileCount = 0;
098: private String statusMessage = "";
099:
100: /**
101: *
102: * @param channel
103: */
104: public FilesystemExplorerPanel(FilesharingContext context) {
105: super ();
106: this .context = context;
107: initialize();
108: enablePanel();
109: context.setFilesystemExplorer(this );
110: }
111:
112: /**
113: *
114: *
115: */
116: protected void initialize() {
117: setLayout(new BorderLayout());
118:
119: // Reduce the preferred size to a reasonable one
120: setPreferredSize(new Dimension(300, 200));
121:
122: // Create explorer tree
123: treeView = new BeanTreeView();
124: treeView.setBorder(UIManager.getBorder("ScrollPane.border"));
125: treeView.setRootVisible(true);
126: treeView.setAllowedDropActions(DnDConstants.ACTION_COPY);
127:
128: //treeView.setAllowedDragActions(DnDConstants.ACTION_COPY_OR_MOVE);
129: if (getContext().isReadOnlyConversation()) {
130: treeView.setDropTarget(true);
131: }
132:
133: add(treeView, BorderLayout.CENTER);
134:
135: // Add the status line
136: JPanel statusLinePanel = new JPanel();
137: statusLinePanel.setLayout(new BorderLayout());
138: statusLine.setBorder(new ThinBevelBorder(
139: ThinBevelBorder.LOWERED));
140: statusLinePanel.add(statusLine, BorderLayout.CENTER);
141: add(statusLinePanel, BorderLayout.SOUTH);
142: setStatusLineText(NbBundle.getMessage(
143: FilesystemExplorerPanel.class,
144: "LBL_FilesystemExplorerPanel_NumFiles", new Integer(0)));
145:
146: // Populate the action map
147: ActionMap map = getActionMap();
148: map.put(DefaultEditorKit.copyAction, ExplorerUtils
149: .actionCopy(getExplorerManager()));
150:
151: // map.put(DefaultEditorKit.cutAction,
152: // ExplorerUtils.actionCut(getExplorerManager()));
153: map.put(DefaultEditorKit.pasteAction, ExplorerUtils
154: .actionPaste(getExplorerManager()));
155: map.put("delete", ExplorerUtils.actionDelete(
156: getExplorerManager(), true)); // or false
157:
158: // Create the lookup
159: lookup = ExplorerUtils.createLookup(getExplorerManager(), map);
160:
161: try {
162: FileSystem filesystem = getContext().getCollabFilesystem();
163:
164: if (filesystem == null) {
165: throw new IllegalArgumentException(
166: "Filesystem was null");
167: }
168:
169: Debug.log("CollabFileHandlerSupport",
170: "FilesystemExplorerPanel, user: "
171: + context.getLoginUser());
172: rootNode = new ProjectsRootNode(filesystem);
173: getExplorerManager().setRootContext(rootNode);
174: rootNode.init();
175: } catch (Exception e) {
176: // TODO: Proper error handling
177: Debug.errorManager.notify(e);
178: }
179:
180: // Accessibility
181: getAccessibleContext().setAccessibleName(
182: NbBundle.getMessage(FilesystemExplorerPanel.class,
183: "ACSD_FilesystemExplorerPanel_Name")); // NOI18N
184: getAccessibleContext().setAccessibleDescription(
185: NbBundle.getMessage(FilesystemExplorerPanel.class,
186: "ACSD_FilesystemExplorerPanel_Description")); // NOI18N
187:
188: setHelpCtx();
189: }
190:
191: /**
192: *set help ctx map id for context sensitive help
193: *
194: */
195: private void setHelpCtx() {
196: HelpCtx.setHelpIDString(this , "collab_sharing_files"); //NOI18n
197: }
198:
199: /**
200: * updateStatusLineText
201: *
202: * @param fileEvent
203: * @param fileCreated
204: */
205: public void updateStatusLineText(int fileCount, String statusMessage) {
206: this .fileCount = fileCount;
207: this .statusMessage = statusMessage;
208:
209: String value = NbBundle.getMessage(
210: FilesystemExplorerPanel.class,
211: "LBL_FilesystemExplorerPanel_NumFiles", new Integer(
212: fileCount));
213: setStatusLineText(value + " " + statusMessage);
214: }
215:
216: /**
217: *
218: * @return filesharing context
219: */
220: public FilesharingContext getContext() {
221: return this .context;
222: }
223:
224: /**
225: *
226: * @return explorer manager
227: */
228: public synchronized ExplorerManager getExplorerManager() {
229: if (explorerManager == null) {
230: explorerManager = new ExplorerManager();
231: explorerManager.addPropertyChangeListener(this );
232: }
233:
234: return explorerManager;
235: }
236:
237: /**
238: *
239: * @return ide lookup
240: */
241: public Lookup getLookup() {
242: return lookup;
243: }
244:
245: /**
246: *
247: *
248: */
249: public void addNotify() {
250: super .addNotify();
251: ExplorerUtils.activateActions(getExplorerManager(), true);
252: }
253:
254: /**
255: *
256: *
257: */
258: public void removeNotify() {
259: ExplorerUtils.activateActions(getExplorerManager(), false);
260: super .removeNotify();
261: }
262:
263: /**
264: *
265: * @param event
266: */
267: public void propertyChange(PropertyChangeEvent event) {
268: if (event.getSource() instanceof ExplorerManager
269: && ExplorerManager.PROP_SELECTED_NODES.equals(event
270: .getPropertyName())) {
271: ((FilesharingCollablet) getContext().getChannel())
272: .fireNodeSelectionChange((Node[]) event
273: .getNewValue());
274: } else if (event.getPropertyName().equals(FILE_COUNT_CHANGED)) {
275: final int fileCount = ((Integer) event.getNewValue())
276: .intValue();
277: Debug.out.println("FEP::fileCount:" + fileCount);
278: SwingUtilities.invokeLater(new Runnable() {
279: public void run() {
280: updateStatusLineText(fileCount, statusMessage);
281: }
282: });
283: } else if (event.getPropertyName().equals(FS_STATUS_CHANGE)) {
284: final String statusMessage = ((String) event.getNewValue());
285: Debug.out.println("FEP::message:" + statusMessage);
286: SwingUtilities.invokeLater(new Runnable() {
287: public void run() {
288: updateStatusLineText(fileCount, statusMessage);
289: }
290: });
291: }
292: }
293:
294: /**
295: *
296: * @return status line text
297: */
298: public String getStatusLineText() {
299: return statusLine.getText();
300: }
301:
302: /**
303: *
304: * @param value
305: */
306: public void setStatusLineText(String value) {
307: Debug.out.println("FEP:setStatusLineText" + value);
308: statusLine.setText(" " + value);
309: statusLine.setToolTipText(value);
310: }
311:
312: /*
313: * enable DnD, copy/paste, New
314: *
315: */
316: public void setDropFile(boolean enable) {
317: try {
318: treeView.setDropTarget(enable);
319: } catch (Throwable th) {
320: //ignore, may be the file drop support is not available
321: Debug.log("CollabFileHandlerSupport",
322: "FilesystemExplorerPanel, " + //NoI18n
323: "setDropFile failed"); //NoI18n
324: Debug.logDebugException("FilesystemExplorerPanel, " + //NoI18n
325: "setDropFile failed", //NoI18n
326: th, true);
327: }
328: }
329:
330: /*
331: * is DnD, copy/paste, New
332: *
333: */
334: public boolean isDropFile() {
335: return treeView.isDropTarget();
336: }
337:
338: /*
339: * enable
340: *
341: */
342: public void enablePanel() {
343: Debug.out.println("FEP: enablePanel");
344:
345: String message = "";
346: updateStatusLineText(this .fileCount, message);
347: treeView.setEnabled(true);
348:
349: //hack, to hide wait dialog
350: SwingUtilities.invokeLater(new Runnable() {
351: public void run() {
352: SyncWaitPanel.hideDialog();
353: }
354: });
355: }
356:
357: /*
358: * disable
359: *
360: */
361: public void disablePanel() {
362: Debug.out.println("FEP: disablePanel");
363:
364: String message = NbBundle.getMessage(
365: FilesystemExplorerPanel.class,
366: "LBL_FilesystemExplorerPanel_PauseMessage");
367: updateStatusLineText(this .fileCount, message);
368: treeView.setEnabled(false);
369: }
370:
371: /*
372: * createProjectNode
373: *
374: * @return projectNode
375: */
376: public Node createProjectNode(String name, String projectName)
377: throws IOException {
378: return getRootNode().createProjectNode(name, projectName);
379: }
380:
381: public BeanTreeView getBeanTree() {
382: return treeView;
383: }
384:
385: /*
386: * getRootNode
387: *
388: */
389: public ProjectsRootNode getRootNode() {
390: return rootNode;
391: }
392:
393: public void expandAllTree() {
394: SwingUtilities.invokeLater(new Runnable() {
395: public void run() {
396: try {
397: getBeanTree().expandAll();
398: } catch (Throwable th) {
399: //ignore
400: }
401: }
402: });
403: }
404:
405: public void expandTreeNode(String path) {
406: expandTreeNode(null, path);
407: }
408:
409: public void expandTreeNode(Node destNode, final String path) {
410: expandTreeNode = destNode;
411: SwingUtilities.invokeLater(new Runnable() {
412: public void run() {
413: try {
414: if (expandTreeNode == null) {
415: expandTreeNode = getRootNode();
416: }
417:
418: if ((path == null) || (path.length() == 0)) {
419: getBeanTree().expandNode(expandTreeNode);
420:
421: return;
422: }
423:
424: String[] paths = path.split(FILE_SEPERATOR);
425:
426: for (int j = 0; j < paths.length; j++) {
427: Debug.out.println("paths: " + paths[j]);
428:
429: if ((expandTreeNode != null)
430: && (expandTreeNode.getChildren() != null)) {
431: expandTreeNode = expandTreeNode
432: .getChildren().findChild(paths[j]);
433: } else {
434: Debug.out
435: .println("expandTreeNode children null: "
436: + paths[j]);
437: }
438: }
439:
440: if (expandTreeNode != null) {
441: getBeanTree().expandNode(expandTreeNode);
442: }
443: } catch (Throwable th) {
444: //ignore
445: }
446: }
447: });
448: }
449:
450: }
|