/**
  * Actually submits the selected translation
  *
  * @param userName The content of the User Name Field
  * @param userEmail The content of the User E-Mail address Field
  */
 public void submitTranslation(String userName, String userEmail, boolean contribute) {
   if (this.isValidEmailAddress(userEmail)) {
     this.ui.alert(InternationalisationUtils.getI18NString(I18N_COMMON_INVALID_EMAIL));
   } else {
     String subject = "FrontlineSMS translation: " + this.languageBundle.getLanguageName();
     String textContent =
         "Sent translation: "
             + this.languageBundle.getLanguageName()
             + " ("
             + this.languageBundle.getLanguageCode()
             + ").\n"
             + userName
             + (contribute ? " would" : " wouldn't")
             + " like to appear as a contributor for this translation.";
     try {
       FrontlineUtils.sendToFrontlineSupport(
           userName,
           userEmail,
           subject,
           textContent,
           InternationalisationUtils.getLanguageDirectory()
               + File.separator
               + languageBundle.getFilename());
       this.removeDialog();
       this.ui.infoMessage(InternationalisationUtils.getI18NString(I18N_TRANSLATION_SENT));
     } catch (EmailException e) {
       this.ui.alert(InternationalisationUtils.getI18NString(I18N_UNABLE_SEND_TRANSLATION));
     }
   }
 }
