Java tutorial
/*$Id: MuseumOrganizationFormEditor.java 15539 2010-04-20 15:12:46Z jens $*/ /* **************************************************************************** * * * (c) Copyright 2010 ABM-utvikling * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * 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. http://www.gnu.org/licenses/gpl.html * * * **************************************************************************** */ package no.abmu.questionnaire.propertyeditors; import java.beans.PropertyEditorSupport; import no.abmu.questionnaire.domain.types.MuseumOrganizationForm; import no.abmu.util.string.StringUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * MuseumOrganizationFormEditor. * * @author Jens.Vindvad@abm-utvikling.no * @author $Author: jens $ * @version $Rev: 15539 $ * $Date: 2010-04-20 17:12:46 +0200 (Tue, 20 Apr 2010) $ * copyright ABM-Utvikling */ public class MuseumOrganizationFormEditor extends PropertyEditorSupport { private static final Log logger = (Log) LogFactory.getLog(MuseumHovedOmraadeEditor.class); private final String fieldCode; public MuseumOrganizationFormEditor(String fieldCode) { super(); this.fieldCode = fieldCode; } public String getAsText() { if (logger.isDebugEnabled()) { logger.debug("Execute getAsText field=[" + fieldCode + "], getValue()=[" + getValue() + "]"); } MuseumOrganizationForm organizationForm; if (getValue() == null) { organizationForm = MuseumOrganizationForm.None; } else { organizationForm = (MuseumOrganizationForm) getValue(); } return organizationForm.getCode(); } public void setAsText(String string) { if (logger.isDebugEnabled()) { logger.debug("Execute setAsText field=[" + fieldCode + "], with string=[" + string + "]"); } if (StringUtil.isEmpty(string)) { setValue(null); } else { MuseumOrganizationForm organizationForm = MuseumOrganizationForm.getInstance(string.trim()); setValue(organizationForm); } } }