Package org.compiere.minigrid
Class MiniTable
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JTable
-
- org.compiere.swing.CTable
-
- org.compiere.minigrid.MiniTable
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,CellEditorListener
,ListSelectionListener
,RowSorterListener
,TableColumnModelListener
,TableModelListener
,Scrollable
,IMiniTable
- Direct Known Subclasses:
PosTable
public class MiniTable extends CTable implements IMiniTable
Mini Table. Default Read Only Table for Boolean, String, Number, Timestamp valuesAfter initializing the Table Model, you need to call setColumnClass, add columns via addColumn or in one go prepare the table.
MiniTable mt = new MiniTable(); String sql = mt.prepareTable(..); // table defined // add where to the sql statement ResultSet rs = .. mt.loadTable(rs); rs.close();
- Version:
- $Id: MiniTable.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $
- Author:
- Jorg Janke, Teo Sarca, SC ARHIPAC SERVICE SRL
- BF [ 1891082 ] NPE on MiniTable when you hide some columns
- FR [ 1974299 ] Add MiniTable.getSelectedKeys method
- FR [ 2847295 ] MiniTable multiselection checkboxes not working https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2847295&group_id=176962, Teo Sarca, teo.sarca@gmail.com
- BF [ 2876895 ] MiniTable.loadTable: NPE if column is null https://sourceforge.net/tracker/?func=detail&aid=2876895&group_id=176962&atid=879332
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.DropLocation, JTable.PrintMode
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
-
Fields inherited from class org.compiere.swing.CTable
p_asc, p_keyColumnIndex, p_lastSortIndex, sorting
-
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description MiniTable()
Default Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColumn(String header)
Add Table Column.void
addTotals(Info_Column[] layout)
Adding a new row with the totalsvoid
addTotals(ColumnInfo[] layout)
Adding a new row with the totalsvoid
autoSize()
Size Columns.int
getColorCode(int row)
Get ColorCode for Row.TableColumn
getColumn(int col)
Gets the swing column of given index.int
getColumnCount()
Return number of columns in the mini tableColumnInfo[]
getLayoutInfo()
Get LayoutCollection<Integer>
getSelectedKeys()
Integer
getSelectedRowKey()
Get the key of currently selected row based on layout defined in prepareTableboolean
getShowTotals()
get if Totals is Showboolean
isAutoResize()
boolean
isCellEditable(int row, int column)
Is Cell Editableboolean
isMultiSelection()
Single Selection Tablevoid
loadTable(ResultSet rs)
Load Table from ResultSet - The ResultSet is not closedvoid
loadTable(PO[] pos)
Load Table from Object ArrayString
prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName)
Prepare Table and return SQLvoid
setAutoResize(boolean autoResize)
void
setColorColumn(int modelIndex)
Set the Column to determine the color of the row (based on model index)void
setColorCompare(Object dataCompare)
Set ColorColumn comparison criteriavoid
setColumnClass(int index, Class<?> c, boolean readOnly)
Set Column Editor & Renderer to Class.void
setColumnClass(int index, Class<?> c, boolean readOnly, String header)
Set Column Editor & Renderer to Class (after all columns were added) Lauout of IDColumn depemds on multiSelectionvoid
setColumnReadOnly(int column, boolean readOnly)
Set Column to ReadOnlyvoid
setMultiSelection(boolean multiSelection)
Set Single Selectionvoid
setRowCount(int no)
Clear Table Contentvoid
setShowTotals(boolean show)
Set if Totals is Show-
Methods inherited from class org.compiere.swing.CTable
autoSize, configureColumnControl, createDefaultColumnControl, getColumnControl, getKeyColumnIndex, getSelectedKeyColumnValue, getSelectedValue, getSortColumn, isColumnControlVisible, isColumnVisible, isSortAscending, packColumn, prepareRenderer, setColumnControlVisible, setColumnVisibility, setFont, setKeyColumnIndex, sort, stopEditor, tableChanged, toString
-
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, doLayout, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getUpdateSelectionOnSort, getValueAt, initializeLocalVars, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, print, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setRowSorter, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, setValueAt, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, unconfigureEnclosingScrollPane, updateUI, valueChanged
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.compiere.minigrid.IMiniTable
convertColumnIndexToModel, getRowCount, getSelectedRow, getValueAt, repaint, setValueAt
-
-
-
-
Method Detail
-
isAutoResize
public boolean isAutoResize()
-
setAutoResize
public void setAutoResize(boolean autoResize)
-
getColumn
public TableColumn getColumn(int col)
Gets the swing column of given index. No index checking is done.- Parameters:
col
-- Returns:
-
getColumnCount
public int getColumnCount()
Return number of columns in the mini table- Specified by:
getColumnCount
in interfaceIMiniTable
- Overrides:
getColumnCount
in classJTable
-
autoSize
public void autoSize()
Size Columns. Uses Mimimum Column Size- Specified by:
autoSize
in interfaceIMiniTable
-
isCellEditable
public boolean isCellEditable(int row, int column)
Is Cell Editable- Specified by:
isCellEditable
in interfaceIMiniTable
- Overrides:
isCellEditable
in classJTable
- Parameters:
row
- rowcolumn
- column- Returns:
- true if editable
-
setColumnReadOnly
public void setColumnReadOnly(int column, boolean readOnly)
Set Column to ReadOnly- Specified by:
setColumnReadOnly
in interfaceIMiniTable
- Parameters:
column
- columnreadOnly
- read only
-
prepareTable
public String prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName)
Prepare Table and return SQL- Specified by:
prepareTable
in interfaceIMiniTable
- Parameters:
layout
- array of column infofrom
- SQL FROM contentwhere
- SQL WHERE contentmultiSelection
- multiple selectionstableName
- table name- Returns:
- SQL
-
addColumn
public void addColumn(String header)
Add Table Column. after adding a column, you need to set the column classes again (DefaultTableModel fires TableStructureChanged, which calls JTable.tableChanged .. createDefaultColumnsFromModel- Specified by:
addColumn
in interfaceIMiniTable
- Parameters:
header
- header
-
setColumnClass
public void setColumnClass(int index, Class<?> c, boolean readOnly)
Set Column Editor & Renderer to Class. (after all columns were added)- Specified by:
setColumnClass
in interfaceIMiniTable
- Parameters:
index
- column indexc
- class of column - determines rendererereadOnly
- read only flag
-
setColumnClass
public void setColumnClass(int index, Class<?> c, boolean readOnly, String header)
Set Column Editor & Renderer to Class (after all columns were added) Lauout of IDColumn depemds on multiSelection- Specified by:
setColumnClass
in interfaceIMiniTable
- Parameters:
index
- column indexc
- class of column - determines renderere/editors supported: IDColumn, Boolean, Double (Quantity), BigDecimal (Amount), Integer, Timestamp, String (default)readOnly
- read only flagheader
- optional header value
-
setRowCount
public void setRowCount(int no)
Clear Table Content- Specified by:
setRowCount
in interfaceIMiniTable
- Parameters:
no
- number of rows
-
loadTable
public void loadTable(ResultSet rs)
Load Table from ResultSet - The ResultSet is not closed- Specified by:
loadTable
in interfaceIMiniTable
- Parameters:
rs
- ResultSet with the column layout defined in prepareTable
-
loadTable
public void loadTable(PO[] pos)
Load Table from Object Array- Specified by:
loadTable
in interfaceIMiniTable
- Parameters:
pos
- array of POs
-
getSelectedRowKey
public Integer getSelectedRowKey()
Get the key of currently selected row based on layout defined in prepareTable- Specified by:
getSelectedRowKey
in interfaceIMiniTable
- Returns:
- ID if key
-
getSelectedKeys
public Collection<Integer> getSelectedKeys()
- Returns:
- collection of selected IDs
-
getLayoutInfo
public ColumnInfo[] getLayoutInfo()
Get Layout- Specified by:
getLayoutInfo
in interfaceIMiniTable
- Returns:
- Array of ColumnInfo
-
setMultiSelection
public void setMultiSelection(boolean multiSelection)
Set Single Selection- Specified by:
setMultiSelection
in interfaceIMiniTable
- Parameters:
multiSelection
- multiple selections
-
isMultiSelection
public boolean isMultiSelection()
Single Selection Table- Specified by:
isMultiSelection
in interfaceIMiniTable
- Returns:
- true if multiple rows can be selected
-
setColorColumn
public void setColorColumn(int modelIndex)
Set the Column to determine the color of the row (based on model index)- Parameters:
modelIndex
- model index
-
setColorCompare
public void setColorCompare(Object dataCompare)
Set ColorColumn comparison criteria- Specified by:
setColorCompare
in interfaceIMiniTable
- Parameters:
dataCompare
- data
-
getColorCode
public int getColorCode(int row)
Get ColorCode for Row.If numerical value in compare column is negative = -1, positive = 1, otherwise = 0 If Timestamp
- Specified by:
getColorCode
in interfaceIMiniTable
- Parameters:
row
- row- Returns:
- color code
-
setShowTotals
public void setShowTotals(boolean show)
Set if Totals is Show- Specified by:
setShowTotals
in interfaceIMiniTable
- Parameters:
boolean
- Show
-
getShowTotals
public boolean getShowTotals()
get if Totals is Show- Parameters:
boolean
- Show
-
addTotals
public void addTotals(ColumnInfo[] layout)
Adding a new row with the totals
-
addTotals
public void addTotals(Info_Column[] layout)
Adding a new row with the totals
-
-