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
This commit is contained in:
Ole-Martin Mork
2002-11-21 21:15:48 +00:00
parent 1c8b83e86e
commit 2276103f28
11 changed files with 199 additions and 41 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -129,6 +129,7 @@ public class AvailableListModel extends AbstractListModel {
}
public void refresh() {
list.clear();
try {
RuleSetFactory ruleSetFactory = new RuleSetFactory();
Iterator iterator = ruleSetFactory.getRegisteredRuleSets();

View File

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

View File

@ -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
*

View File

@ -2,7 +2,7 @@
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-77,0,0,2,-115"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,4,0,0,2,109"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
@ -56,6 +56,7 @@
</Properties>
<Events>
<EventHandler event="valueChanged" listener="javax.swing.event.ListSelectionListener" parameters="javax.swing.event.ListSelectionEvent" handler="availableListValueChanged"/>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="availableListMouseClicked"/>
</Events>
</Component>
</SubComponents>
@ -85,6 +86,7 @@
</Properties>
<Events>
<EventHandler event="valueChanged" listener="javax.swing.event.ListSelectionListener" parameters="javax.swing.event.ListSelectionEvent" handler="chosenListValueChanged"/>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="chosenListMouseClicked"/>
</Events>
</Component>
</SubComponents>
@ -190,7 +192,7 @@
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="3" gridY="0" gridWidth="3" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="12" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="3" gridY="0" gridWidth="3" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="11" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
@ -220,22 +222,55 @@
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 200]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[150, 150]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="3" gridY="1" gridWidth="3" gridHeight="3" fill="1" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="14" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="3" gridY="1" gridWidth="3" gridHeight="3" fill="1" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="15" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextPane" name="example">
<Component class="javax.swing.JEditorPane" name="example">
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane5">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 200]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="6" gridY="1" gridWidth="3" gridHeight="3" fill="1" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="14" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="properties">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new PropertiesModel(null)" type="code"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel7">
<Properties>
<Property name="text" type="java.lang.String" value="Properties"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="-1" gridY="-1" gridWidth="3" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="12" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
</SubComponents>

View File

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

View File

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