1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package com.mindtree.techworks.insight.download.sftpbrowse.test;
26
27 import java.awt.Dimension;
28 import java.awt.HeadlessException;
29 import java.awt.Rectangle;
30 import java.awt.event.WindowAdapter;
31 import java.awt.event.WindowEvent;
32 import java.io.File;
33 import java.io.IOException;
34 import java.net.PasswordAuthentication;
35 import java.util.logging.LogManager;
36 import java.util.logging.Logger;
37
38 import javax.swing.JFileChooser;
39 import javax.swing.JFrame;
40
41 import com.mindtree.techworks.insight.download.ftpbrowse.FTPFileFile;
42 import com.mindtree.techworks.insight.download.ftpbrowse.test.FileChooserTestFrame;
43 import com.mindtree.techworks.insight.download.sftpbrowse.SFTPBrowseException;
44 import com.mindtree.techworks.insight.download.sftpbrowse.SFTPRemoteFileSystemView;
45 import com.mindtree.techworks.insight.gui.widgets.InsightRemoteFileChooser;
46
47
48
49
50
51
52
53
54
55
56 public class SFTPFileChooserTestFrame extends JFrame {
57
58
59
60 private static final long serialVersionUID = -4542730691957729838L;
61
62
63
64
65 private static final Logger logger = Logger.getLogger(FileChooserTestFrame.class.getName());
66
67
68
69
70 public SFTPFileChooserTestFrame() throws HeadlessException {
71
72 super();
73
74 addWindowListener(new WindowAdapter() {
75 public void windowClosing(WindowEvent aEvent) {
76 System.exit(0);
77 }
78 });
79 Dimension dim = getToolkit().getScreenSize();
80 Rectangle abounds = getBounds();
81 setLocation((dim.width - abounds.width) / 2,
82 (dim.height - abounds.height) / 2);
83 setVisible(true);
84
85 char[] password = "spnr".toCharArray();
86 PasswordAuthentication passwordAuthentication = new PasswordAuthentication("spnr", password);
87
88 SFTPRemoteFileSystemView remoteFileSystemView = null;
89 try {
90 remoteFileSystemView = new SFTPRemoteFileSystemView(
91 "cendantstp", null,passwordAuthentication, this);
92 } catch (SFTPBrowseException e) {
93 e.printStackTrace();
94 System.exit(1);
95 }
96 JFileChooser fileChooser = new InsightRemoteFileChooser(remoteFileSystemView);
97 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
98 fileChooser.setMultiSelectionEnabled(true);
99
100 File[] selectedFiles = null;
101 if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
102 selectedFiles = fileChooser.getSelectedFiles();
103 for (int i = 0; i < selectedFiles.length; i++ ) {
104 if (selectedFiles[i] instanceof FTPFileFile) {
105 FTPFileFile ftpFile = (FTPFileFile) selectedFiles[i];
106 logger.fine(ftpFile.getName());
107 logger.fine(ftpFile.getPath());
108 } else {
109 logger.fine(selectedFiles[i].toString());
110 logger.fine(selectedFiles[i].getAbsolutePath());
111 }
112 }
113 }
114 remoteFileSystemView.disconnect();
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 System.exit(0);
147 }
148
149
150
151
152
153 public static void main(String[] args) {
154
155
156
157 LogManager logManager = LogManager.getLogManager();
158 try {
159 logManager
160 .readConfiguration(FileChooserTestFrame.class.getClassLoader()
161 .getResourceAsStream("com/mindtree/logging/download/ftpbrowse/test/logging.properties"));
162 } catch (SecurityException e1) {
163
164 e1.printStackTrace();
165 } catch (IOException e1) {
166
167 e1.printStackTrace();
168 }
169
170
171 try {
172 SFTPFileChooserTestFrame fileChooserTestFrame = new SFTPFileChooserTestFrame();
173 fileChooserTestFrame.getHeight();
174 } catch (HeadlessException e) {
175
176 e.printStackTrace();
177 }
178 }
179 }