1 package net.suberic.pooka; 2 3 import javax.mail.*; 4 import javax.mail.event.*; 5 import javax.swing.event.EventListenerList ; 6 import java.util.*; 7 import javax.swing.AbstractAction ; 8 import javax.swing.Action ; 9 import java.awt.event.ActionEvent ; 10 import net.suberic.pooka.gui.*; 11 import net.suberic.pooka.thread.*; 12 import net.suberic.pooka.event.*; 13 import net.suberic.util.ValueChangeListener; 14 import net.suberic.util.thread.ActionThread; 15 16 19 20 public class VirtualFolderInfo extends FolderInfo { 21 FolderInfo[] parents; 22 MessageInfo[] originalMessages; 23 24 28 public VirtualFolderInfo(MessageInfo[] newMessages, FolderInfo[] newParents) { 29 parents = newParents; 30 originalMessages = newMessages; 31 setStatus(CONNECTED); 32 initializeFolderInfo(); 33 34 createFilters(); 35 36 resetDefaultActions(); 37 38 setNotifyNewMessagesMain(false); 39 setNotifyNewMessagesNode(false); 40 } 41 42 45 public void loadFolder() { 46 return; 47 } 48 49 53 protected void initializeFolderInfo() { 54 for (int i = 0; i < parents.length; i++) { 55 parents[i].addMessageCountListener(this); 56 parents[i].addMessageChangedListener(this); 57 } 58 59 loadAllMessages(); 60 } 61 62 65 public void dispose() { 66 for (int i = 0; i < parents.length; i++) { 67 parents[i].removeMessageCountListener(this); 68 parents[i].removeMessageChangedListener(this); 69 } 70 } 71 72 75 public synchronized void loadAllMessages() { 76 if (folderTableModel == null) { 77 Vector messageProxies = new Vector(); 78 createColumnInformation(); 79 80 for (int i = 0 ; i < originalMessages.length; i++) { 81 if (Pooka.isDebug()) 82 System.out.println("originalMessages[" + i + "] = " + originalMessages[i]); 83 messageProxies.add(originalMessages[i].getMessageProxy()); 84 messageToInfoTable.put(originalMessages[i].getMessage(), originalMessages[i]); 85 } 86 87 if (Pooka.isDebug()) { 88 System.out.println("originalMessages.length = " + originalMessages.length + "; messageProxies.size() = " + messageProxies.size() + "; getColumnNames() = " + getColumnNames() + "; getColumnSizes() = " + getColumnSizes()); 89 for (int i = 0 ; i < getColumnNames().size() ; i++) { 90 System.out.println("column name " + i + " = " + getColumnNames().get(i)); 91 } 92 } 93 FolderTableModel ftm = new FolderTableModel(messageProxies, getColumnNames(), getColumnSizes(), getColumnValues(), getColumnIds()); 94 setFolderTableModel(ftm); 95 96 resetMessageCounts(); 97 } 98 } 99 100 103 public int getFirstUnreadMessage() { 104 return -1; 105 } 106 107 110 public void setFlags(MessageInfo[] msgs, Flags flag, boolean value) throws MessagingException { 111 HashMap map = new HashMap(); 113 for (int i = 0; i < parents.length; i++) { 114 map.put(parents[i], new Vector()); 115 } 116 117 for (int i = 0; i < msgs.length; i++) { 118 Vector v = (Vector) map.get(msgs[i].getFolderInfo()); 119 if (v != null) 120 v.add(msgs[i]); 121 } 122 123 for (int i = 0; i < parents.length; i++) { 124 Vector v = (Vector) map.get(parents[i]); 125 if (v.size() > 0) { 126 MessageInfo[] folderMsgs = new MessageInfo[v.size()]; 127 for (int j = 0; j < v.size(); j++) { 128 folderMsgs[j] = (MessageInfo) v.elementAt(j); 129 } 130 131 synchronized(parents[i].getFolderThread().getRunLock()) { 132 parents[i].setFlags(folderMsgs, flag, value); 133 } 134 } 135 136 } 137 } 138 139 142 public void copyMessages(MessageInfo[] msgs, FolderInfo targetFolder) throws MessagingException { 143 HashMap map = new HashMap(); 145 for (int i = 0; i < parents.length; i++) { 146 map.put(parents[i], new Vector()); 147 } 148 149 for (int i = 0; i < msgs.length; i++) { 150 Vector v = (Vector) map.get(msgs[i].getFolderInfo()); 151 if (v != null) 152 v.add(msgs[i]); 153 } 154 155 for (int i = 0; i < parents.length; i++) { 156 Vector v = (Vector) map.get(parents[i]); 157 if (v.size() > 0) { 158 MessageInfo[] folderMsgs = new MessageInfo[v.size()]; 159 for (int j = 0; j < v.size(); j++) { 160 folderMsgs[j] = (MessageInfo) v.elementAt(j); 161 } 162 163 synchronized(parents[i].getFolderThread().getRunLock()) { 164 parents[i].copyMessages(folderMsgs, targetFolder); 165 } 166 } 167 168 } 169 } 170 171 174 public void appendMessages(MessageInfo[] msgs) throws MessagingException { 175 throw new MessagingException (Pooka.getProperty("error.search.appendToSearchFolder", "Cannot append to a Virtual Folder.")); 176 } 177 178 181 public void expunge() throws MessagingException { 182 for (int i = 0; i < parents.length; i++) 183 synchronized(parents[i].getFolderThread().getRunLock()) { 184 parents[i].expunge(); 185 } 186 } 187 188 189 193 protected void runMessageChanged(MessageChangedEvent mce) { 194 fireMessageChangedEvent(mce); 195 resetMessageCounts(); 196 } 197 198 203 public MessageInfo[] search(javax.mail.search.SearchTerm term) 204 throws MessagingException { 205 Vector matches = new Vector(); 206 for (int i = 0; i < getFolderTableModel().getRowCount(); i++) { 207 MessageInfo currentInfo = getFolderTableModel().getMessageProxy(i).getMessageInfo(); 208 if (term.match(currentInfo.getMessage())) { 209 matches.add(currentInfo); 210 } 211 } 212 MessageInfo returnValue[] = new MessageInfo[matches.size()]; 213 for (int i = 0; i < matches.size(); i++) { 214 returnValue[i] = (MessageInfo) matches.elementAt(i); 215 } 216 return returnValue; 217 } 218 219 222 public void showSearchFolder() { 223 Vector allowedValues = new Vector(); 224 allowedValues.add(this); 225 Pooka.getUIFactory().showSearchForm(new FolderInfo[] { this }, allowedValues); 226 } 227 228 protected void removeFromListeners(FolderDisplayUI display) { 229 if (display != null) { 230 removeMessageChangedListener(display); 231 removeMessageCountListener(display); 232 } 233 } 234 235 protected void addToListeners(FolderDisplayUI display) { 236 if (display != null) { 237 addMessageChangedListener(display); 238 addMessageCountListener(display); 239 } 240 } 241 242 245 protected void runMessagesAdded(MessageCountEvent mce) { 246 return; 247 } 248 249 252 public void resetMessageCounts() { 253 if (Pooka.isDebug()) { 254 System.out.println("running resetMessageCounts."); 255 } 256 257 int tmpUnreadCount = 0; 258 int tmpMessageCount = 0; 259 Enumeration msgs = messageToInfoTable.keys(); 260 while (msgs.hasMoreElements()) { 261 MessageInfo mi = (MessageInfo) messageToInfoTable.get(msgs.nextElement()); 262 tmpMessageCount++; 263 if (! mi.isSeen()) 264 tmpUnreadCount++; 265 } 266 unreadCount = tmpUnreadCount; 267 messageCount = tmpMessageCount; 268 } 269 270 public ActionThread getFolderThread() { 271 return Pooka.getSearchThread(); 272 } 273 274 public StoreInfo getParentStore() { 275 return null; 276 } 277 278 public FolderInfo getTrashFolder() { 279 return null; 280 } 281 282 public String getFolderDisplayName() { 283 return Pooka.getProperty("title.searchResults", "Seach Results"); 284 } 285 286 public String getFolderID() { 287 return Pooka.getProperty("title.searchResults", "Search results"); 288 } 289 290 300 public void setFolderDisplayUI(FolderDisplayUI newValue) { 301 super.setFolderDisplayUI(newValue); 302 if (newValue == null) 303 this.dispose(); 304 } 305 } 306 | Popular Tags |