Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 2ada8c0

Browse files
committed
Refine log display
1 parent 47b0c1f commit 2ada8c0

File tree

1 file changed

+64
-45
lines changed

1 file changed

+64
-45
lines changed

edu.rice.cs.hpcviewer.ui/src/edu/rice/cs/hpcviewer/ui/dialogs/InfoLogDialog.java

+64-45
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package edu.rice.cs.hpcviewer.ui.dialogs;
22

3-
import java.io.File;
4-
import java.io.FileInputStream;
53
import java.io.IOException;
64
import java.util.List;
75

86
import org.eclipse.core.internal.runtime.Activator;
97
import org.eclipse.core.runtime.Platform;
108
import org.eclipse.jface.dialogs.Dialog;
119
import org.eclipse.jface.dialogs.IDialogConstants;
10+
import org.eclipse.jface.dialogs.MessageDialog;
1211
import org.eclipse.swt.SWT;
1312
import org.eclipse.swt.graphics.Point;
1413
import org.eclipse.swt.layout.FillLayout;
@@ -19,9 +18,12 @@
1918
import org.eclipse.swt.widgets.Text;
2019

2120
import edu.rice.cs.hpclog.LogProperty;
21+
import edu.rice.cs.hpcviewer.ui.util.FileUtility;
2222

2323
public class InfoLogDialog extends Dialog
2424
{
25+
private Text wText;
26+
2527
public InfoLogDialog(Shell shell) {
2628
super(shell);
2729
}
@@ -36,6 +38,64 @@ protected boolean isResizable() {
3638
protected Control createDialogArea(Composite parent) {
3739
Composite content = (Composite) super.createDialogArea(parent);
3840

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+
3999
// set the title
40100
String text = "Log files used by hpcviewer\n";
41101

@@ -45,7 +105,7 @@ protected Control createDialogArea(Composite parent) {
45105
for (String log: logUser) {
46106
text += "File: " + log + "\n";
47107
try {
48-
text += getFileContent(log);
108+
text += FileUtility.getFileContent(log);
49109
} catch (IOException e) {
50110
// do nothing
51111
}
@@ -57,57 +117,16 @@ protected Control createDialogArea(Composite parent) {
57117
if (activator != null) {
58118
String locUser = Platform.getLogFileLocation().toOSString();
59119
text += "File: " + locUser + "\n";
60-
text += getFileContent(locUser);
120+
text += FileUtility.getFileContent(locUser);
61121
}
62122
} catch (IOException e) {
63123
// do nothing
64124
}
65125
text += "\n";
66-
67-
Text wText = new Text(content, SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
68126
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-
}
85127

86-
@Override
87-
protected void createButtonsForButtonBar(Composite parent) {
88-
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
89128
}
90129

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-
}
111130

112131
static public void main(String argv[]) {
113132
Display d = new Display();

0 commit comments

Comments
 (0)