コード例 #1
1
  @Override
  protected void onConfigure() {
    super.onConfigure();

    // set all components visible
    Components.show(help, label, feedback);

    // clear feedback message and current state
    stateClassName.setObject("");
    feedback.setDefaultModelObject("");

    final List<FormComponent<?>> formComponents = findFormComponents();
    for (final FormComponent<?> fc : formComponents) {
      final FeedbackMessages messages = fc.getFeedbackMessages();

      if (!messages.isEmpty()) {
        final FeedbackMessage worstMessage = getWorstMessage(messages);
        worstMessage.markRendered();

        stateClassName.setObject(toClassName(worstMessage));
        feedback.setDefaultModelObject(worstMessage.getMessage());

        break; // render worst message of first found child component with feedback message
      }
    }

    Components.hideIfModelIsEmpty(help);
    Components.hideIfModelIsEmpty(label);
    Components.hideIfModelIsEmpty(feedback);
  }
コード例 #2
0
  private void setFormFieldsFromQuestion(Question question) {
    Answer.AnswerType aType = question.getAnswerType();

    questionTitleField.setModelObject(question.getTitle());
    questionPromptField.setModelObject(question.getPrompt());
    questionPrefaceField.setModelObject(question.getPreface());
    questionCitationField.setModelObject(question.getCitation());
    questionResponseTypeModel.setObject(question.getAnswerType());
    Long answerReasonId = question.getAnswerReasonExpressionId();
    questionAnswerReasonModel.setObject(
        answerReasonId == null ? answerAlways : Expressions.get(answerReasonId));
    String msg = "Asking style in setFormFields: " + askingStyleModel.getObject();
    askingStyleModel.setObject(question.getAskingStyleList());
    msg +=
        " -> "
            + askingStyleModel.getObject()
            + " (question had "
            + question.getAskingStyleList()
            + ")";
    // throw new RuntimeException(msg);
    // questionUseIfField.setModelObject(question.getUseIfExpression());
    otherSpecifyCheckBox.setModelObject(question.getOtherSpecify());
    noneButtonCheckBox.setModelObject(question.getNoneButton());
    if (aType == Answer.AnswerType.NUMERICAL) {
      numericLimitsPanel.setVisible(true);
    } else if (aType == Answer.AnswerType.MULTIPLE_SELECTION) {
      multipleSelectionLimitsPanel.setVisible(true);
      noneButtonLabel.setVisible(true);
      noneButtonCheckBox.setVisible(true);
    }
    if (aType == Answer.AnswerType.SELECTION || aType == Answer.AnswerType.MULTIPLE_SELECTION) {
      otherSpecifyLabel.setVisible(true);
      otherSpecifyCheckBox.setVisible(true);
    } else {
      otherSpecifyLabel.setVisible(false);
      otherSpecifyCheckBox.setVisible(false);
    }
    if (aType == Answer.AnswerType.DATE || aType == Answer.AnswerType.TIME_SPAN) {
      timeUnitsPanel.setVisible(true);
    } else {
      timeUnitsPanel.setVisible(false);
    }
    numericLimitsPanel.setMinLimitType(question.getMinLimitType());
    numericLimitsPanel.setMinLiteral(question.getMinLiteral());
    numericLimitsPanel.setMinPrevQues(question.getMinPrevQues());
    numericLimitsPanel.setMaxLimitType(question.getMaxLimitType());
    numericLimitsPanel.setMaxLiteral(question.getMaxLiteral());
    numericLimitsPanel.setMaxPrevQues(question.getMaxPrevQues());

    multipleSelectionLimitsPanel.setMinCheckableBoxes(question.getMinCheckableBoxes());
    multipleSelectionLimitsPanel.setMaxCheckableBoxes(question.getMaxCheckableBoxes());

    listLimitsPanel.setQuestion(question);
  }
