@Override
  protected ApplicationAdvice appliesTo(IModel<?> model) {
    if (model instanceof ScalarModel) {
      ScalarModel mo = (ScalarModel) model;
      ObjectSpecification os = mo.getTypeOfSpecification();
      ObjectSpecification locatableSpec =
          getSpecificationLoader().loadSpecification(ReportPrinter.class);
      if (os.isOfType(locatableSpec)) {
        System.out.println(locatableSpec);
        return ApplicationAdvice.APPLIES;
      }

      /* Remove
      Object obj = model.getObject();
      PropertyMemento pm = ((ScalarModel) model).getPropertyMemento();
      if (pm != null && pm.getIdentifier().equals("description")){
      	//return ApplicationAdvice.APPLIES_EXCLUSIVELY;
      }
      if (obj != null) {
      	if (obj instanceof PojoAdapter) {
      		PojoAdapter po = (PojoAdapter) obj;
      		ObjectSpecification os2 =  po.getSpecification();
      		System.out.println(os2.getSingularName());
      		System.out.println(po.getSpecification().getCorrespondingClass().getName());
      		if (po.getSpecification().getCorrespondingClass().isAnnotationPresent(Html.class)) {
      			//return ApplicationAdvice.APPLIES;
      		}
      	}
      }
      */
    }
    return ApplicationAdvice.DOES_NOT_APPLY;
  }
Ejemplo n.º 2
0
 public EntityModel toViewMode() {
   setMode(Mode.VIEW);
   for (final ScalarModel scalarModel : propertyScalarModels.values()) {
     scalarModel.toViewMode();
   }
   return this;
 }
Ejemplo n.º 3
0
 public EntityModel toEditMode() {
   setMode(Mode.EDIT);
   for (final ScalarModel scalarModel : propertyScalarModels.values()) {
     scalarModel.toEditMode();
   }
   return this;
 }
Ejemplo n.º 4
0
 @Override
 public int getAutoCompleteOrChoicesMinLength(ScalarModel scalarModel) {
   if (scalarModel.hasAutoComplete()) {
     final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
     final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
     return actionParameter.getAutoCompleteMinLength();
   } else {
     return 0;
   }
 }
Ejemplo n.º 5
0
 /**
  * Resets the {@link #propertyScalarModels hash} of {@link ScalarModel}s for each {@link
  * PropertyMemento property} to the value held in the underlying {@link #getObject() entity}.
  */
 public void resetPropertyModels() {
   adapterMemento.resetVersion();
   for (final PropertyMemento pm : propertyScalarModels.keySet()) {
     final ScalarModel scalarModel = propertyScalarModels.get(pm);
     final ObjectAdapter adapter = getObject();
     final ObjectAdapter associatedAdapter =
         pm.getProperty().get(adapter, InteractionInitiatedBy.USER);
     scalarModel.setObject(associatedAdapter);
   }
 }
Ejemplo n.º 6
0
      @Override
      public int getAutoCompleteOrChoicesMinLength(ScalarModel scalarModel) {

        if (scalarModel.hasAutoComplete()) {
          final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
          final OneToOneAssociation property = propertyMemento.getProperty();
          return property.getAutoCompleteMinLength();
        } else {
          return 0;
        }
      }
Ejemplo n.º 7
0
  /**
   * Apply changes to the underlying adapter (possibly returning a new adapter).
   *
   * @return adapter, which may be different from the original (if a {@link
   *     ViewModelFacet#isCloneable(Object) cloneable} view model, for example.
   */
  public ObjectAdapter apply() {
    ObjectAdapter adapter = getObjectAdapterMemento().getObjectAdapter(ConcurrencyChecking.CHECK);
    for (final ScalarModel scalarModel : propertyScalarModels.values()) {
      final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();

      //
      // previously there was a guard here to only apply changes provided:
      //
      // property.containsDoOpFacet(NotPersistedFacet.class) == null
      //
      // however, that logic is wrong; although a property may not be directly
      // persisted so far as JDO is concerned, it may be indirectly persisted
      // as the result of business logic in the setter.
      //
      // for example, see ExampleTaggableEntity (in isisaddons-module-tags).
      //

      //
      // on the other hand, we mustn't attempt to apply changes for disabled properties...
      // even if the property is persisted (it might be written to by an action), it is never
      // updated by
      // an edit.
      //
      // Fundamentally, then, any non-disabled property (whether persisted or not) should be updated
      // in the
      // Isis runtime.
      //

      if (property.containsDoOpFacet(DisabledFacet.class)) {
        // skip, as per comments above
        continue;
      }

      final ObjectAdapter associate = scalarModel.getObject();
      property.set(adapter, associate, InteractionInitiatedBy.USER);
    }

    final ViewModelFacet recreatableObjectFacet =
        adapter.getSpecification().getFacet(ViewModelFacet.class);
    if (recreatableObjectFacet != null) {
      final Object viewModel = adapter.getObject();
      final boolean cloneable = recreatableObjectFacet.isCloneable(viewModel);
      if (cloneable) {
        final Object newViewModel = recreatableObjectFacet.clone(viewModel);
        adapter = getAdapterManager().adapterFor(newViewModel);
      }
    }

    getObjectAdapterMemento().setAdapter(adapter);
    toViewMode();

    return adapter;
  }
