KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folderoptions > AbstractFolderOptionsPlugin


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.folderoptions;
17
18 import org.columba.api.plugin.IExtensionInterface;
19 import org.columba.core.xml.XmlElement;
20 import org.columba.mail.config.FolderItem;
21 import org.columba.mail.folder.IMailbox;
22 import org.columba.mail.gui.frame.MailFrameMediator;
23
24 /**
25  * AbstractMessageFolder options plugin abstract class.
26  * <p>
27  * Plugins implementing this abstract class can load/save their configuration
28  * data. They don't need to take care if this data is applied globally or on a
29  * per-folder basis.
30  * <p>
31  * The most interest methods which you need to implement are:
32  * <ul>
33  * <li>createDefaultElement(boolean)</li>
34  * <li>loadOptionsFromXml(AbstractMessageFolder)</li>
35  * <li>saveOptionsToXml(AbstractMessageFolder)</li>
36  * </ul>
37  * <p>
38  * Note, that every {@link MailFrameMediator} keeps its own
39  * {@link FolderOptionsController}, which makes sure that all plugins are
40  * singletons.
41  *
42  * @author fdietz
43  */

44 public abstract class AbstractFolderOptionsPlugin implements IExtensionInterface {
45     /**
46      * mail frame mediator
47      */

48     private MailFrameMediator mediator;
49
50     /**
51      * name of configuration node
52      */

53     private String JavaDoc name;
54
55     /**
56      * Constructor
57      *
58      * TODO (@author fdietz): pluginID is never used locally
59      * @param name
60      * name of plugin
61      * @param pluginId
62      * id of plugin used by plugin handler
63      * @param mediator
64      * mail frame mediator
65      */

66     public AbstractFolderOptionsPlugin(String JavaDoc name, String JavaDoc pluginId,
67             MailFrameMediator mediator) {
68         this.name = name;
69         this.mediator = mediator;
70     }
71
72     /**
73      * Save configuration of this plugin.
74      * <p>
75      *
76      * Following a simple example of a toolbar configuration:<br>
77      *
78      * <pre>
79      *
80      *
81      * &lt;toolbar enabled=&quot;true&quot; show_icon=&quot;true&quot; show_text=&quot;false&quot;&gt;
82      * &lt;button name=&quot;Cut&quot;/&gt;
83      * &lt;button name=&quot;Copy&quot;/&gt;
84      * &lt;button name=&quot;Paste&quot;/&gt;
85      * &lt;button name=&quot;Delete&quot;/&gt;
86      * &lt;/toolbar&gt;
87      *
88      *
89      * </pre>
90      *
91      * @param folder
92      * selected folder
93      */

94     public abstract void saveOptionsToXml(IMailbox folder);
95
96     /**
97      * Load options of this plugin.
98      *
99      * @param folder
100      * selected folder
101      */

102     public abstract void loadOptionsFromXml(IMailbox folder);
103
104     /**
105      * Get frame mediator
106      *
107      * @return frame mediator
108      */

109     public MailFrameMediator getMediator() {
110         return mediator;
111     }
112
113     /**
114      * Get configuration node.
115      * <p>
116      * Determine if this should be applied globally or on a per-folder basis.
117      * <p>
118      * This way, plugins don't have to know, if they work on global or local
119      * options.
120      * <p>
121      * Example for the sorting plugin configuration node. This is how it can be
122      * found in options.xml and tree.xml:<br>
123      *
124      * <pre>
125      *
126      *
127      * &lt;sorting column=&quot;Date&quot; order=&quot;true&quot; /&gt;
128      *
129      *
130      * </pre>
131      *
132      * @param folder
133      * currently selected folder
134      * @return xml node
135      */

136     public XmlElement getConfigNode(IMailbox folder) {
137         // global option
138
if (folder == null) {
139             XmlElement result = FolderItem.getGlobalOptions().getElement(getName());
140             if( result == null ) {
141                 return createDefaultElement(true);
142             } else {
143                 return result;
144             }
145         }
146
147         // use folder specific options
148
XmlElement parent = folder.getConfiguration().getFolderOptions();
149
150         XmlElement child = parent.getElement(getName());
151
152         // create element if not available
153
if (child == null) {
154             child = createDefaultElement(false);
155             parent.addElement(child);
156         }
157
158         // check if this folder is overwriting global options
159
if (child.getAttribute("overwrite").equals("true")) {
160             // use folder-based options
161
return child;
162         } else {
163             // use global options
164
parent = FolderItem.getGlobalOptions();
165             child = parent.getElement(getName());
166
167             if (child == null) {
168                 child = createDefaultElement(true);
169                 parent.addElement(child);
170             }
171
172             return child;
173         }
174     }
175
176     /**
177      * Create default node.
178      * <p>
179      * Overwrite this method to add plugin-specific information to the parent
180      * node.
181      * <p>
182      *
183      * @param global
184      * true, if this is a global options. False, otherwise
185      *
186      * @return xml node
187      */

188     public XmlElement createDefaultElement(boolean global) {
189         XmlElement parent = new XmlElement(getName());
190
191         // only local options have overwrite attribute
192
if (!global) {
193             parent.addAttribute("overwrite", "false");
194         }
195
196         return parent;
197     }
198
199     /**
200      * Get name of configuration node
201      *
202      * @return config name
203      */

204     public String JavaDoc getName() {
205         return name;
206     }
207 }
208
Popular Tags