Package adams.gui.tools
Class AbstractManagementPanel<T extends Comparable>
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.tools.AbstractManagementPanel<T>
-
- Type Parameters:
T- the type of the objects in the table model
- All Implemented Interfaces:
CleanUpHandler,LoggingSupporter,MenuBarProvider,ImageObserver,MenuContainer,Serializable,Accessible
- Direct Known Subclasses:
AbstractManagementPanelWithDatabase,AbstractManagementPanelWithProperties
public abstract class AbstractManagementPanel<T extends Comparable> extends BasePanel implements CleanUpHandler, MenuBarProvider, LoggingSupporter
A panel for managing objects.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
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 BaseButtonm_ButtonAddthe button for adding an object.protected BaseButtonm_ButtonClearthe button for clearing the input.protected BaseButtonm_ButtonLoadthe button for loading the selected object.protected BaseButtonm_ButtonRefreshthe button for refreshing the table.protected BaseButtonm_ButtonRemovethe button for deleting selected objects.protected BaseButtonm_ButtonUpdatethe button for updating an object.protected SpreadSheetFileChooserm_FileChooserthe file chooser for saving the spreadsheet.protected Loggerm_Loggerthe logger instance to use.protected JMenuBarm_MenuBarthe menu bar.protected JMenuItemm_MenuItemEditAddthe menu item for adding.protected JMenuItemm_MenuItemEditClearthe menu item for clearing.protected JMenuItemm_MenuItemEditRemovethe menu item for removing.protected JMenuItemm_MenuItemEditUpdatethe menu item for updating.protected JMenuItemm_MenuItemFileRefreshthe menu item for refreshing.protected AbstractManagementTableModel<T>m_ModelValuesthe table model for the objects.protected SearchPanelm_PanelSearchthe search panel.protected JPanelm_PanelTablethe panel with the currently available objects.protected ParameterPanelWithButtonsm_PanelValuesthe panel with the values for adding/updating objects.protected SortableAndSearchableTableWithButtonsm_TableValuesthe table for displaying the objects.-
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 AbstractManagementPanel()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddActionListener(JComboBox combo)Adds an action listener to the combobox.protected voidaddChangeListener(AbstractChooserPanel chooser)Adds a change listener to the chooser.protected voidaddDocumentListener(Document doc)Adds the appropriate document listener to the document.protected abstract voidaddFields(ParameterPanelWithButtons panel)For adding all the fields.protected voidaddListener(Component comp)Adds the appropriate listener to the component.protected voidaddObject()Adds the object and refreshes the table.protected voidaddOtherMenus(JMenuBar menubar)For adding additional menus.protected booleanaddToEditMenu(JMenu menu)Hook method for adding items to the "Edit" menu.protected booleanaddToFileMenu(JMenu menu)Hook method for adding items to the "File" menu.protected abstract booleancanAddObject()Returns whether all the required fields are set to add the object.protected abstract booleancanClearFields()Returns whether the fields can be cleared, i.e., if there is any input.protected booleancanRemoveObjects()Returns whether objects can be deleted.voidcleanUp()Cleans up data structures, frees up memory.protected abstract voidclear()Resets the input fields.protected abstract booleanexists(T value)Checks whether the object already exists.protected abstract TfieldsToObject()Turns the fields into an object.protected voidfinishInit()Finishes the initialization.protected SpreadSheetFileChoosergetFileChooser()Returns the filechooser for saving the table as spreadsheet.protected StringgetID(T value)Returns the ID from the object.protected StringgetItemName(boolean multiple)Returns a human-readable string describing the managed objects.LoggergetLogger()Returns the logger in use.protected abstract ClassgetManagedClass()Returns the class that is being managed.protected intgetMaximumColumnWidth()Returns the maximum column width to use when determining the optimal column width.JMenuBargetMenuBar()Creates a menu bar (singleton per panel object).protected List<T>getSelectedValues()Returns the selected values.protected voidinitGUI()Initializes the widgets.booleanisLoggingEnabled()Returns whether logging is enabled.protected abstract booleanisReadOnly()Returns whether modified data cannot be stored.protected abstract List<T>loadAll()Loads all the objects.protected voidloadValue()Loads the Object from the table and displays it in the GUI.protected abstract AbstractManagementTableModel<T>newTableModel()Returns an instance of a new table model.protected abstract voidobjectToFields(T value)Updates the field with the specified object.protected voidrefresh()Refreshes the table.protected abstract booleanremove(T value)Removes the object.protected voidremoveObjects()Removes the selected objects and refreshes the table.protected abstract booleanstore(T value)Stores the object.protected voidupdate()Updates the enabled state of the widgets.protected voidupdateButtons()Updates the enabled state of the widgets.protected voidupdateMenu()updates the enabled state of the menu items.protected voidupdateObject()Updates the object and refreshes the table.-
Methods inherited from class adams.gui.core.BasePanel
afterHide, afterShow, beforeHide, beforeShow, closeParent, getParentChild, getParentDialog, getParentFrame, getParentInternalFrame, getParentTitle, initFileChooser, initialize, 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, grabFocus, 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, setEnabled, 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_ButtonClear
protected BaseButton m_ButtonClear
the button for clearing the input.
-
m_ButtonAdd
protected BaseButton m_ButtonAdd
the button for adding an object.
-
m_ButtonUpdate
protected BaseButton m_ButtonUpdate
the button for updating an object.
-
m_TableValues
protected SortableAndSearchableTableWithButtons m_TableValues
the table for displaying the objects.
-
m_ModelValues
protected AbstractManagementTableModel<T extends Comparable> m_ModelValues
the table model for the objects.
-
m_ButtonRefresh
protected BaseButton m_ButtonRefresh
the button for refreshing the table.
-
m_ButtonRemove
protected BaseButton m_ButtonRemove
the button for deleting selected objects.
-
m_ButtonLoad
protected BaseButton m_ButtonLoad
the button for loading the selected object.
-
m_PanelValues
protected ParameterPanelWithButtons m_PanelValues
the panel with the values for adding/updating objects.
-
m_PanelTable
protected JPanel m_PanelTable
the panel with the currently available objects.
-
m_PanelSearch
protected SearchPanel m_PanelSearch
the search panel.
-
m_FileChooser
protected SpreadSheetFileChooser m_FileChooser
the file chooser for saving the spreadsheet.
-
m_MenuBar
protected JMenuBar m_MenuBar
the menu bar.
-
m_MenuItemFileRefresh
protected JMenuItem m_MenuItemFileRefresh
the menu item for refreshing.
-
m_MenuItemEditClear
protected JMenuItem m_MenuItemEditClear
the menu item for clearing.
-
m_MenuItemEditAdd
protected JMenuItem m_MenuItemEditAdd
the menu item for adding.
-
m_MenuItemEditUpdate
protected JMenuItem m_MenuItemEditUpdate
the menu item for updating.
-
m_MenuItemEditRemove
protected JMenuItem m_MenuItemEditRemove
the menu item for removing.
-
m_Logger
protected Logger m_Logger
the logger instance to use.
-
-
Method Detail
-
finishInit
protected void finishInit()
Finishes the initialization.- Overrides:
finishInitin classBasePanel
-
getLogger
public Logger getLogger()
Returns the logger in use.- Specified by:
getLoggerin interfaceLoggingSupporter- Returns:
- the logger
-
isLoggingEnabled
public boolean isLoggingEnabled()
Returns whether logging is enabled.- Specified by:
isLoggingEnabledin interfaceLoggingSupporter- Returns:
- true if at least
Level.INFO
-
addToFileMenu
protected boolean addToFileMenu(JMenu menu)
Hook method for adding items to the "File" menu.- Parameters:
menu- the menu to update- Returns:
- true if an item was added
-
addToEditMenu
protected boolean addToEditMenu(JMenu menu)
Hook method for adding items to the "Edit" menu.- Parameters:
menu- the menu to update- Returns:
- true if an item was added
-
addOtherMenus
protected void addOtherMenus(JMenuBar menubar)
For adding additional menus.- Parameters:
menubar- the menubar to extend
-
getMenuBar
public JMenuBar getMenuBar()
Creates a menu bar (singleton per panel object). Can be used in frames.- Specified by:
getMenuBarin interfaceMenuBarProvider- Returns:
- the menu bar
-
updateMenu
protected void updateMenu()
updates the enabled state of the menu items.
-
getFileChooser
protected SpreadSheetFileChooser getFileChooser()
Returns the filechooser for saving the table as spreadsheet.- Returns:
- the filechooser
-
addDocumentListener
protected void addDocumentListener(Document doc)
Adds the appropriate document listener to the document.- Parameters:
doc- the document to add the listener to- See Also:
addListener(Component)
-
addActionListener
protected void addActionListener(JComboBox combo)
Adds an action listener to the combobox.- Parameters:
combo- the combobox to add the listener to- See Also:
addListener(Component)
-
addChangeListener
protected void addChangeListener(AbstractChooserPanel chooser)
Adds a change listener to the chooser.- Parameters:
chooser- the chooser to add the listener to- See Also:
addListener(Component)
-
addListener
protected void addListener(Component comp)
Adds the appropriate listener to the component.- Parameters:
comp- the component to add a listener to
-
addFields
protected abstract void addFields(ParameterPanelWithButtons panel)
For adding all the fields.- Parameters:
panel- the panel to add the fields to
-
newTableModel
protected abstract AbstractManagementTableModel<T> newTableModel()
Returns an instance of a new table model.- Returns:
- the table model
-
getManagedClass
protected abstract Class getManagedClass()
Returns the class that is being managed.- Returns:
- the class being managed
-
getItemName
protected String getItemName(boolean multiple)
Returns a human-readable string describing the managed objects.- Parameters:
multiple- true if to return the plural- Returns:
- the name of the objects
-
clear
protected abstract void clear()
Resets the input fields.
-
fieldsToObject
protected abstract T fieldsToObject()
Turns the fields into an object.- Returns:
- the generated object
-
objectToFields
protected abstract void objectToFields(T value)
Updates the field with the specified object.- Parameters:
value- the object to display
-
exists
protected abstract boolean exists(T value)
Checks whether the object already exists.- Parameters:
value- the value to look for- Returns:
- true if already available
-
store
protected abstract boolean store(T value)
Stores the object.- Parameters:
value- the value to store- Returns:
- true if successfully stored
-
remove
protected abstract boolean remove(T value)
Removes the object.- Parameters:
value- the value to remove- Returns:
- true if successfully removed
-
getID
protected String getID(T value)
Returns the ID from the object.
Default implementation only returns and ID if the object implementsIDHandler.- Parameters:
value- the object to get the ID from- Returns:
- the ID, null if it could not be retrieved
-
addObject
protected void addObject()
Adds the object and refreshes the table.
-
updateObject
protected void updateObject()
Updates the object and refreshes the table.
-
removeObjects
protected void removeObjects()
Removes the selected objects and refreshes the table.
-
loadValue
protected void loadValue()
Loads the Object from the table and displays it in the GUI.
-
getSelectedValues
protected List<T> getSelectedValues()
Returns the selected values.- Returns:
- the selected values
-
refresh
protected void refresh()
Refreshes the table.
-
getMaximumColumnWidth
protected int getMaximumColumnWidth()
Returns the maximum column width to use when determining the optimal column width.- Returns:
- the maximum
-
canClearFields
protected abstract boolean canClearFields()
Returns whether the fields can be cleared, i.e., if there is any input.- Returns:
- true if input can be cleared
-
isReadOnly
protected abstract boolean isReadOnly()
Returns whether modified data cannot be stored.- Returns:
- true if storing is not available
-
canRemoveObjects
protected boolean canRemoveObjects()
Returns whether objects can be deleted. Default implementation returns inverse ofisReadOnly().- Returns:
- true if delete supported
-
canAddObject
protected abstract boolean canAddObject()
Returns whether all the required fields are set to add the object.- Returns:
- true if required fields are filled in
-
update
protected void update()
Updates the enabled state of the widgets.
-
updateButtons
protected void updateButtons()
Updates the enabled state of the widgets.
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUpin interfaceCleanUpHandler
-
-