com.ca.directory.jxplorer.search
Class BuildFilterPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--com.ca.commons.cbutil.CBPanel
                                |
                                +--com.ca.directory.jxplorer.search.BuildFilterPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class BuildFilterPanel
extends CBPanel

Creates a scrollable panel that can add and remove rows that are used to build raw filters. Each row consists of an attribute combo box ('sn'), a function combo box ('Equal To'), and text field that the user can enter the filter value. If there are more than one row, an And/Or combo is added to the second row and and And/Or labels to all rows there after. The And/Or labels always show the value of the And/Or combo box.

This idea behind this class is that a user can build simple raw filters (e.g. (&(cn=f*)(sn=f*)) with only one function ('|' or '&').

This panel is controlled by the SearchGUI class. I.e. the SearchGUI class tells this class to add or remove a row or to edit or load a certain filter. It also feeds back to the SearchGUI the values of it's components when required.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class com.ca.commons.cbutil.CBPanel
c, xpos, ypos
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
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
BuildFilterPanel(JXplorer jx)
          Constructor that sets up the Build tab with a not check box, and the first row e.g an attribute combo, a function combo and a text field.
 
Method Summary
protected  void addFilterRow()
          Addes a row or line to the Join tab.
protected  void checkForSpecialEditor(java.lang.String attrName, javax.swing.JTextField field)
          Takes an attribute name and checks its syntax against that of the GeneralizedTime syntax (~121.1.24).
protected  boolean displayFilter(java.lang.String filter)
          Attempts to display a filter usually after someone has selected to load a filter via the load dialog or via the edit button in the search dialog.
protected  java.lang.String getAttributeComboValue(java.lang.String filter)
          Returns the attribute value that is being search for.
protected  java.lang.String[] getAttributes()
          Gets a list of attributes that are available in the schema which can be used for searching.
protected  java.lang.String getFilter()
          Constructs the filter by adding filter parts to a string buffer for each row in the filter constructor.
protected  java.lang.String getFilterFieldText(java.lang.String filter)
          Returns the value that is being search for.
protected  java.lang.String getFunctionPart(int i)
          Constructs the body ('(cn=w*)') of the filter by reading the attribute type selected (i.e.
protected  int getFunctionPosition(java.lang.String filter)
          Determines what the function of the filter is for example if it is a ~= or (!)
protected  int getOccurrences(java.lang.String string, java.lang.String substring)
          Counts the number of times a substring occurs within a string.
protected  boolean isFilterValid()
          Checks if the filter is valid.
protected  void removeFilterRow()
          Removes lines (rows) from the filter constructor.
protected  java.lang.String replace(java.lang.String string, java.lang.String oldString, java.lang.String newString)
          Takes a string and replaces any occurances of a given string with another given string.
protected  java.lang.String trimFilter(java.lang.String filter)
          Trims a string by two places at the beginning of the string and one place at the end of the string.
 
Methods inherited from class com.ca.commons.cbutil.CBPanel
add, add, add, addGreedyWide, addGreedyWide, addLine, addLines, addln, addWide, makeHeavy, makeHigh, makeLight, makeWide, newLine, toString
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BuildFilterPanel

public BuildFilterPanel(JXplorer jx)
Constructor that sets up the Build tab with a not check box, and the first row e.g an attribute combo, a function combo and a text field.

Parameters:
jx - JXplorer, used to get the search broker.
Method Detail

displayFilter

protected boolean displayFilter(java.lang.String filter)
Attempts to display a filter usually after someone has selected to load a filter via the load dialog or via the edit button in the search dialog. This method needs to set values for the andOr combo and labels, the not check box, the attribute combos and the function combos.

Parameters:
filter - the actual raw filter to be displayed e.g. '(!(|(!(sn=r*))(sn=e*)))'.
Returns:
true if the display was successful, false otherwise.

getAttributeComboValue

protected java.lang.String getAttributeComboValue(java.lang.String filter)
Returns the attribute value that is being search for. For example, 'cn' in this filter: '(cn=Bob)'. The way it does this is by removing the brackets (and '!' if present) from the beginning of the filter then cutting anything off the filter after any one of the following operators: '>=', '<=', '~=' or '='.

Parameters:
filter - the search filter that the value (or text) is to be extracted from (e.g '(cn=Bob)').
Returns:
the attribute value, for example 'cn'.

getFilterFieldText

protected java.lang.String getFilterFieldText(java.lang.String filter)
Returns the value that is being search for. For example, 'Bob' in this filter: '(cn=Bob)'. The way it does this is by checking the filter for one of the following operators: '=*' or '='. Then makes a substring from the end of the opeator to the end of the filter, for example, 'Bob)'. To remove the end bracket(s), a check is done to see if the filter was a 'not' filter ('(!(cn=Bob))'). If it was two brackets are removed, otherwise one. The final check is to see if the filter ends with a '*' i.e containing or begins with. If so it is removed also.

Parameters:
filter - the search filter that the value (or text) is to be extracted from (e.g '(cn=Bob)').
Returns:
the value, for example 'Bob'.

getFunctionPosition

protected int getFunctionPosition(java.lang.String filter)
Determines what the function of the filter is for example if it is a ~= or (!)~=. Returns the position or location in the function Combo of this function. For example (!)~= is at position 15.

Parameters:
filter - the filter that we are to determine the function of.
Returns:
the position of this function in the functionCombo.

getOccurrences

protected int getOccurrences(java.lang.String string,
                             java.lang.String substring)
Counts the number of times a substring occurs within a string.

Parameters:
string - the string that is getting checked for the occurence of a substring.
substring - the substring that is being checked for.
Returns:
the number of times the substring occurs within the string.

trimFilter

protected java.lang.String trimFilter(java.lang.String filter)
Trims a string by two places at the beginning of the string and one place at the end of the string. Usually used to trim the operator from a filter eg (&(cn=f*)(sn=f*)) => (cn=f*)(sn=f*).

Parameters:
filter - the string (e.g. (&(cn=f*)(sn=f*))) to trim.
Returns:
the trimmed string (e.g. (cn=f*)(sn=f*))

addFilterRow

protected void addFilterRow()
Addes a row or line to the Join tab. A line consists of an attribute combo, a function combo and text field. If the second row is added, an And/Or combo is added, if there are any more rows that are added after the second an And/Or label is added with the value of the And/Or combo. If the And/Or combo is changed by the user the And/Or labels are updated to reflect the change via a listener on the And/Or combo. The components in a row are added according to row number for example if the second row is being added, an attriubte combo is created and stored in the attribute combo array at that row position.


checkForSpecialEditor

protected void checkForSpecialEditor(java.lang.String attrName,
                                     javax.swing.JTextField field)
Takes an attribute name and checks its syntax against that of the GeneralizedTime syntax (~121.1.24). If they are the same the GeneralizedTime editor is opened & the Search dialog is forced to wait until the user has finished entering date and time info. This can be expanded to check for other editors - currently it just checks for one.

Parameters:
attrName - the attribute name - usually from the combo box in the Search dialog (Build tab).
field - the text field where the text will be set after the time dialog is closed.

removeFilterRow

protected void removeFilterRow()
Removes lines (rows) from the filter constructor. Starting from the last added.


getAttributes

protected java.lang.String[] getAttributes()
Gets a list of attributes that are available in the schema which can be used for searching. These are used in the attributeCombo part of the filter.

Returns:
a string array of the available attributes to JX (null - if no schema publishing i.e. LDAP V2).

isFilterValid

protected boolean isFilterValid()
Checks if the filter is valid. A filter is not valid if any attribute or function combo contains an empty string or a null. returns true if all combo contain a value, false otherwise.


getFilter

protected java.lang.String getFilter()
Constructs the filter by adding filter parts to a string buffer for each row in the filter constructor.

Returns:
the filter.

getFunctionPart

protected java.lang.String getFunctionPart(int i)
Constructs the body ('(cn=w*)') of the filter by reading the attribute type selected (i.e. 'cn'), the function (i.e. 'Beginning With') and reading the actual filter (i.e. 'w') for a given row number.

Parameters:
i - the row number that is being processed.
Returns:
returns the function string which is then appended to a global string buffer that is used in the search.

replace

protected java.lang.String replace(java.lang.String string,
                                   java.lang.String oldString,
                                   java.lang.String newString)
Takes a string and replaces any occurances of a given string with another given string.

Parameters:
string - the string that contains the text to be replaced.
oldString - the text to be replaced.
newString - the text to take the place of the old text.
Returns:
the string with the new text in place.