Package adams.gui.selection
Class AbstractTableBasedSelectionPanel<T>
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.selection.AbstractSelectionPanel
-
- adams.gui.selection.AbstractTableBasedSelectionPanel<T>
-
- Type Parameters:
T
- the type of items to display
- All Implemented Interfaces:
CleanUpHandler
,ImageObserver
,MenuContainer
,Serializable
,Accessible
- Direct Known Subclasses:
AbstractDatabaseSelectionPanel
,SelectEmailAddressPanel
public abstract class AbstractTableBasedSelectionPanel<T> extends AbstractSelectionPanel
Abstract ancestor for selection panels that use a JTable for displaying the options.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractTableBasedSelectionPanel.AbstractSelectionTableModel<T>
A simple table model for displaying the data.static interface
AbstractTableBasedSelectionPanel.SelectionPopupMenuSupplier
Interface for classes that supply a popup menu for the selection table.-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
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 Modifier and Type Field Description protected T[]
m_Current
the selected items.protected HashSet<DoubleClickListener>
m_DoubleClickListeners
the double-click listeners.protected JLabel
m_LabelCounts
the label for displaying the total and selected counts.protected JPanel
m_PanelAdditional
the panel for additional components.protected JPanel
m_PanelAll
the panel that encompasses all widgets.protected JPanel
m_PanelCounts
the panel for displaying total and selected count.protected AbstractTableBasedSelectionPanel.SelectionPopupMenuSupplier
m_PopupMenuSupplier
the popup menu supplier.protected SearchPanel
m_SearchPanel
the search panel.protected AbstractTableBasedSelectionPanel<T>
m_Self
the panel itself.protected SortableAndSearchableTable
m_TableData
the table for displaying the items.protected AbstractTableBasedSelectionPanel.AbstractSelectionTableModel<T>
m_TableDataModel
the underlying table model.-
Fields inherited from class adams.gui.selection.AbstractSelectionPanel
DEFAULT_REFRESH_TIMEOUT
-
Fields inherited from class adams.gui.core.BasePanel
m_FileChooser
-
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 AbstractTableBasedSelectionPanel()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addDoubleClickListener(DoubleClickListener l)
Adds the given listener to the list of double-click listeners.void
addListSelectionListener(ListSelectionListener l)
Adds the given listener to the table's list of ListSelectionListeners.protected boolean
addToMissing(T item)
Returns whether to add the item really to the missing list.protected void
beforeShow()
Hook method just before the dialog is made visible.void
cleanUp()
Cleans up data structures, frees up memory.protected T[]
getCurrentItems()
Returns the currently selected items, null if none chosen or dialog canceled.T
getItem()
Returns the item, null if none chosen or dialog canceled.protected abstract Class
getItemClass()
Returns the class of the items displayed, same as "T".int
getItemCount()
Returns the count of currently displayed items.T[]
getItems()
Returns the selected items, null if none chosen or dialog canceled.AbstractTableBasedSelectionPanel.SelectionPopupMenuSupplier
getPopupMenuSupplier()
Returns the current popup menu supplier.int
getSelectedItemCount()
Returns the count of currently selected items.int
getSelectedRowCount()
Returns the number of selected rows.void
grabFocus()
The text field for the search tries to grab the focus.protected void
initGUI()
initializes the GUI elements.protected void
initialize()
For initializing members.boolean
isCountsVisible()
Returns whether the total/selected counts are displayed.boolean
isMultipleSelection()
Returns whether multiple or single selection is active.protected boolean
isValidItem(T item)
Checks whether the item is valid.protected SearchPanel
newSearchPanel()
Creates a new search panel widget.protected abstract AbstractTableBasedSelectionPanel.AbstractSelectionTableModel<T>
newTableModel()
Returns an empty table model.protected void
notifyDoubleClickListeners(DoubleClickEvent e)
Sends the event to all double-click listeners.protected void
processMissing(List<T> missing)
Hook method for processing items that were not found when trying to select them initially.void
removeDoubleClickListener(DoubleClickListener l)
Removes the given listener from the list of double-click listeners.void
removeListSelectionListener(ListSelectionListener l)
Removes the given listener from the table's list of ListSelectionListeners.void
scrollIntoView()
Makes sure that the first selected row is visible.protected void
search()
Performs a search.protected List<T>
select(T[] value)
Selects the items.void
setCountsVisible(boolean value)
Sets whether the total/selected counts are displayed.void
setDefaultPopupMenuSupplier()
Sets a default popup menu supplier.void
setEnabled(boolean value)
Sets the enabled state of the panel.void
setItem(T value)
Sets the initially selected item.void
setItems(T[] value)
Sets the initially selected items.void
setMultipleSelection(boolean value)
Sets whether multiple or single selection is used.void
setPopupMenuSupplier(AbstractTableBasedSelectionPanel.SelectionPopupMenuSupplier value)
Sets the popup menu supplier, if the user right-clicks on the table cells.protected void
updateCounts()
Updates the total/selected counts.-
Methods inherited from class adams.gui.selection.AbstractSelectionPanel
waitForEnabled, waitForEnabled
-
Methods inherited from class adams.gui.core.BasePanel
afterHide, afterShow, beforeHide, closeParent, finishInit, getParentChild, getParentDialog, getParentFrame, getParentInternalFrame, getParentTitle, initFileChooser, main, printErrorMessage, printException, saveComponent, setEnabledCascade, setEnabledCascade, setParentTitle, setVisible
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, 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, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
m_Self
protected AbstractTableBasedSelectionPanel<T> m_Self
the panel itself.
-
m_TableData
protected SortableAndSearchableTable m_TableData
the table for displaying the items.
-
m_TableDataModel
protected AbstractTableBasedSelectionPanel.AbstractSelectionTableModel<T> m_TableDataModel
the underlying table model.
-
m_PanelAll
protected JPanel m_PanelAll
the panel that encompasses all widgets.
-
m_SearchPanel
protected SearchPanel m_SearchPanel
the search panel.
-
m_PanelAdditional
protected JPanel m_PanelAdditional
the panel for additional components.
-
m_PanelCounts
protected JPanel m_PanelCounts
the panel for displaying total and selected count.
-
m_LabelCounts
protected JLabel m_LabelCounts
the label for displaying the total and selected counts.
-
m_Current
protected T[] m_Current
the selected items.
-
m_DoubleClickListeners
protected HashSet<DoubleClickListener> m_DoubleClickListeners
the double-click listeners.
-
m_PopupMenuSupplier
protected AbstractTableBasedSelectionPanel.SelectionPopupMenuSupplier m_PopupMenuSupplier
the popup menu supplier.
-
-
Method Detail
-
initialize
protected void initialize()
For initializing members.- Overrides:
initialize
in classBasePanel
-
initGUI
protected void initGUI()
initializes the GUI elements.
-
newSearchPanel
protected SearchPanel newSearchPanel()
Creates a new search panel widget.- Returns:
- the search panel
-
newTableModel
protected abstract AbstractTableBasedSelectionPanel.AbstractSelectionTableModel<T> newTableModel()
Returns an empty table model.- Returns:
- the model
-
getItemClass
protected abstract Class getItemClass()
Returns the class of the items displayed, same as "T".- Returns:
- the class of the items
-
setMultipleSelection
public void setMultipleSelection(boolean value)
Sets whether multiple or single selection is used.- Parameters:
value
- if true multiple items can be selected
-
isMultipleSelection
public boolean isMultipleSelection()
Returns whether multiple or single selection is active.- Returns:
- true if multiple selection is active
-
getSelectedRowCount
public int getSelectedRowCount()
Returns the number of selected rows.- Returns:
- the number of selected rows
-
search
protected void search()
Performs a search.
-
addListSelectionListener
public void addListSelectionListener(ListSelectionListener l)
Adds the given listener to the table's list of ListSelectionListeners.- Parameters:
l
- the listener to add
-
removeListSelectionListener
public void removeListSelectionListener(ListSelectionListener l)
Removes the given listener from the table's list of ListSelectionListeners.- Parameters:
l
- the listener to remove
-
addDoubleClickListener
public void addDoubleClickListener(DoubleClickListener l)
Adds the given listener to the list of double-click listeners.- Parameters:
l
- the listener to add
-
removeDoubleClickListener
public void removeDoubleClickListener(DoubleClickListener l)
Removes the given listener from the list of double-click listeners.- Parameters:
l
- the listener to remove
-
notifyDoubleClickListeners
protected void notifyDoubleClickListeners(DoubleClickEvent e)
Sends the event to all double-click listeners.- Parameters:
e
- the event to send
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.
-
setEnabled
public void setEnabled(boolean value)
Sets the enabled state of the panel.- Overrides:
setEnabled
in classJComponent
- Parameters:
value
- if true then the components will be enabled
-
grabFocus
public void grabFocus()
The text field for the search tries to grab the focus.- Specified by:
grabFocus
in classAbstractSelectionPanel
-
getItemCount
public int getItemCount()
Returns the count of currently displayed items.- Returns:
- the total count
-
getSelectedItemCount
public int getSelectedItemCount()
Returns the count of currently selected items.- Returns:
- the selection count
-
getCurrentItems
protected T[] getCurrentItems()
Returns the currently selected items, null if none chosen or dialog canceled.- Returns:
- the selected items
-
getItem
public T getItem()
Returns the item, null if none chosen or dialog canceled.- Returns:
- the selected item
-
getItems
public T[] getItems()
Returns the selected items, null if none chosen or dialog canceled.- Returns:
- the selected items
-
setItem
public void setItem(T value)
Sets the initially selected item.- Parameters:
value
- the item to select
-
processMissing
protected void processMissing(List<T> missing)
Hook method for processing items that were not found when trying to select them initially.
The default implementation merely outputs the items.- Parameters:
missing
- the missing items
-
isValidItem
protected boolean isValidItem(T item)
Checks whether the item is valid.
Default implementation only checks for null.- Parameters:
item
- the item to check- Returns:
- true if valid
-
addToMissing
protected boolean addToMissing(T item)
Returns whether to add the item really to the missing list.
Default implementation returns always true.- Parameters:
item
- the item to check- Returns:
- true if to add the item to the missing list, false otherwise
-
select
protected List<T> select(T[] value)
Selects the items.- Parameters:
value
- the items to select- Returns:
- the actually selected items
-
setItems
public void setItems(T[] value)
Sets the initially selected items.- Parameters:
value
- the items to select
-
scrollIntoView
public void scrollIntoView()
Makes sure that the first selected row is visible.
-
beforeShow
protected void beforeShow()
Hook method just before the dialog is made visible.- Overrides:
beforeShow
in classBasePanel
-
setPopupMenuSupplier
public void setPopupMenuSupplier(AbstractTableBasedSelectionPanel.SelectionPopupMenuSupplier value)
Sets the popup menu supplier, if the user right-clicks on the table cells.- Parameters:
value
- the supplier, can be null to turn off menu
-
getPopupMenuSupplier
public AbstractTableBasedSelectionPanel.SelectionPopupMenuSupplier getPopupMenuSupplier()
Returns the current popup menu supplier.- Returns:
- the supplier, can be null if turned off
-
setDefaultPopupMenuSupplier
public void setDefaultPopupMenuSupplier()
Sets a default popup menu supplier. Simply allows to copy all the column values to the clipboard.
-
setCountsVisible
public void setCountsVisible(boolean value)
Sets whether the total/selected counts are displayed.- Parameters:
value
- if true then the total/selected counts are displayed
-
isCountsVisible
public boolean isCountsVisible()
Returns whether the total/selected counts are displayed.- Returns:
- true if the total/selected counts are displayed
-
updateCounts
protected void updateCounts()
Updates the total/selected counts.
-
-