Package com.google.wave.api

Examples of com.google.wave.api.FormView


  /**
   * Parse the form elements in the blip to derive their current values.
   */
  private void parseBlip() {
    try {
      FormView formView = blip.getDocument().getFormView();
      title = formView.getFormElement(TITLE_INPUT).getValue();
      question = formView.getFormElement(QUESTION_INPUT).getValue();

      String choiceString = formView.getFormElement(CHOICES_INPUT).getValue();
      choices = new ArrayList<String>();
      if (!choiceString.isEmpty()) {
        for (String line : choiceString.split("\\n")) {
          choices.add(line.replace("* ", ""));
        }
      }
     
      recipients = formView.getFormElement(RECIPIENTS_INPUT).getValue();
    } catch(NullPointerException npx) {
      // Form will not be valid until it has been fully created.
    }
  }
View Full Code Here


   * so, the button is reset into the unclicked/default state.
   *
   * @return true if the button was clicked, false otherwise.
   */
  public boolean isDistributePollButtonPressed() {
    FormView formView = blip.getDocument().getFormView();
    FormElement distributePoll = formView.getFormElement(DISTRIBUTE_POLL_BUTTON);
   
    boolean isPressed = "clicked".equals(distributePoll.getValue());
    if (isPressed) {
      distributePoll.setValue(distributePoll.getDefaultValue());
      formView.replace(distributePoll);
    }
   
    return isPressed;
  }
View Full Code Here

   * Sets/updates the poll question in the preview.
   *
   * @param question the new poll question.
   */
  public void setQuestion(String question) {
    FormView formView = blip.getDocument().getFormView();
    FormElement questionLabel = formView.getFormElement(PREV_QUESTION_LABEL);
    questionLabel.setValue(question);
    formView.replace(questionLabel);
  }
View Full Code Here

   *
   * @param choices the new list of choices.
   */
  public void setChoices(List<String> choices) {
    TextView textView = blip.getDocument();
    FormView formView = textView.getFormView();
   
    // Count existing choice elements
    int existingCount = 0;
    for (FormElement formElement : formView.getFormElements()) {
      if (formElement.getType() == ElementType.LABEL &&
          formElement.getName().startsWith(PREV_CHOICE_PREFIX) &&
          formElement.getName().endsWith(PREV_CHOICE_LABEL_SUFFIX)) {
        ++existingCount;
      }
    }
   
    // Prune extra choices
    if (existingCount > choices.size()) {
      for (int i = existingCount - 1; i >= choices.size(); --i) {
        String choiceLabel = PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_LABEL_SUFFIX;
        int position = textView.getPosition(formView.getFormElement(choiceLabel));

        // Delete the carriage return following the label.
        textView.delete(new Range(position + 1, position + 2));
        // Delete the label.
        formView.delete(choiceLabel);
        // Delete the radio button.
        formView.delete(PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_RADIO_SUFFIX);
      }
      existingCount = choices.size();
    }
   
    // Replace existing labels.
    for (int i = 0; i < existingCount; ++i) {
      String choiceLabel = PREV_CHOICE_PREFIX + String.valueOf(i) + PREV_CHOICE_LABEL_SUFFIX;
      FormElement label = formView.getFormElement(choiceLabel);
      if (!choices.get(i).equals(metadata.getChoices().get(i))) {
        label.setValue(choices.get(i));
        formView.replace(label);
      }
    }
   
    // Add new labels.
    if (existingCount < choices.size()) {
      // Get the position of the last label.
      int lastLabelPosition;
      if (existingCount == 0) {
        lastLabelPosition = textView.getPosition(formView.getFormElement(PREV_CHOICES_RADIOGROUP));
      } else {
        String choiceLabel = PREV_CHOICE_PREFIX + String.valueOf(existingCount - 1) +
            PREV_CHOICE_LABEL_SUFFIX;
        lastLabelPosition = textView.getPosition(formView.getFormElement(choiceLabel)) + 1;
      }
     
      for (int i = existingCount; i < choices.size(); ++i) {
        FormElement radioButton = new FormElement(
            ElementType.RADIO_BUTTON,
View Full Code Here

   * so, the button is reset into the unclicked/default state.
   *
   * @return true if the button was clicked, false otherwise.
   */
  public boolean isSubmitPollButtonPressed() {
    FormView formView = blip.getDocument().getFormView();
    FormElement submitPoll = formView.getFormElement(PREV_SUBMIT_POLL_BUTTON);
   
    boolean isPressed = "clicked".equals(submitPoll.getValue());
    if (isPressed) {
      submitPoll.setValue(submitPoll.getDefaultValue());
      formView.replace(submitPoll);
    }
   
    return isPressed;
  }
View Full Code Here

   * Returns the currently selected choice in the poll.
   *
   * @return the currently selected choice in the poll.
   */
  public String getVote() {
    FormView formView = blip.getDocument().getFormView();
    String selectedRadio = formView.getFormElement(PREV_CHOICES_RADIOGROUP).getValue();
    if (selectedRadio != null && !selectedRadio.isEmpty()) {
      // Derive the choice from the radio button's name.
      return selectedRadio.substring(PREV_CHOICE_PREFIX.length(),
          PREV_CHOICE_PREFIX.length() + 1);
    } else {
View Full Code Here

        case FORM_BUTTON_CLICKED:
          if (event.getButtonName().equals("my_button")) {
            String clicker = event.getModifiedBy();
            wavelet.appendBlip().getDocument().append(clicker + " has clicked the button!");
          }
          FormView formView = currentBlip.getDocument().getFormView();         
          if (formView.getFormElement("my_button") != null) {
           
          }         
          break;            
      }     
    }       
View Full Code Here

TOP

Related Classes of com.google.wave.api.FormView

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.