Fixed 2 bugs. One caused a NullPointerException when saving a

rule property.  The other bug was saving the rule set files without
the ".xml" file extension.  Also, the selected no will save its data from
the Swing component to the tree node when the Save button is pressed.


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@873 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Don Leckie
2002-09-09 16:19:42 +00:00
parent 6feabab9a3
commit 43567bfc11
8 changed files with 100 additions and 53 deletions

View File

@ -77,4 +77,15 @@ class RuleAllEditingPanel extends JPanel
{
return m_rulePropertyPanel;
}
/**
*******************************************************************************
*
*/
protected void saveData()
{
m_ruleSetPanel.saveData();
m_rulePanel.saveData();
m_rulePropertyPanel.saveData();
}
}

View File

@ -180,7 +180,7 @@ public class RuleEditingPanel extends JPanel
*******************************************************************************
*
*/
private void saveData()
protected void saveData()
{
if (m_currentData != null)
{

View File

@ -47,6 +47,32 @@ public class RuleEditingTabbedPane extends JTabbedPane implements TreeSelectionL
rulesTree.addTreeSelectionListener(this);
}
/**
*******************************************************************************
*
*/
protected void saveData()
{
Object object = getSelectedComponent();
if (object == m_ruleAllEditingPanel)
{
m_ruleAllEditingPanel.saveData();
}
else if (object == m_ruleSetEditingPanel)
{
m_ruleSetEditingPanel.saveData();
}
else if (object == m_ruleEditingPanel)
{
m_ruleEditingPanel.saveData();
}
else if (object == m_rulePropertyEditingPanel)
{
m_rulePropertyEditingPanel.saveData();
}
}
/**
*******************************************************************************
*
@ -54,7 +80,7 @@ public class RuleEditingTabbedPane extends JTabbedPane implements TreeSelectionL
*/
public void valueChanged(TreeSelectionEvent event)
{
if (this.getSelectedComponent() != m_ruleAllEditingPanel)
if (getSelectedComponent() != m_ruleAllEditingPanel)
{
TreePath treePath = event.getPath();
Object component = treePath.getLastPathComponent();

View File

@ -113,7 +113,7 @@ public class RulePropertyEditingPanel extends JPanel
*******************************************************************************
*
*/
private void saveData()
protected void saveData()
{
if (m_currentData != null)
{

View File

@ -129,7 +129,7 @@ public class RuleSetEditingPanel extends JPanel
*******************************************************************************
*
*/
private void saveData()
protected void saveData()
{
if (m_currentData != null)
{

View File

@ -54,6 +54,7 @@ class RulesEditor extends JDialog
private PMDViewer m_pmdViewer;
private RulesTree m_tree;
private RuleEditingTabbedPane m_editingTabbedPane;
/**
*******************************************************************************
@ -90,10 +91,14 @@ class RulesEditor extends JDialog
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
buildTree();
JScrollPane treeScrollPane = createTreeScrollPane();
JTabbedPane editingTabbedPane = new RuleEditingTabbedPane(m_tree);
JSplitPane splitPane = createSplitPane(treeScrollPane, editingTabbedPane);
JPanel buttonPanel = createButtonPanel();
JScrollPane treeScrollPane;
JSplitPane splitPane;
JPanel buttonPanel;
treeScrollPane = createTreeScrollPane();
m_editingTabbedPane = new RuleEditingTabbedPane(m_tree);
splitPane = createSplitPane(treeScrollPane, m_editingTabbedPane);
buttonPanel = createButtonPanel();
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.add(splitPane, BorderLayout.CENTER);
@ -276,7 +281,7 @@ class RulesEditor extends JDialog
for (int n = 0; n < rules.length; n++)
{
RulesTreeNode ruleNode = new RulesTreeNode(rules[n]);
RulesTreeNode ruleNode = new RulesTreeNode(ruleSetNode, rules[n]);
ruleSetNode.add(ruleNode);
loadProperties(ruleNode);
@ -314,9 +319,13 @@ class RulesEditor extends JDialog
for (int n = 0; n < propertyNames.length; n++)
{
String propertyName = propertyNames[n];
String propertyValue = (String) properties.getProperty(propertyName);
RulesTreeNode propertyNode = new RulesTreeNode(propertyName, propertyValue);
String propertyName;
String propertyValue;
RulesTreeNode propertyNode;
propertyName = propertyNames[n];
propertyValue = (String) properties.getProperty(propertyName);
propertyNode = new RulesTreeNode(ruleNode, propertyName, propertyValue);
ruleNode.add(propertyNode);
@ -460,11 +469,13 @@ class RulesEditor extends JDialog
*/
public void actionPerformed(ActionEvent event)
{
m_editingTabbedPane.saveData();
RulesTreeNode rootNode = (RulesTreeNode) m_tree.getModel().getRoot();
saveData(rootNode);
if (saveRuleSets(rootNode))
if (writeRuleSets(rootNode))
{
RulesEditor.this.setVisible(false);
}
@ -477,18 +488,7 @@ class RulesEditor extends JDialog
*/
private void saveData(RulesTreeNode treeNode)
{
if (treeNode.isRuleSet())
{
treeNode.saveRuleSetData();
}
else if (treeNode.isRule())
{
treeNode.saveRuleData();
}
else if (treeNode.isProperty())
{
treeNode.saveRulePropertyData();
}
treeNode.saveData();
Enumeration children = treeNode.children();
@ -503,7 +503,7 @@ class RulesEditor extends JDialog
*
* @param treeNode
*/
private boolean saveRuleSets(RulesTreeNode treeNode)
private boolean writeRuleSets(RulesTreeNode treeNode)
{
Preferences preferences = m_pmdViewer.getPreferences();
String ruleSetDirectory = preferences.getCurrentRuleSetDirectory();
@ -514,7 +514,7 @@ class RulesEditor extends JDialog
FileOutputStream fileOutputStream = null;
RulesTreeNode ruleSetNode = (RulesTreeNode) ruleSetNodes.nextElement();
RuleSet ruleSet = ruleSetNode.getRuleSet();
String fileName = ruleSetDirectory + File.separator + ruleSet.getName();
String fileName = ruleSetDirectory + File.separator + ruleSet.getName() + ".xml";
try
{

View File

@ -41,6 +41,7 @@ class RulesTree extends JTree
/**
***************************************************************************
*
* @param node
*/
protected void expandNode(RulesTreeNode node)
{
@ -49,6 +50,18 @@ class RulesTree extends JTree
expandPath(treePath);
}
/**
***************************************************************************
*
* @return
*/
protected RulesTreeNode getSelectedNode()
{
TreePath treePath = getSelectionPath();
return (RulesTreeNode) treePath.getLastPathComponent();
}
/**
*******************************************************************************
*******************************************************************************

View File

@ -76,7 +76,7 @@ class RulesTreeNode extends DefaultMutableTreeNode implements IRulesEditingData
*
* @param name
*/
protected RulesTreeNode(Rule rule)
protected RulesTreeNode(RulesTreeNode ruleSetNode, Rule rule)
{
super();
@ -85,6 +85,7 @@ class RulesTreeNode extends DefaultMutableTreeNode implements IRulesEditingData
m_message = trim(rule.getMessage());
m_description = trim(rule.getDescription());
m_example = trim(rule.getExample());
m_ruleSet = ruleSetNode.getRuleSet();
m_rule = rule;
m_flags |= IS_RULE;
@ -101,13 +102,15 @@ class RulesTreeNode extends DefaultMutableTreeNode implements IRulesEditingData
*
* @param name
*/
protected RulesTreeNode(String propertyName, String propertyValue)
protected RulesTreeNode(RulesTreeNode ruleNode, String propertyName, String propertyValue)
{
super();
m_name = trim(propertyName);
m_propertyValue = trim(propertyValue);
m_flags |= IS_PROPERTY;
m_rule = ruleNode.getRule();
m_ruleSet = ((RulesTreeNode) ruleNode.getParent()).getRuleSet();
setDisplayName();
}
@ -392,31 +395,25 @@ class RulesTreeNode extends DefaultMutableTreeNode implements IRulesEditingData
*************************************************************************
*
*/
protected void saveRuleSetData()
protected void saveData()
{
m_ruleSet.setName(m_name);
m_ruleSet.setDescription(m_description);
}
/**
*************************************************************************
*
*/
protected void saveRuleData()
{
m_rule.setName(m_name);
m_rule.setMessage(m_message);
m_rule.setDescription(m_description);
m_rule.setExample(m_example);
}
/**
*************************************************************************
*
*/
protected void saveRulePropertyData()
{
m_rule.addProperty(m_name, m_propertyValue);
if (isRuleSet())
{
m_ruleSet.setName(m_name);
m_ruleSet.setDescription(m_description);
}
else if (isRule())
{
m_rule.setName(m_name);
m_rule.setMessage(m_message);
m_rule.setDescription(m_description);
m_rule.setExample(m_example);
m_rule.setInclude(include());
}
else if (isProperty())
{
m_rule.addProperty(m_name, m_propertyValue);
}
}
/**