1 package net.suberic.pooka.gui.propedit; 2 import java.util.*; 3 import net.suberic.pooka.*; 4 import net.suberic.util.gui.propedit.*; 5 import net.suberic.util.VariableBundle; 6 7 10 public class AddressEntryController extends WizardController { 11 12 AddressBook mBook; 13 AddressBookEntry mEntry = null; 14 String mOriginalEntryName = null; 15 16 19 public AddressEntryController(String sourceTemplate, WizardEditorPane wep) { 20 super(sourceTemplate, wep); 21 } 22 23 26 protected void saveProperties() throws PropertyValueVetoException { 27 String name = getManager().getCurrentProperty("AddressBook.editor.addressList._newAddress.personalName", ""); 29 if (mOriginalEntryName == null || ! name.equalsIgnoreCase(mOriginalEntryName)) { 30 if (mBook.getAddressMatcher().matchExactly(name).length > 0) { 31 throw new PropertyValueVetoException("AddressBook.editor.addressList._newAddress.personalName", name, "Address already exists", null); 32 } 33 mEntry = mBook.newAddressBookEntry(); 34 } else { 35 AddressBookEntry[] matches = mBook.getAddressMatcher().matchExactly(name); 36 if (matches != null && matches.length > 0) { 37 mEntry = matches[0]; 38 } else { 39 mEntry = mBook.newAddressBookEntry(); 40 } 41 } 42 43 44 mEntry.setPersonalName(name); 45 mEntry.setFirstName(getManager().getCurrentProperty("AddressBook.editor.addressList._newAddress.firstName", "")); 46 mEntry.setLastName(getManager().getCurrentProperty("AddressBook.editor.addressList._newAddress.lastName", "")); 47 48 49 try { 50 mEntry.setAddress(new javax.mail.internet.InternetAddress (getManager().getCurrentProperty("AddressBook.editor.addressList._newAddress.address", ""))); 51 } catch (Exception e) { 52 throw new PropertyValueVetoException(e.getMessage()); 53 } 54 55 mBook.addAddress(mEntry); 56 57 59 getManager().setProperty("AddressBook.editor.addressList._newAddress.personalName", ""); 60 getManager().setProperty("AddressBook.editor.addressList._newAddress.firstName", ""); 61 getManager().setProperty("AddressBook.editor.addressList._newAddress.lastName", ""); 62 63 getManager().setProperty("AddressBook.editor.addressList._newAddress.address", ""); 64 65 } 66 69 public void finishWizard() throws PropertyValueVetoException { 70 getEditorPane().validateProperty(mState); 71 72 saveProperties(); 73 getEditorPane().getWizardContainer().closeWizard(); 74 } 75 76 public void setUniqueProperty(PropertyEditorUI editor, String originalValue, String propertyName) { 77 String value = originalValue; 78 boolean success = false; 79 for (int i = 0 ; ! success && i < 10; i++) { 80 if (i != 0) { 81 value = originalValue + "_" + i; 82 } 83 try { 84 editor.setOriginalValue(value); 85 editor.resetDefaultValue(); 86 getManager().setTemporaryProperty(propertyName, value); 87 success = true; 88 } catch (PropertyValueVetoException pvve) { 89 } 91 } 92 } 93 94 97 public void loadEntry(AddressBookEntry pEntry) { 98 try { 99 getManager().getPropertyEditor("AddressBook.editor.addressList._newAddress.personalName").setOriginalValue(pEntry.getPersonalName()); 100 getManager().getPropertyEditor("AddressBook.editor.addressList._newAddress.personalName").resetDefaultValue(); 101 getManager().getPropertyEditor("AddressBook.editor.addressList._newAddress.firstName").setOriginalValue(pEntry.getFirstName()); 102 getManager().getPropertyEditor("AddressBook.editor.addressList._newAddress.firstName").resetDefaultValue(); 103 getManager().getPropertyEditor("AddressBook.editor.addressList._newAddress.lastName").setOriginalValue(pEntry.getLastName()); 104 getManager().getPropertyEditor("AddressBook.editor.addressList._newAddress.lastName").resetDefaultValue(); 105 getManager().getPropertyEditor("AddressBook.editor.addressList._newAddress.address").setOriginalValue(pEntry.getAddressString() != null ? pEntry.getAddressString() : ""); 106 getManager().getPropertyEditor("AddressBook.editor.addressList._newAddress.address").resetDefaultValue(); 107 } catch (Exception e) { 108 e.printStackTrace(); 109 } 110 mOriginalEntryName = pEntry.getPersonalName(); 111 } 112 113 116 public void setAddressBook(AddressBook pBook) { 117 mBook = pBook; 118 } 119 120 123 public AddressBookEntry getEntry() { 124 return mEntry; 125 } 126 } 127 | Popular Tags |