Example #1
0
  @Override
  protected void onBeforeRenderWhenDisabled(final String disableReason) {
    super.onBeforeRenderWhenDisabled(disableReason);
    final EntityModel entityLinkModel = (EntityModel) entityLink.getModel();
    entityLinkModel.toViewMode();

    entityLink.syncVisibilityAndUsability();
  }
Example #2
0
  /**
   * Mandatory hook method to build the component to render the model when in {@link
   * Rendering#COMPACT compact} format.
   */
  @Override
  protected Component addComponentForCompact() {

    final ScalarModel scalarModel = getModel();
    final String name = scalarModel.getName();

    entityLink =
        (EntityLinkSelect2Panel)
            getComponentFactoryRegistry().createComponent(ComponentType.ENTITY_LINK, getModel());

    entityLink.setOutputMarkupId(true);
    entityLink.setLabel(Model.of(name));

    final FormComponentLabel labelIfCompact =
        new FormComponentLabel(ID_SCALAR_IF_COMPACT, entityLink);
    labelIfCompact.add(entityLink);

    addOrReplace(labelIfCompact);

    return labelIfCompact;
  }
Example #3
0
  @Override
  protected FormComponentLabel addComponentForRegular() {
    final ScalarModel scalarModel = getModel();
    final String name = scalarModel.getName();

    entityLink =
        (EntityLinkSelect2Panel)
            getComponentFactoryRegistry().createComponent(ComponentType.ENTITY_LINK, getModel());

    entityLink.setOutputMarkupId(true);
    entityLink.setLabel(Model.of(name));

    final FormComponentLabel labelIfRegular =
        new FormComponentLabel(ID_SCALAR_IF_REGULAR, entityLink);
    labelIfRegular.add(entityLink);

    final String describedAs = getModel().getDescribedAs();
    if (describedAs != null) {
      labelIfRegular.add(new AttributeModifier("title", Model.of(describedAs)));
    }

    final Label scalarName = new Label(ID_SCALAR_NAME, getRendering().getLabelCaption(entityLink));
    labelIfRegular.add(scalarName);

    addOrReplace(labelIfRegular);

    addFeedbackTo(labelIfRegular, entityLink);
    addAdditionalLinksTo(labelIfRegular);

    addStandardSemantics();
    addSemantics();

    if (getModel().isRequired()) {
      labelIfRegular.add(new CssClassAppender("mandatory"));
    }
    return labelIfRegular;
  }
Example #4
0
  private void addObjectAdapterValidator() {
    final ScalarModel scalarModel = getModel();

    entityLink.add(
        new IValidator<ObjectAdapter>() {

          private static final long serialVersionUID = 1L;

          @Override
          public void validate(final IValidatable<ObjectAdapter> validatable) {
            final ObjectAdapter proposedAdapter = validatable.getValue();
            final String reasonIfAny = scalarModel.validate(proposedAdapter);
            if (reasonIfAny != null) {
              final ValidationError error = new ValidationError();
              error.setMessage(reasonIfAny);
              validatable.error(error);
            }
          }
        });
  }
Example #5
0
 @Override
 protected void onBeforeRenderWhenViewMode() {
   super.onBeforeRenderWhenViewMode();
   entityLink.setEnabled(true);
   entityLink.syncVisibilityAndUsability();
 }
Example #6
0
 private void setRequiredIfSpecified() {
   final ScalarModel scalarModel = getModel();
   final boolean required = scalarModel.isRequired();
   entityLink.setRequired(required);
 }