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);
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations