1 package org.columba.mail.gui.config.filter.plugins; 17 18 import javax.swing.ComboBoxModel ; 19 import javax.swing.JComboBox ; 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 32 public class AccountCriteriaRow extends DefaultCriteriaRow { 33 private JComboBox accountComboBox; 34 private JComboBox matchComboBox; 35 36 41 public AccountCriteriaRow(IExtensionHandler pluginHandler, 42 CriteriaList criteriaList, FilterCriteria c) { 43 super(pluginHandler, criteriaList, c); 44 } 45 46 47 public void initComponents() { 48 super.initComponents(); 49 50 matchComboBox = new JComboBox (); 51 matchComboBox.addItem("is"); 52 matchComboBox.addItem("is not"); 53 54 accountComboBox = new JComboBox (); 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 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 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 ) matchComboBox.getSelectedItem()); 91 92 AccountComboBoxItem item = (AccountComboBoxItem) accountComboBox.getSelectedItem(); 93 criteria.setInteger("account.uid", item.getAccountID()); 94 } 95 } 96 97 101 private class AccountComboBoxItem { 102 private AccountItem accountItem; 103 104 108 public AccountComboBoxItem(AccountItem item) { 109 accountItem = item; 110 } 111 112 113 public String toString() { 114 return accountItem.getName(); 115 } 116 117 121 public int getAccountID() { 122 return accountItem.getUid(); 123 } 124 } 125 } 126 | Popular Tags |