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 org.columba.api.plugin.IExtensionInterface;
019: import org.columba.core.xml.XmlElement;
020: import org.columba.mail.config.FolderItem;
021: import org.columba.mail.folder.IMailbox;
022: import org.columba.mail.gui.frame.MailFrameMediator;
023:
024: /**
025: * AbstractMessageFolder options plugin abstract class.
026: * <p>
027: * Plugins implementing this abstract class can load/save their configuration
028: * data. They don't need to take care if this data is applied globally or on a
029: * per-folder basis.
030: * <p>
031: * The most interest methods which you need to implement are:
032: * <ul>
033: * <li>createDefaultElement(boolean)</li>
034: * <li>loadOptionsFromXml(AbstractMessageFolder)</li>
035: * <li>saveOptionsToXml(AbstractMessageFolder)</li>
036: * </ul>
037: * <p>
038: * Note, that every {@link MailFrameMediator} keeps its own
039: * {@link FolderOptionsController}, which makes sure that all plugins are
040: * singletons.
041: *
042: * @author fdietz
043: */
044: public abstract class AbstractFolderOptionsPlugin implements
045: IExtensionInterface {
046: /**
047: * mail frame mediator
048: */
049: private MailFrameMediator mediator;
050:
051: /**
052: * name of configuration node
053: */
054: private String name;
055:
056: /**
057: * Constructor
058: *
059: * TODO (@author fdietz): pluginID is never used locally
060: * @param name
061: * name of plugin
062: * @param pluginId
063: * id of plugin used by plugin handler
064: * @param mediator
065: * mail frame mediator
066: */
067: public AbstractFolderOptionsPlugin(String name, String pluginId,
068: MailFrameMediator mediator) {
069: this .name = name;
070: this .mediator = mediator;
071: }
072:
073: /**
074: * Save configuration of this plugin.
075: * <p>
076: *
077: * Following a simple example of a toolbar configuration:<br>
078: *
079: * <pre>
080: *
081: *
082: * <toolbar enabled="true" show_icon="true" show_text="false">
083: * <button name="Cut"/>
084: * <button name="Copy"/>
085: * <button name="Paste"/>
086: * <button name="Delete"/>
087: * </toolbar>
088: *
089: *
090: * </pre>
091: *
092: * @param folder
093: * selected folder
094: */
095: public abstract void saveOptionsToXml(IMailbox folder);
096:
097: /**
098: * Load options of this plugin.
099: *
100: * @param folder
101: * selected folder
102: */
103: public abstract void loadOptionsFromXml(IMailbox folder);
104:
105: /**
106: * Get frame mediator
107: *
108: * @return frame mediator
109: */
110: public MailFrameMediator getMediator() {
111: return mediator;
112: }
113:
114: /**
115: * Get configuration node.
116: * <p>
117: * Determine if this should be applied globally or on a per-folder basis.
118: * <p>
119: * This way, plugins don't have to know, if they work on global or local
120: * options.
121: * <p>
122: * Example for the sorting plugin configuration node. This is how it can be
123: * found in options.xml and tree.xml:<br>
124: *
125: * <pre>
126: *
127: *
128: * <sorting column="Date" order="true" />
129: *
130: *
131: * </pre>
132: *
133: * @param folder
134: * currently selected folder
135: * @return xml node
136: */
137: public XmlElement getConfigNode(IMailbox folder) {
138: // global option
139: if (folder == null) {
140: XmlElement result = FolderItem.getGlobalOptions()
141: .getElement(getName());
142: if (result == null) {
143: return createDefaultElement(true);
144: } else {
145: return result;
146: }
147: }
148:
149: // use folder specific options
150: XmlElement parent = folder.getConfiguration()
151: .getFolderOptions();
152:
153: XmlElement child = parent.getElement(getName());
154:
155: // create element if not available
156: if (child == null) {
157: child = createDefaultElement(false);
158: parent.addElement(child);
159: }
160:
161: // check if this folder is overwriting global options
162: if (child.getAttribute("overwrite").equals("true")) {
163: // use folder-based options
164: return child;
165: } else {
166: // use global options
167: parent = FolderItem.getGlobalOptions();
168: child = parent.getElement(getName());
169:
170: if (child == null) {
171: child = createDefaultElement(true);
172: parent.addElement(child);
173: }
174:
175: return child;
176: }
177: }
178:
179: /**
180: * Create default node.
181: * <p>
182: * Overwrite this method to add plugin-specific information to the parent
183: * node.
184: * <p>
185: *
186: * @param global
187: * true, if this is a global options. False, otherwise
188: *
189: * @return xml node
190: */
191: public XmlElement createDefaultElement(boolean global) {
192: XmlElement parent = new XmlElement(getName());
193:
194: // only local options have overwrite attribute
195: if (!global) {
196: parent.addAttribute("overwrite", "false");
197: }
198:
199: return parent;
200: }
201:
202: /**
203: * Get name of configuration node
204: *
205: * @return config name
206: */
207: public String getName() {
208: return name;
209: }
210: }
|