Source Code Cross Referenced for CreateVFolderOnMessageCommand.java in  » Mail-Clients » columba-1.4 » org » columba » mail » folder » command » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Mail Clients » columba 1.4 » org.columba.mail.folder.command 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014:        //
015:        //All Rights Reserved.
016:        package org.columba.mail.folder.command;
017:
018:        import java.util.logging.Logger;
019:
020:        import org.columba.api.command.ICommandReference;
021:        import org.columba.api.command.IWorkerStatusController;
022:        import org.columba.api.gui.frame.IFrameMediator;
023:        import org.columba.core.command.Command;
024:        import org.columba.core.command.StatusObservableImpl;
025:        import org.columba.core.command.Worker;
026:        import org.columba.core.filter.FilterRule;
027:        import org.columba.core.filter.IFilterRule;
028:        import org.columba.mail.command.IMailFolderCommandReference;
029:        import org.columba.mail.filter.MailFilterCriteria;
030:        import org.columba.mail.folder.FolderFactory;
031:        import org.columba.mail.folder.IMailbox;
032:        import org.columba.mail.folder.virtual.VirtualFolder;
033:        import org.columba.mail.gui.config.filter.ConfigFrame;
034:        import org.columba.mail.gui.tree.FolderTreeModel;
035:        import org.columba.ristretto.message.Header;
036:
037:        /**
038:         * This class is used to create a virtual folder based on the currently
039:         * selected message (if multiple selected, the first one in the selection array
040:         * is used) - either using Subject, To or From.
041:         *
042:         * @author Karl Peder Olesen (karlpeder), 20030621
043:         */
044:        public class CreateVFolderOnMessageCommand extends Command {
045:
046:            /** JDK 1.4+ logging framework logger, used for logging. */
047:            private static final Logger LOG = Logger
048:                    .getLogger("org.columba.mail.folder.command");
049:
050:            /** Used for creating a virtual folder based on Subject */
051:            public static final String VFOLDER_ON_SUBJECT = "Subject";
052:
053:            /** Used for creating a virtual folder based on From */
054:            public static final String VFOLDER_ON_FROM = "From";
055:
056:            /** Used for creating a virtual folder based on To */
057:            public static final String VFOLDER_ON_TO = "To";
058:
059:            /** Type of virtual folder to create (Subject/From/To) */
060:            private String vfolderType;
061:
062:            /** Parent for the virtual folder */
063:            private IMailbox parentFolder = null;
064:
065:            /** Virtual folder created created */
066:            private VirtualFolder vfolder = null;
067:
068:            private IFrameMediator mediator;
069:
070:            /**
071:             * Constructor for CreateVFolderOnMessageCommand. Calls super constructor
072:             * and saves flag for which kind of virtual folder to create. Default for
073:             * filter type is FILTER_ON_SUBJECT.
074:             *
075:             * @param frameMediator
076:             * @param references
077:             * @param vfolderType
078:             *            Which type of filter to create. Used defined constants
079:             */
080:            public CreateVFolderOnMessageCommand(
081:                    IFrameMediator frameController,
082:                    ICommandReference reference, String vfolderType) {
083:                super (reference);
084:                this .vfolderType = vfolderType;
085:                this .mediator = frameController;
086:            }
087:
088:            /**
089:             * Displays search dialog for user modifications after creation of the
090:             * virtual folder in execute. Also refreshes the tree view.
091:             *
092:             * @see org.columba.api.command.Command#updateGUI()
093:             */
094:            public void updateGUI() throws Exception {
095:                FolderTreeModel.getInstance()
096:                        .nodeStructureChanged(parentFolder);
097:
098:                if (vfolder != null) {
099:                    //vfolder.showFilterDialog((AbstractMailFrameController) getFrameMediator());
100:                    new ConfigFrame(mediator, vfolder);
101:                }
102:            }
103:
104:            /**
105:             * This method generates a virtual folder based on Subject, From or To
106:             * (depending on parameter transferred to constructor) of the currently
107:             * selected message.
108:             *
109:             * @param worker
110:             * @see org.columba.api.command.Command#execute(Worker)
111:             */
112:            public void execute(IWorkerStatusController worker)
113:                    throws Exception {
114:                // get references to selected folder and message
115:                IMailFolderCommandReference r = (IMailFolderCommandReference) getReference();
116:                Object[] uids = r.getUids(); // uid for messages to save
117:
118:                if (uids.length == 0) {
119:                    LOG
120:                            .fine("No virtual folder created since no message was selected");
121:
122:                    return; // no message selected.
123:                }
124:
125:                Object uid = uids[0];
126:                parentFolder = (IMailbox) r.getSourceFolder();
127:
128:                //register for status events
129:                ((StatusObservableImpl) parentFolder.getObservable())
130:                        .setWorker(worker);
131:
132:                // get value of Subject, From or To header
133:                Header header = parentFolder.getHeaderFields(uid, new String[] {
134:                        "Subject", "From", "To" });
135:                String headerValue = (String) header.get(vfolderType);
136:
137:                if (headerValue == null) {
138:                    LOG.warning("Error getting " + vfolderType
139:                            + " header. No virtual folder created");
140:
141:                    return;
142:                }
143:
144:                // create virtual folder (is attached to parentFolder)
145:                String name = vfolderType + " contains [" + headerValue + "]";
146:                vfolder = createVirtualFolder(name, vfolderType, headerValue,
147:                        parentFolder);
148:            }
149:
150:            /**
151:             * Private utility for creating a virtual folder on a given headerfield.
152:             * The criteria used is "contains".
153:             *
154:             * @param folderName
155:             *            Name of virtual folder
156:             * @param headerField
157:             *            The header field to base virtual folder on
158:             * @param pattern
159:             *            The pattern to use in the virtual folder
160:             * @param parent
161:             *            Parent folder
162:             * @return The filter created
163:             */
164:            public VirtualFolder createVirtualFolder(String folderName,
165:                    String headerField, String pattern, IMailbox parent) {
166:                // create virtual folder
167:                VirtualFolder vfolder;
168:
169:                try {
170:                    vfolder = (VirtualFolder) FolderFactory.getInstance()
171:                            .createChild(parent, folderName, "VirtualFolder");
172:                } catch (Exception e) {
173:                    LOG.warning("Error creating new virtual folder: "
174:                            + e.getMessage());
175:
176:                    return null;
177:                }
178:
179:                // set properties for virtual folder
180:                String parentUid = "101"; // default is inbox if parent is null
181:
182:                if (parent != null) {
183:                    parentUid = parent.getId();
184:                }
185:
186:                vfolder.getConfiguration().setString("property", "source_uid",
187:                        parentUid);
188:                vfolder.getConfiguration().setBoolean("property",
189:                        "include_subfolders", false);
190:
191:                // define filter rule
192:                IFilterRule rule = vfolder.getFilter().getFilterRule();
193:                rule.setCondition("matchall");
194:                rule.removeAll();
195:                rule.addEmptyCriteria();
196:
197:                // define criteria
198:                MailFilterCriteria c = new MailFilterCriteria(rule.get(0));
199:                c.setCriteriaString("contains");
200:                c.setHeaderfieldString(headerField);
201:                c.setTypeString(headerField);
202:                c.setPatternString(pattern);
203:
204:                return vfolder;
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.