コード例 #3
0
  private void importReportFromStreamPerformed(AjaxRequestTarget target) {
    String xml = xmlEditorModel.getObject();
    if (StringUtils.isEmpty(xml)) {
      error(getString("PageNewReport.message.emptyXml"));
      target.add(getFeedbackPanel());

      return;
    }

    OperationResult result = new OperationResult(OPERATION_IMPORT_REPORT_XML);
    InputStream stream = null;
    try {

      setResponsePage(new PageReport(new ReportDto(Base64.encodeBase64(xml.getBytes()))));
    } catch (Exception ex) {
      result.recordFatalError("Couldn't import object.", ex);
      LoggingUtils.logException(LOGGER, "Error occured during xml import", ex);
    } finally {
      if (stream != null) {
        IOUtils.closeQuietly(stream);
      }
    }

    if (result.isSuccess()) {
      xmlEditorModel.setObject(null);
    }

    showResult(result);
    target.add(getFeedbackPanel());
  }
コード例 #4
0
  @Override
  protected void onInitialize() {
    super.onInitialize();
    InjectorHolder.getInjector().inject(this);
    modelName.setObject(_user.getName());
    addFeedback(this, "feedback");

    Form<String> form =
        new Form<String>("form") {
          @Override
          protected void onSubmit() {
            onSubmitForm();
          }
        };

    Button cancel =
        new Button("cancel") {
          public void onSubmit() {
            setResponsePage(UserOverviewPage.class);
          }
        };
    cancel.setDefaultFormProcessing(false);
    form.add(cancel);

    addTextInputField(form, "username", modelName, true);
    form.add(new PasswordTextField("password1", modelPassword1));
    form.add(new PasswordTextField("password2", modelPassword2));

    form.add(new Button("submit"));

    List<UserRoles> current = new ArrayList<UserRoles>();
    current.add(UserRoles.NONE);
    modelRoles = new MyModel(current);

    List<? extends UserRoles> choices = UserRoles.asList();
    ListMultipleChoice<UserRoles> roleSelect =
        new ListMultipleChoice<UserRoles>("roleSelect", modelRoles, choices);
    form.add(roleSelect);

    List<String> providers = facade.availableProviders();
    selectedProvider = providers.get(0);
    ListChoice<String> providerSelect =
        new ListChoice<String>(
            "providerSelect", new PropertyModel<String>(this, "selectedProvider"), providers);
    form.add(providerSelect);
    add(form);
  }
コード例 #5
0
 public void setTooltipMessage(String message) {
   messageModel.setObject(message);
 }
