1 85 package com.ivata.groupware.business.library.comment.tree; 86 87 import java.io.IOException ; 88 import java.io.ObjectInputStream ; 89 import java.io.ObjectOutputStream ; 90 import java.io.Serializable ; 91 import java.util.List ; 92 93 import javax.swing.event.TreeModelListener ; 94 import javax.swing.tree.TreeModel ; 95 import javax.swing.tree.TreePath ; 96 97 import com.ivata.groupware.admin.security.server.SecuritySession; 98 import com.ivata.groupware.business.library.Library; 99 import com.ivata.groupware.business.library.comment.CommentDO; 100 import com.ivata.groupware.business.library.item.LibraryItemDO; 101 import com.ivata.mask.util.SystemException; 102 103 104 127 public class CommentTreeModel implements TreeModel , Serializable { 128 131 private LibraryItemDO item; 132 private Library library; 133 private SecuritySession securitySession; 134 135 138 public CommentTreeModel(Library library, 139 SecuritySession securitySession) { 140 this.library = library; 141 this.securitySession = securitySession; 142 } 143 144 149 public void addTreeModelListener(final TreeModelListener l) { 150 throw new UnsupportedOperationException ( 151 "Method addTreeModelListener( ) not implemented."); 152 } 153 154 164 public final Object getChild(final Object parent, 165 final int index) { 166 CommentDO parentComment = (CommentDO) parent; 167 return getReplies(parentComment).get(index); 168 } 169 170 171 178 public final int getChildCount(final Object parent) { 179 CommentDO parentComment = (CommentDO) parent; 180 return getReplies(parentComment).size(); 181 } 182 183 191 public final int getIndexOfChild(final Object parent, 192 final Object child) { 193 CommentDO parentComment = (CommentDO) parent; 194 return getReplies(parentComment).indexOf(child); 195 } 196 197 203 public final LibraryItemDO getItem() { 204 return item; 205 } 206 207 212 private List getReplies(final CommentDO parent) { 213 if (parent.getId() == null) { 215 try { 216 return library.findCommentByItem(securitySession, parent.getItem().getId()); 217 } catch (SystemException e) { 218 throw new RuntimeException (e); 219 } 220 } else { 221 try { 222 return library.findCommentByParent(securitySession, parent.getId()); 223 } catch (SystemException e) { 224 throw new RuntimeException (e); 225 } 226 } 227 } 228 229 239 public final Object getRoot() { 240 CommentDO root = new CommentDO(); 241 root.setId(null); 242 root.setItem(item); 243 return root; 244 } 245 246 253 public boolean isLeaf(final Object node) { 254 return false; 255 } 256 257 264 private void readObject(final ObjectInputStream ois) 265 throws ClassNotFoundException , IOException { 266 ois.defaultReadObject(); 267 } 268 269 274 public void removeTreeModelListener(final TreeModelListener l) { 275 throw new UnsupportedOperationException ( 276 "Method removeTreeModelListener( ) not implemented."); 277 } 278 284 public final void setItem(final LibraryItemDO item) { 285 this.item = item; 286 } 287 288 294 public void valueForPathChanged(final TreePath path, 295 final Object newValue) { 296 throw new UnsupportedOperationException ( 297 "Method valueForPathChanged( ) not implemented."); 298 } 299 300 306 private void writeObject(final ObjectOutputStream oos) throws IOException { 307 oos.defaultWriteObject(); 308 } 309 310 } 311 | Popular Tags |