1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.browser; 22 23 24 import java.util.Arrays ; 25 26 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 27 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult; 28 29 30 37 public class BrowserSearchResultPage 38 { 39 40 41 private BrowserSorter sorter; 42 43 44 private int first; 45 46 47 private int last; 48 49 50 private ISearch search; 51 52 53 private BrowserSearchResultPage parentSearchResultPage; 54 55 56 private BrowserSearchResultPage[] subpages; 57 58 59 68 public BrowserSearchResultPage( ISearch search, int first, int last, BrowserSearchResultPage[] subpages, 69 BrowserSorter sorter ) 70 { 71 this.search = search; 72 this.first = first; 73 this.last = last; 74 this.subpages = subpages; 75 this.sorter = sorter; 76 77 if ( subpages != null ) 78 { 79 for ( int i = 0; i < subpages.length; i++ ) 80 { 81 subpages[i].parentSearchResultPage = this; 82 } 83 } 84 } 85 86 87 93 public Object [] getChildren() 94 { 95 if ( subpages != null ) 96 { 97 return subpages; 98 } 99 else 100 { 101 ISearchResult[] children = search.getSearchResults(); 103 104 sorter.sort( null, children ); 106 107 if ( children != null ) 109 { 110 ISearchResult[] childrenRange = new ISearchResult[last - first + 1]; 111 for ( int i = first; i <= last; i++ ) 112 { 113 childrenRange[i - first] = children[i]; 114 } 115 return childrenRange; 116 } 117 else 118 { 119 return null; 120 } 121 } 122 } 123 124 125 130 public int getFirst() 131 { 132 return first; 133 } 134 135 136 141 public int getLast() 142 { 143 return last; 144 } 145 146 147 152 public ISearch getSearch() 153 { 154 return search; 155 } 156 157 158 166 public BrowserSearchResultPage getParentOf( ISearchResult searchResult ) 167 { 168 if ( subpages != null ) 169 { 170 BrowserSearchResultPage ep = null; 171 for ( int i = 0; i < subpages.length && ep == null; i++ ) 172 { 173 ep = subpages[i].getParentOf( searchResult ); 174 } 175 return ep; 176 } 177 else 178 { 179 ISearchResult[] sr = ( ISearchResult[] ) getChildren(); 180 if ( sr != null && Arrays.asList( sr ).contains( searchResult ) ) 181 { 182 return this; 183 } 184 else 185 { 186 return null; 187 } 188 } 189 } 190 191 192 197 public Object getParent() 198 { 199 return ( parentSearchResultPage != null ) ? ( Object ) parentSearchResultPage : ( Object ) search; 200 } 201 202 203 206 public String toString() 207 { 208 return search.toString() + "[" + first + "..." + last + "]" + hashCode(); 209 } 210 211 } 212 | Popular Tags |