Search in sources :

Example 46 with TableModel

use of javax.swing.table.TableModel in project adempiere by adempiere.

the class VTable method sort.

//  getColorCode
/**
	 *  Sort Table
	 *  @param modelColumnIndex model column sort index
	 */
protected void sort(int modelColumnIndex) {
    int rows = getRowCount();
    if (rows == 0)
        return;
    //
    TableModel model = getModel();
    if (!(model instanceof GridTable)) {
        super.sort(modelColumnIndex);
        return;
    }
    sorting = true;
    //  other sort column
    if (modelColumnIndex != p_lastSortIndex)
        p_asc = true;
    else
        p_asc = !p_asc;
    p_lastSortIndex = modelColumnIndex;
    //
    log.config("#" + modelColumnIndex + " - rows=" + rows + ", asc=" + p_asc);
    ((GridTable) model).sort(modelColumnIndex, p_asc);
    sorting = false;
//  table model fires "Sorted" DataStatus event which causes MTab to position to row 0
}
Also used : GridTable(org.compiere.model.GridTable) TableModel(javax.swing.table.TableModel)

Example 47 with TableModel

use of javax.swing.table.TableModel in project adempiere by adempiere.

the class MiniTable method autoSize.

/**
	 *	Size Columns.
	 *  Uses Mimimum Column Size
	 */
public void autoSize() {
    if (!autoResize)
        return;
    long start = System.currentTimeMillis();
    //
    //	making sure it fits in a column
    final int SLACK = 8;
    //	max size of a column
    final int MAXSIZE = 300;
    //
    TableModel model = this.getModel();
    int size = model.getColumnCount();
    //	for all columns
    for (int col = 0; col < size; col++) {
        //  Column & minimum width
        TableColumn tc = this.getColumnModel().getColumn(col);
        int width = 0;
        if (m_minWidth.size() > col)
            width = ((Integer) m_minWidth.get(col)).intValue();
        //  log.config( "Column=" + col + " " + column.getHeaderValue());
        //	Header
        TableCellRenderer renderer = tc.getHeaderRenderer();
        if (renderer == null)
            renderer = new DefaultTableCellRenderer();
        Component comp = renderer.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, 0);
        //	log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth());
        width = Math.max(width, comp.getPreferredSize().width + SLACK);
        //	Cells
        //  first 30 rows
        int maxRow = Math.min(30, getRowCount());
        for (int row = 0; row < maxRow; row++) {
            renderer = getCellRenderer(row, col);
            comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
            if (comp != null) {
                int rowWidth = comp.getPreferredSize().width + SLACK;
                width = Math.max(width, rowWidth);
            }
        }
        //	Width not greater ..
        width = Math.min(MAXSIZE, width);
        tc.setPreferredWidth(width);
    //	log.fine( "width=" + width);
    }
    //	for all columns
    log.finer("Cols=" + size + " - " + (System.currentTimeMillis() - start) + "ms");
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Component(java.awt.Component) JComponent(javax.swing.JComponent) TableColumn(javax.swing.table.TableColumn) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 48 with TableModel

use of javax.swing.table.TableModel in project Gargoyle by callakrsos.

the class ExcelUtil method createExcel.

/**
	 * 2014. 10. 3. KYJ
	 *
	 * @param createJtable
	 * @return
	 * @throws Exception
	 * @처리내용 : JTable의 데이터를 이용하여 엑셀파일을 생성한다.
	 */
