Example usage for javax.swing.table DefaultTableModel getRowCount

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

Introduction

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

Prototype

public int getRowCount() 

Source Link

Document

Returns the number of rows in this data table.

Usage

From source file:com.view.PortfolioManagerWindow.java

private void PMSendOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMSendOrderActionPerformed
    DefaultTableModel dtm = (DefaultTableModel) PMSendOrderTable.getModel();
    int nRow = dtm.getRowCount();
    long currUID = 0;
    int nCol = dtm.getColumnCount();
    Object[][] tableData = new Object[nRow][nCol];
    List<SingleOrder> parsedOrders = new ArrayList();
    String selectedTrader = String.valueOf(PMSelectTraderOptions.getSelectedItem());

    for (int t = 0; t < traderListForBox.size(); t++) {
        if (traderListForBox.get(t).getUsername().equals(selectedTrader)) {
            currUID = traderListForBox.get(t).getU_id();
            System.out.println("OUR TRADER WE ASSIGN TO IS: " + selectedTrader + " HIS ID IS: " + currUID);
        }//from w w w  . ja v  a 2s.  co m
    }

    boolean thereAreOrders = false;
    boolean ignoreRowFlag = false;

    for (int i = 0; i < nRow; i++) {
        for (int j = 0; j < nCol; j++) {
            tableData[i][j] = dtm.getValueAt(i, j);
        }
        System.out.println("Retrieved all table data");
        boolean trigg = true;

        for (int k = 0; k < nCol; k++) {
            if (tableData[i][k] != null) {
                ignoreRowFlag = false;
            } else {
                ignoreRowFlag = true;
                System.out.println("IGNORING EMPTY ROW");
            }
        }

        //double check symbol is not null
        if (ignoreRowFlag == false) {
            if (tableData[i][2] == null) {
                trigg = false;
            } else if (tableData[i][2].toString().trim().equals("")) {
                showMessageDialog(null, "Please enter non-empty Symbol.");
                trigg = false;
            } else if (!(tableData[i][2].toString().trim()
                    .equals(tableData[i][2].toString().trim().toUpperCase()))) {
                showMessageDialog(null, "Please enter the Symbol in all capital letters.");
                trigg = false;
            }

            if (tableData[i][0] != null && tableData[i][1] != null && tableData[i][2] != null
                    && tableData[i][3] != null && tableData[i][4] != null && tableData[i][5] != null) {
                if (tableData[i][0] != null) {
                    long portIDC = (long) tableData[i][0];
                    if (portIDC < 0) {
                        showMessageDialog(null,
                                "You have entered a negative portfolio ID value. Please fix this value before submitting the order.");
                        trigg = false;
                    }
                }
                if (tableData[i][3] != null) {
                    int quantityC = (int) tableData[i][3];
                    if (quantityC < 0) {
                        showMessageDialog(null,
                                "You have entered a negative quantity value. Please fix this value before submitting the order.");
                        trigg = false;
                    }
                }
                if (tableData[i][5] != null) {
                    String orderType = (String) tableData[i][5];
                    switch (orderType) {
                    case "Market":
                        if ((tableData[i][6] != null && tableData[i][7] != null)
                                || (tableData[i][6] != null && tableData[i][7] == null)
                                || (tableData[i][6] == null && tableData[i][7] != null)) {
                            showMessageDialog(null,
                                    "A market order should have neither a stop price nor a limit price.");
                            trigg = false;
                        }
                        break;
                    case "Limit":
                        if ((tableData[i][6] != null && tableData[i][7] == null)
                                || (tableData[i][6] != null && tableData[i][7] != null)
                                || (tableData[i][6] == null && tableData[i][7] == null)) {
                            showMessageDialog(null,
                                    "A limit order should have a limit price and no stop price.");
                            trigg = false;
                        }
                        break;
                    case "Stop":
                        if ((tableData[i][6] == null && tableData[i][7] != null)
                                || (tableData[i][6] != null && tableData[i][7] != null)
                                || (tableData[i][6] == null && tableData[i][7] == null)) {
                            showMessageDialog(null,
                                    "A stop order should have a stop price and no limit price.");
                            trigg = false;
                        }
                        break;
                    case "Stop Limit":
                        if ((tableData[i][6] == null && tableData[i][7] == null)
                                || (tableData[i][6] != null && tableData[i][7] == null)
                                || (tableData[i][6] == null && tableData[i][7] != null)) {
                            showMessageDialog(null,
                                    "A Stop Limit order should have both a stop price and a limit price.");
                            trigg = false;
                        }
                        break;
                    default:
                        showMessageDialog(null, "Something messed up in cases for order type.");
                    }
                }

                if (tableData[i][6] != null) {
                    double stopC = (double) tableData[i][6];
                    if (stopC < 0) {
                        showMessageDialog(null,
                                "You have entered a negative stop price value. Please fix this value before submitting the order.");
                        trigg = false;
                    }
                }
                if (tableData[i][7] != null) {
                    double limitC = (double) tableData[i][7];
                    if (limitC < 0) {
                        showMessageDialog(null,
                                "You have entered a negative limit price value. Please fix this value before submitting the order.");
                        trigg = false;
                    }
                }

                if (trigg == true) {
                    thereAreOrders = true;
                    SingleOrder o = new SingleOrder(tableData[i]);
                    parsedOrders.add(o);
                }
            } else {
                String a, b, c, d, e, f;
                if (tableData[i][0] == null) {
                    a = "Portfolio ID";
                } else {
                    a = "";
                }
                if (tableData[i][1] == null) {
                    b = "Stock Exchange";
                } else {
                    b = "";
                }
                if (tableData[i][2] == null || tableData[i][2].toString().trim().equals("")) {
                    c = "Symbol";
                } else {
                    c = "";
                }
                if (tableData[i][3] == null) {
                    d = "Quantity";
                } else {
                    d = "";
                }
                if (tableData[i][4] == null) {
                    e = "Action";
                } else {
                    e = "";
                }
                if (tableData[i][5] == null) {
                    f = "Order Type";
                } else {
                    f = "";
                }

                showMessageDialog(null, "You need to fill in the necessary fields before sending the order:\n"
                        + a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f);
            }
        }
    }

    if (thereAreOrders) {
        showMessageDialog(null, "You have successfully sent your trades.");
        dtm.setRowCount(0);
        dtm.addRow(new Object[] { null, null, null, null, null, null, null, null, null });
        Order toSend = new Order(selectedTrader, parsedOrders);
        toSend.setAssignedTo(currUID);
        Long currID = CMAIN.reportUser().getU_id();
        String currUname = CMAIN.reportUser().getUsername();
        toSend.setPmId(currID);
        toSend.setPmUsername(currUname);
        ControllerPMCreatedOrders.handleOrder(toSend);
    }
}

