Search in sources :

Example 1 with Filter

use of edu.umd.cs.findbugs.filter.Filter in project spotbugs by spotbugs.

the class MainFrame method shouldDisplayIssue.

// @SuppressWarnings({ "SimplifiableIfStatement" })
boolean shouldDisplayIssue(BugInstance b) {
    Project project = getProject();
    Filter suppressionFilter = project.getSuppressionFilter();
    if (null == getBugCollection() || suppressionFilter.match(b)) {
        return false;
    }
    return viewFilter.show(b);
}
Also used : Project(edu.umd.cs.findbugs.Project) Filter(edu.umd.cs.findbugs.filter.Filter)

Example 2 with Filter

use of edu.umd.cs.findbugs.filter.Filter in project spotbugs by spotbugs.

the class MainFrameTree method bugListPanel.

public JPanel bugListPanel() {
    tableheader = new JTableHeader();
    getTableheader().setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
    // Listener put here for when user double clicks on sorting
    // column header SorterDialog appears.
    getTableheader().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            Debug.println("tableheader.getReorderingAllowed() = " + getTableheader().getReorderingAllowed());
            if (!getTableheader().getReorderingAllowed()) {
                return;
            }
            if (e.getClickCount() == 2) {
                SorterDialog.getInstance().setVisible(true);
            }
        }

        @Override
        public void mouseReleased(MouseEvent arg0) {
            if (!getTableheader().getReorderingAllowed()) {
                return;
            }
            BugTreeModel bt = (BugTreeModel) (getTree().getModel());
            bt.checkSorter();
        }
    });
    sorter = GUISaveState.getInstance().getStarterTable();
    getTableheader().setColumnModel(getSorter());
    getTableheader().setToolTipText(edu.umd.cs.findbugs.L10N.getLocalString("tooltip.reorder_message", "Drag to reorder tree folder and sort order"));
    tree = new JTree();
    getTree().setLargeModel(true);
    getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    getTree().setCellRenderer(new BugRenderer());
    getTree().setRowHeight((int) (Driver.getFontSize() + 7));
    getTree().setModel(new BugTreeModel(mainFrame, getTree(), getSorter(), new BugSet(new ArrayList<BugLeafNode>())));
    setupTreeListeners();
    mainFrame.setProject(new Project());
    treeScrollPane = new JScrollPane(getTree());
    treePanel = new JPanel(new BorderLayout());
    treePanel.add(treeScrollPane, BorderLayout.CENTER);
    JTable t = new JTable(new DefaultTableModel(0, sortables().length));
    t.setTableHeader(getTableheader());
    textFieldForPackagesToDisplay = new JTextField();
    ActionListener filterAction = e -> {
        try {
            String text = textFieldForPackagesToDisplay.getText();
            if (text.indexOf('/') >= 0) {
                text = text.replace('/', '.');
                textFieldForPackagesToDisplay.setText(text);
            }
            mainFrame.getViewFilter().setPackagesToDisplay(text);
            mainFrame.resetViewCache();
        } catch (IllegalArgumentException err) {
            JOptionPane.showMessageDialog(mainFrame, err.getMessage(), "Bad class search string", JOptionPane.ERROR_MESSAGE);
        }
    };
    textFieldForPackagesToDisplay.addActionListener(filterAction);
    JButton filterButton = new JButton("Filter");
    filterButton.addActionListener(filterAction);
    JPanel filterPanel = new JPanel();
    filterPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy = 1;
    filterPanel.add(textFieldForPackagesToDisplay, gbc);
    gbc.weightx = 0;
    gbc.fill = GridBagConstraints.NONE;
    filterPanel.add(filterButton, gbc);
    filterPanel.setToolTipText("Only show classes containing the word(s) you specify");
    JPanel sortablePanel = new JPanel(new GridBagLayout());
    JLabel sortableLabel = new JLabel("Group bugs by:");
    sortableLabel.setLabelFor(getTableheader());
    gbc = new GridBagConstraints();
    gbc.weightx = 0;
    gbc.gridy = 1;
    gbc.insets = new Insets(3, 3, 3, 3);
    gbc.fill = GridBagConstraints.BOTH;
    sortablePanel.add(sortableLabel, gbc);
    gbc.weightx = 1;
    sortablePanel.add(getTableheader(), gbc);
    getTableheader().setBorder(new LineBorder(Color.BLACK));
    JPanel topPanel = makeNavigationPanel("Class name filter:", filterPanel, sortablePanel, treePanel);
    cardPanel = new JPanel(new CardLayout());
    JPanel waitPanel = new JPanel();
    waitPanel.setLayout(new BoxLayout(waitPanel, BoxLayout.Y_AXIS));
    waitPanel.add(new JLabel("Please wait..."));
    waitStatusLabel = new JLabel();
    waitPanel.add(waitStatusLabel);
    cardPanel.add(topPanel, MainFrame.BugCard.TREECARD.name());
    cardPanel.add(waitPanel, MainFrame.BugCard.WAITCARD.name());
    return cardPanel;
}
Also used : Color(java.awt.Color) Insets(java.awt.Insets) Arrays(java.util.Arrays) TreeModelEvent(javax.swing.event.TreeModelEvent) CardLayout(java.awt.CardLayout) ActionListener(java.awt.event.ActionListener) Filter(edu.umd.cs.findbugs.filter.Filter) JTextField(javax.swing.JTextField) Cursor(java.awt.Cursor) Action(javax.swing.Action) LineBorder(javax.swing.border.LineBorder) JTableHeader(javax.swing.table.JTableHeader) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ArrayList(java.util.ArrayList) SwingUtilities(javax.swing.SwingUtilities) TreeSelectionListener(javax.swing.event.TreeSelectionListener) JMenuItem(javax.swing.JMenuItem) FilterActivityNotifier(edu.umd.cs.findbugs.gui2.FilterActivity.FilterActivityNotifier) MouseAdapter(java.awt.event.MouseAdapter) BorderLayout(java.awt.BorderLayout) ActionMap(javax.swing.ActionMap) MouseListener(java.awt.event.MouseListener) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) Project(edu.umd.cs.findbugs.Project) JButton(javax.swing.JButton) DefaultTableModel(javax.swing.table.DefaultTableModel) TreePath(javax.swing.tree.TreePath) Window(java.awt.Window) JPopupMenu(javax.swing.JPopupMenu) Matcher(edu.umd.cs.findbugs.filter.Matcher) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) JTree(javax.swing.JTree) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) Dimension(java.awt.Dimension) List(java.util.List) JLabel(javax.swing.JLabel) JTable(javax.swing.JTable) GridBagLayout(java.awt.GridBagLayout) Collections(java.util.Collections) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) DefaultTableModel(javax.swing.table.DefaultTableModel) LineBorder(javax.swing.border.LineBorder) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JTableHeader(javax.swing.table.JTableHeader) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) JScrollPane(javax.swing.JScrollPane) CardLayout(java.awt.CardLayout) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Project(edu.umd.cs.findbugs.Project) JTree(javax.swing.JTree) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable)

