Example usage for javax.swing JTable getSelectedColumnCount

List of usage examples for javax.swing JTable getSelectedColumnCount

Introduction

In this page you can find the example usage for javax.swing JTable getSelectedColumnCount.

Prototype

@BeanProperty(bound = false)
public int getSelectedColumnCount() 

Source Link

Document

Returns the number of selected columns.

Usage

From source file:net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.GenericWikiTableTransformer.java

/**
 * @see//from  ww w .  j av a 2 s.c o  m
 * net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.IWikiTableTransformer
 * #transform(javax.swing.JTable)
 */
@Override
public String transform(JTable table) {
    int nbrSelRows = table.getSelectedRowCount();
    int nbrSelCols = table.getSelectedColumnCount();
    int[] selRows = table.getSelectedRows();
    int[] selCols = table.getSelectedColumns();

    if (selRows.length != 0 && selCols.length != 0) {
        StringBuilder buf = new StringBuilder(1024);
        // Start the table
        appendWithReplacement(buf, configuration.getTableStartTag());
        // Create the header
        appendWithReplacement(buf, configuration.getHeaderStartTag());
        for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) {
            appendWithReplacement(buf, configuration.getHeaderCell(), table.getColumnName(selCols[colIdx]));
        }
        appendWithReplacement(buf, configuration.getHeaderEndTag());
        // Now fill all the table rows
        for (int rowIdx = 0; rowIdx < nbrSelRows; ++rowIdx) {
            appendWithReplacement(buf, configuration.getRowStartTag());
            for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) {
                TableCellRenderer cellRenderer = table.getCellRenderer(selRows[rowIdx], selCols[colIdx]);
                Object cellObj = table.getValueAt(selRows[rowIdx], selCols[colIdx]);

                if (cellRenderer instanceof SquirrelTableCellRenderer) {
                    cellObj = ((SquirrelTableCellRenderer) cellRenderer).renderValue(cellObj);
                }

                String value = null;
                if (cellObj == null) {
                    value = ""; //$NON-NLS-1$
                } else {
                    final String tmp = cellObj.toString();
                    if (tmp.trim().equals("")) { //$NON-NLS-1$
                        value = ""; //$NON-NLS-1$
                    } else {
                        value = tmp;
                    }
                }
                appendWithReplacement(buf, configuration.getDataCell(), value);
            }
            appendWithReplacement(buf, configuration.getRowEndTag());
        }
        appendWithReplacement(buf, configuration.getTableEndTag());
        return buf.toString();
    } else {
        return null;
    }

}