Skip to content

Commit

Permalink
Added filter to not show selected integrity checks (#1588)
Browse files Browse the repository at this point in the history
* Added filter to not show selected integrity checks

* Removed unused variable
  • Loading branch information
oscargus authored Jul 20, 2016
1 parent 82b8f6e commit ad09d78
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- [#1026](https://github.com/JabRef/jabref/issues/1026) JabRef does no longer delete user comments outside of BibTeX entries and strings
- [#1249](https://github.com/JabRef/jabref/issues/1249) Date layout formatter added
- Added ISBN integrity checker
- Added filter to not show selected integrity checks

### Fixed
- Fixed [#1264](https://github.com/JabRef/jabref/issues/1264): S with caron does not render correctly
Expand Down
64 changes: 55 additions & 9 deletions src/main/java/net/sf/jabref/gui/actions/IntegrityCheckAction.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package net.sf.jabref.gui.actions;

import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.RowFilter;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.JabRefFrame;
Expand All @@ -17,6 +26,9 @@
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.preferences.JabRefPreferences;

import com.jgoodies.forms.builder.FormBuilder;
import com.jgoodies.forms.layout.FormLayout;

public class IntegrityCheckAction extends MnemonicAwareAction {

private static final String ELLIPSES = "...";
Expand All @@ -38,13 +50,15 @@ public void actionPerformed(ActionEvent e) {
if (messages.isEmpty()) {
JOptionPane.showMessageDialog(frame.getCurrentBasePanel(), Localization.lang("No problems found."));
} else {
Map<String, Boolean> showMessage = new HashMap<>();
// prepare data model
Object[][] model = new Object[messages.size()][3];
int i = 0;
for (IntegrityMessage message : messages) {
model[i][0] = message.getEntry().getCiteKey();
model[i][1] = message.getFieldName();
model[i][2] = message.getMessage();
showMessage.put(message.getMessage(), true);
i++;
}

Expand All @@ -53,30 +67,62 @@ public void actionPerformed(ActionEvent e) {
new Object[] {Localization.lang("BibTeX key"), Localization.lang("Field"),
Localization.lang("Message")});

table.setAutoCreateRowSorter(true);
RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {

@Override
public boolean include(Entry<?, ?> entry) {
return showMessage.get(entry.getStringValue(2));
}
};

TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
sorter.setRowFilter(filter);
table.setRowSorter(sorter);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
ListSelectionModel selectionModel = table.getSelectionModel();


selectionModel.addListSelectionListener(event -> {
if (!event.getValueIsAdjusting()) {
String citeKey = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0];
String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][1];
frame.getCurrentBasePanel().editEntryByKeyAndFocusField(citeKey, fieldName);
try {
String citeKey = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0];
String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][1];
frame.getCurrentBasePanel().editEntryByKeyAndFocusField(citeKey, fieldName);
} catch (ArrayIndexOutOfBoundsException exception) {
// Ignore -- most likely caused by filtering out the earlier selected row
}
}
});

table.setRowHeight(Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE) + 2);

table.getColumnModel().getColumn(0).setPreferredWidth(80);
table.getColumnModel().getColumn(1).setPreferredWidth(30);
table.getColumnModel().getColumn(2).setPreferredWidth(250);
table.getColumnModel().getColumn(0).setPreferredWidth(100);
table.getColumnModel().getColumn(1).setPreferredWidth(60);
table.getColumnModel().getColumn(2).setPreferredWidth(400);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
JScrollPane scrollPane = new JScrollPane(table);
String title = Localization.lang("%0 problem(s) found", String.valueOf(messages.size()));
JDialog dialog = new JDialog(frame, title, false);
dialog.add(scrollPane);
dialog.setSize(600, 500);

JPopupMenu menu = new JPopupMenu();
for (String messageString : showMessage.keySet()) {
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(messageString, true);
menuItem.addActionListener(event -> {
showMessage.put(messageString, menuItem.isSelected());
((AbstractTableModel) table.getModel()).fireTableDataChanged();
});
menu.add(menuItem);
}
JButton menuButton = new JButton(Localization.lang("Filter"));
menuButton.addActionListener(entry -> menu.show(menuButton, 0, menuButton.getHeight()));
FormBuilder builder = FormBuilder.create()
.layout(new FormLayout("fill:pref:grow", "fill:pref:grow, 2dlu, pref"));

builder.add(scrollPane).xy(1, 1);
builder.add(menuButton).xy(1, 3, "c, b");
dialog.add(builder.getPanel());
dialog.setSize(600, 600);

// show view
dialog.setVisible(true);
Expand Down

0 comments on commit ad09d78

Please sign in to comment.