Skip to content

Commit

Permalink
Add filters on rules list
Browse files Browse the repository at this point in the history
- Filter on Option panel
- Filter on Rule details panel
  • Loading branch information
philippefichet committed Apr 13, 2020
1 parent f6c87ed commit d63f946
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 77 deletions.
66 changes: 38 additions & 28 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
= sonarlint4netbeans

== SonarLint integration for Apache Netbeans

Features:

- Support Java and Javascript
- Annotation in editor
- Type SonarLint in Action Items
- Enable/Disable Rules in Tools/Options/Miscellaneous/SonarLint
- Severity icons

== Screenshot

.SonarLint in Java editor and show action items for selected project
image::docs/JavaEditorAnnotationAndActionItems.jpg[]

.Show Action Items fo currently edited file only
image::docs/JavascriptActionItems.jpg[]

.SonarLint analyzer name and version
image::docs/OptionsSonarLintAnalyzers.jpg[]

.SonarLint rules enabled or disabled
image::docs/OptionsSonarLintRules.jpg[]

.Sonar rule details window
image::docs/SonarRuleDetailsWindow.jpg[]
= sonarlint4netbeans

== SonarLint integration for Apache Netbeans

Features:

- Support Java and Javascript
- Annotation in editor
- Type SonarLint in Action Items
- Enable/Disable Rules in Tools/Options/Miscellaneous/SonarLint
- Filter Rules in Tools/Options/Miscellaneous/SonarLint option panel and "Sonar Rule Details" window
- Severity icons

== Screenshot

.SonarLint in Java editor and show action items for selected project
image::docs/JavaEditorAnnotationAndActionItems.jpg[]

.Show Action Items fo currently edited file only
image::docs/JavascriptActionItems.jpg[]

.SonarLint analyzer name and version
image::docs/OptionsSonarLintAnalyzers.jpg[]

.SonarLint rules enabled or disabled
image::docs/OptionsSonarLintRules.jpg[]

.SonarLint rules enabled or disabled with key filter
image::docs/OptionsSonarLintRulesWithKeyFilter.jpg[]

.SonarLint rules enabled or disabled with name filter
image::docs/OptionsSonarLintRulesWithNameFilter.jpg[]

.Sonar rule details window with key filter
image::docs/SonarRuleDetailsWindowWithKeyFilter.jpg[]

.Sonar rule details window with name filter
image::docs/SonarRuleDetailsWindowWithNameFilter.jpg[]
Binary file modified docs/OptionsSonarLintRules.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/OptionsSonarLintRulesWithKeyFilter.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/OptionsSonarLintRulesWithNameFilter.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added docs/SonarRuleDetailsWindowWithNameFilter.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.philippefichet.sonarlint</groupId>
<artifactId>sonarlint4netbeans</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
<packaging>nbm</packaging>
<name>SonarLint for Netbeans</name>
<organization>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
-->

<Form version="1.4" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection component="Form" name="preferredSize" type="property"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
Expand All @@ -31,7 +36,7 @@
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="0"/>
<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,44,0,0,1,-112"/>
</AuxValues>

Expand Down Expand Up @@ -72,6 +77,8 @@
<StringItem index="1" value="Analyzers"/>
</StringArray>
</Property>
<Property name="selectionMode" type="int" value="0"/>
<Property name="selectedIndex" type="int" value="0"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
Expand All @@ -81,10 +88,10 @@
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="optionPanel">
<Container class="javax.swing.JScrollPane" name="optionScrollPane">
<Properties>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Curseur par d&#xe9;faut"/>
<Property name="viewportView" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="null"/>
</Property>
</Properties>
<Constraints>
Expand All @@ -93,7 +100,18 @@
</Constraint>
</Constraints>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="optionPanel">
<Properties>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Curseur par d&#xe9;faut"/>
</Property>
</Properties>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,28 @@

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import org.openide.util.Lookup;
import org.sonarsource.sonarlint.core.client.api.common.RuleDetails;
import org.sonarsource.sonarlint.core.client.api.common.RuleKey;
import org.sonarsource.sonarlint.core.client.api.connected.LoadedAnalyzer;

Expand All @@ -49,17 +53,7 @@ public final class SonarLintPanel extends javax.swing.JPanel {
private final Map<RuleKey, Boolean> ruleKeyChanged = new HashMap<>();
private DefaultTableModel analyzerDefaultTableModel = new DefaultTableModel();

private DefaultTableModel rulesDefaultTableModel = new DefaultTableModel() {
@Override
public boolean isCellEditable(int row, int column) {
return column < 1;
}

@Override
public Class<?> getColumnClass(int columnIndex) {
return columnIndex == 0 ? Boolean.class : String.class;
}
};
private SonarLintRuleTableModel rulesDefaultTableModel = new SonarLintRuleTableModel();

public SonarLintPanel(SonarLintOptionsPanelController controller) {
this.controller = controller;
Expand Down Expand Up @@ -88,23 +82,7 @@ public SonarLintPanel(SonarLintOptionsPanelController controller) {
});
}