コード例 #6
0
  private void build() {

    feedbackPanel = new FeedbackPanel("feedback");
    add(feedbackPanel);

    form = new Form("questionForm");
    form.setOutputMarkupId(true);

    questionTitleField = new TextField("questionTitleField", new Model(""));
    questionTitleField.setRequired(true);
    questionTitleField.add(new FocusOnLoadBehavior());
    form.add(questionTitleField);

    if (question.getType().equals(Question.QuestionType.ALTER)) {
      form.add(new Label("promptHelpText", "(Refer to the alter as $$)"));
    } else if (question.getType().equals(Question.QuestionType.ALTER_PAIR)) {
      form.add(new Label("promptHelpText", "(Refer to the alters as $$1 and $$2)"));
    } else {
      form.add(new Label("promptHelpText", ""));
    }

    numericLimitsPanel = new NumericLimitsPanel("numericLimitsPanel", question);
    form.add(numericLimitsPanel);
    numericLimitsPanel.setVisible(false);

    multipleSelectionLimitsPanel = new MultipleSelectionLimitsPanel("multipleSelectionLimitsPanel");
    form.add(multipleSelectionLimitsPanel);
    multipleSelectionLimitsPanel.setVisible(false);

    timeUnitsPanel = new TimeUnitsPanel("timeUnitsPanel", question);
    form.add(timeUnitsPanel);
    timeUnitsPanel.setVisible(false);

    listLimitsPanel = new ListLimitsPanel("listLimitsPanel", question);
    form.add(listLimitsPanel);
    listLimitsPanel.setVisible(question.getAskingStyleList());

    questionPromptField = new TextArea("questionPromptField", new Model(""));
    questionPromptField.setRequired(true);
    form.add(questionPromptField);

    questionPrefaceField = new TextArea("questionPrefaceField", new Model(""));
    form.add(questionPrefaceField);

    questionCitationField = new TextArea("questionCitationField", new Model(""));
    form.add(questionCitationField);

    questionResponseTypeModel = new Model(Answer.AnswerType.TEXTUAL); // Could also leave this null.
    dropDownQuestionTypes =
        new DropDownChoice(
            "questionResponseTypeField",
            questionResponseTypeModel,
            Arrays.asList(Answer.AnswerType.values()));

    dropDownQuestionTypes.add(
        new AjaxFormComponentUpdatingBehavior("onchange") {
          protected void onUpdate(AjaxRequestTarget target) {
            onSelectionChanged(Integer.parseInt(dropDownQuestionTypes.getModelValue()));
            // target.addComponent(form);
            target.addComponent(numericLimitsPanel);
            target.addComponent(multipleSelectionLimitsPanel);
            target.addComponent(noneButtonLabel);
            target.addComponent(noneButtonCheckBox);
            target.addComponent(otherSpecifyLabel);
            target.addComponent(otherSpecifyCheckBox);
            target.addComponent(timeUnitsPanel);
            target.addComponent(listLimitsPanel);
          }
        });

    form.add(dropDownQuestionTypes);

    questionAnswerReasonModel = new Model(answerAlways);
    List<Object> answerChoices = new ArrayList<Object>();
    answerChoices.add(answerAlways);
    for (Expression expression : Expressions.forStudy(question.getStudyId())) {
      answerChoices.add(expression);
    }
    form.add(
        new DropDownChoice("questionAnswerReasonField", questionAnswerReasonModel, answerChoices));

    Label askingStyleListLabel = new Label("askingStyleListLabel", "Ask with list of alters:");
    askingStyleModel = new Model();
    askingStyleModel.setObject(Boolean.FALSE);
    AjaxCheckBox askingStyleListField =
        new AjaxCheckBox("askingStyleListField", askingStyleModel) {
          protected void onUpdate(AjaxRequestTarget target) {
            Boolean listLimitsVisible = false;

            if (questionResponseTypeModel.getObject().equals(Answer.AnswerType.MULTIPLE_SELECTION)
                || questionResponseTypeModel.getObject().equals(Answer.AnswerType.SELECTION))
              listLimitsVisible = (Boolean) askingStyleModel.getObject();

            listLimitsPanel.setVisible(listLimitsVisible);
            target.addComponent(form);
          }
        };
    askingStyleListLabel.setOutputMarkupId(true);
    askingStyleListLabel.setOutputMarkupPlaceholderTag(true);
    askingStyleListField.setOutputMarkupId(true);
    askingStyleListField.setOutputMarkupPlaceholderTag(true);
    form.add(askingStyleListLabel);
    form.add(askingStyleListField);
    if (question.getType().equals(Question.QuestionType.EGO)
        || question.getType().equals(Question.QuestionType.EGO_ID)) {
      askingStyleListLabel.setVisible(false);
      askingStyleListField.setVisible(false);
    }

    otherSpecifyLabel = new Label("otherSpecifyLabel", "Other/Specify Type Question?: ");
    otherSpecifyModel = new Model();
    otherSpecifyModel.setObject(Boolean.FALSE);
    otherSpecifyCheckBox = new CheckBox("otherSpecifyField", otherSpecifyModel);
    form.add(otherSpecifyLabel);
    form.add(otherSpecifyCheckBox);
    otherSpecifyLabel.setOutputMarkupId(true);
    otherSpecifyCheckBox.setOutputMarkupId(true);
    otherSpecifyLabel.setOutputMarkupPlaceholderTag(true);
    otherSpecifyCheckBox.setOutputMarkupPlaceholderTag(true);
    noneButtonLabel = new Label("noneButtonLabel", "NONE Button?: ");
    noneButtonModel = new Model();
    noneButtonModel.setObject(Boolean.FALSE);
    noneButtonCheckBox = new CheckBox("noneButtonField", noneButtonModel);
    form.add(noneButtonLabel);
    form.add(noneButtonCheckBox);
    noneButtonLabel.setOutputMarkupId(true);
    noneButtonCheckBox.setOutputMarkupId(true);
    noneButtonLabel.setOutputMarkupPlaceholderTag(true);
    noneButtonCheckBox.setOutputMarkupPlaceholderTag(true);
    noneButtonLabel.setVisible(false);
    noneButtonCheckBox.setVisible(false);

    // questionUseIfField = new TextField("questionUseIfField", new Model(""));
    // form.add(questionUseIfField);

    form.add(
        new AjaxFallbackButton("submitQuestion", form) {
          @Override
          public void onSubmit(AjaxRequestTarget target, Form form) {
            insertFormFieldsIntoQuestion(question);
            if (question.getId() == null) {
              List<Question> questions =
                  Questions.getQuestionsForStudy(question.getStudyId(), question.getType());
              questions.add(question);
              for (Integer i = 0; i < questions.size(); i++) {
                questions.get(i).setOrdering(i);
                DB.save(questions.get(i));
              }
            } else {
              DB.save(question);
            }
            form.setVisible(false);
            target.addComponent(parentThatNeedsUpdating);
            target.addComponent(form);
          }
        });
    add(form);

    setFormFieldsFromQuestion(question);
  }