Example 3 with Filter

use of edu.umd.cs.findbugs.filter.Filter in project spotbugs by spotbugs.

the class MainFrameLoadSaveHelper method importFilter.

/**
 * This method is for when the user wants to open a file.
 */
void importFilter() {
    filterOpenFileChooser.setDialogTitle(L10N.getLocalString("dlg.importFilter_ttl", "Import and merge filter..."));
    boolean retry = true;
    File f;
    while (retry) {
        retry = false;
        int value = filterOpenFileChooser.showOpenDialog(mainFrame);
        if (value != JFileChooser.APPROVE_OPTION) {
            return;
        }
        f = filterOpenFileChooser.getSelectedFile();
        if (!f.exists()) {
            JOptionPane.showMessageDialog(filterOpenFileChooser, "No such file", "Invalid File", JOptionPane.WARNING_MESSAGE);
            retry = true;
            continue;
        }
        Filter filter;
        try {
            filter = Filter.parseFilter(f.getPath());
        } catch (IOException e) {
            JOptionPane.showMessageDialog(filterOpenFileChooser, "Could not load filter.");
            retry = true;
            continue;
        }
        mainFrame.setProjectChanged(true);
        Filter suppressionFilter = mainFrame.getProject().getSuppressionFilter();
        for (Matcher m : filter.getChildren()) {
            suppressionFilter.addChild(m);
        }
        PreferencesFrame.getInstance().updateFilterPanel();
    }
}
Also used : Filter(edu.umd.cs.findbugs.filter.Filter) FileFilter(javax.swing.filechooser.FileFilter) Matcher(edu.umd.cs.findbugs.filter.Matcher) IOException(java.io.IOException) File(java.io.File)