Ejemplo n.º 8
0
 @Override
 public String disable(final ScalarModel scalarModel, final Where where) {
   final ObjectAdapter parentAdapter =
       scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
   final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
   try {
     final AuthenticationSession session = scalarModel.getAuthenticationSession();
     final Consent usable = property.isUsable(session, parentAdapter, where);
     return usable.isAllowed() ? null : usable.getReason();
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
Ejemplo n.º 9
0
 /** Lazily populates with the current value of each property. */
 public ScalarModel getPropertyModel(final PropertyMemento pm) {
   ScalarModel scalarModel = propertyScalarModels.get(pm);
   if (scalarModel == null) {
     scalarModel = new ScalarModel(getObjectAdapterMemento(), pm);
     if (isViewMode()) {
       scalarModel.toViewMode();
     } else {
       scalarModel.toEditMode();
     }
     propertyScalarModels.put(pm, scalarModel);
   }
   return scalarModel;
 }
Ejemplo n.º 10
0
 @Override
 public Integer getScale(ScalarModel scalarModel) {
   final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
   final OneToOneAssociation property = propertyMemento.getProperty();
   final BigDecimalValueFacet facet = property.getFacet(BigDecimalValueFacet.class);
   return facet != null ? facet.getScale() : null;
 }
Ejemplo n.º 11
0
 @Override
 public String getLongName(final ScalarModel scalarModel) {
   ObjectSpecId objectSpecId = scalarModel.parentObjectAdapterMemento.getObjectSpecId();
   final String specShortName =
       SpecUtils.getSpecificationFor(objectSpecId).getShortIdentifier();
   return specShortName + "-" + scalarModel.getPropertyMemento().getProperty().getId();
 }
Ejemplo n.º 12
0
 @Override
 public Integer getScale(ScalarModel scalarModel) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   final BigDecimalValueFacet facet = actionParameter.getFacet(BigDecimalValueFacet.class);
   return facet != null ? facet.getScale() : null;
 }
Ejemplo n.º 13
0
 @Override
 public String parseAndValidate(
     final ScalarModel scalarModel, final String proposedPojoAsStr) {
   final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
   ParseableFacet parseableFacet = property.getFacet(ParseableFacet.class);
   if (parseableFacet == null) {
     parseableFacet = property.getSpecification().getFacet(ParseableFacet.class);
   }
   try {
     final ObjectAdapter parentAdapter =
         scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
     final ObjectAdapter currentValue = property.get(parentAdapter);
     Localization localization = IsisContext.getLocalization();
     final ObjectAdapter proposedAdapter =
         parseableFacet.parseTextEntry(currentValue, proposedPojoAsStr, localization);
     final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter);
     return valid.isAllowed() ? null : valid.getReason();
   } catch (final ConcurrencyException ex) {
     // disregard concurrency exceptions because will pick up at the IFormValidator level
     // rather
     // than each individual property.
     return null;
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
Ejemplo n.º 14
0
 @Override
 public String getLongName(final ScalarModel scalarModel) {
   final ObjectAdapterMemento adapterMemento = scalarModel.getObjectAdapterMemento();
   if (adapterMemento == null) {
     // shouldn't happen
     return null;
   }
   ObjectSpecId objectSpecId = adapterMemento.getObjectSpecId();
   final String specShortName =
       SpecUtils.getSpecificationFor(objectSpecId).getShortIdentifier();
   final String parmId =
       scalarModel
           .getParameterMemento()
           .getActionParameter()
           .getIdentifier()
           .toNameIdentityString();
   return specShortName + "-" + parmId + "-" + scalarModel.getParameterMemento().getNumber();
 }
Ejemplo n.º 15
0
 @Override
 public List<ObjectAdapter> getChoices(
     final ScalarModel scalarModel, final ObjectAdapter[] argumentsIfAvailable) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   final ObjectAdapter[] choices =
       actionParameter.getChoices(
           scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK),
           argumentsIfAvailable);
   return choicesAsList(choices);
 }
