Search in sources :

Example 1 with DocumentSearch

use of de.schaeffer.compiere.tools.DocumentSearch in project adempiere by adempiere.

the class VTreePanel method keyPressed.

//	getDividerLocation
/**
	 *  Enter Key
	 *  @param e event
	 */
protected void keyPressed(KeyEvent e) {
    //CHANGED - document search
    if (e.getSource() == treeSearch && treeSearch.getText() != null && treeSearch.getText().length() > 0 && treeSearch.getText().substring(0, 1).equals(PREFIX_DOCUMENT_SEARCH)) {
        setBusy(true);
        DocumentSearch search = new DocumentSearch();
        if (search.openDocumentsByDocumentNo(treeSearch.getText().substring(1)))
            treeSearch.setText(null);
        setBusy(false);
        return;
    }
    //  *** Tree ***
    if (e.getSource() instanceof JTree || //	InputEvent.CTRL_MASK
    (e.getSource() == treeSearch && e.getModifiers() != 0)) {
        TreePath tp = tree.getSelectionPath();
        if (tp == null)
            ADialog.beep();
        else {
            MTreeNode tn = (MTreeNode) tp.getLastPathComponent();
            setSelectedNode(tn);
        }
    } else //  *** treeSearch ***
    if (e.getSource() == treeSearch) {
        String search = treeSearch.getText();
        boolean found = false;
        //  at the end - try from top
        if (m_nodeEn != null && !m_nodeEn.hasMoreElements())
            m_search = "";
        //  this is the first time
        if (!search.equals(m_search)) {
            //  get enumeration of all nodes
            m_nodeEn = m_root.preorderEnumeration();
            m_search = search;
        }
        //  search the nodes
        while (!found && m_nodeEn != null && m_nodeEn.hasMoreElements()) {
            MTreeNode nd = (MTreeNode) m_nodeEn.nextElement();
            //	compare in upper case
            if (nd.toString().toUpperCase().indexOf(search.toUpperCase()) != -1) {
                found = true;
                TreePath treePath = new TreePath(nd.getPath());
                tree.setSelectionPath(treePath);
                //	expand it
                tree.makeVisible(treePath);
                tree.scrollPathToVisible(treePath);
            }
        }
        if (!found)
            ADialog.beep();
    }
//  treeSearch
}
Also used : MTreeNode(org.compiere.model.MTreeNode) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) DocumentSearch(de.schaeffer.compiere.tools.DocumentSearch)

Aggregations

DocumentSearch (de.schaeffer.compiere.tools.DocumentSearch)1 JTree (javax.swing.JTree)1 TreePath (javax.swing.tree.TreePath)1 MTreeNode (org.compiere.model.MTreeNode)1