1
1
package edu .rice .cs .hpcviewer .ui .dialogs ;
2
2
3
- import java .io .File ;
4
- import java .io .FileInputStream ;
5
3
import java .io .IOException ;
6
4
import java .util .List ;
7
5
8
6
import org .eclipse .core .internal .runtime .Activator ;
9
7
import org .eclipse .core .runtime .Platform ;
10
8
import org .eclipse .jface .dialogs .Dialog ;
11
9
import org .eclipse .jface .dialogs .IDialogConstants ;
10
+ import org .eclipse .jface .dialogs .MessageDialog ;
12
11
import org .eclipse .swt .SWT ;
13
12
import org .eclipse .swt .graphics .Point ;
14
13
import org .eclipse .swt .layout .FillLayout ;
19
18
import org .eclipse .swt .widgets .Text ;
20
19
21
20
import edu .rice .cs .hpclog .LogProperty ;
21
+ import edu .rice .cs .hpcviewer .ui .util .FileUtility ;
22
22
23
23
public class InfoLogDialog extends Dialog
24
24
{
25
+ private Text wText ;
26
+
25
27
public InfoLogDialog (Shell shell ) {
26
28
super (shell );
27
29
}
@@ -36,6 +38,64 @@ protected boolean isResizable() {
36
38
protected Control createDialogArea (Composite parent ) {
37
39
Composite content = (Composite ) super .createDialogArea (parent );
38
40
41
+ wText = new Text (content , SWT .MULTI | SWT .READ_ONLY | SWT .V_SCROLL | SWT .H_SCROLL );
42
+ fillText ();
43
+
44
+ content .setLayout (new FillLayout ());
45
+
46
+ return content ;
47
+ }
48
+
49
+ @ Override
50
+ protected Point getInitialSize () {
51
+ return new Point (600 , 400 );
52
+ }
53
+
54
+ @ Override
55
+ protected void configureShell (Shell newShell ) {
56
+ super .configureShell (newShell );
57
+ newShell .setText ("Log files" );
58
+ }
59
+
60
+ @ Override
61
+ protected void createButtonsForButtonBar (Composite parent ) {
62
+ createButton (parent , IDialogConstants .HELP_ID , "Clear logs" , true );
63
+ createButton (parent , IDialogConstants .OK_ID , IDialogConstants .OK_LABEL , true );
64
+ }
65
+
66
+
67
+ @ Override
68
+ protected void buttonPressed (int buttonId ) {
69
+ if (buttonId == IDialogConstants .HELP_ID ) {
70
+ if (!MessageDialog .openConfirm (getShell (), "Removing log files" , "Are you sure to clear log files?" )) {
71
+ return ;
72
+ }
73
+ List <String > logUser = LogProperty .getLogFile ();
74
+
75
+ // get the content for each log files
76
+ for (String log : logUser ) {
77
+ try {
78
+ FileUtility .clearFileContent (log );
79
+ } catch (IOException e ) {
80
+ }
81
+ }
82
+ Activator activator = Activator .getDefault ();
83
+ if (activator != null ) {
84
+ String locUser = Platform .getLogFileLocation ().toOSString ();
85
+ try {
86
+ FileUtility .clearFileContent (locUser );
87
+ } catch (IOException e ) {
88
+ }
89
+ }
90
+ fillText ();
91
+
92
+ } else {
93
+ super .buttonPressed (buttonId );
94
+ }
95
+ }
96
+
97
+ private void fillText () {
98
+
39
99
// set the title
40
100
String text = "Log files used by hpcviewer\n " ;
41
101
@@ -45,7 +105,7 @@ protected Control createDialogArea(Composite parent) {
45
105
for (String log : logUser ) {
46
106
text += "File: " + log + "\n " ;
47
107
try {
48
- text += getFileContent (log );
108
+ text += FileUtility . getFileContent (log );
49
109
} catch (IOException e ) {
50
110
// do nothing
51
111
}
@@ -57,57 +117,16 @@ protected Control createDialogArea(Composite parent) {
57
117
if (activator != null ) {
58
118
String locUser = Platform .getLogFileLocation ().toOSString ();
59
119
text += "File: " + locUser + "\n " ;
60
- text += getFileContent (locUser );
120
+ text += FileUtility . getFileContent (locUser );
61
121
}
62
122
} catch (IOException e ) {
63
123
// do nothing
64
124
}
65
125
text += "\n " ;
66
-
67
- Text wText = new Text (content , SWT .MULTI | SWT .READ_ONLY | SWT .V_SCROLL | SWT .H_SCROLL );
68
126
wText .setText (text );
69
-
70
- content .setLayout (new FillLayout ());
71
-
72
- return content ;
73
- }
74
-
75
- @ Override
76
- protected Point getInitialSize () {
77
- return new Point (600 , 400 );
78
- }
79
-
80
- @ Override
81
- protected void configureShell (Shell newShell ) {
82
- super .configureShell (newShell );
83
- newShell .setText ("Log files" );
84
- }
85
127
86
- @ Override
87
- protected void createButtonsForButtonBar (Composite parent ) {
88
- createButton (parent , IDialogConstants .OK_ID , IDialogConstants .OK_LABEL , true );
89
128
}
90
129
91
- /***
92
- * Read the content of the file
93
- * @param filename
94
- * @return String
95
- * @throws IOException
96
- */
97
- private String getFileContent (String filename ) throws IOException {
98
- File file = new File (filename );
99
- if (!file .canRead ())
100
- return "" ;
101
-
102
- FileInputStream fis = new FileInputStream (file );
103
- byte [] data = new byte [(int ) file .length ()];
104
- fis .read (data );
105
-
106
- String content = new String (data , "UTF-8" );
107
- fis .close ();
108
-
109
- return content ;
110
- }
111
130
112
131
static public void main (String argv []) {
113
132
Display d = new Display ();
0 commit comments