org.jsurveylib.model.question
Class Question

java.lang.Object
  extended by org.jsurveylib.model.question.Question
All Implemented Interfaces:
Template, SurveyElement, Visitable
Direct Known Subclasses:
FreeTextQuestion, OneChoiceQuestion

public abstract class Question
extends java.lang.Object
implements SurveyElement, Template

FOR INTERNAL USE ONLY.

A single question on the survey


Constructor Summary
Question(java.lang.String id)
           
 
Method Summary
 void addAnswerListener(AnswerListener listener)
          Add an answer listener.
 void addEnableListener(EnableListener listener)
           
 void addValidationListener(ValidationListener listener)
          Adds a validation listener to this question.
 void addVisibilityListener(VisibilityListener listener)
          Adds a visibility listener to this question.
 void fireAnswerChanged()
          Fire an State Changed Event for this question.
 void fireAnswerChanged(boolean evaluateScript)
          Fire an State Changed Event for this question
abstract  java.lang.String getAnswer()
          The answer of this question.
 java.lang.String getCurrentValidationMessage()
          This will return the current validation message.
 java.lang.String getId()
           
 Label getLabel()
          Returns the Label of this question.
 java.lang.String getOnAnswerChanged()
           
 boolean isAnswerable()
          Returns true if the question is visible and editable.
abstract  boolean isAnswered()
           
 boolean isEnabled()
           
 boolean isMandatory()
           
 boolean isValid()
           
 boolean isVisible()
           
 Question populateTemplate(java.lang.String newId, java.lang.String newLabel, boolean mandatory, java.lang.String answer)
          Calling this method makes a duplicate of the current question but it doesn't save any of the original question's state.
 void removeAnswerListener(AnswerListener listener)
          Remove an answer listener.
 void removeEnableListener(EnableListener listener)
           
 void removeValidationListener(ValidationListener listener)
           
 void removeVisibilityListener(VisibilityListener listener)
           
abstract  void setAnswer(java.lang.String answer)
          Sets the answer of this question.
 void setEnabled(boolean enabled)
           
 void setLabel(Label label)
          Set the Label of this question.
 void setLabel(java.lang.String labelText)
          Set the Label of this question.
 void setMandatory(boolean mandatory)
           
 void setOnAnswerChanged(java.lang.String onAnswerChanged)
           
 void setValid(boolean valid, java.lang.String message)
           
 void setVisible(boolean visible)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jsurveylib.model.Visitable
accept
 

Constructor Detail

Question

public Question(java.lang.String id)
Method Detail

addAnswerListener

public void addAnswerListener(AnswerListener listener)
Add an answer listener. The answer listener is notified every time this question's answer changes.

Parameters:
listener - The answer listener that will be notified when a question's answer changes

removeAnswerListener

public void removeAnswerListener(AnswerListener listener)
Remove an answer listener. The answer listener is notified every time this question's answer changes.

Parameters:
listener - The answer listener that will be notified when a question's answer changes

addVisibilityListener

public void addVisibilityListener(VisibilityListener listener)
Adds a visibility listener to this question. This question will notify all listeners when its visibility changes. If this question does not have a visibility handler (which would only happen if it didn't have a visibility script) then calling this method will have no effect.

Parameters:
listener - The listener to add.

removeVisibilityListener

public void removeVisibilityListener(VisibilityListener listener)

addValidationListener

public void addValidationListener(ValidationListener listener)
Adds a validation listener to this question. This question will notify all listeners when its validation changes. If this question does not have a validation handler (which would only happen if it didn't have any validation scripts) then calling this method will have no effect.

Parameters:
listener - The listener to add.

removeValidationListener

public void removeValidationListener(ValidationListener listener)

addEnableListener

public void addEnableListener(EnableListener listener)

removeEnableListener

public void removeEnableListener(EnableListener listener)

getCurrentValidationMessage

public java.lang.String getCurrentValidationMessage()
This will return the current validation message. When the question is valid, this will return "", when it is invalid, it will return the message to that error.

Returns:
"" when the question is valid, otherwise the invalid message.

isAnswerable

public boolean isAnswerable()
Returns true if the question is visible and editable.

Returns:
true if the question is visible and editable, otherwise false.

isAnswered

public abstract boolean isAnswered()

getLabel

public Label getLabel()
Returns the Label of this question. If this question has no label this will return a Label with text of "".

Returns:
The Label of the question.

setLabel

public void setLabel(Label label)
Set the Label of this question. If you pass in null, the Label will be set to a Label with text of ""

Parameters:
label - The Label the question will use.

setLabel

public void setLabel(java.lang.String labelText)
Set the Label of this question. If you pass in null, the Label will be set to a Label with text of ""

Parameters:
labelText - The label String the question will use.

getId

public java.lang.String getId()

isMandatory

public boolean isMandatory()

setMandatory

public void setMandatory(boolean mandatory)

getAnswer

public abstract java.lang.String getAnswer()
The answer of this question. This should never return null, it should return "" instead.

Returns:
The answer to the question or "" if there is no answer.

setAnswer

public abstract void setAnswer(java.lang.String answer)
Sets the answer of this question. If null is passed in, getAnswer() should return "" instead of null.

Parameters:
answer - The answer or "" if there is no answer. This should never return null.

isVisible

public boolean isVisible()

setVisible

public void setVisible(boolean visible)

isValid

public boolean isValid()

setValid

public void setValid(boolean valid,
                     java.lang.String message)

isEnabled

public boolean isEnabled()

setEnabled

public void setEnabled(boolean enabled)

fireAnswerChanged

public void fireAnswerChanged()
Fire an State Changed Event for this question. The script will be evaluated after this is called.


fireAnswerChanged

public void fireAnswerChanged(boolean evaluateScript)
Fire an State Changed Event for this question

Parameters:
evaluateScript - If true, the script will be evaluated from this change. If false, the script will not be evaluated

populateTemplate

public Question populateTemplate(java.lang.String newId,
                                 java.lang.String newLabel,
                                 boolean mandatory,
                                 java.lang.String answer)
Calling this method makes a duplicate of the current question but it doesn't save any of the original question's state. You can set the new id, the new label, whether or not the new question is mandatory, and the answer the new question will have. Setting the answer will not call any AnswerListeners.

Specified by:
populateTemplate in interface Template
Parameters:
newId - The new ID of this question.
newLabel - The new label of the question or null if the current label should be used.
mandatory - True if this new question should be mandatory, otherwise the question is optional.
answer - The question will start with this answer. If set to "" or null, the default is used.
Returns:
A question that has the same structure as this template but a new id/label/mandatory status/answer

getOnAnswerChanged

public java.lang.String getOnAnswerChanged()

setOnAnswerChanged

public void setOnAnswerChanged(java.lang.String onAnswerChanged)