forked from phoedos/pmd
added directory popup feature
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1243 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -23,4 +23,3 @@ pmd-check-current-directory-recursively.label=Check directory recursively
|
||||
#
|
||||
options.PMD.title=PMD
|
||||
options.PMD.label=PMD
|
||||
|
||||
|
@ -22,8 +22,8 @@ import net.sourceforge.pmd.*;
|
||||
public class PMDJEditPlugin extends EditPlugin {
|
||||
|
||||
public static final String NAME = "PMD";
|
||||
public static final String PROPERTY_PREFIX = "plugin.net.sourceforge.pmd.jedit.";
|
||||
public static final String OPTION_RULES_PREFIX = "options.pmd.rules.";
|
||||
public static final String OPTION_UI_DIRECTORY_POPUP = "options.pmd.ui.directorypopup";
|
||||
|
||||
public static class JavaFileOrDirectoryFilter implements FilenameFilter {
|
||||
public boolean accept(File dir, String filename) {
|
||||
@ -60,31 +60,42 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
}
|
||||
|
||||
public void instanceCheckDirectory(View view) {
|
||||
final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser");
|
||||
if(browser == null) {
|
||||
JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
new Thread(new Runnable () {
|
||||
public void run() {
|
||||
processFiles(findFilesInDirectory(browser.getDirectory()));
|
||||
if (jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) {
|
||||
final String dir = JOptionPane.showInputDialog(jEdit.getFirstView(), "Please type in a directory to scan", NAME, JOptionPane.QUESTION_MESSAGE);
|
||||
process(findFilesInDirectory(dir));
|
||||
} else {
|
||||
final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser");
|
||||
if(browser == null) {
|
||||
JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
}).start();
|
||||
process(findFilesInDirectory(browser.getDirectory()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void checkDirectoryRecursively(View view) {
|
||||
instance.instanceCheckDirectoryRecursively(view);
|
||||
}
|
||||
|
||||
public void instanceCheckDirectoryRecursively(View view) {
|
||||
final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser");
|
||||
if(browser == null) {
|
||||
JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
if (jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) {
|
||||
final String dir = JOptionPane.showInputDialog(jEdit.getFirstView(), "Please type in a directory to scan recursively", NAME, JOptionPane.QUESTION_MESSAGE);
|
||||
process(findFilesRecursively(dir));
|
||||
} else {
|
||||
final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser");
|
||||
if(browser == null) {
|
||||
JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
process(findFilesRecursively(browser.getDirectory()));
|
||||
}
|
||||
}
|
||||
|
||||
private void process(final List files) {
|
||||
new Thread(new Runnable () {
|
||||
public void run() {
|
||||
processFiles(findFilesRecursively(browser.getDirectory()));
|
||||
processFiles(files);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ package net.sourceforge.pmd.jedit;
|
||||
|
||||
import org.gjt.sp.jedit.OptionPane;
|
||||
import org.gjt.sp.jedit.AbstractOptionPane;
|
||||
import org.gjt.sp.jedit.jEdit;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
@ -63,6 +64,8 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
|
||||
|
||||
private SelectedRules rules;
|
||||
private JTextArea exampleTextArea= new JTextArea(10, 50);
|
||||
private JCheckBox directoryPopupBox;
|
||||
|
||||
public PMDOptionPane() {
|
||||
super(PMDJEditPlugin.NAME);
|
||||
try {
|
||||
@ -87,14 +90,25 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
|
||||
textPanel.setBorder(BorderFactory.createTitledBorder("Example"));
|
||||
textPanel.add(new JScrollPane(exampleTextArea));
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.add(rulesPanel, BorderLayout.NORTH);
|
||||
panel.add(textPanel, BorderLayout.SOUTH);
|
||||
addComponent(panel);
|
||||
if (!jEdit.getProperties().containsKey(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) {
|
||||
jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP, false);
|
||||
}
|
||||
|
||||
directoryPopupBox = new JCheckBox("Ask for directory?", jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP));
|
||||
|
||||
JPanel mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
mainPanel.add(rulesPanel, BorderLayout.NORTH);
|
||||
mainPanel.add(textPanel, BorderLayout.CENTER);
|
||||
mainPanel.add(directoryPopupBox, BorderLayout.SOUTH);
|
||||
|
||||
addComponent(mainPanel);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
rules.save();
|
||||
if (directoryPopupBox != null) {
|
||||
jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP, directoryPopupBox.isSelected());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user