@Override public TemplateModel get(String key) throws TemplateModelException { if ("toStringDisplayDefault".equals(key)) { return new SInstanceZeroArgumentMethodTemplate<>(getInstance(), key, i -> i.toStringDisplayDefault()); } else if ("value".equals(key) || "getValue".equals(key)) { return new SInstanceZeroArgumentMethodTemplate<>(getInstance(), key, i -> getValue()); } else if ("_inst".equals(key)) { Optional<Constructor<?>> constructor = Arrays.stream(getClass().getConstructors()) .filter(c -> c.getParameterCount() == 1 && c.getParameterTypes()[0].isAssignableFrom(getInstance().getClass())) .findFirst(); if (! constructor.isPresent()) { throw new SingularFormException( "Não foi encontrado o construtor " + getClass().getSimpleName() + "(SInstance)"); } SInstanceTemplateModel<INSTANCE> newSelf; try { newSelf = (SInstanceTemplateModel<INSTANCE>) constructor.get().newInstance(getInstance()); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new SingularFormException("Erro instanciado _inst", e); } newSelf.invertedPriority = true; return newSelf; } else if ("toStringDisplay".equals(key)) { return new SInstanceZeroArgumentMethodTemplate<>(getInstance(), key, i -> i.toStringDisplay()); } return null; }
pb.addAttribute(STypeAttachment.class, ATR_ALLOWED_FILE_TYPES); pb.getType(SType.class).asAtr().displayString(ctx -> ctx.instance().toStringDisplayDefault());
pb.addAttribute(STypeAttachment.class, ATR_ALLOWED_FILE_TYPES); pb.getType(SType.class).asAtr().displayString(ctx -> ctx.instance().toStringDisplayDefault());