1 4 package org.openedit.links; 5 6 import java.io.Serializable ; 7 import java.util.ArrayList ; 8 import java.util.Iterator ; 9 import java.util.List ; 10 11 12 16 public class Link implements Serializable 17 { 18 21 private static final long serialVersionUID = 6696306680268063277L; 22 protected String fieldPath; 23 protected String fieldText; 24 protected String fieldId; 25 protected boolean fieldSelected; 26 27 protected String [] fieldParsedId; 28 protected Link fieldParentLink; 29 protected List fieldChildren; 30 protected String fieldUserData; 31 protected String fieldRedirectPath; 32 protected String fieldAccessKey; 33 protected boolean fieldAutoLoadChildren; 34 35 public String getText() 36 { 37 return fieldText; 38 } 39 public void setText(String inText) 40 { 41 fieldText = inText; 42 } 43 44 45 public String getPath() 46 { 47 return fieldPath; 48 } 49 public String getHref() 50 { 51 return getPath(); 52 } 53 public String getUrl() 54 { 55 return getPath(); 56 } 57 public void setPath(String inString) 58 { 59 fieldPath = inString; 60 } 61 62 public String getId() 63 { 64 return fieldId; 65 } 66 public void setId(String inId) 67 { 68 fieldId = inId; 69 fieldParsedId = null; 70 } 71 public int getDepth() 72 { 73 int i = 0; 74 Link parent = getParentLink(); 75 while(parent != null) 76 { 77 i++; 78 parent = parent.getParentLink(); 79 } 80 return i; 81 } 82 public String [] getParsedId() 83 { 84 if ( fieldParsedId == null) 85 { 86 List ids = new ArrayList (); 87 ids.add(0,getId()); 88 Link parent = getParentLink(); 89 while( parent != null) 90 { 91 ids.add(0,parent.getId()); 92 parent = getParentLink(); 93 } 94 fieldParsedId = (String [])ids.toArray(new String [ids.size()]); 95 } 96 return fieldParsedId; 97 } 98 public boolean hasChildren() 99 { 100 return fieldChildren != null && fieldChildren.size() > 0; 101 } 102 107 public List getChildrenInRows(int inColCount) 108 { 109 double rowscount = (double)getChildren().size() / (double)inColCount; 110 111 List rows = new ArrayList (); 112 for (int i = 0; i < rowscount; i++) 113 { 114 int start = i*inColCount; 115 int end = i*inColCount + inColCount; 116 List sublist = getChildren().subList(start,Math.min( getChildren().size(),end )); 118 rows.add(sublist); 119 } 120 return rows; 121 } 122 public List getChildren() 123 { 124 if ( fieldChildren == null) 125 { 126 fieldChildren = new ArrayList (); 127 } 128 return fieldChildren; 129 } 130 public void setChildren(List inChildren) 131 { 132 fieldChildren = inChildren; 133 } 134 public Link getParentLink() 135 { 136 return fieldParentLink; 137 } 138 public void setParentLink(Link inParentLink) 139 { 140 fieldParentLink = inParentLink; 141 } 142 145 public void addChild(Link inLink) 146 { 147 inLink.setParentLink(this); 148 getChildren().add(inLink); 149 } 150 public void insertChild(Link inLink) 151 { 152 inLink.setParentLink(this); 153 getChildren().add(0,inLink); 154 } 157 public void removeChild(Link inLink) 158 { 159 getChildren().remove(inLink); 160 inLink.setParentLink(null); 161 } 162 165 public void moveUp(Link inLink) 166 { 167 int index = getChildren().indexOf(inLink); 168 if ( index != -1 && index != 0) 169 { 170 getChildren().remove(index); 171 index--; 172 getChildren().add(index,inLink); 173 } 174 } 175 178 public void moveDown(Link inLink) 179 { 180 int index = getChildren().indexOf(inLink); 181 if ( index != -1 && index != getChildren().size()-1) 182 { 183 getChildren().remove(index); 184 index++; 185 getChildren().add(index,inLink); 186 } 187 } 188 192 public Link getChildAbove(Link inLink) 193 { 194 int count = getChildren().indexOf(inLink); 195 if ( count != -1 && count != 0) 196 { 197 count--; 198 Link brother = (Link)getChildren().get(count); 199 return brother; 200 } 201 return null; 202 } 203 public Link getChildBelow(Link inLink) 204 { 205 int count = getChildren().indexOf(inLink); 206 if ( count != -1 && count != getChildren().size() -1) 207 { 208 count++; 209 Link brother = (Link)getChildren().get(count); 210 return brother; 211 } 212 return null; 213 } 214 215 public Link getDecendant(String inId) 216 { 217 for (Iterator iter = getChildren().iterator(); iter.hasNext();) 218 { 219 Link child = (Link) iter.next(); 220 if (child.getId().equals(inId)) 221 { 222 return child; 223 } 224 else 225 { 226 Link decendant = child.getDecendant(inId); 227 if (decendant != null) 228 { 229 return decendant; 230 } 231 } 232 } 233 return null; 234 } 235 236 237 241 public void addChildNearLocation(Link inLink, Link inParent1) 242 { 243 int count = getChildren().indexOf(inParent1); 244 if ( count != -1 ) 245 { 246 getChildren().add(count+1,inLink); 247 } 248 else 249 { 250 getChildren().add(inLink ); 251 } 252 inLink.setParentLink(this); 253 } 254 258 public List list() 259 { 260 ArrayList fieldAllLinks = new ArrayList (); 261 addLinksToList(this,fieldAllLinks); 262 return fieldAllLinks; 263 } 264 268 protected void addLinksToList(Link inRootLink, List inAllLinks) 269 { 270 inAllLinks.add(inRootLink); 271 if ( inRootLink.hasChildren() ) 272 { 273 for (Iterator iter = inRootLink.getChildren().iterator(); iter.hasNext();) 274 { 275 Link element = (Link) iter.next(); 276 addLinksToList(element, inAllLinks); 277 } 278 } 279 } 280 281 public String getUserData() 282 { 283 return fieldUserData; 284 } 285 public void setUserData(String inUserData) 286 { 287 fieldUserData = inUserData; 288 } 289 public boolean isSelected() 290 { 291 return fieldSelected; 292 } 293 public void setSelected(boolean inSelected) 294 { 295 fieldSelected = inSelected; 296 } 297 300 public boolean isChildSelected() 301 { 302 if ( isSelected()) 303 { 304 return true; 305 } 306 if ( hasChildren() ) 307 { 308 for (Iterator iter = getChildren().iterator(); iter.hasNext();) 309 { 310 Link child = (Link) iter.next(); 311 if ( child.isChildSelected()) 312 { 313 return true; 314 } 315 } 316 } 317 return false; 318 } 319 323 public boolean isChild(Link inUrl) 324 { 325 for (Iterator iter = getChildren().iterator(); iter.hasNext();) 326 { 327 Link element = (Link) iter.next(); 328 if ( element == inUrl) 329 { 330 return true; 331 } 332 if( element.isChild(inUrl) ) 333 { 334 return true; 335 } 336 } 337 return false; 338 } 339 342 public String getRedirectPath() 343 { 344 return fieldRedirectPath; 345 } 346 349 public void setRedirectPath(String inRedirectPath) 350 { 351 fieldRedirectPath = inRedirectPath; 352 } 353 public String getAccessKey() 354 { 355 return fieldAccessKey; 356 } 357 public void setAccessKey(String inAccessKey) 358 { 359 fieldAccessKey = inAccessKey; 360 } 361 public boolean isAutoLoadChildren() 362 { 363 return fieldAutoLoadChildren; 364 } 365 public void setAutoLoadChildren(boolean inAutoLoadChildren) 366 { 367 fieldAutoLoadChildren = inAutoLoadChildren; 368 } 369 public String toString() 370 { 371 return getHref(); 372 } 373 } 374 | Popular Tags |