com.billpringle.utils
Class WrpEditValidationRules

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by com.billpringle.utils.WrpEditValidationRules
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.ComponentListener, java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class WrpEditValidationRules
extends javax.swing.JFrame
implements java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.ComponentListener

This class allows a user edit validation rules that are stored in a database.

In addition to editing the rules, the user can also compile them, and even execute them to validate a specified CSV line or all of the lines within a specified CSV file.

Author:
pringlb
See Also:
Serialized Form

Nested Class Summary
private  class WrpEditValidationRules.RuleModel
          Internal class that is the model for the rules table
 
Nested classes/interfaces inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
(package private)  javax.swing.JButton btnCompile
          button to compile the validation rules
(package private)  javax.swing.JButton btnCsv
          Button to specify a CSV string to parse
(package private)  javax.swing.JButton btnExecute
          Button to validate one or more CSV strings
(package private)  javax.swing.JButton btnFile
          Button to specify a CSV file to parse
(package private)  javax.swing.JButton btnGet
          button to load validation rules
(package private)  javax.swing.JButton btnPrint
          button to print validation rules
(package private)  javax.swing.JButton btnQuit
          button to terminate the program
(package private)  javax.swing.JButton btnRenum
          button to renumber statements
(package private)  javax.swing.JButton btnSave
          button to save validation rules
protected  int[] colWidth
          The width of the rules columns that was set by the user.
protected  int compileErrors
          number of compile errors (-1 means no compile)
protected  WrpCsv csv
          The CSV string that can be validated.
protected  java.io.File csvFile
          The file containing CSV records that can be validated.
protected  int csvLine
          the unique line number for this record
protected  WrpDb db
          the connection to the database
protected  int execErrors
          number of run-time errors (-1 means no execution)
(package private)  javax.swing.JFileChooser fc
          a file chooser to select the CSV file
(package private)  javax.swing.JLabel lblTitle
          label for title at top of page
protected  java.util.Vector<java.lang.Boolean> modified
          vector indicating what rules have been modified
(package private)  javax.swing.JPanel pnlScroll
          scroll panel for the validation rules
(package private)  javax.swing.JPanel pnlTop
          panel at top of page
(package private)  javax.swing.JPanel pnlTopPage
          wrapper panel to prevent top of page resizing
(package private)  javax.swing.JPopupMenu popup
          pop up menu
protected  int rulesRead
          The number of rules read from the database
(package private)  javax.swing.JScrollPane scroll
          scroll pane for the validation rules
(package private) static long serialVersionUID
          unique serializing identifier
(package private)  javax.swing.JTable tblRules
          table of validation rules
(package private)  java.awt.Dimension topSize
          size of the top portion of the page
(package private)  javax.swing.JTextField txtHighSeq
          optional upper sequence number to load a subset of the validation rules
(package private)  javax.swing.JTextField txtLowSeq
          optional lower sequence number to load a subset of the validation rules
(package private)  javax.swing.JTextField txtTable
          optional field to indicate stored procedure
protected  WrpValidateCsv Val
          CSV validation object
protected  java.util.Vector<WrpValidateCsv.ValidationRule> validations
          vector of validation rules
protected  java.lang.String ValTbl
          the database table name containing validation rules
protected  WrpZipCode zipCodes
          list of valid zip code combinations
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
WrpEditValidationRules(WrpDb db)
          Default (and only) constructor
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void buildHtmlFooter(java.io.PrintStream prt)
          Create the bottom part of the HTML rules file.
 void buildHtmlHeader(java.io.PrintStream prt)
          Build the beginning of an HTML file for printing rules.
 void buildMenu()
          Creates the main menu (e.g., File)
 void buildPage()
          Creates the actual page content
 void compileRules()
          Compile current set of rules, and display results.
 void componentHidden(java.awt.event.ComponentEvent e)
           
 void componentMoved(java.awt.event.ComponentEvent e)
           
 void componentResized(java.awt.event.ComponentEvent e)
           
 void componentShown(java.awt.event.ComponentEvent e)
           
 void deleteRule(WrpValidateCsv.ValidationRule v)
          Delete the specified validation rule from the database
 void executeRules()
          Execute the rules using the specified CSV string or file.
 java.util.Vector<WrpValidateCsv.ValidationRule> getRules()
          Get the current collection of validation rules
 java.lang.String getValidationTable()
          Get the name of the table containing the validation rules
 void ifPopup(java.awt.event.MouseEvent e)
           
 void insertRule(WrpValidateCsv.ValidationRule v)
          Insert a new rule into the database
 void loadCsv(int CsvLine)
          Select a CSV file to load for validation.
 void loadRules()
          Retrieve the rules for the current field from the database
