private void addFile(final String searchPattern, final File file, boolean subdirs, boolean first)
{
System.out.println("In add file");
if (file.isFile())
{
if (containsPattern(file.toString(), searchPattern))
{
System.out.println(file);
// Need to add to model in event thread
EventQueue.invokeLater(new Runnable()
{
public void run()
{}
});
Results(searchPattern, file);
}
} //end if
else if (file.isDirectory())
{
if (first || subdirs)
{ // need to let first pass through
File files[] = file.listFiles();
for (int i = 0; i < files.length; i++)
{
addFile(searchPattern, files[i], subdirs, false);
} //end for loop
}
}
}//end addFile
public void Results(final String searchPattern, final File file)
{
final String files = file.toString();
TableItem tableItem = new TableItem(rsTable, SWT.NONE);
tableItem.setText(files);
rsTable.addMouseListener(new MouseListener()
{
public void mouseDoubleClick(MouseEvent arg0)
{
System.out.println("ShowHighlighted");
// Don't block the event thread
new Thread()
{
public void run()
{
final JDialog dialog = new JDialog();
Container contentPane = dialog.getContentPane();
try
{
FileReader reader = new FileReader(files);
JTextPane textPane = new JTextPane();
textPane.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textPane);
contentPane.add(scrollPane);
// Read in file
textPane.read(reader, null);
// Make highlight attribute
final SimpleAttributeSet set = new SimpleAttributeSet();
set.addAttribute(
StyleConstants.CharacterConstants.Bold,
Boolean.TRUE);
// Get Document for text pane
final DefaultStyledDocument document =
(DefaultStyledDocument)textPane.getDocument();
// Handle newlines across platforms
document.putProperty(
DefaultEditorKit.EndOfLineStringProperty, "\n");
// highlight areas
String text = textPane.getText();
Pattern thePattern = Pattern.compile(searchPattern);
final Matcher matcher = thePattern.matcher(text);
EventQueue.invokeLater(new Runnable()
{
public void run()
{
while (matcher.find())
{
int start = matcher.start();
int length = matcher.end() - start;
document.setCharacterAttributes(start, length, set, false);
}// end while
// show results
dialog.setSize(300, 300);
dialog.show();
}//end inside run
} //end invokeQ
);
} //end try
catch (IOException ex)
{
System.err.println("Unable to show highlights" + ex); }//end catch
}//end outside run
} //end thread
.start();
}
public void mouseDown(MouseEvent arg0)
{
}
public void mouseUp(MouseEvent arg0)
{
}
});
filePath.pack(); // column
rsTable.pack(); //table
} //end results method