[1009] | 1 | /** |
---|
| 2 | * This class does something. |
---|
| 3 | * @author Diorgenes Felipe Grzesiuk <diorgenes@prognus.com.br> |
---|
| 4 | * @copyright Copyright 2007-2008 Prognus |
---|
| 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License version 2 as published by |
---|
| 8 | * the Free Software Foundation. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with Foobar; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 18 | */ |
---|
| 19 | package br.com.prognus.psync.admin; |
---|
| 20 | |
---|
| 21 | import java.io.Serializable; |
---|
| 22 | import java.util.ArrayList; |
---|
| 23 | import java.util.List; |
---|
| 24 | |
---|
| 25 | import br.com.prognus.psync.engine.source.PIMContactSyncSource; |
---|
| 26 | import br.com.prognus.psync.engine.source.PIMSyncSource; |
---|
| 27 | |
---|
| 28 | import com.funambol.admin.AdminException; |
---|
| 29 | import com.funambol.framework.engine.source.ContentType; |
---|
| 30 | import com.funambol.framework.engine.source.SyncSource; |
---|
| 31 | import com.funambol.framework.engine.source.SyncSourceInfo; |
---|
| 32 | |
---|
| 33 | public class PIMContactSyncSourceConfigPanel extends PIMSyncSourceConfigPanel |
---|
| 34 | implements Serializable { |
---|
| 35 | |
---|
| 36 | // --------------------------------------------------------------- Constants |
---|
| 37 | protected static final String PANEL_NAME = "Edit PIM Contact SyncSource"; |
---|
| 38 | |
---|
| 39 | protected static final String TYPE_LABEL_SIFC = "SIF-C"; |
---|
| 40 | |
---|
| 41 | protected static final String TYPE_LABEL_VCARD = "VCard"; |
---|
| 42 | |
---|
| 43 | protected static final String TYPE_SIFC = "text/x-s4j-sifc"; |
---|
| 44 | |
---|
| 45 | protected static final String TYPE_VCARD = "text/x-vcard"; |
---|
| 46 | |
---|
| 47 | protected static final String VERSION_SIFC = "1.0"; |
---|
| 48 | |
---|
| 49 | protected static final String VERSION_VCARD = "2.1"; |
---|
| 50 | |
---|
| 51 | // ------------------------------------------------------------ Constructors |
---|
| 52 | |
---|
| 53 | /** Creates a new instance of PIMContactSyncSourceConfigPanel. */ |
---|
| 54 | public PIMContactSyncSourceConfigPanel() { |
---|
| 55 | super(); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | // ---------------------------------------------------------- Public methods |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * Updates the form |
---|
| 62 | */ |
---|
| 63 | @Override |
---|
| 64 | public void updateForm() { |
---|
| 65 | |
---|
| 66 | if (!(getSyncSource() instanceof PIMContactSyncSource)) { |
---|
| 67 | notifyError(new AdminException( |
---|
| 68 | "This is not a PIMContactSyncSources! " |
---|
| 69 | + "Unable to process SyncSource values.")); |
---|
| 70 | return; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | super.updateForm(); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // ------------------------------------------------------- Protected methods |
---|
| 77 | |
---|
| 78 | /** |
---|
| 79 | * Returns the panel name |
---|
| 80 | * |
---|
| 81 | * @return the panel name |
---|
| 82 | */ |
---|
| 83 | @Override |
---|
| 84 | protected String getPanelName() { |
---|
| 85 | return PANEL_NAME; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | /** |
---|
| 89 | * Returns the available types |
---|
| 90 | * |
---|
| 91 | * @return the available types; |
---|
| 92 | */ |
---|
| 93 | @Override |
---|
| 94 | protected List getTypes() { |
---|
| 95 | List supportedTypes = new ArrayList(); |
---|
| 96 | supportedTypes.add(TYPE_LABEL_SIFC); |
---|
| 97 | supportedTypes.add(TYPE_LABEL_VCARD); |
---|
| 98 | return supportedTypes; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * Returns the type to select based on the given syncsource |
---|
| 103 | * |
---|
| 104 | * @return the type to select based on the given syncsource |
---|
| 105 | */ |
---|
| 106 | @Override |
---|
| 107 | protected String getTypeToSelect(SyncSource syncSource) { |
---|
| 108 | String preferredType = null; |
---|
| 109 | if (syncSource.getInfo() != null |
---|
| 110 | && syncSource.getInfo().getPreferredType() != null) { |
---|
| 111 | |
---|
| 112 | preferredType = syncSource.getInfo().getPreferredType().getType(); |
---|
| 113 | if (TYPE_VCARD.equals(preferredType)) { |
---|
| 114 | return TYPE_LABEL_VCARD; |
---|
| 115 | } |
---|
| 116 | if (TYPE_SIFC.equals(preferredType)) { |
---|
| 117 | return TYPE_LABEL_SIFC; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | return null; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | /** |
---|
| 124 | * Sets the source info of the given syncsource based on the given |
---|
| 125 | * selectedType |
---|
| 126 | */ |
---|
| 127 | @Override |
---|
| 128 | public void setSyncSourceInfo(SyncSource syncSource, String selectedType) { |
---|
| 129 | PIMSyncSource pimSource = (PIMSyncSource) syncSource; |
---|
| 130 | ContentType[] contentTypes = null; |
---|
| 131 | if (TYPE_LABEL_SIFC.equals(selectedType)) { |
---|
| 132 | contentTypes = new ContentType[1]; |
---|
| 133 | contentTypes[0] = new ContentType(TYPE_SIFC, VERSION_SIFC); |
---|
| 134 | } else if (TYPE_LABEL_VCARD.equals(selectedType)) { |
---|
| 135 | contentTypes = new ContentType[1]; |
---|
| 136 | contentTypes[0] = new ContentType(TYPE_VCARD, VERSION_VCARD); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | pimSource.setInfo(new SyncSourceInfo(contentTypes, 0)); |
---|
| 140 | } |
---|
| 141 | // --------------------------------------------------------- Private methods |
---|
| 142 | |
---|
| 143 | } |
---|