Search in sources :

Example 6 with RowFilter

use of javax.swing.RowFilter in project jabref by JabRef.

the class IntegrityCheckAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    IntegrityCheck check = new IntegrityCheck(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getFileDirectoryPreferences(), Globals.prefs.getBibtexKeyPatternPreferences(), Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()));
    List<IntegrityMessage> messages = check.checkBibtexDatabase();
    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()][4];
        int i = 0;
        for (IntegrityMessage message : messages) {
            model[i][0] = message.getEntry().getId();
            model[i][1] = message.getEntry().getCiteKeyOptional().orElse("");
            model[i][2] = message.getFieldName();
            model[i][3] = message.getMessage();
            showMessage.put(message.getMessage(), true);
            i++;
        }
        // construct view
        JTable table = new JTable(model, new Object[] { "ID", Localization.lang("BibTeX key"), Localization.lang("Field"), Localization.lang("Message") });
        // hide IDs
        TableColumnModel columnModel = table.getColumnModel();
        columnModel.removeColumn(columnModel.getColumn(0));
        RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {

            @Override
            public boolean include(Entry<?, ?> entry) {
                return showMessage.get(entry.getStringValue(3));
            }
        };
        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()) {
                try {
                    String entryId = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0];
                    String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][2];
                    frame.getCurrentBasePanel().editEntryByIdAndFocusField(entryId, fieldName);
                } catch (ArrayIndexOutOfBoundsException exception) {
                }
            }
        });
        // BibTeX key
        table.getColumnModel().getColumn(0).setPreferredWidth(100);
        // field name
        table.getColumnModel().getColumn(1).setPreferredWidth(60);
        // message
        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);
        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);
    }
}
Also used : HashMap(java.util.HashMap) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) IntegrityCheck(org.jabref.logic.integrity.IntegrityCheck) IntegrityMessage(org.jabref.logic.integrity.IntegrityMessage) RowFilter(javax.swing.RowFilter) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) ListSelectionModel(javax.swing.ListSelectionModel) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel) JDialog(javax.swing.JDialog)

Example 7 with RowFilter

use of javax.swing.RowFilter in project CCDD by nasa.

the class CcddFieldTableEditorDialog method displayDataFieldTableEditor.

/**
 ********************************************************************************************
 * Create the data field table editor dialog. This is executed in a separate thread since it
 * can take a noticeable amount time to complete, and by using a separate thread the GUI is
 * allowed to continue to update. The GUI menu commands, however, are disabled until the
 * telemetry scheduler initialization completes execution
 ********************************************************************************************
 */
