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:app.RunApp.java

/**
 * Action for Invert button from principal tab
 * /*  w w  w  . jav  a  2s  .  c  o m*/
 * @param evt Event
 * @param jtable Table
 */
private void buttonInvertActionButtonPerformed(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        if ((Boolean) tmodel.getValueAt(i, 2)) {
            tmodel.setValueAt(Boolean.FALSE, i, 2);
        } else {
            tmodel.setValueAt(Boolean.TRUE, i, 2);
        }
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Action for Invert button from multiple datasets tab
 * // w w w. j  a v a 2 s  .c  om
 * @param evt Event
 * @param jtable Table
 */
private void buttonInvertActionPerformedMulti(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        if ((Boolean) tmodel.getValueAt(i, 1)) {
            tmodel.setValueAt(Boolean.FALSE, i, 1);
        } else {
            tmodel.setValueAt(Boolean.TRUE, i, 1);
        }
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Clear table of metrics from principal tab
 *//*ww  w.jav  a 2  s  .co  m*/
private void clearTableMetricsPrincipal() {
    ArrayList<String> metricsList = MetricUtils.getAllMetrics();

    for (String metric : metricsList) {
        if (metric.charAt(0) != '<') {
            tableMetrics.put(metric, "-");
        } else {
            tableMetrics.put(metric, "");
        }
    }

    TableModel model = jTablePrincipal.getModel();

    for (int i = 0; i < model.getRowCount(); i++) {
        if (metricsList.get(i).charAt(0) != '<') {
            model.setValueAt(tableMetrics.get(model.getValueAt(i, 0).toString()), i, 1);
        }
    }

    jTablePrincipal.repaint();
}

From source file:app.RunApp.java

/**
 * Action for Calculate button from principal tab
 * //from  ww w . j  a v a 2s  .  com
 * @param evt Event
 * @param jtable Table
 */
private void buttonCalculateActionPerformedPrincipal(java.awt.event.ActionEvent evt, JTable jtable) {
    ArrayList<String> metricsList = getMetricsSelectedPrincipal(jtable);

    if (dataset == null) {
        JOptionPane.showMessageDialog(null, "You must load a dataset.", "Warning", JOptionPane.ERROR_MESSAGE);
        return;
    } else if (metricsList.isEmpty()) {
        JOptionPane.showMessageDialog(null, "You must select any metric.", "Warning",
                JOptionPane.ERROR_MESSAGE);
        return;
    }

    //ImbalancedFeature[] label_frenquency = MetricUtils.getImbalancedDataByAppearances(dataset);
    //label_frenquency = MetricUtils.sortByFrequency(label_frenquency);// ordena de mayor a menor

    String value;

    progressBar.setMinimum(0);
    progressBar.setMaximum(metricsList.size() + 1);
    progressBar.setValue(0);
    int v = 1;
    for (String metric : metricsList) {
        progressBar.setValue(v);
        //If metric value exists, don't calculate
        if ((tableMetrics.get(metric) == null) || (tableMetrics.get(metric).equals("-"))) {
            value = MetricUtils.getMetricValue(metric, dataset);
            tableMetrics.put(metric, value.replace(",", "."));
        }

        v++;
    }

    TableModel model = jtable.getModel();

    for (int i = 0; i < model.getRowCount(); i++) {
        model.setValueAt(MetricUtils.getValueFormatted(model.getValueAt(i, 0).toString(),
                tableMetrics.get(model.getValueAt(i, 0).toString())), i, 1);
    }

    jtable.repaint();
}

From source file:org.apache.metamodel.jdbc.JdbcDataContextTest.java

public void testUsingDataSource() throws Exception {
    Connection con = getTestDbConnection();
    DataSource ds = EasyMock.createMock(DataSource.class);

    CloseableConnectionWrapper con1 = new CloseableConnectionWrapper(con);
    CloseableConnectionWrapper con2 = new CloseableConnectionWrapper(con);
    CloseableConnectionWrapper con3 = new CloseableConnectionWrapper(con);
    CloseableConnectionWrapper con4 = new CloseableConnectionWrapper(con);
    CloseableConnectionWrapper con5 = new CloseableConnectionWrapper(con);

    assertFalse(con1.isClosed());//  ww  w  .j  ava 2s  . c o  m
    assertFalse(con2.isClosed());
    assertFalse(con3.isClosed());
    assertFalse(con4.isClosed());
    assertFalse(con5.isClosed());

    EasyMock.expect(ds.getConnection()).andReturn(con1);
    EasyMock.expect(ds.getConnection()).andReturn(con2);
    EasyMock.expect(ds.getConnection()).andReturn(con3);
    EasyMock.expect(ds.getConnection()).andReturn(con4);
    EasyMock.expect(ds.getConnection()).andReturn(con5);

    EasyMock.replay(ds);

    JdbcDataContext dc = new JdbcDataContext(ds);
    dc.refreshSchemas();
    dc.refreshSchemas();

    Schema schema = dc.getDefaultSchema();
    Query q = new Query();
    q.from(schema.getTableByName("CUSTOMERS")).select(new SelectItem("COUNT(*)", null));
    DataSet data = dc.executeQuery(q);
    TableModel tableModel = new DataSetTableModel(data);
    assertEquals(1, tableModel.getRowCount());
    assertEquals(1, tableModel.getColumnCount());
    assertEquals(122, tableModel.getValueAt(0, 0));

    EasyMock.verify(ds);

    String assertionFailMsg = "Expected 5x true: " + con1.isClosed() + "," + con2.isClosed() + ","
            + con3.isClosed() + "," + con4.isClosed() + "," + con5.isClosed();

    assertTrue(assertionFailMsg, con1.isClosed());
    assertTrue(assertionFailMsg, con2.isClosed());
    assertTrue(assertionFailMsg, con3.isClosed());
    assertTrue(assertionFailMsg, con4.isClosed());
    assertTrue(assertionFailMsg, con5.isClosed());
}

From source file:org.apache.metamodel.jdbc.JdbcDataContextTest.java

public void testMaxRowsRewrite() throws Exception {
    JdbcDataContext dc = new JdbcDataContext(getTestDbConnection(), new TableType[] { TableType.TABLE }, null);
    IQueryRewriter rewriter = new DefaultQueryRewriter(dc) {
        @Override//w ww .jav a2  s . c  om
        public String rewriteQuery(Query query) {
            return "SELECT COUNT(*) FROM PUBLIC.CUSTOMERS";
        }
    };
    dc = dc.setQueryRewriter(rewriter);
    TableModel tm = new DataSetTableModel(dc.executeQuery(new Query().selectCount()));
    assertEquals(1, tm.getRowCount());
    assertEquals(1, tm.getColumnCount());
    assertEquals("122", tm.getValueAt(0, 0).toString());
}

From source file:org.broad.igv.cbio.FilterGeneNetworkUI.java

/**
 * Export the current table to a tab-delimited file.
 * String exported should be the same as what user sees
 *
 * @param outFile/*  w ww .  j  a  va2 s. com*/
 * @throws IOException
 */
private void saveTable(File outFile) throws FileNotFoundException {
    PrintWriter writer = new PrintWriter(outFile);
    TableModel model = geneTable.getModel();
    String delimiter = "\t";

    //Write header
    String header = model.getColumnName(0);
    for (int col = 1; col < model.getColumnCount(); col++) {
        header += delimiter + model.getColumnName(col);
    }

    writer.println(header);

    for (int row = 0; row < model.getRowCount(); row++) {
        String rowStr = "" + model.getValueAt(row, 0);
        for (int col = 1; col < model.getColumnCount(); col++) {
            rowStr += delimiter + model.getValueAt(row, col);
        }

        writer.println(rowStr);
    }

    writer.flush();
    writer.close();
}

From source file:org.formic.wizard.step.gui.RequirementsValidationStep.java

/**
 * {@inheritDoc}/*w w w  .j  a  v  a2s  . c o m*/
 * @see org.formic.wizard.WizardStep#displayed()
 */
public void displayed() {
    form.showInfoMessage(null);
    requirementInfo.setText(null);
    retryButton.setEnabled(false);

    setBusy(true);
    try {
        Integer result = (Integer) Worker.post(new Task() {
            public Object run() throws Exception {
                Integer result = OK;
                TableModel model = table.getModel();
                for (int ii = 0; ii < model.getRowCount(); ii++) {
                    final JLabel label = (JLabel) model.getValueAt(ii, 1);
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            label.setIcon(busyIcon);
                            busyIcon.setImageObserver(table);
                            table.revalidate();
                            table.repaint();
                        }
                    });
                    Requirement requirement = (Requirement) model.getValueAt(ii, 0);
                    final RequirementProvider.Status status = provider.validate(requirement);
                    requirement.setStatus(status);
                    if (status.getCode() == RequirementProvider.FAIL) {
                        result = FAIL;
                    } else if (OK.equals(result) && status.getCode() == RequirementProvider.WARN) {
                        result = WARN;
                    }

                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            switch (status.getCode()) {
                            case RequirementProvider.OK:
                                label.setIcon(okIcon);
                                break;
                            case RequirementProvider.WARN:
                                label.setIcon(warnIcon);
                                break;
                            default:
                                label.setIcon(failedIcon);
                            }
                            table.revalidate();
                            table.repaint();
                        }
                    });
                }
                return result;
            }
        });
        if (FAIL.equals(result)) {
            form.showErrorMessage(Installer.getString("requirements.message.failed"));
        } else if (WARN.equals(result)) {
            form.showWarningMessage(Installer.getString("requirements.message.warning"));
        } else {
            form.showInfoMessage(Installer.getString("requirements.message.ok"));
        }
        boolean valid = !result.equals(FAIL);
        setValid(valid);
        retryButton.setVisible(retryButton.isVisible() || !valid);
        retryButton.setEnabled(!valid);
    } catch (Exception e) {
        GuiDialogs.showError(e);
        setValid(false);
    } finally {
        setBusy(false);
    }
}

From source file:org.omegat.gui.issues.IssuesPanelController.java

Optional<IIssue> getIssueAtRow(int row) {
    if (row < 0) {
        return Optional.empty();
    }//from  w  w w.jav a2s . c  o m
    TableModel model = panel.table.getModel();
    if (!(model instanceof IssuesTableModel) || model.getRowCount() == 0) {
        return Optional.empty();
    }
    IssuesTableModel imodel = (IssuesTableModel) model;
    int realSelection = panel.table.getRowSorter().convertRowIndexToModel(row);
    return Optional.of(imodel.getIssueAt(realSelection));
}

From source file:org.ops4j.pax.idea.runner.forms.OsgiConfigEditorForm.java

private void retrieveSystemProperties(ConfigBean data) {
    TableModel model = m_systemProperties.getModel();
    Map<String, String> sysProps = new HashMap<String, String>();
    int rowCount = model.getRowCount();
    for (int row = 0; row < rowCount; row++) {
        String key = (String) model.getValueAt(row, 0);
        String value = (String) model.getValueAt(row, 1);
        sysProps.put(key, value);//from ww  w . j a v  a  2 s . co  m
    }
    data.setSystemProperties(sysProps);
}