Ejemplo n.º 16
0
 @Override
 public List<ObjectAdapter> getChoices(
     final ScalarModel scalarModel, final ObjectAdapter[] argumentsIfAvailable) {
   final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
   final OneToOneAssociation property = propertyMemento.getProperty();
   final ObjectAdapter[] choices =
       property.getChoices(
           scalarModel.parentObjectAdapterMemento.getObjectAdapter(
               ConcurrencyChecking.NO_CHECK));
   return choicesAsList(choices);
 }
Ejemplo n.º 17
0
 @Override
 public List<ObjectAdapter> getAutoComplete(final ScalarModel scalarModel, String searchArg) {
   final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
   final OneToOneAssociation property = propertyMemento.getProperty();
   final ObjectAdapter[] choices =
       property.getAutoComplete(
           scalarModel.parentObjectAdapterMemento.getObjectAdapter(
               ConcurrencyChecking.NO_CHECK),
           searchArg);
   return choicesAsList(choices);
 }
Ejemplo n.º 18
0
 @Override
 public String validate(final ScalarModel scalarModel, final ObjectAdapter proposedAdapter) {
   final ObjectAdapter parentAdapter =
       scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
   final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
   try {
     final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter);
     return valid.isAllowed() ? null : valid.getReason();
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
Ejemplo n.º 19
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;
  }
Ejemplo n.º 20
0
 @Override
 public List<ObjectAdapter> getAutoComplete(
     final ScalarModel scalarModel, final String searchArg) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   final ObjectAdapter[] choices =
       actionParameter.getAutoComplete(
           scalarModel.parentObjectAdapterMemento.getObjectAdapter(
               ConcurrencyChecking.NO_CHECK),
           searchArg);
   return choicesAsList(choices);
 }
  @Override
  public void query(
      final String term,
      final int page,
      final com.vaynberg.wicket.select2.Response<ObjectAdapterMemento> response) {

    final List<ObjectAdapterMemento> mementos = Lists.newArrayList(obtainMementos(term));
    // if not mandatory, and the list doesn't contain null already, then add it in.
    if (!scalarModel.isRequired() && !mementos.contains(null)) {
      mementos.add(0, null);
    }
    response.addAll(mementos);
  }
Ejemplo n.º 22
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;
  }
Ejemplo n.º 23
0
 @Override
 public String parseAndValidate(
     final ScalarModel scalarModel, final String proposedPojoAsStr) {
   final ObjectActionParameter parameter =
       scalarModel.getParameterMemento().getActionParameter();
   ParseableFacet parseableFacet = parameter.getFacet(ParseableFacet.class);
   if (parseableFacet == null) {
     parseableFacet = parameter.getSpecification().getFacet(ParseableFacet.class);
   }
   try {
     final ObjectAdapter parentAdapter =
         scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
     Localization localization = IsisContext.getLocalization();
     final String invalidReasonIfAny =
         parameter.isValid(parentAdapter, proposedPojoAsStr, localization);
     return invalidReasonIfAny;
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
Ejemplo n.º 24
0
 @Override
 public <T extends Facet> T getFacet(final ScalarModel scalarModel, final Class<T> facetType) {
   final FacetHolder facetHolder = scalarModel.getParameterMemento().getActionParameter();
   return facetHolder.getFacet(facetType);
 }
Ejemplo n.º 25
0
 private void setRequiredIfSpecified() {
   final ScalarModel scalarModel = getModel();
   final boolean required = scalarModel.isRequired();
   entityLink.setRequired(required);
 }
Ejemplo n.º 26
0
 @Override
 public boolean hasAutoComplete(final ScalarModel scalarModel) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   return actionParameter.hasAutoComplete();
 }
Ejemplo n.º 27
0
 @Override
 public String getDescribedAs(final ScalarModel scalarModel) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   return actionParameter.getDescription();
 }
Ejemplo n.º 28
0
 @Override
 public String getName(final ScalarModel scalarModel) {
   return scalarModel.getPropertyMemento().getProperty().getName();
 }
Ejemplo n.º 29
0
 @Override
 public ObjectSpecification getScalarTypeSpec(final ScalarModel scalarModel) {
   ObjectSpecId type = scalarModel.getPropertyMemento().getType();
   return SpecUtils.getSpecificationFor(type);
 }
Ejemplo n.º 30
0
 @Override
 public String getIdentifier(final ScalarModel scalarModel) {
   return scalarModel.getPropertyMemento().getIdentifier();
 }