From 2276103f2870bfffab8a7a7f878892dc8e81b02d Mon Sep 17 00:00:00 2001 From: Ole-Martin Mork Date: Thu, 21 Nov 2002 21:15:48 +0000 Subject: [PATCH] More work on the properties dialog. Enabled viewing of properties. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1259 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd-netbeans/src/manifest.mf | 2 +- pmd-netbeans/src/pmd/FaultRegistry.java | 17 ++-- pmd-netbeans/src/pmd/PMDOutputListener.java | 2 +- pmd-netbeans/src/pmd/RunPMDAction.java | 4 +- .../config/PMDOptionsSettingsBeanInfo.java | 6 +- .../src/pmd/config/ui/AvailableListModel.java | 1 + .../src/pmd/config/ui/PropertiesModel.java | 60 ++++++++++++ .../src/pmd/config/ui/RuleEditor.java | 4 +- .../src/pmd/config/ui/RuleEnabler.form | 45 ++++++++- .../src/pmd/config/ui/RuleEnabler.java | 97 +++++++++++++++---- .../src/pmd/config/ui/SelectedListModel.java | 2 - 11 files changed, 199 insertions(+), 41 deletions(-) create mode 100644 pmd-netbeans/src/pmd/config/ui/PropertiesModel.java diff --git a/pmd-netbeans/src/manifest.mf b/pmd-netbeans/src/manifest.mf index 3c6a95cc09..5f0e19d796 100644 --- a/pmd-netbeans/src/manifest.mf +++ b/pmd-netbeans/src/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 -OpenIDE-Module-Specification-Version: 0.50 +OpenIDE-Module-Specification-Version: 0.50.3 Created-By: NetBeans Class-Path: ext/pmd-1.01.jar OpenIDE-Module: pmd diff --git a/pmd-netbeans/src/pmd/FaultRegistry.java b/pmd-netbeans/src/pmd/FaultRegistry.java index 8011faa31f..3344262917 100644 --- a/pmd-netbeans/src/pmd/FaultRegistry.java +++ b/pmd-netbeans/src/pmd/FaultRegistry.java @@ -37,11 +37,16 @@ import org.openide.loaders.DataObject; * @author Ole-Martin Mørk * @created 24. oktober 2002 */ -abstract class FaultRegistry { +public class FaultRegistry { /** The registered faults */ - private static Map faults = new HashMap(); - + private Map faults = new HashMap(); + private static FaultRegistry instance = new FaultRegistry(); + private FaultRegistry() {} + + public static FaultRegistry getInstance() { + return instance; + } /** * Returns the associated dataobject @@ -50,13 +55,13 @@ abstract class FaultRegistry { * @return the associated dataobject * @see pmd.Fault#getFault() */ - public static DataObject getDataObject( String key ) { + public DataObject getDataObject( String key ) { return ( DataObject )faults.get( key ); } /** Clears all entries of the registry */ - public static void clearRegistry() { + public void clearRegistry() { faults.clear(); } @@ -68,7 +73,7 @@ abstract class FaultRegistry { * @param object the object where the fault is * @see pmd.Fault#getFault() */ - public static void registerFault( Fault fault, DataObject object ) { + public void registerFault( Fault fault, DataObject object ) { faults.put( fault.getFault(), object ); } } diff --git a/pmd-netbeans/src/pmd/PMDOutputListener.java b/pmd-netbeans/src/pmd/PMDOutputListener.java index b5d8c809d7..0cd711cd79 100644 --- a/pmd-netbeans/src/pmd/PMDOutputListener.java +++ b/pmd-netbeans/src/pmd/PMDOutputListener.java @@ -78,7 +78,7 @@ public class PMDOutputListener implements OutputListener { */ public void outputLineAction( OutputEvent outputEvent ) { annotation.detach(); - DataObject object = FaultRegistry.getDataObject( outputEvent.getLine() ); + DataObject object = FaultRegistry.getInstance().getDataObject( outputEvent.getLine() ); LineCookie cookie = ( LineCookie )object.getCookie( LineCookie.class ); Set lineset = cookie.getLineSet(); int lineNum = Fault.getLineNum( outputEvent.getLine() ); diff --git a/pmd-netbeans/src/pmd/RunPMDAction.java b/pmd-netbeans/src/pmd/RunPMDAction.java index 66679309f2..d7a50bf36f 100644 --- a/pmd-netbeans/src/pmd/RunPMDAction.java +++ b/pmd-netbeans/src/pmd/RunPMDAction.java @@ -159,7 +159,7 @@ public class RunPMDAction extends CookieAction { buffer.append( violation.getDescription() ); Fault fault = new Fault( violation.getLine(), name, buffer.toString() ); list.add( fault ); - FaultRegistry.registerFault( fault, dataobject ); + FaultRegistry.getInstance().registerFault( fault, dataobject ); } Collections.sort( list ); for( int i = 0; i < list.size(); i++ ) { @@ -178,7 +178,7 @@ public class RunPMDAction extends CookieAction { protected void performAction( Node[] node ) { PMDOutputListener listener = PMDOutputListener.getInstance(); listener.detach(); - FaultRegistry.clearRegistry(); + FaultRegistry.getInstance().clearRegistry(); try { printed = false; InputOutput io = TopManager.getDefault().getIO( "PMD output", false ); diff --git a/pmd-netbeans/src/pmd/config/PMDOptionsSettingsBeanInfo.java b/pmd-netbeans/src/pmd/config/PMDOptionsSettingsBeanInfo.java index 745df6bcb5..b6f3d57c4a 100644 --- a/pmd-netbeans/src/pmd/config/PMDOptionsSettingsBeanInfo.java +++ b/pmd-netbeans/src/pmd/config/PMDOptionsSettingsBeanInfo.java @@ -37,7 +37,6 @@ 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}. @@ -54,17 +53,18 @@ public class PMDOptionsSettingsBeanInfo extends SimpleBeanInfo { */ public PropertyDescriptor[] getPropertyDescriptors() { PropertyEditorManager.registerEditor( PMDOptionsSettingsBeanInfo.class, RuleEditor.class ); + PropertyDescriptor descriptor[] = new PropertyDescriptor[1]; try { 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}; + descriptor[0] = rules; } catch( IntrospectionException ie ) { TopManager.getDefault().getErrorManager().notify( ie ); - return null; } + return descriptor; } diff --git a/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java b/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java index 5fc742eef3..a963cb0603 100644 --- a/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java +++ b/pmd-netbeans/src/pmd/config/ui/AvailableListModel.java @@ -129,6 +129,7 @@ public class AvailableListModel extends AbstractListModel { } public void refresh() { + list.clear(); try { RuleSetFactory ruleSetFactory = new RuleSetFactory(); Iterator iterator = ruleSetFactory.getRegisteredRuleSets(); diff --git a/pmd-netbeans/src/pmd/config/ui/PropertiesModel.java b/pmd-netbeans/src/pmd/config/ui/PropertiesModel.java new file mode 100644 index 0000000000..3818108ff6 --- /dev/null +++ b/pmd-netbeans/src/pmd/config/ui/PropertiesModel.java @@ -0,0 +1,60 @@ +/* + * PropertiesModel.java + * + * Created on 21. november 2002, 20:59 + */ + +package pmd.config.ui; + +import java.util.Enumeration; +import javax.swing.table.AbstractTableModel; +import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.RuleProperties; + +/** + * + * @author ole martin mørk + */ +public class PropertiesModel extends AbstractTableModel { + + private final String values[][]; + /** Creates a new instance of PropertiesModel */ + public PropertiesModel( Rule rule ) { + if( rule == null ) { + values = new String[0][0]; + return; + } + RuleProperties properties = rule.getProperties(); + values = new String[properties.size()][2]; + Enumeration keys = properties.keys(); + int counter = 0; + while(keys.hasMoreElements() ) { + String key = (String)keys.nextElement(); + values[counter][0] = key; + values[counter][1] = properties.getProperty( key ); + counter++; + } + + } + + public int getColumnCount() { + return 2; + } + + public int getRowCount() { + return values.length; + } + + public Object getValueAt(int param, int param1) { + return values[param][param1]; + } + + public String getColumnName( int column ) { + return column == 0 ? "Name" : "Value"; + } + + public boolean isCellEditable( int rowIndex, int columnIndex ) { + return columnIndex == 1; + } + +} \ No newline at end of file diff --git a/pmd-netbeans/src/pmd/config/ui/RuleEditor.java b/pmd-netbeans/src/pmd/config/ui/RuleEditor.java index 0688ad5f64..56744c0086 100644 --- a/pmd-netbeans/src/pmd/config/ui/RuleEditor.java +++ b/pmd-netbeans/src/pmd/config/ui/RuleEditor.java @@ -36,7 +36,6 @@ public class RuleEditor extends PropertyEditorSupport { return true; } - /** * Gets the value attribute of the RuleEditor object * @@ -44,10 +43,9 @@ public class RuleEditor extends PropertyEditorSupport { */ public Object getValue() { String string = getValueAsText( SelectedListModel.getSelectedListModelInstance().getData() ); + //JOptionPane.showMessageDialog( null, string ); return string; } - - /** * Gets the asText attribute of the RuleEditor object * diff --git a/pmd-netbeans/src/pmd/config/ui/RuleEnabler.form b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.form index 1d07e1c6a2..e449544f74 100644 --- a/pmd-netbeans/src/pmd/config/ui/RuleEnabler.form +++ b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.form @@ -2,7 +2,7 @@
- + @@ -56,6 +56,7 @@ + @@ -85,6 +86,7 @@ + @@ -190,7 +192,7 @@ - + @@ -220,22 +222,55 @@ + + + - + - + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + diff --git a/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java index b153b06512..8bb63fdcb7 100644 --- a/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java +++ b/pmd-netbeans/src/pmd/config/ui/RuleEnabler.java @@ -6,18 +6,8 @@ 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; /** @@ -25,7 +15,7 @@ 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; @@ -58,7 +48,10 @@ public class RuleEnabler extends JPanel { jScrollPane4 = new javax.swing.JScrollPane(); information = new javax.swing.JEditorPane(); jScrollPane2 = new javax.swing.JScrollPane(); - example = new javax.swing.JTextPane(); + example = new javax.swing.JEditorPane(); + jScrollPane5 = new javax.swing.JScrollPane(); + properties = new javax.swing.JTable(); + jLabel7 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); @@ -79,6 +72,12 @@ public class RuleEnabler extends JPanel { } }); + availableList.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + availableListMouseClicked(evt); + } + }); + jScrollPane1.setViewportView(availableList); gridBagConstraints = new java.awt.GridBagConstraints(); @@ -98,6 +97,12 @@ public class RuleEnabler extends JPanel { } }); + chosenList.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + chosenListMouseClicked(evt); + } + }); + jScrollPane3.setViewportView(chosenList); gridBagConstraints = new java.awt.GridBagConstraints(); @@ -201,7 +206,7 @@ public class RuleEnabler extends JPanel { gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); jPanel6.add(jLabel5, gridBagConstraints); @@ -220,7 +225,7 @@ public class RuleEnabler extends JPanel { jPanel6.add(jScrollPane4, gridBagConstraints); jScrollPane2.setPreferredSize(new java.awt.Dimension(300, 200)); - example.setEditable(false); + jScrollPane2.setMinimumSize(new java.awt.Dimension(150, 150)); jScrollPane2.setViewportView(example); gridBagConstraints = new java.awt.GridBagConstraints(); @@ -229,10 +234,32 @@ public class RuleEnabler extends JPanel { gridBagConstraints.gridwidth = 3; gridBagConstraints.gridheight = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; + gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); jPanel6.add(jScrollPane2, gridBagConstraints); + jScrollPane5.setPreferredSize(new java.awt.Dimension(300, 200)); + properties.setModel(new PropertiesModel(null)); + jScrollPane5.setViewportView(properties); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 6; + 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(jScrollPane5, gridBagConstraints); + + jLabel7.setText("Properties"); + gridBagConstraints = new java.awt.GridBagConstraints(); + 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(jLabel7, gridBagConstraints); + jPanel3.add(jPanel6); add(jPanel3, java.awt.BorderLayout.CENTER); @@ -251,17 +278,30 @@ public class RuleEnabler extends JPanel { }//GEN-END:initComponents + private void chosenListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chosenListMouseClicked + if( evt.getClickCount() >= 2 ) { + removeOneActionPerformed( null ); + } + }//GEN-LAST:event_chosenListMouseClicked + + private void availableListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_availableListMouseClicked + if( evt.getClickCount() >= 2 ) { + chooseOneActionPerformed( null ); + } + }//GEN-LAST:event_availableListMouseClicked + 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() ); + properties.setModel( new PropertiesModel( rule ) ); }//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() ); - + properties.setModel( new PropertiesModel( rule ) ); }//GEN-LAST:event_availableListValueChanged private void removeAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeAllActionPerformed @@ -272,6 +312,7 @@ public class RuleEnabler extends JPanel { }//GEN-LAST:event_removeAllActionPerformed private void removeOneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeOneActionPerformed + int index = chosenList.getSelectedIndex(); Object object[] = chosenList.getSelectedValues(); if( object != null ) { for( int i = 0; i < object.length; i++ ) { @@ -279,7 +320,15 @@ 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 >= 0 ) { + chosenList.setSelectedIndex( index ); + chosenList.requestFocus(); + } } + }//GEN-LAST:event_removeOneActionPerformed private void choseAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choseAllActionPerformed @@ -289,6 +338,7 @@ public class RuleEnabler extends JPanel { }//GEN-LAST:event_choseAllActionPerformed private void chooseOneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseOneActionPerformed + int index = availableList.getSelectedIndex(); Object object[] = availableList.getSelectedValues(); if( object != null ) { for( int i = 0; i < object.length; i++ ) { @@ -296,7 +346,15 @@ 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 >= 0 ) { + availableList.setSelectedIndex( index ); + availableList.requestFocus(); + } + } + }//GEN-LAST:event_chooseOneActionPerformed @@ -304,8 +362,11 @@ public class RuleEnabler extends JPanel { private javax.swing.JButton removeAll; private javax.swing.JList availableList; private javax.swing.JButton chooseOne; + private javax.swing.JTable properties; private javax.swing.JButton choseAll; - private javax.swing.JTextPane example; + private javax.swing.JEditorPane example; + private javax.swing.JLabel jLabel7; + private javax.swing.JScrollPane jScrollPane5; private javax.swing.JLabel jLabel6; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JLabel jLabel5; diff --git a/pmd-netbeans/src/pmd/config/ui/SelectedListModel.java b/pmd-netbeans/src/pmd/config/ui/SelectedListModel.java index 3f5d8cce90..7f185b0f51 100644 --- a/pmd-netbeans/src/pmd/config/ui/SelectedListModel.java +++ b/pmd-netbeans/src/pmd/config/ui/SelectedListModel.java @@ -8,7 +8,6 @@ package pmd.config.ui; import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import net.sourceforge.pmd.Rule; /** @@ -33,7 +32,6 @@ public class SelectedListModel extends AvailableListModel { } public void setData( String rules ) { - refresh(); Iterator iterator = AvailableListModel.getInstance().getData().iterator(); while( iterator.hasNext() ) { Rule rule = (Rule)iterator.next();