Example 4 with Filter

use of edu.umd.cs.findbugs.filter.Filter in project spotbugs by spotbugs.

the class MainFrameTree method createBranchPopUpMenu.

/**
 * Creates the branch pop up menu that ask if the user wants to hide all the
 * bugs in that branch.
 */
JPopupMenu createBranchPopUpMenu() {
    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem filterMenuItem = MainFrameHelper.newJMenuItem("menu.filterTheseBugs", "Filter these bugs");
    filterMenuItem.addActionListener(evt -> {
        try {
            int startCount;
            TreePath path = MainFrame.getInstance().getTree().getSelectionPath();
            TreePath deletePath = path;
            startCount = ((BugAspects) (path.getLastPathComponent())).getCount();
            int count = ((BugAspects) (path.getParentPath().getLastPathComponent())).getCount();
            while (count == startCount) {
                deletePath = deletePath.getParentPath();
                if (// We are at the
                deletePath.getParentPath() == null) // top of the
                // tree, don't
                // let this be
                // removed,
                // rebuild tree
                // from root.
                {
                    Matcher m1 = mainFrame.getCurrentSelectedBugAspects().getMatcher();
                    Filter suppressionFilter1 = MainFrame.getInstance().getProject().getSuppressionFilter();
                    suppressionFilter1.addChild(m1);
                    PreferencesFrame.getInstance().updateFilterPanel();
                    FilterActivity.notifyListeners(FilterListener.Action.FILTERING, null);
                    return;
                }
                count = ((BugAspects) (deletePath.getParentPath().getLastPathComponent())).getCount();
            }
            /*
                 * deletePath should now be a path to the highest ancestor
                 * branch with the same number of elements as the branch to
                 * be deleted in other words, the branch that we actually
                 * have to remove in order to correctly remove the selected
                 * branch.
                 */
            BugTreeModel model = MainFrame.getInstance().getBugTreeModel();
            TreeModelEvent event = new TreeModelEvent(mainFrame, deletePath.getParentPath(), new int[] { model.getIndexOfChild(deletePath.getParentPath().getLastPathComponent(), deletePath.getLastPathComponent()) }, new Object[] { deletePath.getLastPathComponent() });
            Matcher m2 = mainFrame.getCurrentSelectedBugAspects().getMatcher();
            Filter suppressionFilter2 = MainFrame.getInstance().getProject().getSuppressionFilter();
            suppressionFilter2.addChild(m2);
            PreferencesFrame.getInstance().updateFilterPanel();
            model.sendEvent(event, BugTreeModel.TreeModification.REMOVE);
            // FilterActivity.notifyListeners(FilterListener.Action.FILTERING,
            // null);
            mainFrame.setProjectChanged(true);
            // Selects
            MainFrame.getInstance().getTree().setSelectionRow(0);
        // the
        // top
        // of
        // the
        // Jtree
        // so
        // the
        // CommentsArea
        // syncs
        // up.
        } catch (RuntimeException e) {
            MainFrame.getInstance().showMessageDialog("Unable to create filter: " + e.getMessage());
        }
    });
    popupMenu.add(filterMenuItem);
    return popupMenu;
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) TreePath(javax.swing.tree.TreePath) Matcher(edu.umd.cs.findbugs.filter.Matcher) Filter(edu.umd.cs.findbugs.filter.Filter) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 5 with Filter

