18 * |
18 * |
19 * CDDL HEADER END |
19 * CDDL HEADER END |
20 */ |
20 */ |
21 |
21 |
22 /* |
22 /* |
23 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
23 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
24 */ |
24 */ |
25 |
25 |
26 package com.oracle.solaris.vp.panel.common.api.file; |
26 package com.oracle.solaris.vp.panel.common.api.file; |
27 |
27 |
28 import java.io.*; |
28 import java.io.*; |
29 import java.lang.reflect.UndeclaredThrowableException; |
29 import java.lang.reflect.UndeclaredThrowableException; |
30 import java.util.*; |
30 import java.util.*; |
31 import javax.swing.*; |
31 import javax.swing.*; |
32 import javax.swing.filechooser.FileSystemView; |
32 import javax.swing.filechooser.FileSystemView; |
33 import com.oracle.solaris.adr.Stability; |
33 import com.oracle.solaris.rad.client.RadObjectException; |
34 import com.oracle.solaris.rad.ObjectException; |
|
35 import com.oracle.solaris.vp.panel.common.*; |
34 import com.oracle.solaris.vp.panel.common.*; |
36 import com.oracle.solaris.vp.util.misc.IOUtil; |
35 import com.oracle.solaris.vp.util.misc.IOUtil; |
37 |
36 |
38 public class RemoteFileSystemView extends FileSystemView { |
37 public class RemoteFileSystemView extends FileSystemView { |
39 // |
38 // |
40 // Instance data |
39 // Instance data |
41 // |
40 // |
42 |
41 |
43 private MXBeanTracker<FileBrowserMXBean> tracker; |
42 private BeanTracker<FileBrowser> tracker; |
44 |
43 |
45 // |
44 // |
46 // Constructors |
45 // Constructors |
47 // |
46 // |
48 |
47 |
49 public RemoteFileSystemView(ClientContext context) |
48 public RemoteFileSystemView(ClientContext context) |
50 throws TrackerException { |
49 throws TrackerException { |
51 |
50 |
52 tracker = new MXBeanTracker<FileBrowserMXBean>( |
51 tracker = new BeanTracker<FileBrowser>( |
53 FileBrowserUtil.OBJECT_NAME, FileBrowserMXBean.class, |
52 (new FileBrowser()).getName(), FileBrowser.class, context); |
54 Stability.PRIVATE, context); |
|
55 } |
53 } |
56 |
54 |
57 // |
55 // |
58 // FileSystemView methods |
56 // FileSystemView methods |
59 // |
57 // |
67 } |
65 } |
68 |
66 |
69 @Override |
67 @Override |
70 public RemoteFile createFileObject(String path) { |
68 public RemoteFile createFileObject(String path) { |
71 try { |
69 try { |
72 FileBrowserMXBean browser = tracker.getBean(); |
70 FileBrowser browser = tracker.getBean(); |
73 FileSnapshot snap = browser.getFile(path); |
71 FileSnapshot snap = browser.getFile(path); |
74 return snap != null ? |
72 return snap != null ? |
75 new RemoteFile(browser, browser.getFile(path)) : null; |
73 new RemoteFile(browser, browser.getFile(path)) : null; |
76 } catch (ObjectException ex) { |
74 } catch (RadObjectException ex) { |
77 return null; |
75 return null; |
78 } |
76 } |
79 } |
77 } |
80 |
78 |
81 @Override |
79 @Override |
105 |
103 |
106 @Override |
104 @Override |
107 public RemoteFile[] getFiles(File dir, boolean useFileHiding) { |
105 public RemoteFile[] getFiles(File dir, boolean useFileHiding) { |
108 List<RemoteFile> files = new ArrayList<RemoteFile>(); |
106 List<RemoteFile> files = new ArrayList<RemoteFile>(); |
109 |
107 |
110 FileBrowserMXBean browser = tracker.getBean(); |
108 FileBrowser browser = tracker.getBean(); |
111 List<FileSnapshot> snapshots; |
109 List<FileSnapshot> snapshots; |
112 try { |
110 try { |
113 snapshots = browser.getFiles(dir.getAbsolutePath()); |
111 snapshots = browser.getFiles(dir.getAbsolutePath()); |
114 } catch (ObjectException e) { |
112 } catch (RadObjectException e) { |
115 return (new RemoteFile[0]); |
113 return (new RemoteFile[0]); |
116 } catch (java.lang.reflect.UndeclaredThrowableException e) { |
114 } catch (java.lang.reflect.UndeclaredThrowableException e) { |
117 /* |
115 /* |
118 * Our caller, BasicDirectoryModel, may interrupt us at |
116 * Our caller, BasicDirectoryModel, may interrupt us at |
119 * any time. This can cause exceptions to be thrown. |
117 * any time. This can cause exceptions to be thrown. |
120 * In our case, our transport may throw an exception |
118 * In our case, our transport may throw an exception |
121 * which is mapped by the MBean proxy to a |
119 * which is mapped by the proxy to a |
122 * UndeclaredThrowableException. |
120 * UndeclaredThrowableException. |
123 * |
121 * |
124 * Unfortunately, the FileSystemView interface doesn't |
122 * Unfortunately, the FileSystemView interface doesn't |
125 * allow us to throw exceptions, and letting an |
123 * allow us to throw exceptions, and letting an |
126 * unchecked exception by results in noise to the |
124 * unchecked exception by results in noise to the |
150 public RemoteFile getParentDirectory(File dir) { |
148 public RemoteFile getParentDirectory(File dir) { |
151 return toRemoteFile(dir).getParentFile(); |
149 return toRemoteFile(dir).getParentFile(); |
152 } |
150 } |
153 |
151 |
154 public RemoteFile[] getRoots() { |
152 public RemoteFile[] getRoots() { |
155 FileBrowserMXBean browser = tracker.getBean(); |
153 FileBrowser browser = tracker.getBean(); |
156 List<FileSnapshot> snapshots = browser.getroots(); |
154 List<FileSnapshot> snapshots = browser.getroots(); |
157 return RemoteFile.toFiles(browser, snapshots); |
155 return RemoteFile.toFiles(browser, snapshots); |
158 } |
156 } |
159 |
157 |
160 @Override |
158 @Override |