@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; }
public EntityModel toViewMode() { setMode(Mode.VIEW); for (final ScalarModel scalarModel : propertyScalarModels.values()) { scalarModel.toViewMode(); } return this; }
public EntityModel toEditMode() { setMode(Mode.EDIT); for (final ScalarModel scalarModel : propertyScalarModels.values()) { scalarModel.toEditMode(); } return this; }
@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; } }
/** * 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); } }
@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; } }
/** * 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; }
@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(); } }
/** 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; }
@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; }
@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(); }
@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; }
@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(); } }
@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(); }
@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); }
@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); }
@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); }
@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(); } }
/** * 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; }
@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); }
@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; }
@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(); } }
@Override public <T extends Facet> T getFacet(final ScalarModel scalarModel, final Class<T> facetType) { final FacetHolder facetHolder = scalarModel.getParameterMemento().getActionParameter(); return facetHolder.getFacet(facetType); }
private void setRequiredIfSpecified() { final ScalarModel scalarModel = getModel(); final boolean required = scalarModel.isRequired(); entityLink.setRequired(required); }
@Override public boolean hasAutoComplete(final ScalarModel scalarModel) { final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); return actionParameter.hasAutoComplete(); }
@Override public String getDescribedAs(final ScalarModel scalarModel) { final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); return actionParameter.getDescription(); }
@Override public String getName(final ScalarModel scalarModel) { return scalarModel.getPropertyMemento().getProperty().getName(); }
@Override public ObjectSpecification getScalarTypeSpec(final ScalarModel scalarModel) { ObjectSpecId type = scalarModel.getPropertyMemento().getType(); return SpecUtils.getSpecificationFor(type); }
@Override public String getIdentifier(final ScalarModel scalarModel) { return scalarModel.getPropertyMemento().getIdentifier(); }