Example usage for javax.swing.table DefaultTableModel getColumnCount

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

Introduction

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

Prototype

public int getColumnCount() 

Source Link

Document

Returns the number of columns in this data table.

Usage

From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java

/**
 * @return/* w  ww.j  a va2  s. co  m*/
 */
public CollectionResultType initialize() {

    collectionInfoList = CollectionInfo.getCollectionInfoList(oldDBConn, false);
    //fixIdaho();
    if (collectionInfoList == null) {
        if (CollectionInfo.isAskForFix()) {
            if (ConvertTaxonHelper.fixTaxonomicUnitType(oldDBConn)) {
                collectionInfoList = CollectionInfo.getCollectionInfoList(oldDBConn, true);
            } else {
                try {
                    oldDBConn.close();
                } catch (SQLException e) {
                }
                System.exit(0);
            }
        } else {
            try {
                oldDBConn.close();
            } catch (SQLException e) {
            }
            System.exit(0);
        }
    }

    collectionInfoShortList = CollectionInfo.getFilteredCollectionInfoList();

    if (collectionInfoList != null && collectionInfoList.size() > 0) {
        int paleoCnt = 0;

        // This is a Hash of TaxonObjectType to see how many collections use the same TaxonObjectType
        HashMap<Integer, HashSet<CollectionInfo>> taxonomyTypeHash = new HashMap<Integer, HashSet<CollectionInfo>>();

        // Get a List for each type of Paleo Collection, hashed by the Root Id
        HashMap<Integer, Vector<CollectionInfo>> paleoColInfoHash = new HashMap<Integer, Vector<CollectionInfo>>();
        HashMap<Integer, HashSet<DisciplineType.STD_DISCIPLINES>> paleoDispTypeHash = new HashMap<Integer, HashSet<DisciplineType.STD_DISCIPLINES>>();

        for (CollectionInfo colInfo : collectionInfoShortList) {
            // Tracks a 'set' of CollectionInfo objects for each TaxonomyTypeId
            HashSet<CollectionInfo> taxonomyTypeSet = taxonomyTypeHash.get(colInfo.getTaxonomyTypeId());
            if (taxonomyTypeSet == null) {
                System.out.println("Creating TxTypeID: " + colInfo.getTaxonomyTypeId() + "  From "
                        + colInfo.getCatSeriesName());

                taxonomyTypeSet = new HashSet<CollectionInfo>();
                taxonomyTypeHash.put(colInfo.getTaxonomyTypeId(), taxonomyTypeSet);
            } else {
                System.out.println("Adding TxTypeID: " + colInfo.getTaxonomyTypeId() + "  From "
                        + colInfo.getCatSeriesName() + "  " + taxonomyTypeSet.size());
            }
            taxonomyTypeSet.add(colInfo);

            //---
            DisciplineType dType = getStandardDisciplineName(colInfo.getTaxonomyTypeName(),
                    colInfo.getColObjTypeName(), colInfo.getCatSeriesName());
            colInfo.setDisciplineTypeObj(dType);

            if (dType != null && dType.isPaleo()) {
                Vector<CollectionInfo> ciList = paleoColInfoHash.get(colInfo.getTaxonNameId());
                if (ciList == null) {
                    ciList = new Vector<CollectionInfo>();
                    paleoColInfoHash.put(colInfo.getTaxonNameId(), ciList);
                }
                ciList.add(colInfo);

                HashSet<DisciplineType.STD_DISCIPLINES> typeDispSet = paleoDispTypeHash
                        .get(colInfo.getTaxonNameId());
                if (typeDispSet == null) {
                    typeDispSet = new HashSet<DisciplineType.STD_DISCIPLINES>();
                    paleoDispTypeHash.put(colInfo.getTaxonNameId(), typeDispSet);
                }
                typeDispSet.add(colInfo.getDisciplineTypeObj().getDisciplineType());

                paleoCnt++;
            }
            System.out.println("--------------------------------------");
            //System.out.println(colInfo.toString()+"\n");
        } // for loop

        int cnt = 0;
        StringBuilder msg = new StringBuilder();
        for (Integer taxonomyTypId : taxonomyTypeHash.keySet()) {
            HashSet<CollectionInfo> taxonomyTypeSet = taxonomyTypeHash.get(taxonomyTypId);
            if (taxonomyTypeSet.size() > 1) {
                msg.append(
                        String.format("<html>TaxonomyTypeId %d has more than one Discpline/Collection:<br><OL>",
                                taxonomyTypId));
                for (CollectionInfo ci : taxonomyTypeSet) {
                    msg.append(String.format("<LI>%s - %s - %s</LI>", ci.getCatSeriesName(),
                            ci.getColObjTypeName(), ci.getTaxonomyTypeName()));
                }
                msg.append("</OL>");
                cnt++;
            }
        }

        if (cnt > 0) {
            JOptionPane.showConfirmDialog(null, msg.toString(), "Taxomony Type Issues",
                    JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE);
        }

        // Will be zero for no Paleo collections
        if (paleoCnt > 1) {
            // Check to see if they all use the same tree
            if (paleoColInfoHash.size() > 1) {
                msg.setLength(0);
                // We get here when there is more than one Taxon Tree for the Paleo Collections
                for (Integer treeId : paleoColInfoHash.keySet()) {
                    Vector<CollectionInfo> ciList = paleoColInfoHash.get(treeId);
                    CollectionInfo colInfo = ciList.get(0);
                    msg.append(String.format("The following collections use Taxon Tree '%s':\n",
                            colInfo.getTaxonomyTypeName()));
                    for (CollectionInfo ci : paleoColInfoHash.get(treeId)) {
                        DisciplineType dType = getStandardDisciplineName(ci.getTaxonomyTypeName(),
                                ci.getColObjTypeName(), ci.getCatSeriesName());

                        String name = String.format("%s / %s / %s / %s / %s", ci.getCatSeriesPrefix(),
                                ci.getCatSeriesName(), ci.getColObjTypeName(), ci.getTaxonomyTypeName(),
                                dType.toString());
                        msg.append(name);
                        msg.append("\n");
                    }
                    msg.append("\n");
                }

                JOptionPane.showConfirmDialog(null, msg.toString(), "Paleo Taxon Tree Issues",
                        JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE);

            } else {
                StringBuilder colNames = new StringBuilder();
                for (Integer treeId : paleoColInfoHash.keySet()) {
                    for (CollectionInfo ci : paleoColInfoHash.get(treeId)) {
                        colNames.append("<LI>");
                        colNames.append(ci.getCatSeriesName());
                        colNames.append("</LI>");
                    }
                }

                // You get here when all the Paleo Disciplines use the same tree
                String msgStr = "<html>All the Paleo Collections need to use the same Taxon Tree and<br>therefore needs to be in the same discipline:<br><ol>";
                JOptionPane.showConfirmDialog(null, msgStr + colNames.toString(), "Paleo Taxon Tree Issues",
                        JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE);

                for (Integer treeId : paleoColInfoHash.keySet()) {
                    Vector<CollectionInfo> ciList = paleoColInfoHash.get(treeId);
                    CollectionInfo colInfo = ciList.get(0);
                    for (CollectionInfo ci : paleoColInfoHash.get(treeId)) {
                        ci.setDisciplineTypeObj(colInfo.getDisciplineTypeObj());
                    }
                }
            }
            //
        }

        DefaultTableModel model = CollectionInfo.getCollectionInfoTableModel(false);
        if (model.getRowCount() > 1) {
            TableWriter colInfoTblWriter = convLogger.getWriter("colinfo.html", "Collection Info");

            colInfoTblWriter.startTable();
            colInfoTblWriter.logHdr(CollectionInfoModel.getHeaders());

            Object[] row = new Object[model.getColumnCount()];
            for (int r = 0; r < model.getRowCount(); r++) {
                for (int i = 0; i < model.getColumnCount(); i++) {
                    row[i] = model.getValueAt(r, i);
                }
                colInfoTblWriter.logObjRow(row);
            }
            colInfoTblWriter.endTable();
            colInfoTblWriter.println("<BR><h3>Collections to be Created.</h3>");
            colInfoTblWriter.startTable();
            colInfoTblWriter.logHdr(CollectionInfoModel.getHeaders());

            model = CollectionInfo.getCollectionInfoTableModel(true);
            row = new Object[model.getColumnCount()];
            for (int r = 0; r < model.getRowCount(); r++) {
                for (int i = 0; i < model.getColumnCount(); i++) {
                    row[i] = model.getValueAt(r, i);
                }
                colInfoTblWriter.logObjRow(row);
            }
            colInfoTblWriter.endTable();
            colInfoTblWriter.close();

            File file = new File(colInfoTblWriter.getFileName());
            if (file != null && file.exists()) {
                try {
                    AttachmentUtils.openURI(file.toURI());

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }

        for (CollectionInfo ci : CollectionInfo.getFilteredCollectionInfoList()) {
            String sql = "select preparationmethod, ct.* from usyscollobjprepmeth pt inner join usysmetafieldsetsubtype st on st.fieldsetsubtypeid = pt.fieldsetsubtypeid "
                    + "inner join collectionobjecttype ct1 on ct1.collectionobjecttypeid = st.fieldvalue "
                    + "inner join collectionobjecttype ct on ct.collectionobjecttypename = replace(ct1.collectionobjecttypename, ' Preparation', '') "
                    + "inner join catalogseriesdefinition csd on csd.objecttypeid = ct.collectionobjecttypeid "
                    + "inner join catalogseries cs on cs.catalogseriesid = csd.catalogseriesid "
                    + "WHERE csd.catalogseriesid = " + ci.getCatSeriesId();

            System.out.println("\n------------------");
            System.out.println(ci.getCatSeriesName());
            System.out.println(sql);
            System.out.println("------------------");

            int i = 0;
            Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql);
            if (list.size() > 0) {
                for (Object[] row : list) {
                    System.out.print(i + " - ");
                    for (Object col : row) {
                        System.out.print(col != null ? col.toString() : "null");
                        System.out.print(", ");
                    }
                    System.out.println();
                    i++;
                }
            } else {
                System.out.println("No Results");
            }

            sql = "select ct.*, (select relatedsubtypevalues from usysmetacontrol c "
                    + "left join usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid "
                    + "where objectid = 10290 and ct.taxonomytypeid = c.relatedsubtypevalues) as DeterminationTaxonType "
                    + "from collectiontaxonomytypes ct where ct.biologicalobjecttypeid = "
                    + ci.getColObjTypeId();

            sql = String.format(
                    "SELECT CollectionTaxonomyTypesID, BiologicalObjectTypeID, CollectionObjectTypeName FROM (select ct.*, "
                            + "(SELECT distinct relatedsubtypevalues FROM usysmetacontrol c "
                            + "LEFT JOIN usysmetafieldsetsubtype fst ON fst.fieldsetsubtypeid = c.fieldsetsubtypeid "
                            + "WHERE objectid = 10290 AND ct.taxonomytypeid = c.relatedsubtypevalues) AS DeterminationTaxonType "
                            + "FROM collectiontaxonomytypes ct WHERE ct.biologicalobjecttypeid = %d) T1 "
                            + "INNER JOIN collectionobjecttype cot ON T1.biologicalobjecttypeid = cot.CollectionObjectTypeID",
                    ci.getColObjTypeId());

            System.out.println("\n------------------");
            System.out.println(ci.getColObjTypeName());
            System.out.println(sql);
            System.out.println("------------------");

            i = 0;
            list = BasicSQLUtils.query(oldDBConn, sql);
            if (list.size() > 0) {
                for (Object[] row : list) {
                    System.out.print(i + " - ");
                    for (Object col : row) {
                        System.out.print(col != null ? col.toString() : "null");
                        System.out.print(", ");
                    }
                    System.out.println();
                    i++;
                }
            } else {
                System.out.println("No Results");
            }
        }

        /*
                
        String sql = " select ct.*, (select relatedsubtypevalues from usysmetacontrol c " +
          "left join usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid " +
          "where objectid = 10290 and ct.taxonomytypeid = c.relatedsubtypevalues) as DeterminationTaxonType " +
          "from collectiontaxonomytypes ct where ct.biologicalobjecttypeid = 13";
                
        System.out.println("\n------------------");
        System.out.println("List of the taxonomytypes associated with a CollectionObjectTypeID");
        System.out.println(sql);
        System.out.println("------------------");
                
        int i = 0;
        Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql);
        if (list.size() > 0)
        {
        for (Object[] row : list)
        {
            System.out.print(i+" - ");
            for (Object col: row)
            {
                System.out.print(col != null ? col.toString() : "null");
                System.out.print(", ");
            }
            System.out.println();
        }
        } else
        {
        System.out.println("No Results");
        }*/

        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,2px,f:p:g,10px,p,2px,p:g,8px"));

        JTable tableTop = new JTable(CollectionInfo.getCollectionInfoTableModel(false));
        JTable tableBot = new JTable(
                CollectionInfo.getCollectionInfoTableModel(!CollectionInfo.DOING_ACCESSSION));

        int rows = 10;
        tableTop.setPreferredScrollableViewportSize(new Dimension(
                tableTop.getPreferredScrollableViewportSize().width, rows * tableTop.getRowHeight()));
        tableBot.setPreferredScrollableViewportSize(new Dimension(
                tableBot.getPreferredScrollableViewportSize().width, rows * tableBot.getRowHeight()));

        pb.add(UIHelper.createLabel("Available Specify 5 Taxononmic Types", SwingConstants.CENTER),
                cc.xy(1, 1));
        pb.add(UIHelper.createScrollPane(tableTop), cc.xy(1, 3));

        pb.add(UIHelper.createLabel("Specify 5 Collections to be Created", SwingConstants.CENTER), cc.xy(1, 5));
        pb.add(UIHelper.createScrollPane(tableBot), cc.xy(1, 7));

        pb.setDefaultDialogBorder();
        CustomDialog dlg = new CustomDialog(null, "Taxononic Types", true, pb.getPanel());
        dlg.createUI();

        dlg.setSize(1024, 500);

        UIHelper.centerWindow(dlg);
        dlg.setAlwaysOnTop(true);
        dlg.setVisible(true);

        if (dlg.isCancelled()) {
            return CollectionResultType.eCancel;
        }

        Pair<CollectionInfo, DisciplineType> pair = CollectionInfo.getDisciplineType(oldDBConn);
        if (pair == null || pair.second == null) {
            CollectionInfo colInfo = pair.first;
            disciplineType = getStandardDisciplineName(colInfo.getTaxonomyTypeName(),
                    colInfo.getColObjTypeName(), colInfo.getCatSeriesName());
        } else {
            disciplineType = pair.second;
        }

        return disciplineType != null ? CollectionResultType.eOK : CollectionResultType.eError;
    }
    return CollectionResultType.eError;
}

From source file:org.apache.jmeter.save.CSVSaveService.java

/**
 * Method saves aggregate statistics as CSV from a table model. Same as
 * {@link #saveCSVStats(List, FileWriter, String[])} except that there is no
 * need to create a List containing the data.
 * //from  w w  w  .j a  v  a  2 s.co m
 * @param model
 *            table model containing the data
 * @param writer
 *            output file
 * @param saveHeaders
 *            whether or not to save headers
 * @throws IOException
 *             when writing to <code>writer</code> fails
 */
public static void saveCSVStats(DefaultTableModel model, FileWriter writer, boolean saveHeaders)
        throws IOException {
    final char DELIM = ',';
    final char[] SPECIALS = new char[] { DELIM, QUOTING_CHAR };
    final int columns = model.getColumnCount();
    final int rows = model.getRowCount();
    if (saveHeaders) {
        for (int i = 0; i < columns; i++) {
            if (i > 0) {
                writer.write(DELIM);
            }
            writer.write(quoteDelimiters(model.getColumnName(i), SPECIALS));
        }
        writer.write(LINE_SEP);
    }
    for (int row = 0; row < rows; row++) {
        for (int column = 0; column < columns; column++) {
            if (column > 0) {
                writer.write(DELIM);
            }
            Object item = model.getValueAt(row, column);
            writer.write(quoteDelimiters(String.valueOf(item), SPECIALS));
        }
        writer.write(LINE_SEP);
    }
}

From source file:org.fhaes.gui.AnalysisResultsPanel.java

/**
 * Write the specified DefaultTableModel to the provided Excel spreadsheet
 * //from   ww w .  ja v  a  2  s.c  o  m
 * @param dataSheet
 * @param model
 */
private void writeModelToXLSXSheet(Sheet dataSheet, DefaultTableModel model) {

    if (model == null) {
        Row headerrow = dataSheet.createRow(0);
        Cell cell = headerrow.createCell(0);
        cell.setCellValue("No results available");
        return;
    }

    if (model.getColumnCount() > excelRowColLimit || model.getRowCount() > excelRowColLimit) {
        Row headerrow = dataSheet.createRow(0);
        Cell cell = headerrow.createCell(0);
        cell.setCellValue("Number of rows and/or columns too large to write to Excel");
        return;
    }

    Row headerrow = dataSheet.createRow(0);

    // Write column headers
    for (int i = 0; i < model.getColumnCount(); i++) {
        Cell cell = headerrow.createCell(i);
        cell.setCellValue(model.getColumnName(i));
    }

    // Write data values
    for (int r = 0; r < model.getRowCount(); r++) {
        Row row = dataSheet.createRow(r + 1);

        for (int c = 0; c < model.getColumnCount(); c++) {
            Cell cell = row.createCell(c);

            String value;

            if (model.getValueAt(r, c) == null) {
                value = "";
            } else

            {
                value = model.getValueAt(r, c).toString();
            }

            try {
                Double d = Double.valueOf(value);
                cell.setCellValue(d);
                cell.setCellStyle(doubleStyle);

            } catch (NumberFormatException ex) {
                cell.setCellValue(value);
            }
        }
    }
}

From source file:org.isatools.isacreator.gui.formelements.SubForm.java

protected void removeColumn(int curColDelete) {

    if ((curColDelete == -1) || (curColDelete == 0)) {
        return;// w w w .  j  a  v a  2 s  .c om
    }

    if (defaultTableModel.getColumnCount() == 2 && curColDelete == (defaultTableModel.getColumnCount() - 1)) {
        clearColumn(curColDelete);
        return;
    } else {
        clearColumn(curColDelete);
    }

    if (fieldType == FieldTypes.ASSAY && (dataEntryForm != null) && !uneditableRecords.contains(curColDelete)) {
        clearColumn(curColDelete);
        return;
    }

    DefaultTableModel model = (DefaultTableModel) scrollTable.getModel();

    // get the column. because 1 was added on previously to take account of the first column, we need to remove
    // it this time since the column indexes are now coming from the table.
    TableColumn col = scrollTable.getColumnModel().getColumn(curColDelete - 1);
    int columnModelIndex = col.getModelIndex();
    Vector data = model.getDataVector();
    Vector<String> colIds = new Vector<String>();

    for (int i = 0; i < model.getColumnCount(); i++) {
        colIds.addElement(model.getColumnName(i));
    }

    scrollTable.removeColumn(col);
    colIds.removeElementAt(columnModelIndex);

    // remove any data present in the column on deletion
    for (Object aData : data) {
        Vector row = (Vector) aData;
        row.removeElementAt(columnModelIndex);
    }

    model.setDataVector(data, colIds);

    // decrease each column index after deleted column by 1 so that indexes can be kept intact.
    Enumeration columnEnumeration = scrollTable.getColumnModel().getColumns();

    while (columnEnumeration.hasMoreElements()) {
        TableColumn c = (TableColumn) columnEnumeration.nextElement();

        if (c.getModelIndex() >= columnModelIndex) {
            c.setModelIndex(c.getModelIndex() - 1);
        }
    }

    if (fieldType == FieldTypes.ASSAY && uneditableRecords.contains(defaultTableModel.getColumnCount() - 1)) {
        uneditableRecords.remove(defaultTableModel.getColumnCount() - 1);
    }

    // update the model
    model.fireTableStructureChanged();
    updateTables();
}

From source file:View.Sending.java

private void send_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_send_buttonActionPerformed
    // TODO add your handling code here:
    DefaultTableModel dtm = (DefaultTableModel) user_table.getModel();
    int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
    Boolean count = false;/*from w  w  w .  j a v  a2 s  .c o m*/
    for (int i = 0; i < nRow; i++) {
        boolean isSelected = (boolean) dtm.getValueAt(i, 4);
        if (isSelected) {
            count = true;
            new sendFileThread().start();
            send_button.setEnabled(false);
        }

    }
    if (count == false) {
        JOptionPane.showMessageDialog(rootPane, "Select user");
    }

}

