Java tutorial
/*$Id: MuseumHovedOmraadeEditor.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.MuseumHovedOmraade; import no.abmu.util.string.StringUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * MuseumHovedOmraadeEditor. * * @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 MuseumHovedOmraadeEditor extends PropertyEditorSupport { private static final Log logger = (Log) LogFactory.getLog(MuseumHovedOmraadeEditor.class); private final String fieldCode; public MuseumHovedOmraadeEditor(String fieldCode) { super(); this.fieldCode = fieldCode; } public String getAsText() { if (logger.isDebugEnabled()) { logger.debug("Execute getAsText field=[" + fieldCode + "], getValue()=[" + getValue() + "]"); } MuseumHovedOmraade hovedOmraade; if (getValue() == null) { hovedOmraade = MuseumHovedOmraade.None; } else { hovedOmraade = (MuseumHovedOmraade) getValue(); } return hovedOmraade.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 { MuseumHovedOmraade hovedOmraade = MuseumHovedOmraade.getInstance(string.trim()); setValue(hovedOmraade); } } }