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 javax.swing.table.TableColumn;
021:
022: import org.columa.core.config.IDefaultItem;
023: import org.columba.core.config.DefaultItem;
024: import org.columba.core.xml.XmlElement;
025: import org.columba.mail.folder.IMailbox;
026: import org.columba.mail.gui.frame.MailFrameMediator;
027: import org.columba.mail.gui.frame.TableViewOwner;
028: import org.columba.mail.gui.table.ITableController;
029:
030: /**
031: * Stores all visible columns of the message list.
032: *
033: * @author fdietz
034: */
035: public class ColumnOptionsPlugin extends AbstractFolderOptionsPlugin {
036: public final static String[] COLUMNS = { "Status", "Attachment",
037: "Flagged", "Priority", "Subject", "From", "Date", "Size",
038: "Spam", "To", "Cc", "MultiLine" };
039:
040: /**
041: * Constructor
042: *
043: * @param mediator
044: * mail frame mediator
045: */
046: public ColumnOptionsPlugin(MailFrameMediator mediator) {
047: super ("columns", "ColumnOptions", mediator);
048: }
049:
050: /**
051: * Get list of available columns.
052: *
053: * @return string array of columns
054: */
055: public static String[] getColumns() {
056: return COLUMNS;
057: }
058:
059: /**
060: * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#saveOptionsToXml(IMailbox)
061: */
062: public void saveOptionsToXml(IMailbox folder) {
063: XmlElement columns = getConfigNode(folder);
064:
065: ITableController tableController = ((ITableController) ((TableViewOwner) getMediator())
066: .getTableController());
067:
068: Enumeration enumeration = tableController.getColumnModel()
069: .getColumns();
070:
071: // check if there are columns which need to be saved
072: if (tableController.getColumnModel().getColumnCount() == 0)
073: return;
074:
075: // remove all child nodes
076: columns.removeAllElements();
077:
078: while (enumeration.hasMoreElements()) {
079: TableColumn tc = (TableColumn) enumeration.nextElement();
080: String name = (String) tc.getHeaderValue();
081:
082: XmlElement column = new XmlElement("column");
083: column.addAttribute("name", name);
084:
085: // save width
086: int size = tc.getWidth();
087: column.addAttribute("width", Integer.toString(size));
088:
089: columns.addElement(column);
090: }
091: }
092:
093: /**
094: * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#loadOptionsFromXml(IMailbox)
095: */
096: public void loadOptionsFromXml(IMailbox folder) {
097: XmlElement columns = getConfigNode(folder);
098:
099: /*
100: * if ( columns.count() == 0) { // no columns specified // -> create new
101: * default columns XmlElement parent = columns.getParent();
102: * columns.removeFromParent(); columns = createDefaultElement(true);
103: * parent.addElement(columns);
104: * }
105: */
106:
107: ITableController tableController = ((ITableController) ((TableViewOwner) getMediator())
108: .getTableController());
109: tableController.resetColumnModel();
110:
111: // add columns
112: for (int i = 0; i < columns.count(); i++) {
113: XmlElement column = columns.getElement(i);
114: IDefaultItem columnItem = new DefaultItem(column);
115:
116: String name = columnItem.get("name");
117: int size = columnItem.getInteger("width");
118:
119: //int position= columnItem.getInteger("position");
120: // add column to table model
121: tableController.getHeaderTableModel().addColumn(name);
122:
123: // add column to JTable column model
124: TableColumn tc = tableController.createTableColumn(name,
125: size);
126:
127: //tc.setModelIndex(position);
128: tc.setModelIndex(i);
129:
130: // resize column width
131: tc.setPreferredWidth(size);
132:
133: tableController.addColumn(tc);
134: }
135:
136: }
137:
138: /**
139: * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#createDefaultElement()
140: */
141: public XmlElement createDefaultElement(boolean global) {
142: XmlElement columns = super .createDefaultElement(global);
143:
144: // these are the items, enabled as default
145: columns.addElement(createColumn("Status", "23"));
146: columns.addElement(createColumn("Attachment", "23"));
147: columns.addElement(createColumn("Flagged", "23"));
148: columns.addElement(createColumn("Priority", "23"));
149: columns.addElement(createColumn("Subject", "200"));
150: columns.addElement(createColumn("From", "150"));
151: columns.addElement(createColumn("Date", "60"));
152: columns.addElement(createColumn("Size", "30"));
153: columns.addElement(createColumn("Spam", "23"));
154:
155: return columns;
156: }
157:
158: /**
159: * Create new XmlElement with custom attributes.
160: *
161: * @param name
162: * name of column
163: * @param width
164: * column width
165: * @param position
166: * column position
167: * @return parent xml element
168: */
169: private static XmlElement createColumn(String name, String width) {
170: XmlElement column = new XmlElement("column");
171: column.addAttribute("name", name);
172: column.addAttribute("width", width);
173:
174: return column;
175: }
176:
177: /*
178: * (non-Javadoc)
179: *
180: * @see org.columba.mail.folderoptions.AbstractFolderOptionsPlugin#restoreUISettings()
181: */
182: public void restoreUISettings() {
183:
184: }
185: }
|