01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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.columa.core.config.IDefaultItem;
19: import org.columba.core.config.DefaultItem;
20: import org.columba.core.xml.XmlElement;
21: import org.columba.mail.folder.IMailbox;
22: import org.columba.mail.gui.frame.MailFrameMediator;
23: import org.columba.mail.gui.frame.TableViewOwner;
24: import org.columba.mail.gui.table.ITableController;
25: import org.columba.mail.gui.table.SortingStateObservable;
26:
27: /**
28: * Handles sorting state, including sorting order, which can
29: * be ascending or descending and the actual column.
30: *
31: * @author fdietz
32: */
33: public class SortingOptionsPlugin extends AbstractFolderOptionsPlugin {
34: /**
35: * Constructor
36: *
37: * @param mediator mail framemediator
38: */
39: public SortingOptionsPlugin(MailFrameMediator mediator) {
40: super ("sorting", "SortingOptions", mediator);
41: }
42:
43: /**
44: * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#loadOptionsFromXml(IMailbox)
45: */
46: public void loadOptionsFromXml(IMailbox folder) {
47: XmlElement sorting = getConfigNode(folder);
48: IDefaultItem item = new DefaultItem(sorting);
49:
50: String column = item.get("column");
51:
52: if (column == null) {
53: column = "Date";
54: }
55:
56: boolean order = item.getBooleanWithDefault("order", true);
57:
58: ITableController tableController = ((ITableController) ((TableViewOwner) getMediator())
59: .getTableController());
60:
61: tableController.setSortingColumn(column);
62: tableController.setSortingOrder(order);
63:
64: // notify observers (sorting state submenu)
65: ((SortingStateObservable) tableController
66: .getSortingStateObservable()).setSortingState(column,
67: order);
68: }
69:
70: /**
71: * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#saveOptionsToXml()
72: */
73: public void saveOptionsToXml(IMailbox folder) {
74: XmlElement sorting = getConfigNode(folder);
75: ITableController tableController = ((ITableController) ((TableViewOwner) getMediator())
76: .getTableController());
77:
78: String column = tableController.getSortingColumn();
79: boolean order = tableController.getSortingOrder();
80:
81: sorting.addAttribute("column", column);
82: sorting.addAttribute("order", Boolean.toString(order));
83: }
84:
85: /**
86: * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#createDefaultElement()
87: */
88: public XmlElement createDefaultElement(boolean global) {
89: XmlElement sorting = super .createDefaultElement(global);
90: sorting.addAttribute("column", "Date");
91: sorting.addAttribute("order", "true");
92:
93: return sorting;
94: }
95: }
|