/** * This class does something. * @author Diorgenes Felipe Grzesiuk * @copyright Copyright 2007-2008 Prognus * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Foobar; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package br.com.prognus.psync.admin; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import br.com.prognus.psync.engine.source.PIMContactSyncSource; import br.com.prognus.psync.engine.source.PIMSyncSource; import com.funambol.admin.AdminException; import com.funambol.framework.engine.source.ContentType; import com.funambol.framework.engine.source.SyncSource; import com.funambol.framework.engine.source.SyncSourceInfo; public class PIMContactSyncSourceConfigPanel extends PIMSyncSourceConfigPanel implements Serializable { // --------------------------------------------------------------- Constants protected static final String PANEL_NAME = "Edit PIM Contact SyncSource"; protected static final String TYPE_LABEL_SIFC = "SIF-C"; protected static final String TYPE_LABEL_VCARD = "VCard"; protected static final String TYPE_SIFC = "text/x-s4j-sifc"; protected static final String TYPE_VCARD = "text/x-vcard"; protected static final String VERSION_SIFC = "1.0"; protected static final String VERSION_VCARD = "2.1"; // ------------------------------------------------------------ Constructors /** Creates a new instance of PIMContactSyncSourceConfigPanel. */ public PIMContactSyncSourceConfigPanel() { super(); } // ---------------------------------------------------------- Public methods /** * Updates the form */ @Override public void updateForm() { if (!(getSyncSource() instanceof PIMContactSyncSource)) { notifyError(new AdminException( "This is not a PIMContactSyncSources! " + "Unable to process SyncSource values.")); return; } super.updateForm(); } // ------------------------------------------------------- Protected methods /** * Returns the panel name * * @return the panel name */ @Override protected String getPanelName() { return PANEL_NAME; } /** * Returns the available types * * @return the available types; */ @Override protected List getTypes() { List supportedTypes = new ArrayList(); supportedTypes.add(TYPE_LABEL_SIFC); supportedTypes.add(TYPE_LABEL_VCARD); return supportedTypes; } /** * Returns the type to select based on the given syncsource * * @return the type to select based on the given syncsource */ @Override protected String getTypeToSelect(SyncSource syncSource) { String preferredType = null; if (syncSource.getInfo() != null && syncSource.getInfo().getPreferredType() != null) { preferredType = syncSource.getInfo().getPreferredType().getType(); if (TYPE_VCARD.equals(preferredType)) { return TYPE_LABEL_VCARD; } if (TYPE_SIFC.equals(preferredType)) { return TYPE_LABEL_SIFC; } } return null; } /** * Sets the source info of the given syncsource based on the given * selectedType */ @Override public void setSyncSourceInfo(SyncSource syncSource, String selectedType) { PIMSyncSource pimSource = (PIMSyncSource) syncSource; ContentType[] contentTypes = null; if (TYPE_LABEL_SIFC.equals(selectedType)) { contentTypes = new ContentType[1]; contentTypes[0] = new ContentType(TYPE_SIFC, VERSION_SIFC); } else if (TYPE_LABEL_VCARD.equals(selectedType)) { contentTypes = new ContentType[1]; contentTypes[0] = new ContentType(TYPE_VCARD, VERSION_VCARD); } pimSource.setInfo(new SyncSourceInfo(contentTypes, 0)); } // --------------------------------------------------------- Private methods }