KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > command > ApplyFilterCommand


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.command;
17
18 import org.columba.api.command.ICommandReference;
19 import org.columba.api.command.IWorkerStatusController;
20 import org.columba.core.command.Command;
21 import org.columba.core.command.CompoundCommand;
22 import org.columba.core.command.StatusObservableImpl;
23 import org.columba.core.command.Worker;
24 import org.columba.core.filter.Filter;
25 import org.columba.core.filter.FilterList;
26 import org.columba.core.filter.IFilter;
27 import org.columba.core.filter.IFilterList;
28 import org.columba.mail.command.IMailFolderCommandReference;
29 import org.columba.mail.filter.FilterCompoundCommand;
30 import org.columba.mail.folder.IMailbox;
31
32 /**
33  *
34  * Apply all filters on this folder.
35  *
36  * @author fdietz
37  *
38  */

39 public class ApplyFilterCommand extends Command {
40     /**
41      * Constructor for ApplyFilterCommand.
42      *
43      * @param frameMediator
44      * @param references
45      */

46     public ApplyFilterCommand(ICommandReference reference) {
47         super(reference);
48     }
49
50     /**
51      * @see org.columba.api.command.Command#execute(Worker)
52      */

53     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
54         // get references
55
IMailFolderCommandReference r = (IMailFolderCommandReference) getReference();
56
57         // get source folder
58
IMailbox srcFolder = (IMailbox) r.getSourceFolder();
59
60         // register for status events
61
((StatusObservableImpl) srcFolder.getObservable()).setWorker(worker);
62
63         // display status message
64
worker.setDisplayText("Applying filter to " + srcFolder.getName()
65                 + "...");
66
67         // get filter list from folder
68
IFilterList list = srcFolder.getFilterList();
69
70         if (list == null) {
71             return;
72         }
73
74         // initialize progressbar
75
worker.setProgressBarMaximum(list.count());
76
77         // for each filter
78
for (int i = 0; i < list.count(); i++) {
79             // update progressbar
80
worker.setProgressBarValue(i);
81
82             // get filter
83
IFilter filter = list.get(i);
84             
85             // skip, if filter is disabled
86
if ( filter.getEnabled() == false) continue;
87             
88             // search all messages which match this filter
89
Object JavaDoc[] result = srcFolder.searchMessages(filter);
90
91             if (result == null) {
92                 continue;
93             }
94
95             // if we have a result
96
if (result.length != 0) {
97                 // create a Command for every action of this filter
98
// -> create a compound object which encapsulates all commands
99
CompoundCommand command = new FilterCompoundCommand(filter, srcFolder, result);
100
101                 // add command to scheduler
102
//MainInterface.processor.addOp(command);
103

104                 command.execute(worker);
105             }
106         }
107     }
108 }
Popular Tags