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 classAbstractTableBasedSelectionPanel.AbstractSelectionTableModel<T>A simple table model for displaying the data.static interfaceAbstractTableBasedSelectionPanel.SelectionPopupMenuSupplierInterface 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_Currentthe selected items.protected HashSet<DoubleClickListener>m_DoubleClickListenersthe double-click listeners.protected JLabelm_LabelCountsthe label for displaying the total and selected counts.protected JPanelm_PanelAdditionalthe panel for additional components.protected JPanelm_PanelAllthe panel that encompasses all widgets.protected JPanelm_PanelCountsthe panel for displaying total and selected count.protected AbstractTableBasedSelectionPanel.SelectionPopupMenuSupplierm_PopupMenuSupplierthe popup menu supplier.protected SearchPanelm_SearchPanelthe search panel.protected AbstractTableBasedSelectionPanel<T>m_Selfthe panel itself.protected SortableAndSearchableTablem_TableDatathe table for displaying the items.protected AbstractTableBasedSelectionPanel.AbstractSelectionTableModel<T>m_TableDataModelthe 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 voidaddDoubleClickListener(DoubleClickListener l)Adds the given listener to the list of double-click listeners.voidaddListSelectionListener(ListSelectionListener l)Adds the given listener to the table's list of ListSelectionListeners.protected booleanaddToMissing(T item)Returns whether to add the item really to the missing list.protected voidbeforeShow()Hook method just before the dialog is made visible.voidcleanUp()Cleans up data structures, frees up memory.protected T[]getCurrentItems()Returns the currently selected items, null if none chosen or dialog canceled.TgetItem()Returns the item, null if none chosen or dialog canceled.protected abstract ClassgetItemClass()Returns the class of the items displayed, same as "T".intgetItemCount()Returns the count of currently displayed items.T[]getItems()Returns the selected items, null if none chosen or dialog canceled.AbstractTableBasedSelectionPanel.SelectionPopupMenuSuppliergetPopupMenuSupplier()Returns the current popup menu supplier.intgetSelectedItemCount()Returns the count of currently selected items.intgetSelectedRowCount()Returns the number of selected rows.voidgrabFocus()The text field for the search tries to grab the focus.protected voidinitGUI()initializes the GUI elements.protected voidinitialize()For initializing members.booleanisCountsVisible()Returns whether the total/selected counts are displayed.booleanisMultipleSelection()Returns whether multiple or single selection is active.protected booleanisValidItem(T item)Checks whether the item is valid.protected SearchPanelnewSearchPanel()Creates a new search panel widget.protected abstract AbstractTableBasedSelectionPanel.AbstractSelectionTableModel<T>newTableModel()Returns an empty table model.protected voidnotifyDoubleClickListeners(DoubleClickEvent e)Sends the event to all double-click listeners.protected voidprocessMissing(List<T> missing)Hook method for processing items that were not found when trying to select them initially.voidremoveDoubleClickListener(DoubleClickListener l)Removes the given listener from the list of double-click listeners.voidremoveListSelectionListener(ListSelectionListener l)Removes the given listener from the table's list of ListSelectionListeners.voidscrollIntoView()Makes sure that the first selected row is visible.protected voidsearch()Performs a search.protected List<T>select(T[] value)Selects the items.voidsetCountsVisible(boolean value)Sets whether the total/selected counts are displayed.voidsetDefaultPopupMenuSupplier()Sets a default popup menu supplier.voidsetEnabled(boolean value)Sets the enabled state of the panel.voidsetItem(T value)Sets the initially selected item.voidsetItems(T[] value)Sets the initially selected items.voidsetMultipleSelection(boolean value)Sets whether multiple or single selection is used.voidsetPopupMenuSupplier(AbstractTableBasedSelectionPanel.SelectionPopupMenuSupplier value)Sets the popup menu supplier, if the user right-clicks on the table cells.protected voidupdateCounts()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:
initializein 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:
setEnabledin 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:
grabFocusin 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:
beforeShowin 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.
-
-