@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;
  }
예제 #2
0
 public EntityModel toViewMode() {
   setMode(Mode.VIEW);
   for (final ScalarModel scalarModel : propertyScalarModels.values()) {
     scalarModel.toViewMode();
   }
   return this;
 }
예제 #3
0
 public EntityModel toEditMode() {
   setMode(Mode.EDIT);
   for (final ScalarModel scalarModel : propertyScalarModels.values()) {
     scalarModel.toEditMode();
   }
   return this;
 }
예제 #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;
   }
 }
예제 #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);
   }
 }
예제 #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;
        }
      }
예제 #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;
  }
예제 #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();
   }
 }
예제 #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;
 }
예제 #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;
 }
예제 #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();
 }
예제 #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;
 }
예제 #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();
   }
 }
예제 #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();
 }
예제 #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);
 }
예제 #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);
 }
예제 #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);
 }
예제 #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();
   }
 }
예제 #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;
  }
예제 #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);
  }
예제 #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;
  }
예제 #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();
   }
 }
예제 #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);
 }
예제 #25
0
 private void setRequiredIfSpecified() {
   final ScalarModel scalarModel = getModel();
   final boolean required = scalarModel.isRequired();
   entityLink.setRequired(required);
 }
예제 #26
0
 @Override
 public boolean hasAutoComplete(final ScalarModel scalarModel) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   return actionParameter.hasAutoComplete();
 }
예제 #27
0
 @Override
 public String getDescribedAs(final ScalarModel scalarModel) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   return actionParameter.getDescription();
 }
예제 #28
0
 @Override
 public String getName(final ScalarModel scalarModel) {
   return scalarModel.getPropertyMemento().getProperty().getName();
 }
예제 #29
0
 @Override
 public ObjectSpecification getScalarTypeSpec(final ScalarModel scalarModel) {
   ObjectSpecId type = scalarModel.getPropertyMemento().getType();
   return SpecUtils.getSpecificationFor(type);
 }
예제 #30
0
 @Override
 public String getIdentifier(final ScalarModel scalarModel) {
   return scalarModel.getPropertyMemento().getIdentifier();
 }