Source Code Cross Referenced for FolderOptionsController.java in  » Mail-Clients » columba-1.4 » org » columba » mail » folderoptions » 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.folderoptions 
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.folderoptions;
017:
018:        import java.util.Enumeration;
019:
020:        import org.columba.api.plugin.IExtension;
021:        import org.columba.api.plugin.IExtensionHandler;
022:        import org.columba.api.plugin.PluginException;
023:        import org.columba.api.plugin.PluginHandlerNotFoundException;
024:        import org.columba.core.plugin.PluginManager;
025:        import org.columba.core.xml.XmlElement;
026:        import org.columba.mail.config.FolderItem;
027:        import org.columba.mail.config.IFolderItem;
028:        import org.columba.mail.folder.IMailbox;
029:        import org.columba.mail.gui.frame.MailFrameMediator;
030:        import org.columba.mail.plugin.IExtensionHandlerKeys;
031:
032:        /**
033:         * Controller used by <code>TableController</code> to handle all folder-related
034:         * option plugins.
035:         * <p>
036:         * Note, that every <code>MailFrameMediator</code> keeps its own
037:         * <code>FolderOptionsController<code>, which makes sure that
038:         * all plugins are singletons.
039:         *
040:         * @author fdietz
041:         */
042:        public class FolderOptionsController implements 
043:                IFolderOptionsController {
044:            /**
045:             * Plugins executed before updating the table model
046:             * <p>
047:             * example:<b> Sorting/Filtering state
048:             */
049:            public final static int STATE_BEFORE = 0;
050:
051:            /**
052:             * Plugins executed after updating the table model
053:             * <p>
054:             * example:<br>
055:             * Selection of messages
056:             */
057:            public final static int STATE_AFTER = 1;
058:
059:            /**
060:             * mail frame mediator
061:             */
062:            private MailFrameMediator mediator;
063:
064:            /**
065:             * plugin handler for instanciating folder options plugins
066:             */
067:            private IExtensionHandler handler;
068:
069:            /**
070:             * Constructor
071:             * 
072:             * @param mediator
073:             *            mail frame mediator
074:             */
075:            public FolderOptionsController(MailFrameMediator mediator) {
076:                this .mediator = mediator;
077:
078:                // init plugin handler
079:                try {
080:                    handler = PluginManager
081:                            .getInstance()
082:                            .getExtensionHandler(
083:                                    IExtensionHandlerKeys.ORG_COLUMBA_MAIL_FOLDEROPTIONS);
084:                } catch (PluginHandlerNotFoundException e) {
085:                    // TODO (@author fdietz): show error dialoghere
086:                    e.printStackTrace();
087:                }
088:            }
089:
090:            /**
091:             * Get plugin with specific name.
092:             * 
093:             * @param name
094:             *            name of plugin
095:             * @return instance of plugin
096:             */
097:            public AbstractFolderOptionsPlugin getPlugin(String name) {
098:
099:                AbstractFolderOptionsPlugin plugin = null;
100:
101:                try {
102:                    IExtension extension = handler.getExtension(name);
103:
104:                    plugin = (AbstractFolderOptionsPlugin) extension
105:                            .instanciateExtension(new Object[] { mediator });
106:                } catch (Exception e) {
107:                    // TODO (@author fdietz): add error dialog
108:                    e.printStackTrace();
109:                }
110:
111:                return plugin;
112:
113:            }
114:
115:            /**
116:             * Load all folder options for this folder.
117:             * 
118:             * @param folder
119:             *            selected folder
120:             */
121:            public void load(IMailbox folder, int state) {
122:                // get list of plugins
123:                Enumeration e = handler.getExtensionEnumeration();
124:                while (e.hasMoreElements()) {
125:                    IExtension extension = (IExtension) e.nextElement();
126:                    String stateString = extension.getMetadata().getAttribute(
127:                            "state");
128:                    try {
129:                        AbstractFolderOptionsPlugin plugin = (AbstractFolderOptionsPlugin) extension
130:                                .instanciateExtension(new Object[] { mediator });
131:
132:                        if ((state == STATE_BEFORE)
133:                                && (stateString.equals("before"))) {
134:                            plugin.loadOptionsFromXml(null);
135:                        } else if ((state == STATE_AFTER)
136:                                && (stateString.equals("after"))) {
137:                            plugin.loadOptionsFromXml(folder);
138:                        }
139:                    } catch (PluginException e1) {
140:                        e1.printStackTrace();
141:                    }
142:
143:                }
144:            }
145:
146:            /**
147:             * Save all folder options for this folder.
148:             * 
149:             * @param folder
150:             *            selected folder
151:             */
152:            public void save(IMailbox folder) {
153:                // get list of plugins
154:                String[] ids = handler.getPluginIdList();
155:
156:                for (int i = 0; i < ids.length; i++) {
157:                    AbstractFolderOptionsPlugin plugin = getPlugin(ids[i]);
158:                    plugin.saveOptionsToXml(folder);
159:                }
160:            }
161:
162:            /**
163:             * Load all folder options globally.
164:             * 
165:             */
166:            public void load(int state) {
167:                // get list of plugins
168:                Enumeration e = handler.getExtensionEnumeration();
169:                while (e.hasMoreElements()) {
170:                    IExtension extension = (IExtension) e.nextElement();
171:                    String stateString = extension.getMetadata().getAttribute(
172:                            "state");
173:                    try {
174:                        AbstractFolderOptionsPlugin plugin = (AbstractFolderOptionsPlugin) extension
175:                                .instanciateExtension(new Object[] { mediator });
176:
177:                        if ((state == STATE_BEFORE)
178:                                && (stateString.equals("before"))) {
179:                            plugin.loadOptionsFromXml(null);
180:                        } else if ((state == STATE_AFTER)
181:                                && (stateString.equals("after"))) {
182:                            plugin.loadOptionsFromXml(null);
183:                        }
184:                    } catch (Exception e1) {
185:                        // TODO (@author fdietz): add error dialog
186:                        e1.printStackTrace();
187:                    }
188:                }
189:            }
190:
191:            /**
192:             * Get parent configuration node of plugin.
193:             * <p>
194:             * Example for the sorting plugin configuration node. This is how it can be
195:             * found in options.xml and tree.xml:<br>
196:             * 
197:             * <pre>
198:             *         
199:             *          
200:             *            &lt;sorting column=&quot;Date&quot; order=&quot;true&quot; /&gt;
201:             *           
202:             *          
203:             * </pre>
204:             * 
205:             * <p>
206:             * 
207:             * @param folder
208:             *            selected folder
209:             * @param name
210:             *            name of plugin (example: ColumnOptions)
211:             * @return parent configuration node
212:             */
213:            public XmlElement getConfigNode(IMailbox folder, String name) {
214:                XmlElement parent = null;
215:                boolean global = false;
216:
217:                if ((folder == null) || (name == null)) {
218:                    // if no folder was passed as argument, use global options
219:                    parent = FolderItem.getGlobalOptions();
220:                    global = true;
221:                } else {
222:                    // use folder specific options
223:                    parent = folder.getConfiguration().getFolderOptions();
224:                    global = false;
225:                }
226:
227:                // load plugin
228:                AbstractFolderOptionsPlugin plugin = getPlugin(name);
229:                XmlElement child = parent.getElement(plugin.getName());
230:
231:                if (child == null) {
232:                    // create default configuration
233:                    child = plugin.createDefaultElement(global);
234:                    parent.addElement(child);
235:                }
236:
237:                if (global) {
238:                    return child;
239:                }
240:
241:                String overwrite = child.getAttribute("overwrite");
242:
243:                // check if this folder is overwriting global options
244:                if ((overwrite != null) && (overwrite.equals("true"))) {
245:                    // use folder-based options
246:                    return child;
247:                } else {
248:                    // use global options
249:                    parent = FolderItem.getGlobalOptions();
250:                    child = parent.getElement(plugin.getName());
251:
252:                    return child;
253:                }
254:            }
255:
256:            /**
257:             * Create default settings for this folder.
258:             * 
259:             * @param folder
260:             *            selected folder
261:             */
262:            public void createDefaultSettings(IMailbox folder) {
263:                IFolderItem item = folder.getConfiguration();
264:                XmlElement parent = item.getElement("property");
265:
266:                // use global settings
267:                String[] ids = handler.getPluginIdList();
268:
269:                for (int i = 0; i < ids.length; i++) {
270:                    AbstractFolderOptionsPlugin plugin = getPlugin(ids[i]);
271:                    XmlElement child = plugin.createDefaultElement(false);
272:                    parent.addElement(child);
273:                }
274:            }
275:
276:            /**
277:             * Save global settings.
278:             * <p>
279:             * Method is called when shutting down Columba. Note, that when a folder is
280:             * selected which overwrites options, only his options are saved.
281:             * 
282:             * @param folder
283:             *            selected folder
284:             */
285:            /*
286:             * public void saveGlobalSettings(AbstractFolder folder) { if (folder
287:             * instanceof AbstractMessageFolder) { if
288:             * (isOverwritingDefaults((AbstractMessageFolder) folder)) {
289:             * 
290:             * save((AbstractMessageFolder)folder); } else { save(null); } } }
291:             */
292:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.