rulesDefaultTableModel.addColumn("");
rulesDefaultTableModel.addColumn("Language");
rulesDefaultTableModel.addColumn("Severity");
rulesDefaultTableModel.addColumn("Key");
rulesDefaultTableModel.addColumn("Details");
Collection<RuleDetails> allRuleDetails = engine.getAllRuleDetails();
allRuleDetails.stream().sorted((r1, r2) -> {
return r1.getKey().compareTo(r2.getKey());
}).map(ruleDetail -> new Object[] {
!engine.isExcluded(ruleDetail),
ruleDetail.getLanguageKey(),
ruleDetail.getSeverity(),
ruleDetail.getKey(),
ruleDetail.getName()}
).collect(Collectors.toList()).forEach(rulesDefaultTableModel::addRow);

rulesDefaultTableModel.addTableModelListener((e) -> {
rulesDefaultTableModel.addTableModelListener(e -> {
controller.changed();
int column = e.getColumn();

Expand All @@ -120,7 +98,7 @@ public SonarLintPanel(SonarLintOptionsPanelController controller) {

categoriesList.addListSelectionListener((e) -> {
if ("Rules".equals(categoriesList.getSelectedValue())) {
initRulesPanel();
initRulesPanel(engine);
}
if ("Analyzers".equals(categoriesList.getSelectedValue())) {
initAnalyzersPanel();
Expand All @@ -130,7 +108,7 @@ public SonarLintPanel(SonarLintOptionsPanelController controller) {
});

// Rule panel by default
initRulesPanel();
initRulesPanel(engine);
optionPanel.revalidate();
optionPanel.repaint();
});
Expand All @@ -144,8 +122,35 @@ private void initAnalyzersPanel() {
optionPanel.add(analyzersTable, BorderLayout.CENTER);
}

private void initRulesPanel() {
private void initRulesPanel(SonarLintEngine engine) {
optionPanel.removeAll();

JPanel languageKeyContainer = new JPanel(new FlowLayout());
JTextField rulesFilter = new JTextField();
rulesFilter.setColumns(20);
JComboBox<String> comboLanguageKey = new JComboBox<>();
engine.getAllRuleDetails().stream()
.map(r -> r.getLanguageKey())
.distinct()
.forEach(comboLanguageKey::addItem);
rulesFilter.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
rulesDefaultTableModel.setRules(engine, (String)comboLanguageKey.getSelectedItem(), rulesFilter.getText());
}
});
comboLanguageKey.addActionListener(
e ->
rulesDefaultTableModel.setRules(engine, (String)comboLanguageKey.getSelectedItem(), rulesFilter.getText())
);
languageKeyContainer.add(new JLabel("language key: "));
languageKeyContainer.add(comboLanguageKey);
languageKeyContainer.add(new JSeparator());
languageKeyContainer.add(new JLabel("filter: "));
languageKeyContainer.add(rulesFilter);

JPanel northContainer = new JPanel();
northContainer.setLayout(new BoxLayout(northContainer, BoxLayout.Y_AXIS));
JTable rulesTable = new JTable(rulesDefaultTableModel);
rulesTable.getColumnModel().getColumn(0).setMaxWidth(50);
rulesTable.getColumnModel().getColumn(1).setMaxWidth(250);
Expand All @@ -162,7 +167,11 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
return defaultTableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
});
optionPanel.add(rulesTable.getTableHeader(), BorderLayout.NORTH);

rulesDefaultTableModel.setRules(engine, (String)comboLanguageKey.getSelectedItem(), rulesFilter.getText());
northContainer.add(languageKeyContainer);
northContainer.add(rulesTable.getTableHeader());
optionPanel.add(northContainer, BorderLayout.NORTH);
optionPanel.add(rulesTable, BorderLayout.CENTER);
}

Expand All @@ -178,8 +187,10 @@ private void initComponents() {
categoriesLabel = new javax.swing.JLabel();
categoriesScrollPanel = new javax.swing.JScrollPane();
categoriesList = new javax.swing.JList<>();
optionScrollPane = new javax.swing.JScrollPane();
optionPanel = new javax.swing.JPanel();

setPreferredSize(getPreferredSize());
setLayout(new java.awt.BorderLayout(10, 0));

categoriesPanel.setLayout(new javax.swing.BoxLayout(categoriesPanel, javax.swing.BoxLayout.PAGE_AXIS));
Expand All @@ -192,15 +203,21 @@ private void initComponents() {
public int getSize() { return strings.length; }
public String getElementAt(int i) { return strings[i]; }
});
categoriesList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
categoriesList.setSelectedIndex(0);
categoriesScrollPanel.setViewportView(categoriesList);

categoriesPanel.add(categoriesScrollPanel);

add(categoriesPanel, java.awt.BorderLayout.WEST);

optionScrollPane.setViewportView(null);

optionPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
optionPanel.setLayout(new java.awt.BorderLayout());
add(optionPanel, java.awt.BorderLayout.CENTER);
optionScrollPane.setViewportView(optionPanel);

add(optionScrollPane, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents

void load() {
Expand Down Expand Up @@ -235,10 +252,11 @@ boolean valid() {
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel categoriesLabel;
private javax.swing.JList<String> categoriesList;
private javax.swing.JPanel categoriesPanel;
private javax.swing.JScrollPane categoriesScrollPanel;
private javax.swing.JPanel optionPanel;
javax.swing.JLabel categoriesLabel;
javax.swing.JList<String> categoriesList;
javax.swing.JPanel categoriesPanel;
javax.swing.JScrollPane categoriesScrollPanel;
javax.swing.JPanel optionPanel;
javax.swing.JScrollPane optionScrollPane;
// End of variables declaration//GEN-END:variables
}
Loading

0 comments on commit d63f946

Please sign in to comment.