Ejemplo n.º 2
0
 public IncomingFormMatcher(ApplicationContext appCon) {
   vanillaFormDao = (FormDao) appCon.getBean("formDao");
   formDao = (MedicFormDao) appCon.getBean("MedicFormDao");
   formResponseDao = (MedicFormResponseDao) appCon.getBean("MedicFormResponseDao");
   formFieldResponseDao = (MedicFormFieldResponseDao) appCon.getBean("MedicFormFieldResponseDao");
   patientDao = (PatientDao) appCon.getBean("PatientDao");
   chwDao = (CommunityHealthWorkerDao) appCon.getBean("CHWDao");
   ((EventBus) appCon.getBean("eventBus")).registerObserver(this);
   // create the test harness
   ExtendedThinlet thinlet = new ExtendedThinlet();
   Object panel = thinlet.createPanel("mainPanel");
   thinlet.setWeight(panel, 1, 1);
   Object button = thinlet.createButton("Click me to test form handling");
   thinlet.setAction(button, "testHandler", null, this);
   thinlet.add(panel, button);
   thinlet.add(panel);
   // set up the date formatter
   String dateString =
       InternationalisationUtils.getI18NString(FrontlineSMSConstants.DATEFORMAT_YMD);
   dateString = dateString.toLowerCase();
   dateString = dateString.replace("mm", "MM");
   dateString = dateString.replace("yyyy", "yy");
   shortFormatter = new SimpleDateFormat(dateString);
   longFormatter = InternationalisationUtils.getDateFormat();
   //	FrameLauncher f = new FrameLauncher("Test form handling",thinlet,200,100,null)
   // { public void windowClosing(WindowEvent e){  dispose(); }};
 }
 /** @see BaseGroupActionDialog#getDialogTitle() */
 @Override
 protected String getDialogTitle() {
   return InternationalisationUtils.getI18nString(COMMON_KEYWORD)
       + " \""
       + KeywordTabHandler.getDisplayableKeyword(super.getTargetKeyword())
       + "\" "
       + InternationalisationUtils.getI18nString(COMMON_AUTO_JOIN_GROUP)
       + ":";
 }
 /**
  * Gets a displayable string for a keyword description, replacing the blank keyword with an
  * internationalised string describing the blank keyword.
  *
  * @param keyword
  * @return
  */
 public static String getDisplayableDescription(Keyword keyword) {
   boolean hasDescription =
       (keyword.getDescription() != null && keyword.getDescription().length() > 0);
   if (keyword.getKeyword().length() == 0 && !hasDescription)
     return InternationalisationUtils.getI18nString(
         FrontlineSMSConstants.MESSAGE_BLANK_KEYWORD_DESCRIPTION);
   else if (keyword.getKeyword().equals(FrontlineSMSConstants.MMS_KEYWORD)) {
     return InternationalisationUtils.getI18nString(
         FrontlineSMSConstants.MESSAGE_MMS_KEYWORD_DESCRIPTION);
   } else {
     return keyword.getDescription();
   }
 }
  public void keywordShowAdvancedView() {
    Object divider = find(COMPONENT_KEYWORDS_DIVIDER);
    if (ui.getItems(divider).length >= 2) {
      ui.remove(ui.getItems(divider)[ui.getItems(divider).length - 1]);
    }
    Object panel = ui.loadComponentFromFile(UI_FILE_KEYWORDS_ADVANCED_VIEW, this);
    Object table = ui.find(panel, COMPONENT_ACTION_LIST);
    Keyword keyword = ui.getKeyword(ui.getSelectedItem(keywordListComponent));
    Object lbKeywordDescription = ui.find(panel, COMPONENT_LB_KEYWORD_DESCRIPTION);

    String keywordDescription = getDisplayableDescription(keyword);
    if (keywordDescription != null && keywordDescription.length() > 0) {
      ui.setText(lbKeywordDescription, keywordDescription);
    } else {
      ui.remove(lbKeywordDescription);
    }

    ui.setText(
        panel,
        InternationalisationUtils.getI18nString(
            COMMON_KEYWORD_ACTIONS_OF, getDisplayableKeyword(keyword)));
    for (KeywordAction action : this.keywordActionDao.getActions(keyword)) {
      ui.add(table, ui.getRow(action));
    }
    enableKeywordActionFields(table, ui.find(panel, COMPONENT_KEY_ACT_PANEL));
    ui.add(divider, panel);
  }
  private void setLeaveGroupDisplay(Group group) {
    Object leaveGroupButton = find(COMPONENT_LEAVE_GROUP_SELECT_LABEL);
    ui.setAttachedObject(leaveGroupButton, group);

    ui.setVisible(find("btLeaveGroupSelect"), group == null);
    ui.setVisible(find("btLeaveGroupRemove"), group != null);

    if (group != null) {
      ui.setText(leaveGroupButton, group.getPath());
    } else {
      ui.setText(
          leaveGroupButton,
          InternationalisationUtils.getI18nString(
              I18N_KEYWORD_ACTION_NO_GROUP,
              InternationalisationUtils.getI18nString(I18N_COMMON_NONE)));
    }
  }
 public void validateDate(String date, int lineNumber, List<CsvValidationException> exceptions) {
   try {
     InternationalisationUtils.getDateFormat().parse(date);
   } catch (ParseException e) {
     exceptions.add(
         new CsvValidationException(
             lineNumber, getI18NString("medic.importer.date.format.error") + ": " + date));
   }
 }
  /**
   * Shows the new keyword dialog.
   *
   * @param parentKeyword
   */
  public void showNewKeywordForm() {
    String title = InternationalisationUtils.getI18nString(I18N_CREATE_KEYWORD);
    this.keywordForm = ui.loadComponentFromFile(UI_FILE_NEW_KEYWORD_FORM, this);
    ui.setText(ui.find(keywordForm, COMPONENT_NEW_KEYWORD_FORM_TITLE), title);

    // Update the display for the number of characters left in the description field
    this.keywordDescriptionChanged("");

    ui.add(keywordForm);
  }
 /** UI event called when the user changes tab */
 public void notify(FrontlineEventNotification notification) {
   super.notify(notification);
   // This object is registered to the UIGeneratorController and get notified when the users
   // changes tab
   if (notification instanceof TabChangedNotification) {
     String newTabName = ((TabChangedNotification) notification).getNewTabName();
     if (newTabName.equals(TAB_KEYWORD_MANAGER)) {
       threadSafeRefresh();
       ui.setStatus(InternationalisationUtils.getI18nString(MESSAGE_KEYWORDS_LOADED));
     }
   }
 }
  /**
   * Create a new keyword with the supplied information (newKeyword and description).
   *
   * @param formPanel The panel to be removed from the application.
   * @param newKeyword The desired keyword.
   * @param description The description for this new keyword.
   */
  public void do_createKeyword(String newKeyword, String description) {
    log.trace("ENTER");
    log.debug("Creating keyword [" + newKeyword + "] with description [" + description + "]");
    try {
      // Trim the keyword to remove trailing and leading whitespace
      newKeyword = newKeyword.trim();
      // Remove any double-spaces within the keyword
      newKeyword = newKeyword.replaceAll("\\s+", " ");

      Keyword keyword = new Keyword(newKeyword, description);
      this.keywordDao.saveKeyword(keyword);
    } catch (DuplicateKeyException e) {
      ui.alert(InternationalisationUtils.getI18nString(MESSAGE_KEYWORD_EXISTS));
      log.trace("EXIT");
      return;
    }
    updateKeywordList();
    removeDialog(this.keywordForm);
    log.trace("EXIT");
  }
  /**
   * Shows the keyword dialog for edit purpose.
   *
   * @param keyword The object to be edited.
   */
  private void showKeywordDialogForEdition(Keyword keyword) {
    String key = getDisplayableKeyword(keyword);
    String title = InternationalisationUtils.getI18nString(COMMON_EDITING_KEYWORD, key);
    keywordForm = ui.loadComponentFromFile(UI_FILE_NEW_KEYWORD_FORM, this);
    ui.setAttachedObject(keywordForm, keyword);
    ui.setText(ui.find(keywordForm, COMPONENT_NEW_KEYWORD_FORM_TITLE), title);
    // Pre-populate the textfields with currently-selected keyword attributes strings
    Object textField = ui.find(keywordForm, COMPONENT_NEW_KEYWORD_FORM_KEYWORD);
    Object textFieldDescription = ui.find(keywordForm, COMPONENT_NEW_KEYWORD_FORM_DESCRIPTION);
    ui.setText(textField, key);
    ui.setEnabled(textField, false);

    String displayedDescription = keyword.getDescription();
    if (displayedDescription == null) displayedDescription = "";
    ui.setText(textFieldDescription, displayedDescription);
    this.keywordDescriptionChanged(displayedDescription);

    String method = "finishKeywordEdition(newKeywordForm, newKeywordForm_description.text)";
    ui.setAction(
        ui.find(keywordForm, COMPONENT_NEW_KEYWORD_BUTTON_DONE), method, keywordForm, this);
    ui.add(keywordForm);
  }
 @Override
 public String getOccurrenceLabel() {
   return InternationalisationUtils.getI18nString(RemindersConstants.WEEKDAYS);
 }
