Search in sources :

Example 21 with TableModelListener

use of javax.swing.event.TableModelListener in project blue by kunstmusik.

the class LiveObjectsTableModel method fireTableDataChanged.

private void fireTableDataChanged(TableModelEvent tme) {
    if (tableListeners == null) {
        return;
    }
    for (Iterator iter = tableListeners.iterator(); iter.hasNext(); ) {
        TableModelListener listener = (TableModelListener) iter.next();
        listener.tableChanged(tme);
    }
}
Also used : TableModelListener(javax.swing.event.TableModelListener) Iterator(java.util.Iterator)

Example 22 with TableModelListener

use of javax.swing.event.TableModelListener in project gephi by gephi.

the class AbstractWizardVisualPanel1 method refreshPreviewTable.

public void refreshPreviewTable() {
    try (SheetParser parser = importer.createParser()) {
        Map<String, Integer> headerMap = parser.getHeaderMap();
        final String[] headers = headerMap.keySet().toArray(new String[0]);
        columnCount = headers.length;
        hasSourceNodeColumn = false;
        hasTargetNodeColumn = false;
        int sourceColumnIndex = 0;
        int targetColumnIndex = 0;
        for (String header : headers) {
            if (header.equalsIgnoreCase("source")) {
                hasSourceNodeColumn = true;
                sourceColumnIndex = headerMap.get(header);
            }
            if (header.equalsIgnoreCase("target")) {
                hasTargetNodeColumn = true;
                targetColumnIndex = headerMap.get(header);
            }
        }
        ArrayList<String[]> records = new ArrayList<>();
        hasRowsMissingSourcesOrTargets = false;
        final SpreadsheetGeneralConfiguration.Mode mode = getSelectedMode();
        int maxRowSize = 0;
        String[] currentRecord;
        Iterator<SheetRow> iterator = parser.iterator();
        int count = 0;
        while (iterator.hasNext() && count < MAX_ROWS_PREVIEW) {
            count++;
            final SheetRow row = iterator.next();
            final int rowSize = row.size();
            maxRowSize = Math.max(maxRowSize, row.size());
            currentRecord = new String[rowSize];
            for (int i = 0; i < rowSize; i++) {
                currentRecord[i] = row.get(i);
            }
            // Search for missing source or target columns for edges table
            if (mode == SpreadsheetGeneralConfiguration.Mode.EDGES_TABLE) {
                if (rowSize <= sourceColumnIndex || rowSize <= targetColumnIndex || currentRecord[sourceColumnIndex] == null || currentRecord[targetColumnIndex] == null) {
                    hasRowsMissingSourcesOrTargets = true;
                }
            }
            records.add(currentRecord);
        }
        final String[] columnNames = headers;
        final String[][] values = records.toArray(new String[0][]);
        final int rowSize = maxRowSize;
        final JTable table = getPreviewTable();
        table.setModel(new TableModel() {

            @Override
            public int getRowCount() {
                return values.length;
            }

            @Override
            public int getColumnCount() {
                return rowSize;
            }

            @Override
            public String getColumnName(int columnIndex) {
                if (columnIndex > columnNames.length - 1) {
                    return null;
                }
                return columnNames[columnIndex];
            }

            @Override
            public Class<?> getColumnClass(int columnIndex) {
                return String.class;
            }

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }

            @Override
            public Object getValueAt(int rowIndex, int columnIndex) {
                if (values[rowIndex].length > columnIndex) {
                    return values[rowIndex][columnIndex];
                } else {
                    return null;
                }
            }

            @Override
            public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            }

            @Override
            public void addTableModelListener(TableModelListener l) {
            }

            @Override
            public void removeTableModelListener(TableModelListener l) {
            }
        });
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                boolean needsHeader = headers.length > 0;
                getPreviewTableScrollPane().setColumnHeaderView(needsHeader ? table.getTableHeader() : null);
            }
        });
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ArrayList(java.util.ArrayList) SheetParser(org.gephi.io.importer.plugin.file.spreadsheet.sheet.SheetParser) IOException(java.io.IOException) SheetRow(org.gephi.io.importer.plugin.file.spreadsheet.sheet.SheetRow) SpreadsheetGeneralConfiguration(org.gephi.io.importer.plugin.file.spreadsheet.process.SpreadsheetGeneralConfiguration) JTable(javax.swing.JTable) TableModelListener(javax.swing.event.TableModelListener) TableModel(javax.swing.table.TableModel)

