Source Code Cross Referenced for HyperSearchOperationNode.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » search » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jEdit » org.gjt.sp.jedit.search 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * HyperSearchOperationNode.java - Top result node of a HyperSearch request
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 1998, 1999, 2000, 2001, 2002 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit.search;
024:
025:        //{{{ Imports
026:        import java.io.File;
027:        import java.util.ArrayList;
028:        import java.util.Enumeration;
029:        import java.util.HashMap;
030:        import java.util.List;
031:        import java.util.Map;
032:
033:        import javax.swing.JTree;
034:        import javax.swing.tree.DefaultMutableTreeNode;
035:        import javax.swing.tree.DefaultTreeModel;
036:        import javax.swing.tree.MutableTreeNode;
037:        import javax.swing.tree.TreePath;
038:
039:        //}}}
040:
041:        /**
042:         * @author Slava Pestov
043:         * @version $Id: HyperSearchOperationNode.java 9522 2007-05-10 09:53:53Z kpouer $
044:         */
045:        public class HyperSearchOperationNode {
046:            private boolean treeViewDisplayed;
047:            private final String searchString;
048:            private List<DefaultMutableTreeNode> resultNodes;
049:            private SearchMatcher searchMatcher;
050:
051:            //{{{ HyperSearchOperationNode constructor
052:            public HyperSearchOperationNode(String searchString,
053:                    SearchMatcher searchMatcher) {
054:                this .searchString = searchString;
055:                this .searchMatcher = searchMatcher;
056:            }//}}}
057:
058:            //{{{ toString() method
059:            public String toString() {
060:                return searchString;
061:            }//}}}
062:
063:            //{{{ isTreeViewDisplayed() method
064:            public boolean isTreeViewDisplayed() {
065:                return treeViewDisplayed;
066:            }//}}}
067:
068:            //{{{ setTreeViewDisplayed() method
069:            public void setTreeViewDisplayed(boolean treeViewDisplayed) {
070:                this .treeViewDisplayed = treeViewDisplayed;
071:            }//}}}
072:
073:            //{{{ restoreFlatNodes() method
074:            public void restoreFlatNodes(JTree resultTree,
075:                    DefaultMutableTreeNode operNode) {
076:                for (int i = 0; i < resultNodes.size(); i++) {
077:                    DefaultMutableTreeNode element = resultNodes.get(i);
078:                    if (element.getUserObject() instanceof  HyperSearchFileNode)
079:                        ((HyperSearchFileNode) element.getUserObject()).showFullPath = true;
080:
081:                    operNode.insert(element, operNode.getChildCount());
082:                }
083:
084:                ((DefaultTreeModel) resultTree.getModel())
085:                        .nodeStructureChanged(operNode);
086:
087:                for (Enumeration e = operNode.children(); e.hasMoreElements();) {
088:                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) e
089:                            .nextElement();
090:                    resultTree.expandPath(new TreePath(node.getPath()));
091:                }
092:                resultTree
093:                        .scrollPathToVisible(new TreePath(operNode.getPath()));
094:            }//}}}
095:
096:            //{{{ cacheFlatNodes() method
097:            public void cacheResultNodes(DefaultMutableTreeNode operNode) {
098:                resultNodes = new ArrayList<DefaultMutableTreeNode>(operNode
099:                        .getChildCount());
100:                for (Enumeration e = operNode.children(); e.hasMoreElements();)
101:                    resultNodes.add((DefaultMutableTreeNode) e.nextElement());
102:            }//}}}
103:
104:            //{{{ removeNodeFromCache() method
105:            public static void removeNodeFromCache(MutableTreeNode mnode) {
106:                DefaultMutableTreeNode node = (DefaultMutableTreeNode) mnode;
107:                if (node.getUserObject() instanceof  HyperSearchOperationNode)
108:                    return;
109:
110:                DefaultMutableTreeNode tmpNode = node;
111:                while ((tmpNode = (DefaultMutableTreeNode) tmpNode.getParent()) != null) {
112:                    if (!(tmpNode.getUserObject() instanceof  HyperSearchOperationNode))
113:                        continue;
114:                    HyperSearchOperationNode operNode = (HyperSearchOperationNode) tmpNode
115:                            .getUserObject();
116:                    if (operNode.resultNodes != null) {
117:                        // the nodes aren't cached so no need to remove the node from cache
118:                        operNode.resultNodes.remove(node);
119:                    }
120:                    break;
121:                }
122:
123:            }//}}}
124:
125:            //{{{ insertTreeNodes() method
126:            public void insertTreeNodes(JTree resultTree,
127:                    DefaultMutableTreeNode operNode) {
128:                String fileSep = System.getProperty("file.separator");
129:                String fileSepRegex = System.getProperty("file.separator");
130:                if (fileSep.equals("\\"))
131:                    fileSepRegex = "\\\\";
132:
133:                //find the highest level common path
134:                String[] topPathTmp = null;
135:                int topPathNdx = -1;
136:
137:                for (int i = 0; i < resultNodes.size(); i++) {
138:                    DefaultMutableTreeNode fileTreeNode = resultNodes.get(i);
139:                    Object obj = fileTreeNode.getUserObject();
140:                    if (!(obj instanceof  HyperSearchFileNode))
141:                        continue;
142:                    HyperSearchFileNode fileNode = (HyperSearchFileNode) obj;
143:
144:                    int pos = fileNode.path.lastIndexOf(fileSep);
145:                    String pathName = fileNode.path.substring(0, pos);
146:                    String[] paths = pathName.split(fileSepRegex);
147:                    if (topPathNdx == -1) {
148:                        topPathNdx = paths.length;
149:                        topPathTmp = paths;
150:                    } else if (paths.length < topPathNdx) {
151:                        topPathNdx = paths.length;
152:                        topPathTmp = paths;
153:                    } else {
154:                        for (int ndx = 0; ndx < topPathNdx; ndx++) {
155:                            if (!paths[ndx].equals(topPathTmp[ndx])) {
156:                                topPathNdx = ndx;
157:                                break;
158:                            }
159:                        }
160:                    }
161:                }
162:                String[] topPath = new String[topPathNdx];
163:                String topPathPath = "";
164:                for (int ndx = 0; ndx < topPathNdx; ndx++) {
165:                    topPath[ndx] = topPathTmp[ndx];
166:                    topPathPath = topPathPath.concat(topPath[ndx] + fileSep);
167:                }
168:                Map<String, DefaultMutableTreeNode> treeNodes = new HashMap<String, DefaultMutableTreeNode>();
169:                HyperSearchFolderNode folderNode = new HyperSearchFolderNode(
170:                        new File(topPathPath), true);
171:                DefaultMutableTreeNode folderTreeNode = new DefaultMutableTreeNode(
172:                        folderNode);
173:                operNode.insert(folderTreeNode, operNode.getChildCount());
174:                treeNodes.put(topPathPath, folderTreeNode);
175:
176:                for (int i = 0; i < resultNodes.size(); i++) {
177:                    DefaultMutableTreeNode fileTreeNode = resultNodes.get(i);
178:                    Object obj = fileTreeNode.getUserObject();
179:                    if (!(obj instanceof  HyperSearchFileNode))
180:                        continue;
181:                    HyperSearchFileNode fileNode = (HyperSearchFileNode) obj;
182:
183:                    fileNode.showFullPath = false;
184:                    int pos = fileNode.path.lastIndexOf(fileSep);
185:                    String pathName = fileNode.path.substring(0, pos);
186:                    String[] paths = pathName.split(fileSepRegex);
187:
188:                    DefaultMutableTreeNode insNode = folderTreeNode;
189:                    String partialPath = topPathPath;
190:                    for (int ndx = topPathNdx; ndx < paths.length; ndx++) {
191:                        partialPath = partialPath.concat(paths[ndx] + fileSep);
192:                        DefaultMutableTreeNode tmpNode = treeNodes
193:                                .get(partialPath);
194:                        if (tmpNode == null) {
195:                            HyperSearchFolderNode tmpFolderNode = new HyperSearchFolderNode(
196:                                    new File(partialPath), false);
197:                            tmpNode = new DefaultMutableTreeNode(tmpFolderNode);
198:                            insNode.insert(tmpNode, insNode.getChildCount());
199:                            treeNodes.put(partialPath, tmpNode);
200:                        }
201:                        insNode = tmpNode;
202:                    }
203:                    insNode.insert(fileTreeNode, insNode.getChildCount());
204:                    treeNodes.put(fileNode.path, insNode);
205:                }
206:
207:            }//}}}
208:
209:            //{{{ getSearchMatcher() method
210:            SearchMatcher getSearchMatcher() {
211:                return searchMatcher;
212:            }//}}}
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.