use of edu.umd.cs.findbugs.filter.Filter in project spotbugs by spotbugs.

the class PreferencesFrame method createFilterPane.

/**
 * Create a JPanel to display the filtering controls.
 */
private JPanel createFilterPane() {
    JButton addButton = new JButton(edu.umd.cs.findbugs.L10N.getLocalString("dlg.add_dot_btn", "Add..."));
    JButton removeButton = new JButton(edu.umd.cs.findbugs.L10N.getLocalString("dlg.remove_btn", "Remove"));
    JButton removeAllButton = new JButton(edu.umd.cs.findbugs.L10N.getLocalString("dlg.remove_all_btn", "Remove All"));
    JPanel filterPanel = new JPanel();
    filterPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridheight = 1;
    gbc.gridwidth = 1;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1;
    gbc.weighty = 1;
    filterPanel.add(new JLabel("<HTML>These rules control which bugs are shown and which are hidden in this project"), gbc);
    gbc.gridheight = 4;
    gbc.gridwidth = 1;
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1;
    gbc.weighty = 1;
    filterPanel.add(new JScrollPane(filterCheckBoxList), gbc);
    updateFilterPanel();
    gbc.gridheight = 1;
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 0;
    gbc.weighty = 0;
    filterPanel.add(addButton, gbc);
    addButton.addActionListener(evt -> NewFilterFrame.open());
    gbc.gridy = 2;
    gbc.insets = new Insets(5, 0, 0, 0);
    filterPanel.add(removeButton, gbc);
    removeButton.addActionListener(evt -> {
        List<MatchBox> selected = filterCheckBoxList.getSelectedValuesList();
        if (selected.isEmpty()) {
            return;
        }
        for (MatchBox box : selected) {
            MainFrame.getInstance().getProject().getSuppressionFilter().removeChild(box.getMatcher());
        }
        FilterActivity.notifyListeners(FilterListener.Action.UNFILTERING, null);
        MainFrame.getInstance().setProjectChanged(true);
        updateFilterPanel();
    });
    gbc.gridy = 3;
    gbc.weighty = 0;
    gbc.insets = new Insets(5, 0, 0, 0);
    filterPanel.add(removeAllButton, gbc);
    removeAllButton.addActionListener(evt -> {
        boolean needsRebuild = false;
        Filter suppressionFilter = MainFrame.getInstance().getProject().getSuppressionFilter();
        if (!suppressionFilter.isEmpty()) {
            needsRebuild = true;
        }
        suppressionFilter.clear();
        if (needsRebuild) {
            // filters being cleared were disabled
            FilterActivity.notifyListeners(FilterListener.Action.UNFILTERING, null);
        }
        MainFrame.getInstance().setProjectChanged(true);
        updateFilterPanel();
    });
    gbc.gridy = 4;
    gbc.weighty = 1;
    gbc.insets = new Insets(0, 0, 0, 0);
    filterPanel.add(Box.createGlue(), gbc);
    return filterPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Filter(edu.umd.cs.findbugs.filter.Filter) FileFilter(javax.swing.filechooser.FileFilter) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel)

Aggregations

Filter (edu.umd.cs.findbugs.filter.Filter)12 Matcher (edu.umd.cs.findbugs.filter.Matcher)5 FileFilter (javax.swing.filechooser.FileFilter)4 Project (edu.umd.cs.findbugs.Project)3 JMenuItem (javax.swing.JMenuItem)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JButton (javax.swing.JButton)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 JPopupMenu (javax.swing.JPopupMenu)2 JScrollPane (javax.swing.JScrollPane)2 TreeModelEvent (javax.swing.event.TreeModelEvent)2 TreePath (javax.swing.tree.TreePath)2 CompoundMatcher (edu.umd.cs.findbugs.filter.CompoundMatcher)1 FilterActivityNotifier (edu.umd.cs.findbugs.gui2.FilterActivity.FilterActivityNotifier)1