halfway to getting settings to save in other location
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1684 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -0,0 +1,13 @@
|
||||
package net.sourceforge.pmd.jdeveloper;
|
||||
|
||||
import oracle.ide.Ide;
|
||||
|
||||
public class IDEStorage implements SettingsStorage {
|
||||
public void save(String key, String value) {
|
||||
Ide.setProperty(key, value);
|
||||
}
|
||||
|
||||
public String load(String key) {
|
||||
return Ide.getProperty(key);
|
||||
}
|
||||
}
|
@ -5,10 +5,10 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.util.ResourceLoader;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
@ -5,8 +5,7 @@ import oracle.ide.Ide;
|
||||
import oracle.ide.net.URLFactory;
|
||||
import oracle.jdeveloper.ceditor.CodeEditor;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.DefaultListSelectionModel;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* This class was inspired by a class on Sun's web site in the JList tutorial section. It's
|
||||
|
@ -8,7 +8,6 @@ import net.sourceforge.pmd.RuleViolation;
|
||||
import oracle.ide.ContextMenu;
|
||||
import oracle.ide.Ide;
|
||||
import oracle.ide.IdeAction;
|
||||
import oracle.ide.layout.ViewId;
|
||||
import oracle.ide.addin.Addin;
|
||||
import oracle.ide.addin.Context;
|
||||
import oracle.ide.addin.ContextMenuListener;
|
||||
@ -21,8 +20,7 @@ import oracle.ide.panels.Navigable;
|
||||
import oracle.jdeveloper.model.JProject;
|
||||
import oracle.jdeveloper.model.JavaSourceNode;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Iterator;
|
||||
@ -85,7 +83,7 @@ public class Plugin implements Addin, Controller, ContextMenuListener {
|
||||
if (ideAction.getCommandId() == CHECK_CMD_ID) {
|
||||
try {
|
||||
PMD pmd = new PMD();
|
||||
SelectedRules rs = new SelectedRules();
|
||||
SelectedRules rs = new SelectedRules(SettingsPanel.createSettingsStorage());
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setReport(new Report());
|
||||
if (resolveType(context.getDocument()) == PROJECT) {
|
||||
|
@ -5,10 +5,8 @@ import oracle.ide.Ide;
|
||||
import oracle.ide.layout.ViewId;
|
||||
import oracle.ide.log.AbstractLogPage;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.Component;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class RuleViolationPage extends AbstractLogPage {
|
||||
|
||||
|
@ -4,9 +4,8 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import oracle.ide.Ide;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@ -23,13 +22,13 @@ public class SelectedRules {
|
||||
}
|
||||
});
|
||||
|
||||
public SelectedRules() throws RuleSetNotFoundException {
|
||||
public SelectedRules(SettingsStorage settings) throws RuleSetNotFoundException {
|
||||
RuleSetFactory rsf = new JDeveloperRuleSetFactory();
|
||||
for (Iterator i = rsf.getRegisteredRuleSets(); i.hasNext();) {
|
||||
RuleSet rs = (RuleSet)i.next();
|
||||
for (Iterator j = rs.getRules().iterator(); j.hasNext();) {
|
||||
Rule rule = (Rule)j.next();
|
||||
rules.put(rule, createCheckBox(rule.getName()));
|
||||
rules.put(rule, createCheckBox(rule.getName(), settings));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,10 +62,10 @@ public class SelectedRules {
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
public void save(SettingsStorage settings) {
|
||||
for (Iterator i = rules.keySet().iterator(); i.hasNext();) {
|
||||
Rule rule = (Rule)i.next();
|
||||
Ide.setProperty("pmd.rule." + rule.getName(), String.valueOf(get(rule).isSelected()));
|
||||
settings.save("pmd.rule." + rule.getName(), String.valueOf(get(rule).isSelected()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,9 +80,9 @@ public class SelectedRules {
|
||||
return newRuleSet;
|
||||
}
|
||||
|
||||
private JCheckBox createCheckBox(String name) {
|
||||
private JCheckBox createCheckBox(String name, SettingsStorage settings) {
|
||||
JCheckBox box = new JCheckBox(name);
|
||||
box.setSelected(Boolean.valueOf(Ide.getProperty("pmd.rule." + name)).booleanValue());
|
||||
box.setSelected(Boolean.valueOf(settings.load("pmd.rule." + name)).booleanValue());
|
||||
return box;
|
||||
}
|
||||
|
||||
|
@ -1,22 +1,13 @@
|
||||
package net.sourceforge.pmd.jdeveloper;
|
||||
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import oracle.ide.Ide;
|
||||
import oracle.ide.panels.DefaultTraversablePanel;
|
||||
import oracle.ide.panels.TraversableContext;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.ListCellRenderer;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
@ -65,38 +56,76 @@ public class SettingsPanel extends DefaultTraversablePanel {
|
||||
|
||||
}
|
||||
|
||||
private SelectedRules rules;
|
||||
public static final String RULE_SELECTIONS_STORED_SEPARATELY = "pmd.settings.separate";
|
||||
public static final String RULE_SELECTIONS_FILENAME = "pmd.settings.separate.name";
|
||||
|
||||
private JTextArea exampleTextArea= new JTextArea(10, 50);
|
||||
private JCheckBox selectedRulesStoredSeparatelyBox = new JCheckBox("", Boolean.valueOf(Ide.getProperty(RULE_SELECTIONS_STORED_SEPARATELY)).booleanValue());
|
||||
private JTextField selectedRulesSeparateFileNameField = new JTextField(30);
|
||||
private SelectedRules rules;
|
||||
|
||||
public static SettingsStorage createSettingsStorage() {
|
||||
if (Boolean.valueOf(Ide.getProperty(RULE_SELECTIONS_STORED_SEPARATELY)).booleanValue()) {
|
||||
//return new
|
||||
}
|
||||
return new IDEStorage();
|
||||
}
|
||||
|
||||
public void onEntry(TraversableContext tc) {
|
||||
super.removeAll();
|
||||
removeAll();
|
||||
try {
|
||||
rules = new SelectedRules();
|
||||
rules = new SelectedRules(createSettingsStorage());
|
||||
} catch (RuleSetNotFoundException rsne) {
|
||||
rsne.printStackTrace();
|
||||
}
|
||||
|
||||
JPanel boxesPanel = new JPanel();
|
||||
boxesPanel.setBorder(BorderFactory.createTitledBorder("Rules"));
|
||||
JList list = new CheckboxList(rules.getAllBoxes());
|
||||
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
boxesPanel.add(new JScrollPane(list), BorderLayout.NORTH);
|
||||
JPanel textPanel = new JPanel();
|
||||
textPanel.setBorder(BorderFactory.createTitledBorder("Example"));
|
||||
textPanel.add(new JScrollPane(exampleTextArea));
|
||||
JPanel selectionPanel = new JPanel();
|
||||
selectionPanel.setLayout(new BorderLayout());
|
||||
selectionPanel.add(boxesPanel, BorderLayout.NORTH);
|
||||
selectionPanel.add(textPanel, BorderLayout.CENTER);
|
||||
|
||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
mainPanel.add(new JLabel("Please see http://pmd.sf.net/ for more information"), BorderLayout.NORTH);
|
||||
mainPanel.add(selectionPanel, BorderLayout.CENTER);
|
||||
|
||||
mainPanel.add(createTopPanel(), BorderLayout.NORTH);
|
||||
mainPanel.add(createRulesSelectionPanel(), BorderLayout.SOUTH);
|
||||
add(mainPanel);
|
||||
}
|
||||
|
||||
private JPanel createRulesSelectionPanel() {
|
||||
JPanel checkBoxesPanel = new JPanel();
|
||||
checkBoxesPanel.setBorder(BorderFactory.createTitledBorder("Rules"));
|
||||
JList rulesList = new CheckboxList(rules.getAllBoxes());
|
||||
rulesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
checkBoxesPanel.add(new JScrollPane(rulesList), BorderLayout.NORTH);
|
||||
JPanel examplePanel = new JPanel();
|
||||
examplePanel.setBorder(BorderFactory.createTitledBorder("Example"));
|
||||
examplePanel.add(new JScrollPane(exampleTextArea));
|
||||
JPanel rulesSelectionPanel = new JPanel();
|
||||
rulesSelectionPanel.setLayout(new BorderLayout());
|
||||
rulesSelectionPanel.add(checkBoxesPanel, BorderLayout.NORTH);
|
||||
rulesSelectionPanel.add(examplePanel, BorderLayout.CENTER);
|
||||
return rulesSelectionPanel;
|
||||
}
|
||||
|
||||
private JPanel createTopPanel() {
|
||||
selectedRulesSeparateFileNameField.setText(Ide.getProperty(RULE_SELECTIONS_FILENAME));
|
||||
selectedRulesStoredSeparatelyBox.setSelected(Boolean.valueOf(Ide.getProperty(RULE_SELECTIONS_STORED_SEPARATELY)).booleanValue());
|
||||
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.add(new JLabel("Please see http://pmd.sf.net/ for more information"), BorderLayout.NORTH);
|
||||
JPanel customStoragePanel = new JPanel(new BorderLayout());
|
||||
customStoragePanel.setBorder(BorderFactory.createTitledBorder("Settings storage"));
|
||||
|
||||
JPanel customStorageCheckBoxPanel = new JPanel();
|
||||
customStorageCheckBoxPanel.add(new JLabel("Use centrally managed rule settings?"));
|
||||
customStorageCheckBoxPanel.add(selectedRulesStoredSeparatelyBox);
|
||||
customStoragePanel.add(customStorageCheckBoxPanel, BorderLayout.NORTH);
|
||||
|
||||
JPanel customStorageTextFieldPanel = new JPanel();
|
||||
customStorageTextFieldPanel.add(new JLabel("File:"));
|
||||
customStorageTextFieldPanel.add(selectedRulesSeparateFileNameField);
|
||||
customStoragePanel.add(customStorageTextFieldPanel, BorderLayout.SOUTH);
|
||||
topPanel.add(customStoragePanel, BorderLayout.CENTER);
|
||||
return topPanel;
|
||||
}
|
||||
|
||||
public void onExit(TraversableContext tc) {
|
||||
rules.save();
|
||||
Ide.setProperty(RULE_SELECTIONS_STORED_SEPARATELY, String.valueOf(selectedRulesStoredSeparatelyBox.isSelected()));
|
||||
Ide.setProperty(RULE_SELECTIONS_FILENAME, selectedRulesSeparateFileNameField.getText());
|
||||
rules.save(createSettingsStorage());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package net.sourceforge.pmd.jdeveloper;
|
||||
|
||||
public interface SettingsStorage {
|
||||
void save(String key, String value);
|
||||
String load(String key);
|
||||
}
|
Reference in New Issue
Block a user