private void displayDataFieldTableEditor() {
    // Build the data field editor table dialog in the background
    CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {

        // Create panels to hold the components of the dialog
        JPanel dialogPnl = new JPanel(new GridBagLayout());

        JPanel buttonPnl = new JPanel();

        JButton btnClose;

        /**
         ************************************************************************************
         * Build the data field table editor dialog
         ************************************************************************************
         */
        @Override
        protected void execute() {
            // Set the initial layout manager characteristics
            GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), 0, 0, 0), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0);
            // Define the panel to contain the table
            JPanel tablePnl = new JPanel();
            tablePnl.setLayout(new BoxLayout(tablePnl, BoxLayout.X_AXIS));
            tablePnl.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
            tablePnl.add(createDataFieldTableEditorTable());
            // Add the table to the dialog
            gbc.gridx = 0;
            gbc.gridy++;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.fill = GridBagConstraints.BOTH;
            gbc.weighty = 1.0;
            dialogPnl.add(tablePnl, gbc);
            // Add the field display filter label and a filter check box for each field owner
            // type
            JLabel fieldFilterLbl = new JLabel("Show fields belonging to:");
            fieldFilterLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            fieldFilterLbl.setBorder(emptyBorder);
            gbc.gridwidth = 1;
            gbc.weightx = 0.0;
            gbc.weighty = 0.0;
            gbc.gridy++;
            dialogPnl.add(fieldFilterLbl, gbc);
            final JCheckBox projectFilterCbx = new JCheckBox("Project", isProjectFilter);
            projectFilterCbx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            projectFilterCbx.setBorder(emptyBorder);
            gbc.gridx++;
            dialogPnl.add(projectFilterCbx, gbc);
            final JCheckBox tableFilterCbx = new JCheckBox("Tables", isTableFilter);
            tableFilterCbx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            tableFilterCbx.setBorder(emptyBorder);
            gbc.gridx++;
            dialogPnl.add(tableFilterCbx, gbc);
            final JCheckBox groupFilterCbx = new JCheckBox("Groups", isGroupFilter);
            groupFilterCbx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            groupFilterCbx.setBorder(emptyBorder);
            gbc.gridx++;
            dialogPnl.add(groupFilterCbx, gbc);
            final JCheckBox typeFilterCbx = new JCheckBox("Table types", isTypeFilter);
            typeFilterCbx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            typeFilterCbx.setBorder(emptyBorder);
            gbc.gridx++;
            dialogPnl.add(typeFilterCbx, gbc);
            // Create a row filter for displaying the fields based on selected filter
            rowFilter = new RowFilter<TableModel, Object>() {

                /**
                 ****************************************************************************
                 * Override method that determines if a row should be displayed
                 ****************************************************************************
                 */
                @Override
                public boolean include(Entry<? extends TableModel, ? extends Object> owner) {
                    boolean isFilter = true;
                    // Get the data field owner's name
                    String ownerName = highlightFieldOwner(owner.getValue(FieldTableEditorColumnInfo.OWNER.ordinal()).toString(), false);
                    // Check if this field belongs to the project
                    if (ownerName.startsWith(CcddFieldHandler.getFieldProjectName())) {
                        // Show this row if the project filter check box is selected
                        isFilter = projectFilterCbx.isSelected();
                    } else // Check if this field belongs to a group
                    if (ownerName.startsWith(CcddFieldHandler.getFieldGroupName(""))) {
                        // Show this row if the group filter check box is selected
                        isFilter = groupFilterCbx.isSelected();
                    } else // Check if this field belongs to a table type
                    if (ownerName.startsWith(CcddFieldHandler.getFieldTypeName(""))) {
                        // Show this row if the table type filter check box is selected
                        isFilter = typeFilterCbx.isSelected();
                    } else // The field belongs to a table
                    {
                        // Show this row if the table filter check box is selected
                        isFilter = tableFilterCbx.isSelected();
                    }
                    return isFilter;
                }
            };
            // Create a listener for check box selection changes
            ActionListener filterListener = new ActionListener() {

                /**
                 ****************************************************************************
                 * Handle check box selection changes
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // Set the table's row sorter based on whether or not any rows are visible
                    dataFieldTable.setRowSorter(null);
                    dataFieldTable.setTableSortable();
                    // Issue a table change event so the rows are filtered
                    ((DefaultTableModel) dataFieldTable.getModel()).fireTableDataChanged();
                    ((DefaultTableModel) dataFieldTable.getModel()).fireTableStructureChanged();
                }
            };
            // Add the listener to the filter check boxes
            projectFilterCbx.addActionListener(filterListener);
            tableFilterCbx.addActionListener(filterListener);
            groupFilterCbx.addActionListener(filterListener);
            typeFilterCbx.addActionListener(filterListener);
            // Define the buttons for the lower panel: Select data fields button
            JButton btnSelect = CcddButtonPanelHandler.createButton("Select", OK_ICON, KeyEvent.VK_L, "Select new data fields");
            // Add a listener for the Select button
            btnSelect.addActionListener(new ValidateCellActionListener(dataFieldTable) {

                /**
                 ****************************************************************************
                 * Select the data fields and update the data field editor table
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    // Confirm discarding pending changes if any exist
                    if ((!isFieldTableChanged() || new CcddDialogHandler().showMessageDialog(CcddFieldTableEditorDialog.this, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON)) {
                        // Store the current filter selections
                        isProjectFilter = projectFilterCbx.isSelected();
                        isTableFilter = tableFilterCbx.isSelected();
                        isGroupFilter = groupFilterCbx.isSelected();
                        isTypeFilter = typeFilterCbx.isSelected();
                        // Allow the user to select the data fields to display
                        selectDataFields();
                    }
                }
            });
            // Delete data fields button
            JButton btnRemove = CcddButtonPanelHandler.createButton("Remove", DELETE_ICON, KeyEvent.VK_R, "Remove the selected data field(s) from their table(s)");
            // Add a listener for the Remove button
            btnRemove.addActionListener(new ValidateCellActionListener(dataFieldTable) {

                /**
                 ****************************************************************************
                 * Toggle the removal state of the selected data field(s)
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    toggleRemoveFields();
                }
            });
            // Open tables button
            JButton btnOpen = CcddButtonPanelHandler.createButton("Open", TABLE_ICON, KeyEvent.VK_O, "Open the table(s) associated with the selected data field(s)");
            // Add a listener for the Open button
            btnOpen.addActionListener(new ValidateCellActionListener(dataFieldTable) {

                /**
                 ****************************************************************************
                 * Open the table(s) associated with the selected data field(s)
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    openTables();
                }
            });
            // Print data field editor table button
            JButton btnPrint = CcddButtonPanelHandler.createButton("Print", PRINT_ICON, KeyEvent.VK_P, "Print the data field editor table");
            // Add a listener for the Print button
            btnPrint.addActionListener(new ValidateCellActionListener(dataFieldTable) {

                /**
                 ****************************************************************************
                 * Print the data field editor table
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    dataFieldTable.printTable("Data Field Contents", null, CcddFieldTableEditorDialog.this, PageFormat.LANDSCAPE);
                }
            });
            // Undo button
            JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
            // Create a listener for the Undo command
            btnUndo.addActionListener(new ValidateCellActionListener(dataFieldTable) {

                /**
                 ****************************************************************************
                 * Undo the last cell edit
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    dataFieldTable.getUndoManager().undo();
                }
            });
            // Redo button
            JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
            // Create a listener for the Redo command
            btnRedo.addActionListener(new ValidateCellActionListener(dataFieldTable) {

                /**
                 ****************************************************************************
                 * Redo the last cell edit that was undone
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    dataFieldTable.getUndoManager().redo();
                }
            });
            // Store data field values button
            JButton btnStore = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store data field changes");
            // Add a listener for the Store button
            btnStore.addActionListener(new ValidateCellActionListener(dataFieldTable) {

                /**
                 ****************************************************************************
                 * Store changes to the data field values
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    // and the user confirms the action
                    if (isFieldTableChanged() && new CcddDialogHandler().showMessageDialog(CcddFieldTableEditorDialog.this, "<html><b>Store changes in project database?", "Store Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                        // Build the update lists
                        buildUpdates();
                        // Store the changes to the data fields in the database
                        dbTable.modifyDataFields(fieldModifications, fieldDeletions, CcddFieldTableEditorDialog.this);
                    }
                }
            });
            // Close button
            btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the data field editor dialog");
            // Add a listener for the Close button
            btnClose.addActionListener(new ValidateCellActionListener(dataFieldTable) {

                /**
                 ****************************************************************************
                 * Close the data field editor dialog
                 ****************************************************************************
                 */
                @Override
                protected void performAction(ActionEvent ae) {
                    windowCloseButtonAction();
                }
            });
            // Add the buttons to the panel
            buttonPnl.add(btnSelect);
            buttonPnl.add(btnOpen);
            buttonPnl.add(btnUndo);
            buttonPnl.add(btnStore);
            buttonPnl.add(btnRemove);
            buttonPnl.add(btnPrint);
            buttonPnl.add(btnRedo);
            buttonPnl.add(btnClose);
            // Distribute the buttons across two rows
            setButtonRows(2);
        }

        /**
         ************************************************************************************
         * Data field table editor dialog creation complete
         ************************************************************************************
         */
        @Override
        protected void complete() {
            // Display the data field table editor dialog
            createFrame(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnClose, DIALOG_TITLE, null);
            // Reposition the field table editor dialog
            positionFieldEditorDialog();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) RowFilter(javax.swing.RowFilter) ActionListener(java.awt.event.ActionListener) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 8 with RowFilter