Example 23 with TableModelListener

use of javax.swing.event.TableModelListener in project dna by leifeld.

the class CoderRelationTableModel method setValueAt.

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    CoderRelation cr = Dna.data.getCoderRelations().get(rowIndex);
    if (columnIndex == 0) {
        Dna.data.getCoderById(cr.getOtherCoder()).setName((String) aValue);
    } else if (columnIndex == 1) {
        Dna.data.getCoderRelations().get(rowIndex).setViewStatements((boolean) aValue);
        Dna.dna.sql.updateCoderRelationViewStatements(cr.getId(), (boolean) aValue);
    } else if (columnIndex == 2) {
        Dna.data.getCoderRelations().get(rowIndex).setEditStatements((boolean) aValue);
        Dna.dna.sql.updateCoderRelationEditStatements(cr.getId(), (boolean) aValue);
    } else if (columnIndex == 3) {
        Dna.data.getCoderRelations().get(rowIndex).setViewDocuments((boolean) aValue);
        Dna.dna.sql.updateCoderRelationViewDocuments(cr.getId(), (boolean) aValue);
    } else if (columnIndex == 4) {
        Dna.data.getCoderRelations().get(rowIndex).setEditDocuments((boolean) aValue);
        Dna.dna.sql.updateCoderRelationEditDocuments(cr.getId(), (boolean) aValue);
    }
    TableModelEvent e = new TableModelEvent(this);
    for (int i = 0, n = listeners.size(); i < n; i++) {
        ((TableModelListener) listeners.get(i)).tableChanged(e);
    }
    // fireTableCellUpdated(rowIndex, columnIndex);
    // update statement-related GUI parts
    Dna.dna.gui.textPanel.paintStatements();
    Dna.dna.gui.rightPanel.statementPanel.statementFilter.updateFilter();
    // update document-related GUI parts
    Dna.dna.gui.documentPanel.documentFilter();
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener) CoderRelation(dna.dataStructures.CoderRelation)

Example 24 with TableModelListener

use of javax.swing.event.TableModelListener in project dna by leifeld.

the class StatementTableModel method clear.

public void clear() {
    Dna.data.getStatements().clear();
    TableModelEvent e = new TableModelEvent(this);
    for (int i = 0, n = listeners.size(); i < n; i++) {
        ((TableModelListener) listeners.get(i)).tableChanged(e);
    }
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener)

Example 25 with TableModelListener

use of javax.swing.event.TableModelListener in project dna by leifeld.

the class DocumentTableModel method clear.

public void clear() {
    Dna.data.getDocuments().clear();
    TableModelEvent e = new TableModelEvent(this);
    for (int i = 0, n = listeners.size(); i < n; i++) {
        ((TableModelListener) listeners.get(i)).tableChanged(e);
    }
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener)

Aggregations

TableModelListener (javax.swing.event.TableModelListener)68 TableModelEvent (javax.swing.event.TableModelEvent)54 JScrollPane (javax.swing.JScrollPane)11 Iterator (java.util.Iterator)9 JTable (javax.swing.JTable)9 ListSelectionEvent (javax.swing.event.ListSelectionEvent)9 ActionEvent (java.awt.event.ActionEvent)8 ListSelectionListener (javax.swing.event.ListSelectionListener)8 Dimension (java.awt.Dimension)7 ActionListener (java.awt.event.ActionListener)7 JButton (javax.swing.JButton)7 JPanel (javax.swing.JPanel)7 DefaultTableModel (javax.swing.table.DefaultTableModel)6 TableColumn (javax.swing.table.TableColumn)6 ArrayList (java.util.ArrayList)5 GridBagConstraints (java.awt.GridBagConstraints)4 KeyShortcut (com.igormaznitsa.mindmap.swing.panel.utils.KeyShortcut)3 BorderLayout (java.awt.BorderLayout)3 Insets (java.awt.Insets)3 MouseAdapter (java.awt.event.MouseAdapter)3