Class FindWindow

java.lang.Object
org.zkoss.zk.ui.AbstractComponent
org.zkoss.zk.ui.HtmlBasedComponent
org.zkoss.zul.impl.XulElement
org.zkoss.zul.Window
org.adempiere.webui.component.Window
org.adempiere.webui.window.FindWindow
All Implemented Interfaces:
Serializable, Cloneable, DialogEvents, ValueChangeListener, ISupportMask, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event>, org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.IdSpace, org.zkoss.zk.ui.sys.ComponentCtrl, org.zkoss.zul.ext.Framable

public class FindWindow extends Window implements org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event>, ValueChangeListener, DialogEvents
Find/Search Records dialog.
Author:
Sendy Yagambrum
See Also:
  • Field Details

    • serialVersionUID

      protected static final long serialVersionUID
      generated serial id
      See Also:
    • FIND_ROW_EDITOR

      protected static final String FIND_ROW_EDITOR
      See Also:
    • FIND_ROW_EDITOR_TO

      protected static final String FIND_ROW_EDITOR_TO
      See Also:
    • HISTORY_DAY_ALL

      protected static final String HISTORY_DAY_ALL
      See Also:
    • HISTORY_DAY_YEAR

      protected static final String HISTORY_DAY_YEAR
      See Also:
    • HISTORY_DAY_MONTH

      protected static final String HISTORY_DAY_MONTH
      See Also:
    • HISTORY_DAY_WEEK

      protected static final String HISTORY_DAY_WEEK
      See Also:
    • HISTORY_DAY_DAY

      protected static final String HISTORY_DAY_DAY
      See Also:
    • historyItems

      protected ValueNamePair[] historyItems
    • HISTORY_LABEL

      protected static final String HISTORY_LABEL
      See Also:
    • winMain

      protected MultiTabPart winMain
      Tabbox for window. Center of find window.
    • winLookupRecord

      protected Window winLookupRecord
      Simple search Tab
    • winAdvanced

      protected Window winAdvanced
      Advanced search Tab
    • fQueryName

      protected Combobox fQueryName
      Drop down for user query names
    • advancedPanel

      protected Listbox advancedPanel
      Center of winAdvanced. List of search criterias.
    • contentSimple

      protected Grid contentSimple
      Center of winLookupRecord. Grid layout of search fields.
    • m_targetWindowNo

      protected int m_targetWindowNo
      Target Window No
    • m_targetTabNo

      protected int m_targetTabNo
      Target Tab No
    • m_AD_Table_ID

      protected int m_AD_Table_ID
      Table ID
    • m_tableName

      protected String m_tableName
      Table Name
    • m_whereExtended

      protected String m_whereExtended
      Where
    • m_findFields

      protected GridField[] m_findFields
      Search fields of calling tab (m_AD_Tab_ID)
    • m_gridTab

      protected GridTab m_gridTab
      Grid tab for current row of advancedPanel
    • m_query

      protected MQuery m_query
      Resulting query
    • m_isCancel

      protected boolean m_isCancel
      Is cancel ?
    • log

      protected static final CLogger log
      Logger
    • m_total

      protected int m_total
      Number of records
    • initialSlowQuery

      protected boolean initialSlowQuery
      Set to true if query timeout to get record count
    • m_tabs

      protected MTab[] m_tabs
      target tab (m_AD_Tab_ID) and its child tabs
    • m_sEditors

      protected ArrayList<WEditor> m_sEditors
      List of WEditors for simple search tab
    • m_sEditorsFlag

      protected ArrayList<ToolBarButton> m_sEditorsFlag
      List of button to toggle visibility of to editor. For date and numeric field in simple search tab.
    • m_sEditorsTo

      protected ArrayList<WEditor> m_sEditorsTo
      List of to editor. For date and numeric field in simple search tab.
    • TABNO

      public static final int TABNO
      Tab number for lookup and context
      See Also:
    • FIELDLENGTH

      public static final int FIELDLENGTH
      Max display length of Fields on simple search tab
      See Also:
    • m_AD_Tab_ID

      protected int m_AD_Tab_ID
      AD_Tab_ID of calling tab
    • m_AD_Tab_UU

      protected String m_AD_Tab_UU
      AD_Tab_UU of calling tab
    • userQueries

      protected MUserQuery[] userQueries
      User queries for target tab (m_AD_Tab_ID)
    • contentSimpleRows

      protected Rows contentSimpleRows
    • m_createNew

      protected boolean m_createNew
      true if user click the new record button at simple search tab
    • isvalid

      protected boolean isvalid
    • m_minRecords

      protected int m_minRecords
    • m_title

      protected String m_title
    • btnSave

      protected ToolBarButton btnSave
      Button to save current user query
    • btnShare

      protected ToolBarButton btnShare
      Button to share current user query
    • msgLabel

      protected Label msgLabel
      Message for user query operations
    • INDEX_COLUMNNAME

      public static final int INDEX_COLUMNNAME
      Index ColumnName = 0
      See Also:
    • INDEX_OPERATOR

      public static final int INDEX_OPERATOR
      Index Operator = 1
      See Also:
    • INDEX_VALUE

      public static final int INDEX_VALUE
      Index Value = 2
      See Also:
    • INDEX_VALUE2

      public static final int INDEX_VALUE2
      Index Value2 = 3
      See Also:
    • INDEX_ANDOR

      public static final int INDEX_ANDOR
      Index AndOr = 4
      See Also:
    • INDEX_LEFTBRACKET

      public static final int INDEX_LEFTBRACKET
      Index LeftBracket = 5
      See Also:
    • INDEX_RIGHTBRACKET

      public static final int INDEX_RIGHTBRACKET
      Index RightBracket = 6
      See Also:
    • INDEX_HISTORY

      public static final int INDEX_HISTORY
      Index History
      See Also:
    • INDEX_TABLE

      public static final int INDEX_TABLE
      Index Table
      See Also:
    • m_sNew

      protected String m_sNew
      Search messages using translation
    • FIELD_SEPARATOR

      protected static final String FIELD_SEPARATOR
      See Also:
    • SEGMENT_SEPARATOR

      protected static final String SEGMENT_SEPARATOR
      See Also:
    • HISTORY_SEPARATOR

      protected static final String HISTORY_SEPARATOR
      See Also:
    • historyCombo

      protected Combobox historyCombo
      List of history scope options (all, year, month, etc)
    • m_simpleCtx

      protected Properties m_simpleCtx
      Context for simple search tab
    • m_advanceCtx

      protected Properties m_advanceCtx
      Context for advance search tab
    • rowCount

      protected int rowCount
      Row count of advancedPanel
    • ON_POST_VISIBLE_ATTR

      protected static final String ON_POST_VISIBLE_ATTR
      See Also:
    • COUNTING_RECORDS_TIMED_OUT

      protected static final int COUNTING_RECORDS_TIMED_OUT
      m_total is set to this constant if get record count hit query timeout exception
      See Also:
    • statusBar

      protected StatusBarPanel statusBar
      Status bar. Bottom of find window
    • m_whereUserQuery

      protected String m_whereUserQuery
      IDEMPIERE-2836 User Query Where
    • advancedPanelToolBar

      protected ToolBar advancedPanelToolBar
      Toolbar for advance search tab. North of winAdvanced.
    • m_AD_UserQuery_ID

      protected int m_AD_UserQuery_ID
      IDEMPIERE-4085
    • m_windowPanel

      protected AbstractADWindowContent m_windowPanel
      ADWindow Content part that own this find window instance
    • COLUMNNAME_M_AttributeSetInstance_ID

      protected static final String COLUMNNAME_M_AttributeSetInstance_ID
      Column name attribute set instance
      See Also:
    • isUseEscForTabClosing

      protected boolean isUseEscForTabClosing
  • Constructor Details

    • FindWindow

      public FindWindow(int targetWindowNo, int targetTabNo, String title, int AD_Table_ID, String tableName, String whereExtended, GridField[] findFields, int minRecords, int adTabId)
      FindWindow Constructor
      Parameters:
      targetWindowNo - targetWindowNo
      targetTabNo -
      title - title
      AD_Table_ID - AD_Table_ID
      tableName - tableName
      whereExtended - whereExtended
      findFields - findFields
      minRecords - minRecords
      adTabId -
    • FindWindow

      public FindWindow(int targetWindowNo, int targetTabNo, String title, int AD_Table_ID, String tableName, String whereExtended, GridField[] findFields, int minRecords, int adTabId, AbstractADWindowContent windowPanel)
      FindWindow Constructor
      Parameters:
      targetWindowNo - targetWindowNo
      targetTabNo -
      title - title
      AD_Table_ID - AD_Table_ID
      tableName - tableName
      whereExtended - whereExtended
      findFields - findFields
      minRecords - minRecords
      adTabId -
      windowPanel - AbstractADWindowContent
  • Method Details

    • initialize

      public boolean initialize()
      Initialize find window
      Returns:
      true if init ok
    • validate

      public boolean validate(int targetWindowNo, String title, int AD_Table_ID, String tableName, String whereExtended, GridField[] findFields, int minRecords, int adTabId)
      Parameters:
      targetWindowNo -
      title -
      AD_Table_ID -
      tableName -
      whereExtended -
      findFields -
      minRecords -
      adTabId -
      Returns:
      false if this find window instance doesn't match one of the input parameters
    • initSimple

      protected void initSimple()
      Layout simple search tab (winLookupRecord).
    • initAdvanced

      protected void initAdvanced()
      Layout advance search tab (winAdvanced).
    • initPanel

      protected void initPanel()
      Layout window
    • prepareHistoryCombo

      protected void prepareHistoryCombo()
      Prepare combo of history scope options
    • initFind

      protected void initFind()
      Initialize simple search tab
    • hasAccessSpecialFields

      protected boolean hasAccessSpecialFields(GridField field)
      Parameters:
      field -
      Returns:
      true if log in role has access to window for special field (account combination, resource, chat, image, location, locator and attribute set instance)
    • initFindAdvanced

      protected void initFindAdvanced()
      Initialise advance search tab
    • createFields

      protected void createFields()
      add new row to advancedPanel
    • createFields

      protected void createFields(String[] fields, int row)
      add new row(ListItem) to advancedPanel
      Parameters:
      fields -
      row - current last row index
    • createDateRangeWrapper

      protected org.zkoss.zul.Div createDateRangeWrapper(WEditor editorFrom, WEditor editorTo)
      Parameters:
      editorFrom -
      editorTo -
      Returns:
      Div wrapper with DateRangeButton
    • setValues

      protected void setValues(GridField[] findFields, Combobox listTable, Combobox listColumn, Combobox listOperator, String[] fields)
      Populate listTable, listColumn and listOperator values for advancedPanel row.
      Parameters:
      findFields -
      listTable - tables combo box
      listColumn - columns combo box
      listOperator - operators combo box
      fields - values for advancedPanel column
    • updateColumnListModel

      protected void updateColumnListModel(Combobox listColumn, ValueNamePair[] cols)
      Create list model from cols for listColumn
      Parameters:
      listColumn -
      cols - columns
    • isFilterColumnList

      protected boolean isFilterColumnList()
      Returns:
      true if columns combo in advance search should filter by user enter text
    • addSelectionColumn

      public boolean addSelectionColumn(GridField mField)
      Create editor for mField and add to simple search tab
      Parameters:
      mField - field
      Returns:
      true if editor created and added
    • addSelectionColumn

      public boolean addSelectionColumn(GridField mField, Group group)
      Create editor for mField and add to simple search tab
      Parameters:
      mField - field
      group -
      Returns:
      true if editor created and added
    • setLengthStringField

      protected void setLengthStringField(GridField field, org.zkoss.zk.ui.Component fieldEditor)
    • onEvent

      public void onEvent(org.zkoss.zk.ui.event.Event event) throws Exception
      Specified by:
      onEvent in interface org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event>
      Throws:
      Exception
    • onCancel

      protected void onCancel()
      user cancellation, close dialog
    • onSelectedQueryChanged

      public void onSelectedQueryChanged()
      On selection of user query
    • onSimpleTabSelected

      protected void onSimpleTabSelected()
      On switch to simple search tab
    • onAdvanceTabSelected

      protected void onAdvanceTabSelected()
      On switch to advance search tab
    • focusToLastAdvanceRow

      protected void focusToLastAdvanceRow()
      Set focus to last row of advancedPanel
    • parseUserQuery

      protected void parseUserQuery(MUserQuery userQuery)
      Parse user query
      Parameters:
      userQuery -
    • getHistoryIndex

      protected int getHistoryIndex(String value)
    • parseString

      protected WEditor parseString(GridField field, String in, ListItem listItem, boolean to)
      Create editor and set value to in (for advancedPanel row).
      Parameters:
      field - column
      in - value
      listItem - row of advancedPanel
      to -
      Returns:
      WEditor
    • cmd_saveAdvanced

      protected void cmd_saveAdvanced(boolean saveQuery, boolean shareAllUsers)
      Create advance search query
      Parameters:
      saveQuery - true to save as user query
      shareAllUsers -
    • getLeftBracketValue

      protected String getLeftBracketValue(ListItem row)
      Returns the value selected for the left bracket list item in the current row
      Parameters:
      row -
      Returns:
      empty, (, (( or (((
    • getRightBracketValue

      protected String getRightBracketValue(ListItem row)
      Returns the value selected for the right bracket list item in the current row
      Parameters:
      row -
      Returns:
      empty, ), )) or )))
    • appendCode

      protected void appendCode(StringBuilder code, String columnName, String operator, String value1, String value2, String andOr, String lBrackets, String rBrackets, String tableUID)
      Append values to code
      Parameters:
      code -
      columnName -
      operator -
      value1 -
      value2 -
      andOr -
      lBrackets -
      rBrackets -
      tableUID -
    • saveQuery

      protected void saveQuery(boolean saveQuery, StringBuilder code, boolean shareAllUsers)
      Parameters:
      saveQuery - false to save code as user query, false to do nothing
      code -
      shareAllUsers -
    • cmd_saveSimple

      protected void cmd_saveSimple(boolean saveQuery, boolean shareAllUsers)
      Create simple search query
      Parameters:
      saveQuery - true to save as user query
      shareAllUsers -
    • refreshUserQueries

      protected void refreshUserQueries()
      reload user queries
    • getColumnName

      protected String getColumnName(ListItem row)
      retrieve the columnName of the Column item selected
      Parameters:
      row -
      Returns:
      column name
    • addRowEditor

      protected void addRowEditor(org.zkoss.zk.ui.Component component, ListCell listcell)
      add component to listcell
      Parameters:
      component - editor component
      listcell -
    • addOperators

      protected void addOperators(org.zkoss.zul.Comboitem column, Combobox listOperator)
      Retrieve operators depending on the item selected in the 'Column' field and add them to the selection
      Parameters:
      column - Column field selected
      listOperator -
    • addOperators

      protected void addOperators(ValueNamePair[] op, Combobox listOperator)
      add op to listOperator
      Parameters:
      op - array of operators
      listOperator -
    • getEditor

      public WEditor getEditor(ListItem row, boolean to)
      Create editor for advancedPanel row
      Parameters:
      row - row
      to -
      Returns:
      WEditor
    • getEditorComponent

      public org.zkoss.zk.ui.Component getEditorComponent(ListItem row, boolean to)
      Get editor component for advancedPanel row
      Parameters:
      row - row
      to -
      Returns:
      Editor component
    • getTargetMField

      public GridField getTargetMField(String columnName)
      Find grid field from column name
      Parameters:
      columnName - column name
      Returns:
      GridField
    • cmd_ok_Simple

      protected void cmd_ok_Simple()
      Simple OK Button pressed
    • getHistoryDays

      protected int getHistoryDays(String selectedItem)
      Get days from selected values of history combo
      Parameters:
      selectedItem -
      Returns:
      number of days
    • addHistoryRestriction

      protected void addHistoryRestriction(org.zkoss.zul.Comboitem selectedHistoryItem)
      Adding where clause from history data
      Parameters:
      selectedHistoryItem -
    • dispose

      public void dispose()
      hide window and fire DialogEvents.ON_WINDOW_CLOSE event
      Overrides:
      dispose in class Window
    • cmd_ok_Advanced

      protected void cmd_ok_Advanced()
      Advanced OK Button pressed
    • advancedOkClick

      public void advancedOkClick()
      Simulate the user query selection and click ok
    • getNoOfRecords

      protected int getNoOfRecords(MQuery query, boolean alertRecords)
      Get the number of records of query
      Parameters:
      query - where clause for target tab
      alertRecords - show dialog if there are no records or there are more records than allowed for role/tab
      Returns:
      record count; if the results are more then allowed this method will return 0
    • isProductCategoryField

      protected boolean isProductCategoryField(String columnName)
      Checks the given column.
      Parameters:
      columnName -
      Returns:
      true if the column is a product category column
    • getSubCategoryWhereClause

      protected String getSubCategoryWhereClause(GridField field, int productCategoryId)
      Returns a sql where clause with the given category id and all of its subcategory ids. It is used as restriction in MQuery.
      Parameters:
      field -
      productCategoryId -
      Returns:
      sql where clause
    • getSubCategoriesString

      protected String getSubCategoriesString(int productCategoryId, Vector<FindWindow.SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError
      Recursive search for subcategories with loop detection.
      Parameters:
      productCategoryId -
      categories -
      loopIndicatorId -
      Returns:
      comma separated list of category ids
      Throws:
      AdempiereSystemError - if a loop is detected
    • parseValue

      protected Object parseValue(GridField field, Object in)
      Parse and convert type (if needed)
      Parameters:
      field - GridField
      in - input value
      Returns:
      in converted to appropriate type for field
    • getQuery

      public MQuery getQuery()
      Get Query - Retrieve result
      Returns:
      String representation of query
    • getTotalRecords

      public int getTotalRecords()
      Get Total Records
      Returns:
      no of records
    • valueChange

      public void valueChange(ValueChangeEvent evt)
      Description copied from interface: ValueChangeListener
      On value change event
      Specified by:
      valueChange in interface ValueChangeListener
    • dynamicDisplay

      protected void dynamicDisplay(WEditor editor, ListCell listcell)
      Dynamic display of editor
      Parameters:
      editor -
      listcell -
    • OnPostVisible

      public void OnPostVisible()
      Post visible event. Echo from setVisible(boolean).
    • isCancel

      public boolean isCancel()
      Returns:
      true if dialog cancel by user, false otherwise
    • isCreateNew

      public boolean isCreateNew()
      Returns:
      true if user press the new button
    • setVisible

      public boolean setVisible(boolean visible)
      Specified by:
      setVisible in interface org.zkoss.zk.ui.Component
      Overrides:
      setVisible in class org.zkoss.zul.Window
    • isSearchLike

      protected boolean isSearchLike(GridField field)
      Parameters:
      field -
      Returns:
      true to use Like, false otherwise
    • isValid

      public boolean isValid()
      Returns:
      true if dialog is visible and not cancel
    • setStatusDB

      protected void setStatusDB(int currentCount)
      Display current count
      Parameters:
      currentCount - String representation of current/total
    • hideAdvanced

      protected void hideAdvanced()
      Hide advance search
    • showAdvanced

      protected void showAdvanced()
      Show advance search
    • getAD_UserQuery_ID

      public int getAD_UserQuery_ID()
      Returns:
      AD_UserQuery_ID of selected user query (fQueryName)
    • setAD_UserQuery_ID

      public void setAD_UserQuery_ID(int AD_UserQuery_ID)
      Set selected user query to AD_UserQuery_ID
      Parameters:
      AD_UserQuery_ID -
    • getAttributeSQL

      protected String getAttributeSQL(Integer M_Attribute_ID)
      Parameters:
      M_Attribute_ID -
      Returns:
      sql clause for attribute value
    • parseAttributeString

      protected org.zkoss.zk.ui.Component parseAttributeString(int M_Attribute_ID, String value, ListItem listItem, boolean isValueTo)
      Create editor and set editor value to pass in value parameter
      Parameters:
      M_Attribute_ID -
      value - value
      listItem -
      isValueTo -
      Returns:
      Component of created editor
    • setAttributes

      protected void setAttributes(Combobox listColumn, Combobox listOperator, String[] fields)
      Populate listColumn and listOperator
      Parameters:
      listColumn -
      listOperator -
      fields - value for advancedPanel columns
    • addOperatorsAttribute

      protected void addOperatorsAttribute(org.zkoss.zul.Comboitem column, Combobox listOperator)
      add operators to listOperator depends on the type of attribute
      Parameters:
      column -
      listOperator -
    • getAttributeValuesListComponent

      public org.zkoss.zk.ui.Component getAttributeValuesListComponent(ListItem row, boolean isValueTo) throws Exception
      Create editor for attribute value
      Parameters:
      row -
      isValueTo -
      Returns:
      Component of created editor
      Throws:
      Exception
    • parseAttributeValue

      protected Object parseAttributeValue(int M_Attribute_ID, Object value)
      Convert value to type appropriate for M_Attribute_ID (if needed)
      Parameters:
      M_Attribute_ID -
      value -
      Returns:
      converted value to desire type
    • initTabs

      protected void initTabs()
      Get target tab (m_AD_Tab_ID) and its child tabs into m_tabs
    • isAttributeTable

      protected boolean isAttributeTable()
      Returns:
      true if target tab/table contains column M_AttributeSetInstance_ID