Example usage for javax.swing.table TableModel getRowCount

List of usage examples for javax.swing.table TableModel getRowCount

Introduction

In this page you can find the example usage for javax.swing.table TableModel getRowCount.

Prototype

public int getRowCount();

Source Link

Document

Returns the number of rows in the model.

Usage

From source file:org.pentaho.reporting.engine.classic.extensions.modules.mailer.MailProcessor.java

private static void processRecipients(final MailDefinition definition, final MimeMessage message,
        final DataFactory dataFactory, final DataRow parameterDataRow)
        throws ReportDataFactoryException, MessagingException {
    if (definition.getRecipientsQuery() != null
            && dataFactory.isQueryExecutable(definition.getRecipientsQuery(), parameterDataRow)) {
        final TableModel model = wrapWithParameters(
                dataFactory.queryData(definition.getRecipientsQuery(), parameterDataRow), parameterDataRow);

        for (int r = 0; r < model.getRowCount(); r++) {
            String address = null;
            String name = null;//from  w  ww .  jav  a 2  s  .c  o m
            String type = "TO";
            if (model.getColumnCount() >= 3) {
                type = (String) model.getValueAt(0, 2);
            }
            if (model.getColumnCount() >= 2) {
                name = (String) model.getValueAt(0, 1);
            }
            if (model.getColumnCount() >= 1) {
                address = (String) model.getValueAt(0, 0);
            }
            if (address == null) {
                continue;
            }

            if (name == null) {
                message.addRecipient(parseType(type), new InternetAddress(address, true));
            } else {
                try {
                    message.addRecipient(parseType(type), new InternetAddress(address, name, "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    // Should not happen - UTF-8 is safe to use
                    throw new MessagingException("Failed to encode recipient", e);
                }
            }
        }
    }
}

From source file:org.pentaho.reporting.platform.plugin.cache.PentahoDataCache.java

public synchronized TableModel put(final DataCacheKey key, final TableModel model) {
    if (log.isDebugEnabled()) {
        log.debug("put() called");
    }/* w ww.  j  av  a 2  s  .c o m*/

    final IPentahoSession session = PentahoSessionHolder.getSession();
    if (cacheManager != null) {
        if (model.getRowCount() > maximumRows) {

            if (log.isDebugEnabled()) {
                log.debug("too many rows (" + model.getRowCount() + " > " + maximumRows + ") not caching.");
            }
            return model;
        }

        // Only copy if safe to do so. Check for whitelist of good column types ..
        if (CachableTableModel.isSafeToCache(model) == false) {
            if (log.isDebugEnabled()) {
                log.debug("model is not safe to cache. not caching.");
            }
            return model;
        }

        if (log.isDebugEnabled()) {
            log.debug("placing model in cache for session " + session.getId() + " (rows="
                    + model.getColumnCount() + ")");
        }
        final TableModel cacheModel = new CachableTableModel(model);
        cacheManager.putInRegionCache(CACHE_NAME, new CompositeKey(session.getId(), key), cacheModel);
    }
    return model;
}

From source file:org.rivalry.swingui.SortTablePanel.java

/**
 * @param tableModel Table model./* w w  w  . j a  v  a  2s. c o m*/
 *
 * @return a new row count widget.
 */
private JLabel createRowCountUI(final TableModel tableModel) {
    final String rowCountString = String.valueOf(tableModel.getRowCount()) + " rows";

    final JLabel answer = new JLabel(rowCountString);

    return answer;
}

From source file:org.simmi.GeneSetHead.java

License:asdf

public void updateFilter(int val, String ustr, JTable table, RowFilter filter, Set<Integer> filterset,
        Label label, int... ind) {
    filterset.clear();//from ww  w  .  j ava  2 s  .  c  o  m
    TableModel model = table.getModel();
    for (int r = 0; r < model.getRowCount(); r++) {
        for (int i = 0; i < ind.length; i++) {
            String vstr = (String) model.getValueAt(r, ind[i]);
            String s = vstr != null ? vstr.toLowerCase() : null;

            if ((s != null && s.contains(ustr))) {
                filterset.add(r);
                break;
            }
        }
    }

    if (filterset.isEmpty()) {
        int i = 0;
        if (table.getModel() == groupModel) {
            for (GeneGroup gg : geneset.allgenegroups) {
                for (Gene g : gg.genes) {
                    if (g.refid.toLowerCase().contains(ustr)) {
                        filterset.add(i);
                        break;
                    }
                }
                i++;
            }
        } else {
            for (Gene g : geneset.genelist) {
                if (g.refid.toLowerCase().contains(ustr)) {
                    filterset.add(i);
                }
                i++;
            }
        }
    }

    updateFilter(table, filter, label);
}

From source file:org.tinymediamanager.ui.movies.MoviePanel.java

private void addKeyListener() {
    table.addKeyListener(new KeyListener() {
        private long lastKeypress = 0;
        private String searchTerm = "";

        @Override//from  www .  ja  va2 s .com
        public void keyTyped(KeyEvent arg0) {
            long now = System.currentTimeMillis();
            if (now - lastKeypress > 500) {
                searchTerm = "";
            }
            lastKeypress = now;

            if (arg0.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
                searchTerm += arg0.getKeyChar();
            }

            if (StringUtils.isNotBlank(searchTerm)) {
                TableModel model = table.getModel();
                for (int i = 0; i < model.getRowCount(); i++) {
                    if (model.getValueAt(i, 0) instanceof Movie) {
                        String title = ((Movie) model.getValueAt(i, 0)).getTitleSortable()
                                .toLowerCase(Locale.ROOT);
                        if (title.startsWith(searchTerm)) {
                            ListSelectionModel selectionModel = table.getSelectionModel();
                            selectionModel.setSelectionInterval(i, i);
                            table.scrollRectToVisible(new Rectangle(table.getCellRect(i, 0, true)));
                            break;
                        }
                    }
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
        }
    });
}

From source file:org.yccheok.jstock.file.Statements.java

/**
 * Construct Statements based on given TableModel.
 *
 * @param tableModel given TableModel// w w w  .  j a  v  a  2  s  .  c om
 * @return the constructed Statements. UNKNOWN_STATEMENTS if fail
 */
public static Statements newInstanceFromTableModel(TableModel tableModel, boolean languageIndependent) {
    final CSVHelper csvHelper = (CSVHelper) tableModel;
    final GUIBundleWrapper guiBundleWrapper = GUIBundleWrapper.newInstance(
            languageIndependent ? GUIBundleWrapper.Language.INDEPENDENT : GUIBundleWrapper.Language.DEFAULT);

    final int column = tableModel.getColumnCount();
    final int row = tableModel.getRowCount();

    List<String> strings = new ArrayList<String>();
    for (int i = 0; i < column; i++) {
        final String type = languageIndependent ? csvHelper.getLanguageIndependentColumnName(i)
                : tableModel.getColumnName(i);
        final Class c = tableModel.getColumnClass(i);
        if (c.equals(Stock.class)) {
            final String code_string = guiBundleWrapper.getString("MainFrame_Code");
            final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");
            strings.add(code_string);
            strings.add(symbol_string);
        }
        if (c.equals(StockInfo.class)) {
            final String code_string = guiBundleWrapper.getString("MainFrame_Code");
            final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");
            strings.add(code_string);
            strings.add(symbol_string);
        } else {
            strings.add(type);
        }

    }

    // Comment handling.
    CommentableContainer commentableContainer = null;
    if (tableModel instanceof CommentableContainer) {
        commentableContainer = (CommentableContainer) tableModel;
    }

    Statement.What what = Statement.what(strings);
    final Statements s = new Statements(what.type, what.guiBundleWrapper);

    for (int i = 0; i < row; i++) {
        final List<Atom> atoms = new ArrayList<Atom>();
        for (int j = 0; j < column; j++) {
            final String type = languageIndependent ? csvHelper.getLanguageIndependentColumnName(j)
                    : tableModel.getColumnName(j);
            final Object object = tableModel.getValueAt(i, j);
            final Class c = tableModel.getColumnClass(j);
            if (c.equals(Stock.class)) {
                final Stock stock = (Stock) object;
                // There are no way to represent Stock in text form. We
                // will represent them in Code and Symbol.
                // Code first. Follow by symbol.

                final String code_string = guiBundleWrapper.getString("MainFrame_Code");
                final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");

                atoms.add(new Atom(stock.code.toString(), code_string));
                atoms.add(new Atom(stock.symbol.toString(), symbol_string));
            } else if (c.equals(StockInfo.class)) {
                final StockInfo stockInfo = (StockInfo) object;

                final String code_string = guiBundleWrapper.getString("MainFrame_Code");
                final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");

                atoms.add(new Atom(stockInfo.code.toString(), code_string));
                atoms.add(new Atom(stockInfo.symbol.toString(), symbol_string));
            } else if (c.equals(Date.class)) {
                atoms.add(new Atom(object != null
                        ? org.yccheok.jstock.gui.Utils.commonDateFormat(((Date) object).getTime())
                        : "", type));
            } else {
                // For fall below and rise above, null value is permitted.
                // Use empty string to represent null value.
                atoms.add(new Atom(object != null ? object : "", type));
            }
        }

        // Comment handling.
        if (commentableContainer != null) {
            atoms.add(new Atom(commentableContainer.getCommentable(i).getComment(),
                    guiBundleWrapper.getString("PortfolioManagementJPanel_Comment")));
        }

        final Statement statement = new Statement(atoms);

        if (s.getType() != statement.getType()) {
            // Doesn't not match. Return UNKNOWN_STATEMENTS to indicate we fail to
            // construct Statements from TableModel.
            return UNKNOWN_STATEMENTS;
        }

        s.statements.add(statement);
    }

    // Any metadata? This is special hack since Android introduction.
    if (tableModel instanceof StockTableModel) {
        s.metadatas.put("timestamp", Long.toString(((StockTableModel) tableModel).getTimestamp()));
    }

    return s;
}

From source file:org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.java

private static JScrollPane createScrollableTable(TableModel model) {
    JXTable table = new JXTable(model);
    table.setColumnControlVisible(true);
    table.setVisibleRowCount(Math.min(model.getRowCount() + 1, 5));
    table.packAll();/* w w w  . ja  va 2  s .  c  o  m*/
    return new JScrollPane(table);
}

From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java

public JXTablePerColumnFiltering(TableModel model) {
    super(model);
    this.model = (BeanTableModel<?>) model;

    // Create the 1-row filtering Table

    nColumns = model.getColumnCount();//from   w ww .ja v a  2  s.  c  o m

    // DependencyEngine e = new DependencyEngine(new BasicEngineProvider());

    for (int row = 0; row < model.getRowCount(); row++) {
        for (int i = 0; i < nColumns; i++) {
            if (getColumnName(i).contains("userCell")) {
                // this is a column with cells that can contain formulas in addition to computed values
            } else {

            }
        }
    }

    filteringModel = new DefaultTableModel(1, nColumns);

    initializeFilterModel();

    filteringTable = new JXTableBetterFocus(filteringModel);
    filteringTable.setTableHeader(null);

    for (int i = 0; i < nColumns; i++) {
        TableColumn fColumn = filteringTable.getColumn(i);
        MultiRenderer multiRenderer = getMultiRenderer();

        fColumn.setCellRenderer(multiRenderer);
        fColumn.setCellEditor(multiRenderer);
        fColumn.setWidth(getColumn(i).getWidth());
    }

    this.setRowFilter(filter);

    JTableHeader header = this.getTableHeader();
    if (tips == null) {
        tips = new ColumnHeaderToolTips();
    }
    header.addMouseMotionListener(tips);
}

From source file:pkgnew.line.PluginDialog.java

private void enablePluginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enablePluginActionPerformed
    List<Plugin> plugins = PluginManager.getInstance().getPlugins();
    TableModel model = TablePlugins.getModel();
    int rowCount = model.getRowCount();

    for (int i = 0; i < rowCount; i++) {
        boolean isSelected = (boolean) model.getValueAt(i, 0);
        if (isSelected) {
            plugins.get(i).resume();/*w  w  w  .j  a  v a  2s.c o m*/
        }
    }
    listPlugins();
}

From source file:pkgnew.line.PluginDialog.java

private void disablePluginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disablePluginActionPerformed
    List<Plugin> plugins = PluginManager.getInstance().getPlugins();
    TableModel model = TablePlugins.getModel();
    int rowCount = model.getRowCount();

    for (int i = 0; i < rowCount; i++) {
        boolean isSelected = (boolean) model.getValueAt(i, 0);
        if (isSelected) {
            plugins.get(i).suspend();//  ww w .  j  a va 2s .  co m
        }
    }
    listPlugins();
}