public static boolean createExcel(JTable createJtable, String makeFile) throws Exception {
    int rowCount = createJtable.getRowCount();
    int columnCount = createJtable.getColumnCount();
    TableModel model = createJtable.getModel();
    ExcelSVO svo = new ExcelSVO();
    TableColumnModel columnModel = createJtable.getColumnModel();
    ArrayList<ExcelColDVO> arrayList = new ArrayList<ExcelColDVO>();
    for (int j = 0; j < columnCount; j++) {
        TableColumn column = columnModel.getColumn(j);
        Object headerValue = column.getHeaderValue();
        arrayList.add(new ExcelColDVO(j, (String) headerValue));
    }
    for (int i = 0; i < rowCount; i++) {
        for (int j = 0; j < columnCount; j++) {
            Object valueAt = model.getValueAt(i, j);
            svo.setColDvoList("sheet1", arrayList);
            svo.addSheetExcelDVO("sheet1", new ExcelDataDVO(i, j, valueAt));
        }
    }
    createExcel(makeFile, svo);
    return false;
}
Also used : ExcelDataDVO(com.kyj.fx.voeditor.visual.excels.base.ExcelDataDVO) ExcelColDVO(com.kyj.fx.voeditor.visual.excels.base.ExcelColDVO) ArrayList(java.util.ArrayList) TableColumnModel(javax.swing.table.TableColumnModel) ExcelSVO(com.kyj.fx.voeditor.visual.excels.base.ExcelSVO) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) TableColumn(javax.swing.table.TableColumn) TableModel(javax.swing.table.TableModel)

Example 49 with TableModel

use of javax.swing.table.TableModel in project processdash by dtuma.

the class EVReport method writeTaskTable.

private static void writeTaskTable(Writer out, EVTaskList taskList, EVTaskFilter filter, EVReportSettings settings, String namespace) throws IOException {
    HTMLTableWriter writer = new HTMLTableWriter();
    boolean showTimingIcons = taskList instanceof EVTaskListData && !settings.isExporting();
    TableModel table = customizeTaskTableWriter(writer, taskList, filter, settings, showTimingIcons);
    writer.setTableAttributes("class='sortable' id='" + namespace + "task' border='1'");
    writer.writeTable(out, table);
}
Also used : HTMLTableWriter(net.sourceforge.processdash.ui.lib.HTMLTableWriter) EVTaskListData(net.sourceforge.processdash.ev.EVTaskListData) TreeTableModel(net.sourceforge.processdash.ui.lib.TreeTableModel) TableModel(javax.swing.table.TableModel)

Example 50 with TableModel

use of javax.swing.table.TableModel in project processdash by dtuma.

the class JTableColumnVisibilityAction method createColumnSelector.

private CheckboxList createColumnSelector() {
    Set<Integer> visibleColumns = new HashSet<Integer>();
    Set<Integer> hiddenColumns = new HashSet<Integer>();
    TableColumnModel columnModel = table.getColumnModel();
    for (int i = columnModel.getColumnCount(); i-- > 0; ) {
        TableColumn column = columnModel.getColumn(i);
        if (column.getMaxWidth() == 0)
            hiddenColumns.add(i);
        else
            visibleColumns.add(column.getModelIndex());
    }
    TableModel tableModel = table.getModel();
    List<NumberedColumn> columns = new ArrayList();
    for (int i = 0; i < tableModel.getColumnCount(); i++) {
        String columnName = tableModel.getColumnName(i);
        if (columnCache.containsKey(i) && !hiddenColumns.contains(i) && !isReadOnlyColumnName(columnName)) {
            boolean isVisible = visibleColumns.contains(i);
            columns.add(new NumberedColumn(i, columnName, isVisible));
        }
    }
    CheckboxList list = new CheckboxList(columns.toArray());
    for (int i = columns.size(); i-- > 0; ) list.setChecked(i, columns.get(i).initiallyVisible);
    return list;
}
Also used : ArrayList(java.util.ArrayList) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) TableModel(javax.swing.table.TableModel) HashSet(java.util.HashSet)

Aggregations

TableModel (javax.swing.table.TableModel)53 AbstractTableModel (javax.swing.table.AbstractTableModel)11 JTable (javax.swing.JTable)9 DefaultTableModel (javax.swing.table.DefaultTableModel)9 TableColumn (javax.swing.table.TableColumn)9 ArrayList (java.util.ArrayList)8 TableRowSorter (javax.swing.table.TableRowSorter)8 TableCellRenderer (javax.swing.table.TableCellRenderer)6 ActionEvent (java.awt.event.ActionEvent)5 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 TableCellEditor (javax.swing.table.TableCellEditor)5 Component (java.awt.Component)4 ActionListener (java.awt.event.ActionListener)4 List (java.util.List)4 Set (java.util.Set)4 TableColumnModel (javax.swing.table.TableColumnModel)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)2