static void main(java.lang.String[] args)
          This is a sample driver for this program.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 java.lang.String nbsp(java.lang.String str)
          Substitute empty strings with &nbsp; This method is used when filling data cells within a column.
 void printHtmlRule(WrpValidateCsv.ValidationRule v, java.io.PrintStream prt)
          Format a rule for insertion into the HTML table.
 void printRules()
          Allow the user to print the current rules.
 void renumberStatements()
          Renumber the statements.
private  void renumberStatements(int incr)
          Renumber statements using the specified increment.
 void resizeScroll()
          Resize the window components
 boolean saveChanges()
          If changes were not saved, ask user if they should be changed
 void saveRules()
          Save any new or changed rules
 void selectOpenFile()
          Select the CSV file to be validated.
protected  java.io.File selectSaveFile()
           
 void setRules(java.util.Vector<WrpValidateCsv.ValidationRule> rules)
          Define the current collection of validation rules
 void setValidationTable(java.lang.String valtbl)
          Update the name of the database table containing validation rules
 void updateRule(WrpValidateCsv.ValidationRule v)
          Update the specified validation rules
 void updateTable()
          Save any changes to the current rules to the database.
 void validateFile(java.io.File f)
          Validate a CSV file
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

serialVersionUID

static final long serialVersionUID
unique serializing identifier

See Also:
Constant Field Values

db

protected WrpDb db
the connection to the database


csvLine

protected int csvLine
the unique line number for this record


csv

protected WrpCsv csv
The CSV string that can be validated.

When the "Execute" button is clicked, this string will be validated, provided the user hasn't specified a CSV file to validate.


csvFile

protected java.io.File csvFile
The file containing CSV records that can be validated.

If the user has specified a CSV file, it will be validated when the user clicks on the "Execute" button.


ValTbl

protected java.lang.String ValTbl
the database table name containing validation rules


Val

protected WrpValidateCsv Val
CSV validation object


validations

protected java.util.Vector<WrpValidateCsv.ValidationRule> validations
vector of validation rules


modified

protected java.util.Vector<java.lang.Boolean> modified
vector indicating what rules have been modified


rulesRead

protected int rulesRead
The number of rules read from the database


colWidth

protected int[] colWidth
The width of the rules columns that was set by the user.

When rules are reloaded, these column widths will be retained.


compileErrors

protected int compileErrors
number of compile errors (-1 means no compile)


execErrors

protected int execErrors
number of run-time errors (-1 means no execution)


zipCodes

protected WrpZipCode zipCodes
list of valid zip code combinations


popup

javax.swing.JPopupMenu popup
pop up menu


pnlTop

javax.swing.JPanel pnlTop
panel at top of page


pnlTopPage

javax.swing.JPanel pnlTopPage
wrapper panel to prevent top of page resizing


lblTitle

javax.swing.JLabel lblTitle
label for title at top of page


tblRules

javax.swing.JTable tblRules
table of validation rules


txtLowSeq

javax.swing.JTextField txtLowSeq
optional lower sequence number to load a subset of the validation rules


txtHighSeq

javax.swing.JTextField txtHighSeq
optional upper sequence number to load a subset of the validation rules


txtTable

javax.swing.JTextField txtTable
optional field to indicate stored procedure


btnGet

javax.swing.JButton btnGet
button to load validation rules


btnSave

javax.swing.JButton btnSave
button to save validation rules


btnCompile

javax.swing.JButton btnCompile
button to compile the validation rules


btnPrint

javax.swing.JButton btnPrint
button to print validation rules


btnCsv

javax.swing.JButton btnCsv
Button to specify a CSV string to parse


btnFile

javax.swing.JButton btnFile
Button to specify a CSV file to parse


btnExecute

javax.swing.JButton btnExecute
Button to validate one or more CSV strings

If the user has specified a CSV file, then all the lines in that file are validated using the current set of validation rules. If no CSV file is specified, then the specified CSV string is validated instead.


btnRenum

javax.swing.JButton btnRenum
button to renumber statements


btnQuit

javax.swing.JButton btnQuit
button to terminate the program


pnlScroll

javax.swing.JPanel pnlScroll
scroll panel for the validation rules


scroll

javax.swing.JScrollPane scroll
scroll pane for the validation rules


topSize

java.awt.Dimension topSize
size of the top portion of the page


fc

javax.swing.JFileChooser fc
a file chooser to select the CSV file

Constructor Detail

WrpEditValidationRules

public WrpEditValidationRules(WrpDb db)
Default (and only) constructor

Method Detail

buildMenu

public void buildMenu()
Creates the main menu (e.g., File)


buildPage

public void buildPage()
Creates the actual page content


updateTable

public void updateTable()
Save any changes to the current rules to the database.

This routine loops through the validation rules and updates any modified rule to the database. It will also insert any new validation rules that were added since the previous load. It will also preserve the width of the columns in the form


resizeScroll

public void resizeScroll()
Resize the window components

This method is called when the window is resized or the list changes


getValidationTable