use of javax.swing.RowFilter in project gephi by gephi.

the class AbstractElementsDataTable method setFilterPattern.

public boolean setFilterPattern(String regularExpr, int column) {
    try {
        if (Objects.equals(filterPattern, regularExpr)) {
            return true;
        }
        filterPattern = regularExpr;
        if (regularExpr == null || regularExpr.trim().isEmpty()) {
            table.setRowFilter(null);
        } else {
            if (!regularExpr.startsWith("(?i)")) {
                // CASE_INSENSITIVE
                regularExpr = "(?i)" + regularExpr;
            }
            RowFilter rowFilter = RowFilter.regexFilter(regularExpr, column);
            table.setRowFilter(rowFilter);
        }
    } catch (PatternSyntaxException e) {
        return false;
    }
    return true;
}
Also used : RowFilter(javax.swing.RowFilter) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 9 with RowFilter

use of javax.swing.RowFilter in project dna by leifeld.

the class AttributePanel method variableFilter.

private void variableFilter(String variable, int statementTypeId) {
    RowFilter<AttributeTableModel, Integer> attributeFilter = new RowFilter<AttributeTableModel, Integer>() {

        public boolean include(Entry<? extends AttributeTableModel, ? extends Integer> entry) {
            AttributeTableModel atm = entry.getModel();
            AttributeVector av = atm.get(entry.getIdentifier());
            int stId = av.getStatementTypeId();
            String var = av.getVariable();
            if (variable.equals(var) && stId == statementTypeId) {
                return true;
            } else {
                return false;
            }
        }
    };
    sorter.setRowFilter(attributeFilter);
}
Also used : AttributeVector(dna.dataStructures.AttributeVector) RowFilter(javax.swing.RowFilter) AttributeTableModel(dna.renderer.AttributeTableModel)

