Lines 1-269
Link Here
|
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 |
<html> |
2 |
<html> |
3 |
|
3 |
|
4 |
<head> |
4 |
<head> |
5 |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> |
5 |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> |
6 |
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> |
6 |
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> |
7 |
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2002, 2006. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." > |
7 |
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2002, 2006. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." > |
8 |
<LINK REL="STYLESHEET" HREF="../../book.css" TYPE="text/css"> |
8 |
<LINK REL="STYLESHEET" HREF="../../book.css" TYPE="text/css"> |
9 |
<title>FolderInfoPropertyPage Class After Editing</title> |
9 |
<title>FolderInfoPropertyPage Class After Editing</title> |
10 |
</head> |
10 |
</head> |
11 |
|
11 |
|
12 |
<body bgcolor="#ffffff"> |
12 |
<body bgcolor="#ffffff"> |
13 |
<h1>FolderInfoPropertyPage Class After Editing</h1> |
13 |
<h1>FolderInfoPropertyPage Class After Editing</h1> |
14 |
<p> |
14 |
<p> |
15 |
<pre><samp> |
15 |
<pre><samp> |
16 |
package samples.ui.propertypages; |
16 |
package samples.ui.propertypages; |
17 |
|
17 |
|
18 |
import org.eclipse.rse.files.ui.propertypages.SystemAbstractRemoteFilePropertyPageExtensionAction; |
18 |
import org.eclipse.rse.files.ui.propertypages.SystemAbstractRemoteFilePropertyPageExtensionAction; |
19 |
import org.eclipse.rse.services.clientserver.messages.SystemMessageException; |
19 |
import org.eclipse.rse.services.clientserver.messages.SystemMessageException; |
20 |
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; |
20 |
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; |
21 |
import org.eclipse.rse.ui.SystemWidgetHelpers; |
21 |
import org.eclipse.rse.ui.SystemWidgetHelpers; |
22 |
import org.eclipse.swt.events.SelectionEvent; |
22 |
import org.eclipse.swt.events.SelectionEvent; |
23 |
import org.eclipse.swt.events.SelectionListener; |
23 |
import org.eclipse.swt.events.SelectionListener; |
24 |
import org.eclipse.swt.widgets.Button; |
24 |
import org.eclipse.swt.widgets.Button; |
25 |
import org.eclipse.swt.widgets.Composite; |
25 |
import org.eclipse.swt.widgets.Composite; |
26 |
import org.eclipse.swt.widgets.Control; |
26 |
import org.eclipse.swt.widgets.Control; |
27 |
import org.eclipse.swt.widgets.Display; |
27 |
import org.eclipse.swt.widgets.Display; |
28 |
import org.eclipse.swt.widgets.Label; |
28 |
import org.eclipse.swt.widgets.Label; |
29 |
|
29 |
|
30 |
import samples.RSESamplesPlugin; |
30 |
import samples.RSESamplesPlugin; |
31 |
|
31 |
|
32 |
/** |
32 |
/** |
33 |
* A sample property page for a remote object, which in this case is scoped via the |
33 |
* A sample property page for a remote object, which in this case is scoped via the |
34 |
* extension point xml to only apply to folder objects. |
34 |
* extension point xml to only apply to folder objects. |
35 |
*/ |
35 |
*/ |
36 |
public class FolderInfoPropertyPage |
36 |
public class FolderInfoPropertyPage |
37 |
extends SystemAbstractRemoteFilePropertyPageExtensionAction |
37 |
extends SystemAbstractRemoteFilePropertyPageExtensionAction |
38 |
implements SelectionListener |
38 |
implements SelectionListener |
39 |
{ |
39 |
{ |
40 |
// gui widgets... |
40 |
// gui widgets... |
41 |
private Label sizeLabel, filesLabel, foldersLabel; |
41 |
private Label sizeLabel, filesLabel, foldersLabel; |
42 |
private Button stopButton; |
42 |
private Button stopButton; |
43 |
// state... |
43 |
// state... |
44 |
private int totalSize = 0; |
44 |
private int totalSize = 0; |
45 |
private int totalFolders = 0; |
45 |
private int totalFolders = 0; |
46 |
private int totalFiles = 0; |
46 |
private int totalFiles = 0; |
47 |
private boolean stopped = false; |
47 |
private boolean stopped = false; |
48 |
private Thread workerThread; |
48 |
private Thread workerThread; |
49 |
private Runnable guiUpdater; |
49 |
private Runnable guiUpdater; |
50 |
|
50 |
|
51 |
/** |
51 |
/** |
52 |
* Constructor for FolderInfoPropertyPage. |
52 |
* Constructor for FolderInfoPropertyPage. |
53 |
*/ |
53 |
*/ |
54 |
public FolderInfoPropertyPage() |
54 |
public FolderInfoPropertyPage() |
55 |
{ |
55 |
{ |
56 |
super(); |
56 |
super(); |
57 |
} |
57 |
} |
58 |
|
58 |
|
59 |
// -------------------------- |
59 |
// -------------------------- |
60 |
// Parent method overrides... |
60 |
// Parent method overrides... |
61 |
// -------------------------- |
61 |
// -------------------------- |
62 |
|
62 |
|
63 |
|
63 |
|
64 |
/* (non-Javadoc) |
64 |
/* (non-Javadoc) |
65 |
* @see org.eclipse.rse.files.ui.propertypages.SystemAbstractRemoteFilePropertyPageExtensionAction#createContentArea(org.eclipse.swt.widgets.Composite) |
65 |
* @see org.eclipse.rse.files.ui.propertypages.SystemAbstractRemoteFilePropertyPageExtensionAction#createContentArea(org.eclipse.swt.widgets.Composite) |
66 |
*/ |
66 |
*/ |
67 |
protected Control createContentArea(Composite parent) |
67 |
protected Control createContentArea(Composite parent) |
68 |
{ |
68 |
{ |
69 |
Composite composite = SystemWidgetHelpers.createComposite(parent, 2); |
69 |
Composite composite = SystemWidgetHelpers.createComposite(parent, 2); |
70 |
// draw the gui |
70 |
// draw the gui |
71 |
sizeLabel = SystemWidgetHelpers.createLabeledLabel(composite, |
71 |
sizeLabel = SystemWidgetHelpers.createLabeledLabel(composite, |
72 |
RSESamplesPlugin.getResourceString("pp.size.label"), //$NON-NLS-1$ |
72 |
RSESamplesPlugin.getResourceString("pp.size.label"), //$NON-NLS-1$ |
73 |
RSESamplesPlugin.getResourceString("pp.size.tooltip"), //$NON-NLS-1$ |
73 |
RSESamplesPlugin.getResourceString("pp.size.tooltip"), //$NON-NLS-1$ |
74 |
false); |
74 |
false); |
75 |
filesLabel = SystemWidgetHelpers.createLabeledLabel(composite, |
75 |
filesLabel = SystemWidgetHelpers.createLabeledLabel(composite, |
76 |
RSESamplesPlugin.getResourceString("pp.files.label"), //$NON-NLS-1$ |
76 |
RSESamplesPlugin.getResourceString("pp.files.label"), //$NON-NLS-1$ |
77 |
RSESamplesPlugin.getResourceString("pp.files.tooltip"), //$NON-NLS-1$ |
77 |
RSESamplesPlugin.getResourceString("pp.files.tooltip"), //$NON-NLS-1$ |
78 |
false); |
78 |
false); |
79 |
foldersLabel = SystemWidgetHelpers.createLabeledLabel(composite, |
79 |
foldersLabel = SystemWidgetHelpers.createLabeledLabel(composite, |
80 |
RSESamplesPlugin.getResourceString("pp.folders.label"), //$NON-NLS-1$ |
80 |
RSESamplesPlugin.getResourceString("pp.folders.label"), //$NON-NLS-1$ |
81 |
RSESamplesPlugin.getResourceString("pp.folders.tooltip"), //$NON-NLS-1$ |
81 |
RSESamplesPlugin.getResourceString("pp.folders.tooltip"), //$NON-NLS-1$ |
82 |
false); |
82 |
false); |
83 |
stopButton = SystemWidgetHelpers.createPushButton(composite, null, |
83 |
stopButton = SystemWidgetHelpers.createPushButton(composite, null, |
84 |
RSESamplesPlugin.getResourceString("pp.stopButton.label"), //$NON-NLS-1$ |
84 |
RSESamplesPlugin.getResourceString("pp.stopButton.label"), //$NON-NLS-1$ |
85 |
RSESamplesPlugin.getResourceString("pp.stopButton.tooltip") //$NON-NLS-1$ |
85 |
RSESamplesPlugin.getResourceString("pp.stopButton.tooltip") //$NON-NLS-1$ |
86 |
); |
86 |
); |
87 |
stopButton.addSelectionListener(this); |
87 |
stopButton.addSelectionListener(this); |
88 |
|
88 |
|
89 |
setValid(false); // Disable OK button until thread is done |
89 |
setValid(false); // Disable OK button until thread is done |
90 |
|
90 |
|
91 |
// show "Processing..." message |
91 |
// show "Processing..." message |
92 |
setMessage(RSESamplesPlugin.getPluginMessage("RSSG1002")); //$NON-NLS-1$ |
92 |
setMessage(RSESamplesPlugin.getPluginMessage("RSSG1002")); //$NON-NLS-1$ |
93 |
|
93 |
|
94 |
// create instance of Runnable to allow asynchronous GUI updates from background thread |
94 |
// create instance of Runnable to allow asynchronous GUI updates from background thread |
95 |
guiUpdater = new RunnableGUIClass(); |
95 |
guiUpdater = new RunnableGUIClass(); |
96 |
// spawn a thread to calculate the information |
96 |
// spawn a thread to calculate the information |
97 |
workerThread = new RunnableClass(getRemoteFile()); |
97 |
workerThread = new RunnableClass(getRemoteFile()); |
98 |
workerThread.start(); |
98 |
workerThread.start(); |
99 |
|
99 |
|
100 |
return composite; |
100 |
return composite; |
101 |
} |
101 |
} |
102 |
|
102 |
|
103 |
/** |
103 |
/** |
104 |
* Intercept from PreferencePage. Called when user presses Cancel button. |
104 |
* Intercept from PreferencePage. Called when user presses Cancel button. |
105 |
* We stop the background thread. |
105 |
* We stop the background thread. |
106 |
* @see org.eclipse.jface.preference.PreferencePage#performCancel() |
106 |
* @see org.eclipse.jface.preference.PreferencePage#performCancel() |
107 |
*/ |
107 |
*/ |
108 |
public boolean performCancel() |
108 |
public boolean performCancel() |
109 |
{ |
109 |
{ |
110 |
killThread(); |
110 |
killThread(); |
111 |
return true; |
111 |
return true; |
112 |
} |
112 |
} |
113 |
|
113 |
|
114 |
/** |
114 |
/** |
115 |
* Intercept from DialogPage. Called when dialog going away. |
115 |
* Intercept from DialogPage. Called when dialog going away. |
116 |
* If the user presses the X to close this dialog, we |
116 |
* If the user presses the X to close this dialog, we |
117 |
* need to stop that background thread. |
117 |
* need to stop that background thread. |
118 |
*/ |
118 |
*/ |
119 |
public void dispose() |
119 |
public void dispose() |
120 |
{ |
120 |
{ |
121 |
killThread(); |
121 |
killThread(); |
122 |
super.dispose(); |
122 |
super.dispose(); |
123 |
} |
123 |
} |
124 |
|
124 |
|
125 |
/** |
125 |
/** |
126 |
* Private method to kill our background thread. |
126 |
* Private method to kill our background thread. |
127 |
* Control doesn't return until it ends. |
127 |
* Control doesn't return until it ends. |
128 |
*/ |
128 |
*/ |
129 |
private void killThread() |
129 |
private void killThread() |
130 |
{ |
130 |
{ |
131 |
if (!stopped && workerThread.isAlive()) |
131 |
if (!stopped && workerThread.isAlive()) |
132 |
{ |
132 |
{ |
133 |
stopped = true; |
133 |
stopped = true; |
134 |
try { |
134 |
try { |
135 |
workerThread.join(); // wait for thread to end |
135 |
workerThread.join(); // wait for thread to end |
136 |
} catch (InterruptedException exc) {} |
136 |
} catch (InterruptedException exc) {} |
137 |
} |
137 |
} |
138 |
} |
138 |
} |
139 |
|
139 |
|
140 |
// ------------------------------------------- |
140 |
// ------------------------------------------- |
141 |
// Methods from SelectionListener interface... |
141 |
// Methods from SelectionListener interface... |
142 |
// ------------------------------------------- |
142 |
// ------------------------------------------- |
143 |
|
143 |
|
144 |
/** |
144 |
/** |
145 |
* From SelectionListener |
145 |
* From SelectionListener |
146 |
* @see SelectionListener#widgetSelected(SelectionEvent) |
146 |
* @see SelectionListener#widgetSelected(SelectionEvent) |
147 |
*/ |
147 |
*/ |
148 |
public void widgetSelected(SelectionEvent event) |
148 |
public void widgetSelected(SelectionEvent event) |
149 |
{ |
149 |
{ |
150 |
if (event.getSource() == stopButton) |
150 |
if (event.getSource() == stopButton) |
151 |
{ |
151 |
{ |
152 |
stopped = true; |
152 |
stopped = true; |
153 |
stopButton.setEnabled(false); |
153 |
stopButton.setEnabled(false); |
154 |
} |
154 |
} |
155 |
} |
155 |
} |
156 |
/** |
156 |
/** |
157 |
* From SelectionListener |
157 |
* From SelectionListener |
158 |
* @see SelectionListener#widgetDefaultSelected(SelectionEvent) |
158 |
* @see SelectionListener#widgetDefaultSelected(SelectionEvent) |
159 |
*/ |
159 |
*/ |
160 |
public void widgetDefaultSelected(SelectionEvent event) |
160 |
public void widgetDefaultSelected(SelectionEvent event) |
161 |
{ |
161 |
{ |
162 |
} |
162 |
} |
163 |
|
163 |
|
164 |
// ---------------- |
164 |
// ---------------- |
165 |
// Inner classes... |
165 |
// Inner classes... |
166 |
// ---------------- |
166 |
// ---------------- |
167 |
/** |
167 |
/** |
168 |
* Inner class encapsulating the background work to be done, so it may be executed |
168 |
* Inner class encapsulating the background work to be done, so it may be executed |
169 |
* in background thread. |
169 |
* in background thread. |
170 |
*/ |
170 |
*/ |
171 |
private class RunnableClass extends Thread |
171 |
private class RunnableClass extends Thread |
172 |
{ |
172 |
{ |
173 |
IRemoteFile inputFolder; |
173 |
IRemoteFile inputFolder; |
174 |
|
174 |
|
175 |
RunnableClass(IRemoteFile inputFolder) |
175 |
RunnableClass(IRemoteFile inputFolder) |
176 |
{ |
176 |
{ |
177 |
this.inputFolder = inputFolder; |
177 |
this.inputFolder = inputFolder; |
178 |
} |
178 |
} |
179 |
|
179 |
|
180 |
public void run() |
180 |
public void run() |
181 |
{ |
181 |
{ |
182 |
if (stopped) |
182 |
if (stopped) |
183 |
return; |
183 |
return; |
184 |
walkFolder(inputFolder); |
184 |
walkFolder(inputFolder); |
185 |
updateGUI(); |
185 |
updateGUI(); |
186 |
if (!stopped) |
186 |
if (!stopped) |
187 |
{ |
187 |
{ |
188 |
stopped = true; |
188 |
stopped = true; |
189 |
updateGUI(); |
189 |
updateGUI(); |
190 |
} |
190 |
} |
191 |
} |
191 |
} |
192 |
|
192 |
|
193 |
/** |
193 |
/** |
194 |
* Recursively walk a folder, updating the running tallies. |
194 |
* Recursively walk a folder, updating the running tallies. |
195 |
* Update the GUI after processing each subfolder. |
195 |
* Update the GUI after processing each subfolder. |
196 |
*/ |
196 |
*/ |
197 |
private void walkFolder(IRemoteFile currFolder) |
197 |
private void walkFolder(IRemoteFile currFolder) |
198 |
{ |
198 |
{ |
199 |
try |
199 |
try |
200 |
{ |
200 |
{ |
201 |
IRemoteFile[] folders = currFolder.getParentRemoteFileSubSystem().listFoldersAndFiles( currFolder, null); |
201 |
IRemoteFile[] folders = currFolder.getParentRemoteFileSubSystem().listFoldersAndFiles( currFolder, null); |
202 |
if ((folders != null) && (folders.length>0)) |
202 |
if ((folders != null) && (folders.length>0)) |
203 |
{ |
203 |
{ |
204 |
for (int idx=0; !stopped && (idx<folders.length); idx++) |
204 |
for (int idx=0; !stopped && (idx<folders.length); idx++) |
205 |
{ |
205 |
{ |
206 |
// is this a folder? |
206 |
// is this a folder? |
207 |
if (folders[idx].isDirectory()) |
207 |
if (folders[idx].isDirectory()) |
208 |
{ |
208 |
{ |
209 |
++totalFolders; |
209 |
++totalFolders; |
210 |
walkFolder(folders[idx]); |
210 |
walkFolder(folders[idx]); |
211 |
updateGUI(); |
211 |
updateGUI(); |
212 |
} |
212 |
} |
213 |
// is this a file? |
213 |
// is this a file? |
214 |
else |
214 |
else |
215 |
{ |
215 |
{ |
216 |
++totalFiles; |
216 |
++totalFiles; |
217 |
totalSize += folders[idx].getLength(); |
217 |
totalSize += folders[idx].getLength(); |
218 |
} |
218 |
} |
219 |
} |
219 |
} |
220 |
} |
220 |
} |
221 |
} |
221 |
} |
222 |
catch (SystemMessageException e) |
222 |
catch (SystemMessageException e) |
223 |
{ |
223 |
{ |
224 |
|
224 |
|
225 |
} |
225 |
} |
226 |
} // end of walkFolder method |
226 |
} // end of walkFolder method |
227 |
|
227 |
|
228 |
} // end of inner class |
228 |
} // end of inner class |
229 |
|
229 |
|
230 |
/** |
230 |
/** |
231 |
* Inner class encapsulating the GUI work to be done from the |
231 |
* Inner class encapsulating the GUI work to be done from the |
232 |
* background thread. |
232 |
* background thread. |
233 |
*/ |
233 |
*/ |
234 |
private class RunnableGUIClass implements Runnable |
234 |
private class RunnableGUIClass implements Runnable |
235 |
{ |
235 |
{ |
236 |
public void run() |
236 |
public void run() |
237 |
{ |
237 |
{ |
238 |
if (stopButton.isDisposed()) |
238 |
if (stopButton.isDisposed()) |
239 |
return; |
239 |
return; |
240 |
if (!stopped) |
240 |
if (!stopped) |
241 |
{ |
241 |
{ |
242 |
sizeLabel.setText(Integer.toString(totalSize)); |
242 |
sizeLabel.setText(Integer.toString(totalSize)); |
243 |
filesLabel.setText(Integer.toString(totalFiles)); |
243 |
filesLabel.setText(Integer.toString(totalFiles)); |
244 |
foldersLabel.setText(Integer.toString(totalFolders)); |
244 |
foldersLabel.setText(Integer.toString(totalFolders)); |
245 |
} |
245 |
} |
246 |
else if (stopped) |
246 |
else if (stopped) |
247 |
{ |
247 |
{ |
248 |
setValid(true); // re-enable OK button |
248 |
setValid(true); // re-enable OK button |
249 |
stopButton.setEnabled(false); // disable Stop button |
249 |
stopButton.setEnabled(false); // disable Stop button |
250 |
clearMessage(); // clear "Processing..." message |
250 |
clearMessage(); // clear "Processing..." message |
251 |
} |
251 |
} |
252 |
} |
252 |
} |
253 |
} |
253 |
} |
254 |
|
254 |
|
255 |
|
255 |
|
256 |
/** |
256 |
/** |
257 |
* Update the GUI with the current status |
257 |
* Update the GUI with the current status |
258 |
*/ |
258 |
*/ |
259 |
private void updateGUI() |
259 |
private void updateGUI() |
260 |
{ |
260 |
{ |
261 |
Display.getDefault().asyncExec(guiUpdater); |
261 |
Display.getDefault().asyncExec(guiUpdater); |
262 |
} |
262 |
} |
263 |
|
263 |
|
264 |
|
264 |
|
265 |
} |
265 |
} |
266 |
</samp></pre> |
266 |
</samp></pre> |
267 |
</p> |
267 |
</p> |
268 |
</body> |
268 |
</body> |
269 |
</html> |
269 |
</html> |