From 7e5f6dc0ae2c9b2f50b0bbeb4dd40209932d7c25 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Thu, 3 Apr 2003 16:19:28 +0000 Subject: [PATCH] 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 --- .../pmd/jdeveloper/IDEStorage.java | 13 +++ .../jdeveloper/JDeveloperRuleSetFactory.java | 4 +- .../pmd/jdeveloper/JumpingSelectionModel.java | 3 +- .../sourceforge/pmd/jdeveloper/Plugin.java | 6 +- .../pmd/jdeveloper/RuleViolationPage.java | 6 +- .../pmd/jdeveloper/SelectedRules.java | 15 ++- .../pmd/jdeveloper/SettingsPanel.java | 93 ++++++++++++------- .../pmd/jdeveloper/SettingsStorage.java | 6 ++ 8 files changed, 94 insertions(+), 52 deletions(-) create mode 100644 pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/IDEStorage.java create mode 100644 pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SettingsStorage.java diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/IDEStorage.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/IDEStorage.java new file mode 100644 index 0000000000..749f8217fc --- /dev/null +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/IDEStorage.java @@ -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); + } +} diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JDeveloperRuleSetFactory.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JDeveloperRuleSetFactory.java index 327d3dbf3a..620ea94599 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JDeveloperRuleSetFactory.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JDeveloperRuleSetFactory.java @@ -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; diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java index 2434b987bb..08f3fae812 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java @@ -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 diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java index b2aaadfa0b..58ac7ca574 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java @@ -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) { diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationPage.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationPage.java index 2d1d172b00..d6a6e91796 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationPage.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationPage.java @@ -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 { diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SelectedRules.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SelectedRules.java index 1e1b39a642..8e0002cf64 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SelectedRules.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SelectedRules.java @@ -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; } diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SettingsPanel.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SettingsPanel.java index 3db0db8d9e..6483709772 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SettingsPanel.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SettingsPanel.java @@ -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()); } } diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SettingsStorage.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SettingsStorage.java new file mode 100644 index 0000000000..c3585554d3 --- /dev/null +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/SettingsStorage.java @@ -0,0 +1,6 @@ +package net.sourceforge.pmd.jdeveloper; + +public interface SettingsStorage { + void save(String key, String value); + String load(String key); +}