コード例 #7
0
  private void addUnderlyingViews(
      final String underlyingIdPrefix, final T model, final ComponentFactory factory) {
    final List<ComponentFactory> componentFactories = findOtherComponentFactories(model, factory);

    final int selected = determineInitialFactory(componentFactories, model);

    final LinksSelectorPanelAbstract<T> selectorPanel = LinksSelectorPanelAbstract.this;

    // create all, hide the one not selected
    final Component[] underlyingViews = new Component[MAX_NUM_UNDERLYING_VIEWS];
    int i = 0;
    for (ComponentFactory componentFactory : componentFactories) {
      final String underlyingId = underlyingIdPrefix + "-" + i;

      final T emptyModel = dummyOf(model);
      Component underlyingView =
          componentFactory.createComponent(underlyingId, i == selected ? model : emptyModel);
      underlyingViews[i++] = underlyingView;
      selectorPanel.addOrReplace(underlyingView);
    }

    // hide any unused placeholders
    while (i < MAX_NUM_UNDERLYING_VIEWS) {
      String underlyingId = underlyingIdPrefix + "-" + i;
      permanentlyHide(underlyingId);
      i++;
    }

    // selector
    if (componentFactories.size() <= 1) {
      permanentlyHide(ID_VIEWS);
    } else {
      final Model<ComponentFactory> componentFactoryModel = new Model<ComponentFactory>();

      selectorPanel.selectedComponentFactory = componentFactories.get(selected);
      componentFactoryModel.setObject(selectorPanel.selectedComponentFactory);

      final WebMarkupContainer views = new WebMarkupContainer(ID_VIEWS);

      final WebMarkupContainer container = new WebMarkupContainer(ID_VIEW_LIST);

      views.addOrReplace(container);
      views.setOutputMarkupId(true);

      this.setOutputMarkupId(true);

      final ListView<ComponentFactory> listView =
          new ListView<ComponentFactory>(ID_VIEW_ITEM, componentFactories) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(ListItem<ComponentFactory> item) {

              final int underlyingViewNum = item.getIndex();

              final ComponentFactory componentFactory = item.getModelObject();
              final AbstractLink link =
                  new AjaxLink<Void>(ID_VIEW_LINK) {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick(AjaxRequestTarget target) {

                      for (int i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) {
                        final Component component = underlyingViews[i];
                        T dummyModel = dummyOf(model);

                        if (component != null) {
                          final boolean isSelected = i == underlyingViewNum;
                          applyCssVisibility(component, isSelected);
                          component.setDefaultModel(isSelected ? model : dummyModel);
                        }
                      }
                      selectorPanel.selectedComponentFactory = componentFactory;
                      target.add(selectorPanel, views);
                    }
                  };
              String name = nameFor(componentFactory);
              Label viewTitleLabel = new Label(ID_VIEW_TITLE, name);
              viewTitleLabel.add(new CssClassAppender(StringUtils.toLowerDashed(name)));
              link.add(viewTitleLabel);
              item.add(link);

              link.setEnabled(componentFactory != selectorPanel.selectedComponentFactory);
            }

            private String nameFor(final ComponentFactory componentFactory) {
              return componentFactory instanceof CollectionContentsAsUnresolvedPanelFactory
                  ? "hide"
                  : componentFactory.getName();
            }
          };
      container.add(listView);
      addOrReplace(views);
    }

    for (i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) {
      Component component = underlyingViews[i];
      if (component != null) {
        if (i != selected) {
          component.add(new AttributeAppender("class", " " + INVISIBLE_CLASS));
        }
      }
    }
  }