KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
29  * Handles sorting state, including sorting order, which can
30  * be ascending or descending and the actual column.
31  *
32  * @author fdietz
33  */

34 public class SortingOptionsPlugin extends AbstractFolderOptionsPlugin {
35     /**
36  * Constructor
37  *
38  * @param mediator mail framemediator
39  */

40     public SortingOptionsPlugin(MailFrameMediator mediator) {
41         super("sorting", "SortingOptions", mediator);
42     }
43
44     /**
45  * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#loadOptionsFromXml(IMailbox)
46  */

47     public void loadOptionsFromXml(IMailbox folder) {
48         XmlElement sorting = getConfigNode(folder);
49         IDefaultItem item = new DefaultItem(sorting);
50
51         String JavaDoc column = item.get("column");
52
53         if (column == null) {
54             column = "Date";
55         }
56
57         boolean order = item.getBooleanWithDefault("order", true);
58
59         ITableController tableController = ((ITableController)((TableViewOwner) getMediator()).getTableController());
60
61         tableController.setSortingColumn(column);
62         tableController.setSortingOrder(order);
63
64         // notify observers (sorting state submenu)
65
((SortingStateObservable)tableController.getSortingStateObservable())
66                        .setSortingState(column, order);
67     }
68
69     /**
70  * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#saveOptionsToXml()
71  */

72     public void saveOptionsToXml(IMailbox folder) {
73         XmlElement sorting = getConfigNode(folder);
74         ITableController tableController =((ITableController)((TableViewOwner) getMediator()).getTableController());
75
76         String JavaDoc column = tableController.getSortingColumn();
77         boolean order = tableController.getSortingOrder();
78
79         sorting.addAttribute("column", column);
80         sorting.addAttribute("order", Boolean.toString(order));
81     }
82
83     /**
84  * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#createDefaultElement()
85  */

86     public XmlElement createDefaultElement(boolean global) {
87         XmlElement sorting = super.createDefaultElement(global);
88         sorting.addAttribute("column", "Date");
89         sorting.addAttribute("order", "true");
90
91         return sorting;
92     }
93 }
94
Popular Tags