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
This commit is contained in:
Ole-Martin Mork
2002-11-26 17:58:33 +00:00
parent 4101169603
commit b6fd1a161e
4 changed files with 67 additions and 44 deletions

View File

@ -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;
}
}

View File

@ -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 <CODE>o</CODE> to the list
/**
* Adds object <CODE>o</CODE> 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 <code>o</code> from the list
*
@ -127,7 +127,9 @@ public class AvailableListModel extends AbstractListModel {
}
/** Adds all data in <CODE>coll</CODE> to the list
/**
* Adds all data in <CODE>coll</CODE> 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();
}
}

View File

@ -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() );
}
}

View File

@ -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 );