From source file:gtu._work.ui.SvnLastestCommitInfoUI.java

void reloadSvnTable(String scanText, ScanProcess scanProcess) {
    boolean needFilterScanText = StringUtils.isNotBlank((scanText = StringUtils.defaultString(scanText)));
    DefaultTableModel model = JTableUtil.createModel(true, SvnTableColumn.getColumn());
    for (SvnFile svnFile : svnFileSet) {
        if (!svnFile.file.exists() || !svnFile.file.isFile()) {
            continue;
        }/*ww  w . j a  va  2  s . c  o  m*/
        if (needFilterScanText) {
            scanProcess.process(scanText, svnFile, model);
        } else {
            this.addRow(svnFile, model);
        }
    }
    svnTable.setModel(model);
    matchCount.setText(String.valueOf(model.getRowCount()));
    if (model.getRowCount() != 0) {
        JTableUtil.newInstance(svnTable).setMaxWidth(SvnTableColumn.getMaxWidth());
    }
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private void addContentSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addContentSearchButtonActionPerformed
    DefaultTableModel model = ((DefaultTableModel) contentSearchTable.getModel());
    int row = model.getRowCount();

    model.addRow(new Object[] { ContentType.RAW, "" });

    contentSearchTable.setRowSelectionInterval(row, row);
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private void addMetaDataSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMetaDataSearchButtonActionPerformed
    DefaultTableModel model = ((DefaultTableModel) metaDataSearchTable.getModel());
    int row = model.getRowCount();

    List<MetaDataColumn> metaDataColumns = messageBrowser.getMetaDataColumns();
    if (metaDataColumns.size() > 0) {
        MetaDataColumn metaDataColumn = metaDataColumns.get(0);
        MetaDataSearchOperator operator = MetaDataSearchOperator.EQUAL;

        model.addRow(new Object[] { metaDataColumn.getName(), operator, "", false });

        metaDataSearchTable.setRowSelectionInterval(row, row);
    }//from   w  w  w.  j a va2s .  c  o m
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private List<MetaDataSearchElement> getMetaDataSearch() throws MetaDataColumnException {
    List<MetaDataSearchElement> metaDataSearch = new ArrayList<MetaDataSearchElement>();

    DefaultTableModel model = ((DefaultTableModel) metaDataSearchTable.getModel());
    int rowCount = model.getRowCount();

    if (rowCount == 0) {
        return null;
    } else {//from www .  jav a  2  s.  com
        for (int i = 0; i < rowCount; i++) {
            String metaDataName = (String) model.getValueAt(i, 0);
            String operator = ((MetaDataSearchOperator) model.getValueAt(i, 1)).toFullString();
            String searchText = (String) model.getValueAt(i, 2);
            Boolean ignoreCase = (Boolean) model.getValueAt(i, 3);

            if (StringUtils.isNotEmpty(searchText)) {
                MetaDataColumn column = cachedMetaDataColumns.get(metaDataName);
                metaDataSearch.add(new MetaDataSearchElement(metaDataName, operator,
                        column.getType().castValue(searchText), ignoreCase));
            }
        }

        return metaDataSearch;
    }
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private List<ContentSearchElement> getContentSearch() {
    List<ContentSearchElement> contentSearch = new ArrayList<ContentSearchElement>();
    Map<ContentType, List<String>> contentSearchMap = new HashMap<ContentType, List<String>>();
    DefaultTableModel model = ((DefaultTableModel) contentSearchTable.getModel());
    int rowCount = model.getRowCount();

    for (int i = 0; i < rowCount; i++) {
        ContentType contentType = (ContentType) model.getValueAt(i, 0);
        String searchText = (String) model.getValueAt(i, 1);

        if (searchText.length() > 0) {
            List<String> searchList = contentSearchMap.get(contentType);

            if (searchList == null) {
                searchList = new ArrayList<String>();
                contentSearchMap.put(contentType, searchList);
            }/* w  ww.j a v a 2s. c o m*/
            searchList.add(searchText);
        }
    }

    for (ContentType contentType : ContentType.getDisplayValues()) {
        if (contentSearchMap.containsKey(contentType)) {
            contentSearch.add(new ContentSearchElement(contentType.getContentTypeCode(),
                    contentSearchMap.get(contentType)));
        }
    }

    return contentSearch;
}

From source file:org.jas.gui.MainWindow.java

private void deleteALLRows(JTable descriptionTable) {
    DefaultTableModel model = (DefaultTableModel) descriptionTable.getModel();
    for (int i = model.getRowCount() - 1; i >= 0; i--) {
        model.removeRow(i);//from   w ww .java2  s .  c om
    }
}

From source file:HW3.java

private void clearBusinessTable() {
    DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
    if (model.getRowCount() > 0) {
        deleteAllRows(model);//from  w  w  w . ja  v  a2 s. c o  m
    }
}

From source file:la2launcher.MainFrame.java

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
    for (int i = 0; i < model.getRowCount(); i++) {
        model.setValueAt(true, i, 1);// www.ja  va 2 s.  c om
    }
}

From source file:la2launcher.MainFrame.java

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
    DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
    for (int i = 0; i < model.getRowCount(); i++) {
        model.setValueAt(false, i, 1);/*from  w  ww . j av a2s. co m*/
    }
}