01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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;
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)
39: throws Exception {
40: VirtualFolder vFolder = (VirtualFolder) ((IFolderCommandReference) getReference())
41: .getSourceFolder();
42:
43: worker.setDisplayText(MessageFormat.format(MailResourceLoader
44: .getString("statusbar", "message", "activate_vfolder"),
45: new Object[] { vFolder.getName() }));
46:
47: vFolder.activate();
48: }
49:
50: public static void activateAll(IMailFolder root) {
51: // Find all VirtualFolders and rewrite the FolderReference
52: FolderChildrenIterator it = new FolderChildrenIterator(root);
53:
54: while (it.hasMoreChildren()) {
55: IMailFolder f = it.nextChild();
56: if (f instanceof VirtualFolder
57: && !f.getId().equals("106")
58: && !((IMailFolder) f.getParent()).getId().equals(
59: "106")) {
60: VirtualFolder vFolder = (VirtualFolder) f;
61:
62: // Check if the parentfolder is remote & we are online
63: if (vFolder.getSourceFolder() instanceof AbstractRemoteFolder
64: && !ConnectionStateImpl.getInstance()
65: .isOnline()) {
66: continue;
67: }
68:
69: CommandProcessor.getInstance().addOp(
70: new ActivateVirtualFolderCommand(
71: new MailFolderCommandReference(f)));
72: }
73: }
74:
75: }
76:
77: }
|