Ejemplo n.º 13
0
 /** @see FComponent#getDescription() */
 @Override
 public String getDescription() {
   return InternationalisationUtils.getI18nString(FormsThinletTabController.I18N_FCOMP_CURRENCY);
 }
 public String getTitle() {
   return InternationalisationUtils.getI18nString(I18N_SETTINGS_MENU_DEVICES);
 }
 /**
  * Gets a displayable string for a keyword, replacing the blank keyword with an internationalised
  * string describing the blank keyword.
  *
  * @param keyword
  * @return
  */
 public static String getDisplayableKeyword(Keyword keyword) {
   String displayable = keyword.getKeyword();
   if (displayable.length() == 0)
     return "<" + InternationalisationUtils.getI18nString(COMMON_BLANK) + ">";
   else return displayable;
 }
  public void keywordTab_doSave(Object panel) {
    log.trace("ENTER");
    long startDate;
    try {
      startDate =
          InternationalisationUtils.parseDate(InternationalisationUtils.getDefaultStartDate())
              .getTime();
    } catch (ParseException e) {
      log.debug("We never should get this", e);
      log.trace("EXIT");
      return;
    }

    // Get the KeywordAction details
    String replyText = keywordSimple_getAutoReply(panel);
    Group joinGroup = keywordSimple_getJoin();
    Group leaveGroup = keywordSimple_getLeave();

    // Get the keyword attached to the selected item.  If the "Add Keyword" option is selected,
    // there will be no keyword attached to it.
    Keyword keyword = null;
    Object selectedKeywordItem = ui.getSelectedItem(keywordListComponent);
    if (selectedKeywordItem != null) keyword = ui.getKeyword(selectedKeywordItem);

    if (keyword == null) {
      // Adding keyword as well as actions
      String newkeyword = ui.getText(ui.find(panel, COMPONENT_TF_KEYWORD));
      try {
        keyword = new Keyword(newkeyword, "");
        this.keywordDao.saveKeyword(keyword);
      } catch (DuplicateKeyException e) {
        ui.alert(InternationalisationUtils.getI18nString(MESSAGE_KEYWORD_EXISTS));
        log.trace("EXIT");
        return;
      }
      keywordTab_doClear(panel);
    } else {
      // Editing an existent keyword.  This keyword may already have actions applied to it, so
      // we need to check for actions and update them as appropriate.
      KeywordAction replyAction =
          this.keywordActionDao.getAction(keyword, KeywordAction.Type.REPLY);
      if (replyAction != null) {
        if (replyText == null) {
          // The reply action has been removed
          keywordActionDao.deleteKeywordAction(replyAction);
        } else {
          replyAction.setReplyText(replyText);
          this.keywordActionDao.updateKeywordAction(replyAction);
          // We set null to don't add it in the end
          replyText = null;
        }
      }

      KeywordAction joinAction = this.keywordActionDao.getAction(keyword, KeywordAction.Type.JOIN);
      if (joinAction != null) {
        if (joinGroup == null) {
          // Previous join action has been removed, so delete it.
          keywordActionDao.deleteKeywordAction(joinAction);
        } else {
          // Group to join has been updated
          joinAction.setGroup(joinGroup);
          this.keywordActionDao.updateKeywordAction(joinAction);
          // Join Group has been handled, so unset it.
          joinGroup = null;
        }
      }

      KeywordAction leaveAction =
          this.keywordActionDao.getAction(keyword, KeywordAction.Type.LEAVE);
      if (leaveAction != null) {
        if (leaveGroup == null) {
          keywordActionDao.deleteKeywordAction(leaveAction);
        } else {
          leaveAction.setGroup(leaveGroup);
          this.keywordActionDao.updateKeywordAction(leaveAction);
          // We set null to don't add it in the end
          leaveGroup = null;
        }
      }
    }

    // Handle creation of new KeywordActions if required
    if (replyText != null) {
      KeywordAction action =
          KeywordAction.createReplyAction(keyword, replyText, startDate, DEFAULT_END_DATE);
      keywordActionDao.saveKeywordAction(action);
    }
    if (joinGroup != null) {
      KeywordAction action =
          KeywordAction.createGroupJoinAction(keyword, joinGroup, startDate, DEFAULT_END_DATE);
      keywordActionDao.saveKeywordAction(action);
    }
    if (leaveGroup != null) {
      KeywordAction action =
          KeywordAction.createGroupLeaveAction(keyword, leaveGroup, startDate, DEFAULT_END_DATE);
      keywordActionDao.saveKeywordAction(action);
    }

    // Refresh the UI
    updateKeywordList();
    ui.infoMessage(InternationalisationUtils.getI18nString(MESSAGE_KEYWORD_SAVED));
    log.trace("EXIT");
  }
  public void showSelectedKeyword() {
    Object selected = ui.getSelectedItem(keywordListComponent);

    Object divider = find(COMPONENT_KEYWORDS_DIVIDER);
    if (ui.getItems(divider).length >= 2) {
      ui.remove(ui.getItems(divider)[ui.getItems(divider).length - 1]);
    }

    // If selected is null, then we are here because a keyword has been unselected
    if (selected == null) {
      enableKeywordFields(ui.find(COMPONENT_KEY_PANEL));
      return;
    }

    // An existent keyword is selected, let's check if it is simple or advanced.
    Keyword keyword = ui.getAttachedObject(selected, Keyword.class);
    Collection<KeywordAction> actions = this.keywordActionDao.getActions(keyword);
    boolean simple = actions.size() <= 3;
    if (simple) {
      KeywordAction.Type previousType = null;
      for (KeywordAction action : actions) {
        KeywordAction.Type type = action.getType();
        if (type != KeywordAction.Type.REPLY
            && type != KeywordAction.Type.JOIN
            && type != KeywordAction.Type.LEAVE) {
          simple = false;
          break;
        }

        if (action.getEndDate() != DEFAULT_END_DATE) {
          simple = false;
          break;
        }

        if (type == previousType) {
          simple = false;
          break;
        }

        previousType = type;
      }
    }

    String keywordDescription = getDisplayableDescription(keyword);
    if (simple) {
      Object panel = ui.loadComponentFromFile(UI_FILE_KEYWORDS_SIMPLE_VIEW, this);
      ui.add(divider, panel);

      // Fill every field
      Object tfKeyword = ui.find(panel, COMPONENT_TF_KEYWORD);
      Object lbKeywordDescription = ui.find(panel, COMPONENT_LB_KEYWORD_DESCRIPTION);
      ui.setEnabled(tfKeyword, false);
      ui.setText(tfKeyword, getDisplayableKeyword(keyword));

      // We display the keyword description in the panel
      if (keywordDescription != null && keywordDescription.length() > 0) {
        ui.setText(lbKeywordDescription, keywordDescription);
      } else {
        ui.remove(lbKeywordDescription);
      }

      // We have to set the text in case there is no join/leave keyword actions
      setJoinGroupDisplay(null);
      setLeaveGroupDisplay(null);

      for (KeywordAction action : actions) {
        KeywordAction.Type type = action.getType();
        if (type == KeywordAction.Type.REPLY) {
          Object cbReply = ui.find(panel, COMPONENT_CB_AUTO_REPLY);
          Object tfReply = ui.find(panel, COMPONENT_TF_AUTO_REPLY);
          ui.setSelected(cbReply, true);
          ui.setText(tfReply, action.getUnformattedReplyText());
        } else if (type == KeywordAction.Type.JOIN) {
          setJoinGroupDisplay(action.getGroup());
        } else if (type == KeywordAction.Type.LEAVE) {
          setLeaveGroupDisplay(action.getGroup());
        }
      }
    } else {
      Object panel = ui.loadComponentFromFile(UI_FILE_KEYWORDS_ADVANCED_VIEW, this);
      Object table = ui.find(panel, COMPONENT_ACTION_LIST);
      Object lbKeywordDescription = ui.find(panel, COMPONENT_LB_KEYWORD_DESCRIPTION);

      // We display the keyword description in the panel
      if (keywordDescription != null && keywordDescription.length() > 0) {
        ui.setText(lbKeywordDescription, keywordDescription);
      } else {
        ui.remove(lbKeywordDescription);
      }
      ui.setText(
          panel,
          InternationalisationUtils.getI18nString(
              COMMON_KEYWORD_ACTIONS_OF, getDisplayableKeyword(keyword)));
      // Fill every field
      for (KeywordAction action : actions) {
        ui.add(table, ui.getRow(action));
      }
      ui.add(divider, panel);
      enableKeywordActionFields(table, ui.find(panel, COMPONENT_KEY_ACT_PANEL));
    }
    enableKeywordFields(ui.find(COMPONENT_KEY_PANEL));
  }