public java.lang.String getValidationTable()
Get the name of the table containing the validation rules

Returns:
the name of the database table

setValidationTable

public void setValidationTable(java.lang.String valtbl)
Update the name of the database table containing validation rules

Parameters:
valtbl - the name of the database table

loadRules

public void loadRules()
Retrieve the rules for the current field from the database

This method calls resizeScroll() to resize the page if needed


getRules

public java.util.Vector<WrpValidateCsv.ValidationRule> getRules()
Get the current collection of validation rules

Returns:
list of validation rules

setRules

public void setRules(java.util.Vector<WrpValidateCsv.ValidationRule> rules)
Define the current collection of validation rules

Parameters:
rules - a vector of validation rules

saveChanges

public boolean saveChanges()
If changes were not saved, ask user if they should be changed

This routine is called each time the user requests a save. If any changes were made but not saved, the user is asked if the changes should be save using a Confirmation Dialog box. The possible user responses are:

Returns:
true if the Get request should be canceled; otherwise false.

saveRules

public void saveRules()
Save any new or changed rules


insertRule

public void insertRule(WrpValidateCsv.ValidationRule v)
                throws java.sql.SQLException
Insert a new rule into the database

Parameters:
v - the valiation rule to be inserted
Throws:
java.sql.SQLException

updateRule

public void updateRule(WrpValidateCsv.ValidationRule v)
                throws java.sql.SQLException
Update the specified validation rules

The unique row identifier (primary key) from the database is used to update this specific rule in the database.

Parameters:
v - the validation rule to be updated
Throws:
java.sql.SQLException

deleteRule

public void deleteRule(WrpValidateCsv.ValidationRule v)
                throws java.sql.SQLException
Delete the specified validation rule from the database

Parameters:
v - the validation rule to be deleted
Throws:
java.sql.SQLException

loadCsv

public void loadCsv(int CsvLine)
Select a CSV file to load for validation.

This method uses an input dialog box to obtain a CSV line which can be parsed and validated when the user clicks on the "Execute" button.


selectOpenFile

public void selectOpenFile()
Select the CSV file to be validated.

This method uses a file chooser to obtain a CSV line which can be parsed and validated when the user clicks on the "Execute" button.


selectSaveFile

protected java.io.File selectSaveFile()

renumberStatements

public void renumberStatements()
Renumber the statements.

This method is called if the user clicks on the "Renumber" button. It will ask the user for an increment, and then renumber all of the statements using that increment.


renumberStatements

private void renumberStatements(int incr)
Renumber statements using the specified increment.

Parameters:
incr - increment value for renumbering statements

compileRules

public void compileRules()
Compile current set of rules, and display results.

If any error messages were generated, display them as well.


executeRules

public void executeRules()
                  throws WrpValidateCsv.ValidationRuntimeException
Execute the rules using the specified CSV string or file.

If the rules haven't been compiled yet, or any compile-time errors were found, then nothing is done.

Assuming the rules were compiled without errors, then either the CSV string or the CSV file are validated. If a CSV has been specified, then it is validated; otherwise the specified CSV string is validated. If neither were specified, an error message is displayed.

If any run-time errors are found, report them using a wrpScrollFrame

Throws:
WrpValidateCsv.ValidationRuntimeException

validateFile

public void validateFile(java.io.File f)
Validate a CSV file

Read each line from the file and run the validation commands against each line.

Parameters:
f - the CSV file to be validated

printRules

public void printRules()
Allow the user to print the current rules. This method will create an HTML document containing the current rules formatted in an HTML table.


buildHtmlHeader

public void buildHtmlHeader(java.io.PrintStream prt)
Build the beginning of an HTML file for printing rules.

Parameters:
prt - the output stream for the HTML file

buildHtmlFooter

public void buildHtmlFooter(java.io.PrintStream prt)
Create the bottom part of the HTML rules file.

Parameters:
prt - the output stream for the HTML rules file

printHtmlRule

public void printHtmlRule(WrpValidateCsv.ValidationRule v,
                          java.io.PrintStream prt)
Format a rule for insertion into the HTML table.

Parameters:
v - the validation rule to be printed in a table
prt - the output stream for the HTML rules table

nbsp

public java.lang.String nbsp(java.lang.String str)
Substitute empty strings with &nbsp; This method is used when filling data cells within a column. If an empty string appears, then the table cell can look strange, but if it has a non-breaking space character, it looks just fine.

Parameters:
str - the string to test
Returns:
returns the string, or NBSP if null or an empty string

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

ifPopup

public void ifPopup(java.awt.event.MouseEvent e)

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Specified by:
componentResized in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Specified by:
componentShown in interface java.awt.event.ComponentListener

main

public static void main(java.lang.String[] args)
This is a sample driver for this program. It is expected that the user will create their own main program, using their own database rather than the example UtilDb.

Parameters:
args - not used