From source file:View.Sending.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // TODO add your handling code here:
    DefaultTableModel dtm = (DefaultTableModel) user_table.getModel();
    Dbcon dbcon = new Dbcon();
    int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
    for (int i = 0; i < nRow; i++) {
        boolean isSelected = (boolean) dtm.getValueAt(i, 4);
        if (isSelected) {
            System.out.println(dtm.getValueAt(i, 1) + " is selected");
            int userId = Integer.parseInt(dtm.getValueAt(i, 5).toString());

            ResultSet rs = dbcon.select("select * from tbl_user_details where user_id='" + userId + "'");
            try {
                if (rs.next()) {
                    String receiver_id = rs.getString("email_id");
                    System.out.println(receiver_id);
                    MailSenderThread mailSenderThread = new MailSenderThread(receiver_id);
                    mailSenderThread.start();
                    int ins = dbcon.insert(
                            "insert into tbl_transactions(sender_id, received_id,file,send, transaction_date,history_id) values ("
                                    + Login.logged_in_user_id + " ,' " + userId + "' ,'"
                                    + outputCipherFile.getName() + "',1, '" + System.currentTimeMillis() + "',"
                                    + history_id + ")");
                    if (ins > 0) {
                        System.out.println("inserted");

                    }/*from  w  w w .  j  av  a 2s .com*/
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}