KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > filter > plugins > AccountCriteriaRow


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.gui.config.filter.plugins;
17
18 import javax.swing.ComboBoxModel JavaDoc;
19 import javax.swing.JComboBox JavaDoc;
20
21 import org.columba.api.plugin.IExtensionHandler;
22 import org.columba.core.filter.FilterCriteria;
23 import org.columba.mail.config.AccountItem;
24 import org.columba.mail.config.AccountList;
25 import org.columba.mail.config.MailConfig;
26 import org.columba.mail.gui.config.filter.CriteriaList;
27
28
29 /**
30  * @author Erik Mattsson
31  */

32 public class AccountCriteriaRow extends DefaultCriteriaRow {
33     private JComboBox JavaDoc accountComboBox;
34     private JComboBox JavaDoc matchComboBox;
35
36     /**
37      * @param pluginHandler the plugin handler
38      * @param criteriaList the list containing criterias.
39      * @param c the criteria for this filter.
40      */

41     public AccountCriteriaRow(IExtensionHandler pluginHandler,
42         CriteriaList criteriaList, FilterCriteria c) {
43         super(pluginHandler, criteriaList, c);
44     }
45
46     /** {@inheritDoc} */
47     public void initComponents() {
48         super.initComponents();
49
50         matchComboBox = new JComboBox JavaDoc();
51         matchComboBox.addItem("is");
52         matchComboBox.addItem("is not");
53
54         accountComboBox = new JComboBox JavaDoc();
55
56         AccountList accountList = MailConfig.getInstance().getAccountList();
57         int size = accountList.count();
58
59         for (int i = 0; i < size; i++) {
60             accountComboBox.addItem(new AccountComboBoxItem(accountList.get(i)));
61         }
62
63         addComponent(matchComboBox);
64         addComponent(accountComboBox);
65     }
66
67     /** {@inheritDoc} */
68     public void updateComponents(boolean b) {
69         super.updateComponents(b);
70
71         if (b) {
72             matchComboBox.setSelectedItem(criteria.getCriteriaString());
73
74             int criteriaAccountUid = criteria.getIntegerWithDefault("account.uid", -1);
75
76             if (criteriaAccountUid != -1) {
77                 ComboBoxModel JavaDoc model = accountComboBox.getModel();
78
79                 for (int i = 0; i < model.getSize(); i++) {
80                     AccountComboBoxItem item = (AccountComboBoxItem) model.getElementAt(i);
81
82                     if (item.getAccountID() == criteriaAccountUid) {
83                         accountComboBox.setSelectedIndex(i);
84
85                         break;
86                     }
87                 }
88             }
89         } else {
90             criteria.setCriteriaString((String JavaDoc) matchComboBox.getSelectedItem());
91
92             AccountComboBoxItem item = (AccountComboBoxItem) accountComboBox.getSelectedItem();
93             criteria.setInteger("account.uid", item.getAccountID());
94         }
95     }
96
97     /**
98      * Combobox item for an account item.
99      * @author redsolo
100      */

101     private class AccountComboBoxItem {
102         private AccountItem accountItem;
103
104         /**
105          * Creates a combobox item that wraps the specified account item.
106          * @param item the item.
107          */

108         public AccountComboBoxItem(AccountItem item) {
109             accountItem = item;
110         }
111
112         /** {@inheritDoc} */
113         public String JavaDoc toString() {
114             return accountItem.getName();
115         }
116
117         /**
118          * Returns the Account's UID.
119          * @return the Account's UID.
120          */

121         public int getAccountID() {
122             return accountItem.getUid();
123         }
124     }
125 }
126
Popular Tags