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.gui.config.filter.plugins;
017:
018: import javax.swing.ComboBoxModel;
019: import javax.swing.JComboBox;
020:
021: import org.columba.api.plugin.IExtensionHandler;
022: import org.columba.core.filter.FilterCriteria;
023: import org.columba.mail.config.AccountItem;
024: import org.columba.mail.config.AccountList;
025: import org.columba.mail.config.MailConfig;
026: import org.columba.mail.gui.config.filter.CriteriaList;
027:
028: /**
029: * @author Erik Mattsson
030: */
031: public class AccountCriteriaRow extends DefaultCriteriaRow {
032: private JComboBox accountComboBox;
033: private JComboBox matchComboBox;
034:
035: /**
036: * @param pluginHandler the plugin handler
037: * @param criteriaList the list containing criterias.
038: * @param c the criteria for this filter.
039: */
040: public AccountCriteriaRow(IExtensionHandler pluginHandler,
041: CriteriaList criteriaList, FilterCriteria c) {
042: super (pluginHandler, criteriaList, c);
043: }
044:
045: /** {@inheritDoc} */
046: public void initComponents() {
047: super .initComponents();
048:
049: matchComboBox = new JComboBox();
050: matchComboBox.addItem("is");
051: matchComboBox.addItem("is not");
052:
053: accountComboBox = new JComboBox();
054:
055: AccountList accountList = MailConfig.getInstance()
056: .getAccountList();
057: int size = accountList.count();
058:
059: for (int i = 0; i < size; i++) {
060: accountComboBox.addItem(new AccountComboBoxItem(accountList
061: .get(i)));
062: }
063:
064: addComponent(matchComboBox);
065: addComponent(accountComboBox);
066: }
067:
068: /** {@inheritDoc} */
069: public void updateComponents(boolean b) {
070: super .updateComponents(b);
071:
072: if (b) {
073: matchComboBox.setSelectedItem(criteria.getCriteriaString());
074:
075: int criteriaAccountUid = criteria.getIntegerWithDefault(
076: "account.uid", -1);
077:
078: if (criteriaAccountUid != -1) {
079: ComboBoxModel model = accountComboBox.getModel();
080:
081: for (int i = 0; i < model.getSize(); i++) {
082: AccountComboBoxItem item = (AccountComboBoxItem) model
083: .getElementAt(i);
084:
085: if (item.getAccountID() == criteriaAccountUid) {
086: accountComboBox.setSelectedIndex(i);
087:
088: break;
089: }
090: }
091: }
092: } else {
093: criteria.setCriteriaString((String) matchComboBox
094: .getSelectedItem());
095:
096: AccountComboBoxItem item = (AccountComboBoxItem) accountComboBox
097: .getSelectedItem();
098: criteria.setInteger("account.uid", item.getAccountID());
099: }
100: }
101:
102: /**
103: * Combobox item for an account item.
104: * @author redsolo
105: */
106: private class AccountComboBoxItem {
107: private AccountItem accountItem;
108:
109: /**
110: * Creates a combobox item that wraps the specified account item.
111: * @param item the item.
112: */
113: public AccountComboBoxItem(AccountItem item) {
114: accountItem = item;
115: }
116:
117: /** {@inheritDoc} */
118: public String toString() {
119: return accountItem.getName();
120: }
121:
122: /**
123: * Returns the Account's UID.
124: * @return the Account's UID.
125: */
126: public int getAccountID() {
127: return accountItem.getUid();
128: }
129: }
130: }
|