From b6fd1a161e1d148a43986d39779c28d6e50a622e Mon Sep 17 00:00:00 2001 From: Ole-Martin Mork Date: Tue, 26 Nov 2002 17:58:33 +0000 Subject: [PATCH] Fixed a bug found in the testing today git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1267 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd-netbeans/src/pmd/config/ConfigUtils.java | 53 +++++++++++++++---- .../src/pmd/config/ui/AvailableListModel.java | 40 ++++++-------- .../src/pmd/config/ui/RuleEditor.java | 6 +-- .../src/pmd/config/ui/RuleEnabler.java | 12 ++--- 4 files changed, 67 insertions(+), 44 deletions(-) diff --git a/pmd-netbeans/src/pmd/config/ConfigUtils.java b/pmd-netbeans/src/pmd/config/ConfigUtils.java index b8b174c652..1a518fd885 100644 --- a/pmd-netbeans/src/pmd/config/ConfigUtils.java +++ b/pmd-netbeans/src/pmd/config/ConfigUtils.java @@ -1,26 +1,32 @@ /* - * ConfigUtils.java + * ConfigUtils.java * - * Created on 25. november 2002, 23:35 + * Created on 25. november 2002, 23:35 */ - package pmd.config; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import net.sourceforge.pmd.Rule; -import pmd.config.ui.AvailableListModel; +import net.sourceforge.pmd.RuleSet; +import net.sourceforge.pmd.RuleSetFactory; +import net.sourceforge.pmd.RuleSetNotFoundException; /** - * - * @author ole martin mørk + * @author ole martin mørk + * @created 26. november 2002 */ public class ConfigUtils { - - + + /** + * Description of the Method + * + * @param rules Description of the Parameter + * @return Description of the Return Value + */ public static List createRuleList( String rules ) { - Iterator iterator = AvailableListModel.getInstance().getData().iterator(); + Iterator iterator = getAllAvailableRules().iterator(); List list = new ArrayList(); while( iterator.hasNext() ) { Rule rule = ( Rule )iterator.next(); @@ -30,8 +36,11 @@ public class ConfigUtils { } return list; } - - /** Returns the list as text + + + /** + * Returns the list as text + * * @param value The list to be presented as text * @return A string containing all the values in the list */ @@ -46,4 +55,26 @@ public class ConfigUtils { } return String.valueOf( buffer ); } + + + /** + * Gets the allAvailableRules attribute of the ConfigUtils class + * + * @return The allAvailableRules value + */ + public static List getAllAvailableRules() { + List list = new ArrayList(); + try { + RuleSetFactory ruleSetFactory = new RuleSetFactory(); + Iterator iterator = ruleSetFactory.getRegisteredRuleSets(); + while( iterator.hasNext() ) { + RuleSet ruleset = ( RuleSet )iterator.next(); + list.addAll( ruleset.getRules() ); + } + } + catch( RuleSetNotFoundException e ) { + e.printStackTrace(); + } + return list; + } } diff --git a/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java b/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java index 71883140d1..38cfa68842 100644 --- a/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java +++ b/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java @@ -28,25 +28,22 @@ package pmd.config.ui; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; -import java.util.Set; import javax.swing.AbstractListModel; import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleSet; -import net.sourceforge.pmd.RuleSetFactory; -import net.sourceforge.pmd.RuleSetNotFoundException; +import pmd.config.ConfigUtils; /** * The datamodel for the available rules list + * * @author ole martin mørk * @created 16. november 2002 */ public class AvailableListModel extends AbstractListModel { - /** The instance */ + /** The instance */ private static AvailableListModel listmodel = new AvailableListModel(); - /** The data in the list */ + /** The data in the list */ private List list = new ArrayList(); @@ -97,7 +94,9 @@ public class AvailableListModel extends AbstractListModel { } - /** Adds object o to the list + /** + * Adds object o to the list + * * @param o The parameter to add to the list */ public void add( Object o ) { @@ -107,6 +106,7 @@ public class AvailableListModel extends AbstractListModel { } } + /** * Removes o from the list * @@ -127,7 +127,9 @@ public class AvailableListModel extends AbstractListModel { } - /** Adds all data in coll to the list + /** + * Adds all data in coll to the list + * * @param coll The collection containing Rule elements */ public void addAll( Collection coll ) { @@ -137,28 +139,18 @@ public class AvailableListModel extends AbstractListModel { } - /** Returns the data for the list + /** + * Returns the data for the list + * * @return The data */ - public List getData() { + public List getList() { return list; } /** Resets the list */ public void refresh() { - list.clear(); - try { - RuleSetFactory ruleSetFactory = new RuleSetFactory(); - Iterator iterator = ruleSetFactory.getRegisteredRuleSets(); - while( iterator.hasNext() ) { - RuleSet ruleset = ( RuleSet )iterator.next(); - Set rules = ruleset.getRules(); - addAll( rules ); - } - } - catch( RuleSetNotFoundException e ) { - e.printStackTrace(); - } + list = ConfigUtils.getAllAvailableRules(); } } diff --git a/pmd-netbeans/src/pmd/config/ui/RuleEditor.java b/pmd-netbeans/src/pmd/config/ui/RuleEditor.java index 9e51e4f452..b9df05ac62 100644 --- a/pmd-netbeans/src/pmd/config/ui/RuleEditor.java +++ b/pmd-netbeans/src/pmd/config/ui/RuleEditor.java @@ -60,7 +60,7 @@ public class RuleEditor extends PropertyEditorSupport { */ public Object getValue() { return ConfigUtils.getValueAsText( - SelectedListModel.getSelectedListModelInstance().getData() ); + SelectedListModel.getSelectedListModelInstance().getList() ); } @@ -82,8 +82,8 @@ public class RuleEditor extends PropertyEditorSupport { SelectedListModel.getSelectedListModelInstance().setList( ConfigUtils.createRuleList( (String)obj ) ); AvailableListModel.getInstance().refresh(); - AvailableListModel.getInstance().getData().removeAll( - SelectedListModel.getSelectedListModelInstance().getData() ); + AvailableListModel.getInstance().getList().removeAll( + SelectedListModel.getSelectedListModelInstance().getList() ); } } diff --git a/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java index e64803597a..1c115ac3a7 100644 --- a/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java +++ b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java @@ -407,7 +407,7 @@ public class RuleEnabler extends JPanel { * @param evt the event fired */ private void removeAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeAllActionPerformed - AvailableListModel.getInstance().addAll( SelectedListModel.getSelectedListModelInstance().getData() ); + AvailableListModel.getInstance().addAll( SelectedListModel.getSelectedListModelInstance().getList() ); SelectedListModel.getSelectedListModelInstance().removeAll(); editor.firePropertyChange(); @@ -425,8 +425,8 @@ public class RuleEnabler extends JPanel { AvailableListModel.getInstance().add( object[i] ); } editor.firePropertyChange(); - if( index >= SelectedListModel.getSelectedListModelInstance().getData().size() ) { - index = SelectedListModel.getSelectedListModelInstance().getData().size() - 1; + if( index >= SelectedListModel.getSelectedListModelInstance().getList().size() ) { + index = SelectedListModel.getSelectedListModelInstance().getList().size() - 1; } if( index >= 0 ) { chosenList.setSelectedIndex( index ); @@ -440,7 +440,7 @@ public class RuleEnabler extends JPanel { * @param evt the event fired */ private void choseAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choseAllActionPerformed - SelectedListModel.getSelectedListModelInstance().addAll( AvailableListModel.getInstance().getData() ); + SelectedListModel.getSelectedListModelInstance().addAll( AvailableListModel.getInstance().getList() ); AvailableListModel.getInstance().removeAll(); editor.firePropertyChange(); }//GEN-LAST:event_choseAllActionPerformed @@ -457,8 +457,8 @@ public class RuleEnabler extends JPanel { SelectedListModel.getSelectedListModelInstance().add( object[i] ); } editor.firePropertyChange(); - if( index >= AvailableListModel.getInstance().getData().size() ) { - index = AvailableListModel.getInstance().getData().size() - 1; + if( index >= AvailableListModel.getInstance().getList().size() ) { + index = AvailableListModel.getInstance().getList().size() - 1; } if( index >= 0 ) { availableList.setSelectedIndex( index );