Example 10 with RowFilter

use of javax.swing.RowFilter in project wekapar by gems-uff.

the class PostprocessAssociationsPanel method applyFilter.

/**
 * Apply filter for rules and metrics
 */
@SuppressWarnings("unchecked")
private static void applyFilter() {
    /* Lists for filters */
    List<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>();
    /* Rule's filter */
    RowFilter<Object, Object> rulesFilter = (RowFilter<Object, Object>) buildRulesFilter(comboFilterComponent.getText().trim());
    if (rulesFilter != null) {
        filters.add(rulesFilter);
    }
    /* Filter for metrics */
    RowFilter<Object, Object> metricsFilter = (RowFilter<Object, Object>) buildMetricsFilter();
    if (metricsFilter != null) {
        filters.add(metricsFilter);
    }
    /* Join rule and metric filters */
    RowFilter<Object, Object> andFilter = RowFilter.andFilter(filters);
    /* Apply filter to table */
    sorter.setRowFilter(andFilter);
    /* Update counting of filtered values */
    lblFilteredRulesValue.setText(String.valueOf(table.getRowCount()));
    /* Update max value reference for ProgressCellRenderer */
    List<?> sortKeys = sorter.getSortKeys();
    if (sortKeys.size() > 0) {
        RowSorter.SortKey key = (SortKey) sortKeys.get(0);
        TableModel tableModel = table.getModel();
        RulesTableColumnModel columnModel = table.getColumnModel();
        String columnName = tableModel.getColumnName(key.getColumn());
        if (columnModel.hasColumn(columnName)) {
            int columnIndex = columnModel.getColumnIndex(columnName);
            TableCellRenderer cellRenderer = columnModel.getColumn(columnIndex).getCellRenderer();
            if (cellRenderer instanceof ProgressCellRenderer) {
                ((ProgressCellRenderer) cellRenderer).updateMaxValue(table, columnIndex);
            }
        }
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) RulesTableCellRenderer(wekapar.table.RulesTableCellRenderer) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) ArrayList(java.util.ArrayList) SortKey(javax.swing.RowSorter.SortKey) SortKey(javax.swing.RowSorter.SortKey) ProgressCellRenderer(wekapar.table.ProgressCellRenderer) Point(java.awt.Point) RowFilter(javax.swing.RowFilter) RulesTableColumnModel(wekapar.table.RulesTableColumnModel) RulesTableModel(wekapar.table.RulesTableModel) TableModel(javax.swing.table.TableModel)

Aggregations

RowFilter (javax.swing.RowFilter)11 Point (java.awt.Point)4 TableRowSorter (javax.swing.table.TableRowSorter)4 TableModel (javax.swing.table.TableModel)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JButton (javax.swing.JButton)2 TechAdvancement (megamek.common.TechAdvancement)2 RulesTableColumnModel (wekapar.table.RulesTableColumnModel)2 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)1 ValidateCellActionListener (CCDD.CcddClassesComponent.ValidateCellActionListener)1 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 AttributeVector (dna.dataStructures.AttributeVector)1 Document (dna.dataStructures.Document)1 AttributeTableModel (dna.renderer.AttributeTableModel)1 DocumentTableModel (dna.renderer.DocumentTableModel)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1