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
}
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");
}
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;
}
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);
}
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;
}
Aggregations