KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > virtual > ActivateVirtualFolderCommand


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.folder.virtual;
17
18 import java.text.MessageFormat JavaDoc;
19
20 import org.columba.api.command.ICommandReference;
21 import org.columba.api.command.IWorkerStatusController;
22 import org.columba.core.command.Command;
23 import org.columba.core.command.CommandProcessor;
24 import org.columba.core.connectionstate.ConnectionStateImpl;
25 import org.columba.core.folder.api.IFolderCommandReference;
26 import org.columba.mail.command.MailFolderCommandReference;
27 import org.columba.mail.folder.AbstractRemoteFolder;
28 import org.columba.mail.folder.FolderChildrenIterator;
29 import org.columba.mail.folder.IMailFolder;
30 import org.columba.mail.util.MailResourceLoader;
31
32 public class ActivateVirtualFolderCommand extends Command {
33
34     public ActivateVirtualFolderCommand(ICommandReference reference) {
35         super(reference);
36     }
37
38     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
39         VirtualFolder vFolder = (VirtualFolder) ((IFolderCommandReference) getReference())
40                 .getSourceFolder();
41
42         worker.setDisplayText(MessageFormat.format(MailResourceLoader
43                 .getString("statusbar", "message", "activate_vfolder"),
44                 new Object JavaDoc[] { vFolder.getName() }));
45
46         vFolder.activate();
47     }
48
49     public static void activateAll(IMailFolder root) {
50         // Find all VirtualFolders and rewrite the FolderReference
51
FolderChildrenIterator it = new FolderChildrenIterator(root);
52
53         while (it.hasMoreChildren()) {
54             IMailFolder f = it.nextChild();
55             if (f instanceof VirtualFolder && !f.getId().equals("106") && !((IMailFolder)f.getParent()).getId().equals("106")) {
56                 VirtualFolder vFolder = (VirtualFolder)f;
57                 
58                 // Check if the parentfolder is remote & we are online
59
if( vFolder.getSourceFolder() instanceof AbstractRemoteFolder && !ConnectionStateImpl.getInstance().isOnline()) {
60                     continue;
61                 }
62                     
63                 CommandProcessor.getInstance().addOp(
64                         new ActivateVirtualFolderCommand(
65                                 new MailFolderCommandReference(f)));
66             }
67         }
68
69     }
70
71 }
72
Popular Tags