BufferedReader br = null;
//*-- create the first table column
table.removeAll(); table.clearAll();
tcol1.setText("Log Entries:"); tcol1.setWidth(800);
TableItem ti = null;
LinkedList<String> logList = new LinkedList<String>(); int MAX_ENTRIES = 21;
try
{
//*-- dump a message if the task was cancelled
String lastLine = (success) ? "INFO: The index operation completed normally":
"WARNING: The index operation was aborted";
ti = new TableItem(table, SWT.LEFT); ti.setBackground(backWhite);
ti.setText(lastLine);
//*-- read the file in reverse and save the last 10 entries
String theLine = "";
FileInputStream fis = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fis)); int numItems = 0;
while( (theLine = br.readLine() ) != null)
{ if (++numItems < MAX_ENTRIES) logList.add(theLine);
else { logList.removeFirst(); logList.addLast(theLine); }
} //*-- end of while
//*-- dump the latest log entries to the table
for (int i = 0; i < logList.size(); i++)
{ ti = new TableItem(table, SWT.LEFT, i);
ti.setBackground(backYellow); ti.setForeground(frontBlue);
ti.setText( (String) logList.get(i));
}
}
catch (FileNotFoundException e)
{ ti = new TableItem(table, SWT.LEFT, 0); ti.setBackground(backWhite); ti.setForeground(frontRed);
ti.setText("The log file" + filename + " was not found."); }
catch (IOException e)
{ ti = new TableItem(table, SWT.LEFT, 0); ti.setBackground(backWhite); ti.setForeground(frontRed);
ti.setText("IO Error on log file" + filename + "."); }
finally
{ try { if (br != null) br.close(); }
catch (IOException ie) { System.out.println("Could not close reader"); }
}