package net.sf.egonet.web.panel; import java.util.ArrayList; import org.apache.wicket.model.Model; import com.google.common.collect.Lists; import net.sf.egonet.model.Alter; import net.sf.egonet.model.Answer; import net.sf.egonet.model.Question; import net.sf.egonet.model.Answer.SkipReason; import net.sf.egonet.web.component.FocusOnLoadBehavior; import net.sf.egonet.web.component.TextField; public class TextAnswerFormFieldPanel extends AnswerFormFieldPanel { private TextField textField; private CheckboxesPanel<String> refDKCheck; public TextAnswerFormFieldPanel(String id, Question question, ArrayList<Alter> alters, Long interviewId) { super(id,question,Answer.SkipReason.NONE,alters, interviewId); build(""); } public TextAnswerFormFieldPanel(String id, Question question, String answer, Answer.SkipReason skipReason, ArrayList<Alter> alters, Long interviewId) { super(id,question,skipReason,alters,interviewId); build(answer); } private void build(String answer) { this.textField = new TextField("answer", new Model(answer)); add(textField); ArrayList<String> refAndDK = Lists.newArrayList(); if ( !question.getType().equals(Question.QuestionType.EGO_ID)) { if ( question.getDontKnowButton()) refAndDK.add(dontKnow); if ( question.getRefuseButton()) refAndDK.add(refuse); } ArrayList<String> selectedRefAndDK = Lists.newArrayList(); if(originalSkipReason.equals(SkipReason.DONT_KNOW)) { selectedRefAndDK.add(dontKnow); } if(originalSkipReason.equals(SkipReason.REFUSE)) { selectedRefAndDK.add(refuse); } refDKCheck = new CheckboxesPanel<String>("refDKCheck", refAndDK,selectedRefAndDK); add(refDKCheck); } public String getAnswer() { return textField.getText(); } public void setAutoFocus() { textField.add(new FocusOnLoadBehavior()); } public boolean dontKnow() { return refDKCheck.getSelected().contains(dontKnow); } public boolean refused() { return refDKCheck.getSelected().contains(refuse); } }