From d3bed2baa674770c63a95a1afee07e99fd97a066 Mon Sep 17 00:00:00 2001 From: Ole-Martin Mork Date: Wed, 20 Nov 2002 17:15:19 +0000 Subject: [PATCH] New option dialog git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1256 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd-netbeans/src/pmd/RunPMDAction.java | 25 +- pmd-netbeans/src/pmd/config/Bundle.properties | 4 +- .../src/pmd/config/PMDOptionsSettings.java | 29 +- .../config/PMDOptionsSettingsBeanInfo.java | 13 +- .../src/pmd/config/ui/AvailableListModel.java | 145 ++++++++ pmd-netbeans/src/pmd/config/ui/ListCell.java | 41 +++ .../src/pmd/config/ui/RuleEditor.java | 92 +++++ .../src/pmd/config/ui/RuleEnabler.form | 270 ++++++++++++++ .../src/pmd/config/ui/RuleEnabler.java | 328 ++++++++++++++++++ .../src/pmd/config/ui/SelectedListModel.java | 49 +++ 10 files changed, 976 insertions(+), 20 deletions(-) create mode 100644 pmd-netbeans/src/pmd/config/ui/AvailableListModel.java create mode 100644 pmd-netbeans/src/pmd/config/ui/ListCell.java create mode 100644 pmd-netbeans/src/pmd/config/ui/RuleEditor.java create mode 100644 pmd-netbeans/src/pmd/config/ui/RuleEnabler.form create mode 100644 pmd-netbeans/src/pmd/config/ui/RuleEnabler.java create mode 100644 pmd-netbeans/src/pmd/config/ui/SelectedListModel.java diff --git a/pmd-netbeans/src/pmd/RunPMDAction.java b/pmd-netbeans/src/pmd/RunPMDAction.java index aad27888c4..66679309f2 100644 --- a/pmd-netbeans/src/pmd/RunPMDAction.java +++ b/pmd-netbeans/src/pmd/RunPMDAction.java @@ -34,13 +34,13 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.Iterator; +import java.util.List; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.Report; +import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleSet; -import net.sourceforge.pmd.RuleSetFactory; -import net.sourceforge.pmd.RuleSetNotFoundException; import net.sourceforge.pmd.RuleViolation; import org.openide.TopManager; @@ -57,6 +57,7 @@ import org.openide.windows.InputOutput; import org.openide.windows.OutputWriter; import pmd.config.PMDOptionsSettings; +import pmd.config.ui.SelectedListModel; /** * Action that can always be invoked and work procedurally. @@ -222,15 +223,17 @@ public class RunPMDAction extends CookieAction { * @see pmd.config.PMDOptionsSettings#getRulesets() */ private static RuleSet constructRuleSets() { - RuleSet rules = null; - try { - RuleSetFactory ruleSetFactory = new RuleSetFactory(); - rules = ruleSetFactory.createRuleSet( - PMDOptionsSettings.getDefault().getRulesets() ); - } - catch( RuleSetNotFoundException rsnfe ) { - TopManager.getDefault().getErrorManager().notify( rsnfe ); - } + RuleSet rules = new RuleSet(); + + + + SelectedListModel.getSelectedListModelInstance().setData( PMDOptionsSettings.getDefault().getRules() ); + List list = SelectedListModel.getSelectedListModelInstance().getData(); + Iterator iterator = list.iterator(); + while( iterator.hasNext() ) { + rules.addRule( (Rule)iterator.next() ); + } + return rules; } diff --git a/pmd-netbeans/src/pmd/config/Bundle.properties b/pmd-netbeans/src/pmd/config/Bundle.properties index 3b3dc9b6b3..6b80dc18f1 100644 --- a/pmd-netbeans/src/pmd/config/Bundle.properties +++ b/pmd-netbeans/src/pmd/config/Bundle.properties @@ -1,6 +1,6 @@ # Options API LBL_settings=PMD Settings -PROP_rulesets=Rulesets -HINT_rulesets=The rulesets that the pmd action uses +PROP_rules=Rules +HINT_rules=The rules that the pmd action uses Services/pmd-config-option.settings=\PMD Settings UI/Services/IDEConfiguration/ServerAndExternalToolSettings/pmd-config-option.shadow=link diff --git a/pmd-netbeans/src/pmd/config/PMDOptionsSettings.java b/pmd-netbeans/src/pmd/config/PMDOptionsSettings.java index 74d0b22baf..fe620951d4 100644 --- a/pmd-netbeans/src/pmd/config/PMDOptionsSettings.java +++ b/pmd-netbeans/src/pmd/config/PMDOptionsSettings.java @@ -38,18 +38,19 @@ import org.openide.util.NbBundle; */ public class PMDOptionsSettings extends SystemOption { - // private static final long serialVersionUID = ...; + private static final long serialVersionUID = 8418202279282091070L; /** The constant for the rulesets property */ public final static String PROP_RULESETS = "rulesets"; - + /** The constant for the rulesets property */ + public final static String PROP_RULES = "rules"; // No constructor please! /** Sets the default rulesets and initializes the option */ protected void initialize() { super.initialize(); - setRulesets( "rulesets/basic.xml,rulesets/imports.xml,rulesets/unusedcode.xml,rulesets/braces.xml,rulesets/design.xml,rulesets/strings.xml" ); + setRulesets(""); } @@ -91,6 +92,7 @@ public class PMDOptionsSettings extends SystemOption { */ public String getRulesets() { return ( String )getProperty( PROP_RULESETS ); + } @@ -102,4 +104,25 @@ public class PMDOptionsSettings extends SystemOption { public void setRulesets( String rulesets ) { putProperty( PROP_RULESETS, rulesets, true ); } + + /** + * Returns the rulesets property + * + * @return the rulesets property + */ + public String getRules() { + return ( String )getProperty( PROP_RULES ); + + } + + + /** + * Sets the rulesets property + * + * @param rulesets the rulesets value to set + */ + public void setRules( String rules) { + putProperty( PROP_RULES, rules, true ); + } + } diff --git a/pmd-netbeans/src/pmd/config/PMDOptionsSettingsBeanInfo.java b/pmd-netbeans/src/pmd/config/PMDOptionsSettingsBeanInfo.java index 1bee506983..745df6bcb5 100644 --- a/pmd-netbeans/src/pmd/config/PMDOptionsSettingsBeanInfo.java +++ b/pmd-netbeans/src/pmd/config/PMDOptionsSettingsBeanInfo.java @@ -30,11 +30,14 @@ import java.awt.Image; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; +import java.beans.PropertyEditorManager; import java.beans.SimpleBeanInfo; import org.openide.TopManager; import org.openide.util.NbBundle; import org.openide.util.Utilities; +import pmd.config.ui.RuleEditor; +import pmd.config.ui.RuleEnabler; /** * Description of {@link PMDOptionsSettings}. @@ -50,11 +53,13 @@ public class PMDOptionsSettingsBeanInfo extends SimpleBeanInfo { * @return the description of the rulesets property */ public PropertyDescriptor[] getPropertyDescriptors() { + PropertyEditorManager.registerEditor( PMDOptionsSettingsBeanInfo.class, RuleEditor.class ); try { - PropertyDescriptor rulesets = new PropertyDescriptor( "rulesets", PMDOptionsSettings.class ); - rulesets.setDisplayName( NbBundle.getMessage( PMDOptionsSettingsBeanInfo.class, "PROP_rulesets" ) ); - rulesets.setShortDescription( NbBundle.getMessage( PMDOptionsSettingsBeanInfo.class, "HINT_rulesets" ) ); - return new PropertyDescriptor[]{rulesets}; + PropertyDescriptor rules = new PropertyDescriptor( "rules", PMDOptionsSettings.class, "getRules", "setRules" ); + rules.setDisplayName( NbBundle.getMessage( PMDOptionsSettingsBeanInfo.class, "PROP_rules" ) ); + rules.setShortDescription( NbBundle.getMessage( PMDOptionsSettingsBeanInfo.class, "HINT_rules" ) ); + rules.setPropertyEditorClass( RuleEditor.class ); + return new PropertyDescriptor[]{rules}; } catch( IntrospectionException ie ) { TopManager.getDefault().getErrorManager().notify( ie ); diff --git a/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java b/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java new file mode 100644 index 0000000000..5fc742eef3 --- /dev/null +++ b/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java @@ -0,0 +1,145 @@ +/* + * ListModel.java + * + * Created on 14. november 2002, 21:26 + */ +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; + +/** + * @author ole martin mørk + * @created 16. november 2002 + */ +public class AvailableListModel extends AbstractListModel { + private static AvailableListModel listmodel = new AvailableListModel(); + private List list = new ArrayList(); + + + /** + * Gets the instance attribute of the AvailableListModel class + * + * @return The instance value + */ + public static AvailableListModel getInstance() { + return listmodel; + } + + + /** Creates a new instance of ListModel */ + protected AvailableListModel() { + refresh(); + } + + + /** + * Gets the elementAt attribute of the AvailableListModel object + * + * @param param Description of the Parameter + * @return The elementAt value + */ + public Object getElementAt( int param ) { + return ( ( Rule )list.get( param ) ); + } + + + /** + * Gets the size attribute of the AvailableListModel object + * + * @return The size value + */ + public int getSize() { + return list.size(); + } + + + /** + * Sets the list attribute of the AvailableListModel object + * + * @param list The new list value + */ + public void setList( List list ) { + this.list = list; + } + + + /** + * Description of the Method + * + * @param o Description of the Parameter + */ + public void add( Object o ) { + if( !list.contains( o ) ) { + list.add( ( Rule )o ); + fireIntervalAdded( this, list.size(), list.size() ); + } + } + + + /** + * Description of the Method + * + * @param o Description of the Parameter + */ + public void remove( Object o ) { + int i = list.indexOf( o ); + list.remove( o ); + fireIntervalRemoved( this, i, i ); + } + + + /** Description of the Method */ + public void removeAll() { + int i = list.size(); + list.clear(); + fireIntervalRemoved( this, 0, i ); + } + + + /** + * Adds a feature to the All attribute of the AvailableListModel object + * + * @param coll The feature to be added to the All attribute + */ + public void addAll( Collection coll ) { + int i = list.size(); + list.addAll( coll ); + fireIntervalAdded( this, i, list.size() ); + } + + + /** + * Gets the data attribute of the AvailableListModel object + * + * @return The data value + */ + public List getData() { + return list; + } + + public void refresh() { + 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(); + } + } +} diff --git a/pmd-netbeans/src/pmd/config/ui/ListCell.java b/pmd-netbeans/src/pmd/config/ui/ListCell.java new file mode 100644 index 0000000000..3f5df58da2 --- /dev/null +++ b/pmd-netbeans/src/pmd/config/ui/ListCell.java @@ -0,0 +1,41 @@ +/* + * ListCellRenderer.java + * + * Created on 14. november 2002, 21:46 + */ +package pmd.config.ui; + +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.UIManager; +import javax.swing.border.EmptyBorder; +import net.sourceforge.pmd.Rule; + +/** + * @author ole martin mørk + * @created 16. november 2002 + */ +public class ListCell implements ListCellRenderer { + + + /** + * Gets the listCellRendererComponent attribute of the ListCell object + * + * @param jList Description of the Parameter + * @param obj Description of the Parameter + * @param param Description of the Parameter + * @param param3 Description of the Parameter + * @param param4 Description of the Parameter + * @return The listCellRendererComponent value + */ + public java.awt.Component getListCellRendererComponent( + JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + Rule rule = ( Rule )value; + JLabel box = new JLabel( rule.getName() ); + box.setEnabled( true ); + box.setBorder( isSelected ? UIManager.getBorder( "List.focusCellHighlightBorder" ) : new EmptyBorder( 1, 1, 1, 1 ) ); + return box; + } + +} diff --git a/pmd-netbeans/src/pmd/config/ui/RuleEditor.java b/pmd-netbeans/src/pmd/config/ui/RuleEditor.java new file mode 100644 index 0000000000..0688ad5f64 --- /dev/null +++ b/pmd-netbeans/src/pmd/config/ui/RuleEditor.java @@ -0,0 +1,92 @@ +/* + * RuleEditor.java + * + * Created on 18. november 2002, 21:50 + */ +package pmd.config.ui; + +import java.awt.Component; +import java.beans.PropertyEditorSupport; +import java.util.Iterator; +import java.util.List; +import net.sourceforge.pmd.Rule; + +/** + * @author ole martin mørk + * @created 18. november 2002 + */ +public class RuleEditor extends PropertyEditorSupport { + + /** + * Gets the customEditor attribute of the RuleEditor object + * + * @return The customEditor value + */ + public Component getCustomEditor() { + return new RuleEnabler( this ); + } + + + /** + * Description of the Method + * + * @return Description of the Return Value + */ + public boolean supportsCustomEditor() { + return true; + } + + + /** + * Gets the value attribute of the RuleEditor object + * + * @return The value value + */ + public Object getValue() { + String string = getValueAsText( SelectedListModel.getSelectedListModelInstance().getData() ); + return string; + } + + + /** + * Gets the asText attribute of the RuleEditor object + * + * @return The asText value + */ + public String getAsText() { + return getValue().toString(); + } + + + /** + * Sets the value attribute of the RuleEditor object + * + * @param obj The new value value + */ + public void setValue( Object obj ) { + if( obj != null ) { + SelectedListModel.getSelectedListModelInstance().setData( ( String )obj ); + AvailableListModel.getInstance().refresh(); + AvailableListModel.getInstance().getData().removeAll( SelectedListModel.getSelectedListModelInstance().getData() ); + } + } + public void setAsText( String string ) throws IllegalArgumentException {} + + /** + * Gets the valueAsText attribute of the RuleEditor object + * + * @param value Description of the Parameter + * @return The valueAsText value + */ + private String getValueAsText( List value ) { + StringBuffer buffer = new StringBuffer(); + if( value != null ) { + Iterator iterator = value.iterator(); + while( iterator.hasNext() ) { + Rule rule = ( Rule )iterator.next(); + buffer.append( rule.getName() ).append( ", " ); + } + } + return String.valueOf( buffer ); + } +} \ No newline at end of file diff --git a/pmd-netbeans/src/pmd/config/ui/RuleEnabler.form b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.form new file mode 100644 index 0000000000..1d07e1c6a2 --- /dev/null +++ b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.form @@ -0,0 +1,270 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java new file mode 100644 index 0000000000..b153b06512 --- /dev/null +++ b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java @@ -0,0 +1,328 @@ +/* + * Editor.java + * + * Created on 18. november 2002, 21:19 + */ + +package pmd.config.ui; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.beans.PropertyEditorSupport; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.event.ListSelectionEvent; +import net.sourceforge.pmd.Rule; + +/** + * + * @author ole martin mørk + */ +public class RuleEnabler extends JPanel { + private ArrayList value = new ArrayList(); + private final PropertyEditorSupport editor; + public RuleEnabler( PropertyEditorSupport editor ) { + this.editor = editor; + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + private void initComponents() {//GEN-BEGIN:initComponents + java.awt.GridBagConstraints gridBagConstraints; + + jPanel3 = new javax.swing.JPanel(); + jPanel5 = new javax.swing.JPanel(); + jScrollPane1 = new javax.swing.JScrollPane(); + availableList = new javax.swing.JList(); + jScrollPane3 = new javax.swing.JScrollPane(); + chosenList = new javax.swing.JList(); + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + chooseOne = new javax.swing.JButton(); + choseAll = new javax.swing.JButton(); + removeOne = new javax.swing.JButton(); + removeAll = new javax.swing.JButton(); + jPanel6 = new javax.swing.JPanel(); + jLabel6 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + jScrollPane4 = new javax.swing.JScrollPane(); + information = new javax.swing.JEditorPane(); + jScrollPane2 = new javax.swing.JScrollPane(); + example = new javax.swing.JTextPane(); + jPanel1 = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + + setLayout(new java.awt.BorderLayout()); + + jPanel3.setLayout(new java.awt.GridLayout(2, 0, 0, 5)); + + jPanel5.setLayout(new java.awt.GridBagLayout()); + + jPanel5.setBorder(new javax.swing.border.EtchedBorder()); + jScrollPane1.setPreferredSize(new java.awt.Dimension(270, 200)); + availableList.setModel(AvailableListModel.getInstance()); + availableList.setCellRenderer(new ListCell()); + availableList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { + public void valueChanged(javax.swing.event.ListSelectionEvent evt) { + availableListValueChanged(evt); + } + }); + + jScrollPane1.setViewportView(availableList); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridheight = 4; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + jPanel5.add(jScrollPane1, gridBagConstraints); + + jScrollPane3.setPreferredSize(new java.awt.Dimension(270, 200)); + chosenList.setModel(SelectedListModel.getSelectedListModelInstance()); + chosenList.setCellRenderer(new ListCell()); + chosenList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { + public void valueChanged(javax.swing.event.ListSelectionEvent evt) { + chosenListValueChanged(evt); + } + }); + + jScrollPane3.setViewportView(chosenList); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridheight = 4; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + jPanel5.add(jScrollPane3, gridBagConstraints); + + jLabel3.setText("Available rules"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); + jPanel5.add(jLabel3, gridBagConstraints); + + jLabel4.setText("Chosen rules"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); + jPanel5.add(jLabel4, gridBagConstraints); + + chooseOne.setText(">"); + chooseOne.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + chooseOneActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 1; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; + gridBagConstraints.insets = new java.awt.Insets(2, 1, 0, 1); + jPanel5.add(chooseOne, gridBagConstraints); + + choseAll.setText(">>"); + choseAll.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + choseAllActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 2; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.insets = new java.awt.Insets(0, 1, 0, 1); + jPanel5.add(choseAll, gridBagConstraints); + + removeOne.setText("<"); + removeOne.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + removeOneActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 3; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.insets = new java.awt.Insets(0, 1, 0, 1); + jPanel5.add(removeOne, gridBagConstraints); + + removeAll.setText("<<"); + removeAll.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + removeAllActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 4; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; + gridBagConstraints.insets = new java.awt.Insets(0, 1, 0, 1); + jPanel5.add(removeAll, gridBagConstraints); + + jPanel3.add(jPanel5); + + jPanel6.setLayout(new java.awt.GridBagLayout()); + + jPanel6.setBorder(new javax.swing.border.EtchedBorder()); + jLabel6.setText("Information"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = 3; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + jPanel6.add(jLabel6, gridBagConstraints); + + jLabel5.setText("Example"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 3; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = 3; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + jPanel6.add(jLabel5, gridBagConstraints); + + jScrollPane4.setPreferredSize(new java.awt.Dimension(300, 200)); + jScrollPane4.setMinimumSize(new java.awt.Dimension(150, 150)); + jScrollPane4.setViewportView(information); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = 3; + gridBagConstraints.gridheight = 3; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + jPanel6.add(jScrollPane4, gridBagConstraints); + + jScrollPane2.setPreferredSize(new java.awt.Dimension(300, 200)); + example.setEditable(false); + jScrollPane2.setViewportView(example); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 3; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = 3; + gridBagConstraints.gridheight = 3; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + jPanel6.add(jScrollPane2, gridBagConstraints); + + jPanel3.add(jPanel6); + + add(jPanel3, java.awt.BorderLayout.CENTER); + + jPanel1.setLayout(new java.awt.GridLayout(2, 0)); + + jLabel1.setText("Select rules that should be used"); + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jPanel1.add(jLabel1); + + jLabel2.setText("See http://pmd.sf.net for more information"); + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jPanel1.add(jLabel2); + + add(jPanel1, java.awt.BorderLayout.NORTH); + + }//GEN-END:initComponents + + private void chosenListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_chosenListValueChanged + Rule rule = (Rule)chosenList.getSelectedValue(); + example.setText( rule.getExample().trim()); + information.setText( rule.getDescription().trim() ); + }//GEN-LAST:event_chosenListValueChanged + + private void availableListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_availableListValueChanged + Rule rule = (Rule)availableList.getSelectedValue(); + example.setText( rule.getExample().trim() ); + information.setText( rule.getDescription().trim() ); + + }//GEN-LAST:event_availableListValueChanged + + private void removeAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeAllActionPerformed + AvailableListModel.getInstance().addAll( SelectedListModel.getSelectedListModelInstance().getData() ); + SelectedListModel.getSelectedListModelInstance().removeAll(); + editor.firePropertyChange(); + + }//GEN-LAST:event_removeAllActionPerformed + + private void removeOneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeOneActionPerformed + Object object[] = chosenList.getSelectedValues(); + if( object != null ) { + for( int i = 0; i < object.length; i++ ) { + SelectedListModel.getSelectedListModelInstance().remove( object[i] ); + AvailableListModel.getInstance().add( object[i] ); + } + editor.firePropertyChange(); + } + }//GEN-LAST:event_removeOneActionPerformed + + private void choseAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choseAllActionPerformed + SelectedListModel.getSelectedListModelInstance().addAll( AvailableListModel.getInstance().getData() ); + AvailableListModel.getInstance().removeAll(); + editor.firePropertyChange(); + }//GEN-LAST:event_choseAllActionPerformed + + private void chooseOneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseOneActionPerformed + Object object[] = availableList.getSelectedValues(); + if( object != null ) { + for( int i = 0; i < object.length; i++ ) { + AvailableListModel.getInstance().remove( object[i] ); + SelectedListModel.getSelectedListModelInstance().add( object[i] ); + } + editor.firePropertyChange(); + } + }//GEN-LAST:event_chooseOneActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton removeAll; + private javax.swing.JList availableList; + private javax.swing.JButton chooseOne; + private javax.swing.JButton choseAll; + private javax.swing.JTextPane example; + private javax.swing.JLabel jLabel6; + private javax.swing.JScrollPane jScrollPane4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel4; + private javax.swing.JScrollPane jScrollPane3; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel2; + private javax.swing.JEditorPane information; + private javax.swing.JPanel jPanel6; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JLabel jLabel1; + private javax.swing.JPanel jPanel5; + private javax.swing.JPanel jPanel3; + private javax.swing.JPanel jPanel1; + private javax.swing.JButton removeOne; + private javax.swing.JList chosenList; + // End of variables declaration//GEN-END:variables + +} diff --git a/pmd-netbeans/src/pmd/config/ui/SelectedListModel.java b/pmd-netbeans/src/pmd/config/ui/SelectedListModel.java new file mode 100644 index 0000000000..3f5d8cce90 --- /dev/null +++ b/pmd-netbeans/src/pmd/config/ui/SelectedListModel.java @@ -0,0 +1,49 @@ +/* + * SelectedListModel.java + * + * Created on 16. november 2002, 13:16 + */ + +package pmd.config.ui; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.sourceforge.pmd.Rule; + +/** + * + * @author ole martin mørk + */ +public class SelectedListModel extends AvailableListModel { + + private static SelectedListModel listmodel = new SelectedListModel(); + + /** Creates a new instance of SelectedListModel */ + private SelectedListModel() { + super(); + } + + public static AvailableListModel getInstance() { + return listmodel; + } + + public void refresh() { + setList( new ArrayList() ); + } + + public void setData( String rules ) { + refresh(); + Iterator iterator = AvailableListModel.getInstance().getData().iterator(); + while( iterator.hasNext() ) { + Rule rule = (Rule)iterator.next(); + if( rules.indexOf( rule.getName() + ", " ) > -1 ) { + add( rule ); + } + } + } + + public static SelectedListModel getSelectedListModelInstance() { + return listmodel; + } +}