@Override @SuppressWarnings("unchecked") public STypeCode<SICode<T>, T> getType() { return (STypeCode<SICode<T>, T>) super.getType(); }
@Override @SuppressWarnings("unchecked") public STypeCode<SICode<T>, T> getType() { return (STypeCode<SICode<T>, T>) super.getType(); }
@Override public boolean visitChildren(Object object) { if (object instanceof SInstance) { SInstance ins = (SInstance) object; if (type.isAssignableFrom(ins.getType().getClass())) { return false; } } return true; } }
public default IBehaviorContext update(SInstance... fields) { SType<?>[] types = new SType<?>[fields.length]; for (int i = 0; i < fields.length; i++) types[i] = fields[i].getType(); update(types); return this; } }
public SType<?> getTipo() { if (target == null) { throw new SingularFormException("O objeto alvo dos atributos não foi definido"); } if (target instanceof SType) { return (SType<?>) target; } return ((SInstance) target).getType(); }
/** * Checks if the instance is of the type informed or type derived of the informed type. See more in {@link * SType#isTypeOf(SType)}. */ public boolean isTypeOf(@Nonnull SType<?> parentTypeCandidate) { return getType().isTypeOf(parentTypeCandidate); } }
@Nonnull public static <A extends SType<?>> Optional<SInstance> findAncestor(SInstance node, Class<A> ancestorType) { for (SInstance parent = node.getParent(); parent != null; parent = parent.getParent()) { if (parent.getType().getClass().equals(ancestorType)) { return Optional.of(parent); } } return Optional.empty(); }
public SingularFormException add(SInstance instance) { if (instance != null) { add("instancia path", instance.getPathFull()); add("instancia classe", instance.getClass().getName()); add("instancia type", instance.getType()); if (! instance.getType().getClass().getPackage().equals(STypeString.class.getPackage())) { add("instancia type class", instance.getType().getClass().getName()); } } return this; }
public static List<SType<?>> getFields(SIComposite instance) { List<SType<?>> list = new ArrayList<>(); instance.getAllChildren().forEach(child -> addFieldToList(child.getType(), list)); return list; }
@Override public void validate(IInstanceValidatable<SIComposite> v) { Set<Boolean> nullValues = v.getInstance().streamDescendants(false) .filter(it -> it.getType() instanceof STypeSimple<?, ?>) .map(it -> it.getValue() == null) .collect(toSet()); // os campos devem ser todos nulos ou todos preenchidos if (nullValues.size() != 1) v.error("Endereço incompleto"); } }
public static Object fieldValue(SInstance instance) { Optional<RelationalColumnConverter> converter = aspectRelationalColumnConverter(instance.getType()); if (converter.isPresent()) { return converter.get().toRelationalColumn(instance); } return instance.getValue(); }
@Override public void load(SInstance instance, List<RelationalData> fromList) { for (SInstance item : getChildren(instance)) { RelationalSQL.persistenceStrategy(item.getType()).load(item, fromList); } }
private boolean setDateValue(SInstance instance) { SType type = instance.getType(); STypeSimple typeSimple = (STypeSimple) type; if (typeSimple instanceof STypeDate || type instanceof STypeDateTime || type instanceof STypeTime) { dateValue = (Date) typeSimple.convert(instance.getValue(), typeSimple.getValueClass()); return true; } return false; }
public String getReadOnlyFormattedText(WicketBuildContext ctx, IModel<? extends SInstance> model) { final SInstance mi = model.getObject(); if (mi != null && mi.getValue() != null) { Serializable instanceObject = mi.getType().asAtrProvider().getConverter().toObject(mi); if (instanceObject != null) { return mi.getType().asAtrProvider().getDisplayFunction().apply(instanceObject); } } return StringUtils.EMPTY; }
@SuppressWarnings("unchecked") public <ST extends SType<?>> List<SInstance> getChoices(IFunction<T, ST> typeFinder) { SInstance subInstance = resolveTypeFinderInstance(typeFinder); ST subtype = (ST) subInstance.getType(); Component component = getComponentForSType(subtype); SInstanceConverter converter = subInstance.asAtrProvider().getConverter(); return (List<SInstance>) ((AbstractChoice) component).getChoices().stream().map(serializable -> { SInstance choiceInstance = subtype.newInstance(); converter.fillInstance(choiceInstance, (Serializable) serializable); return choiceInstance; }).collect(Collectors.toList()); }
/** * Executa as inicilização de atribuição de valor da instância (ver {@link SType#withInitListener(IConsumer)}). Pode * sobrepor valores preexistentes. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public final void init() { //Não deve chamar o init se estiver no modo de leitura do XML if (!getDocument().isRestoreMode()) { ((SType) getType()).init(() -> this); } }
/** Retorna o primeiro diff que encotrar na árvore que é do tipo informado ou de sub tipo do tipo informado. */ final Optional<DiffInfo> findFirst(SType<?> field) { return findFirst(diff -> (diff.getOriginal() != null && diff.getOriginal().getType().isTypeOf(field)) || (diff.getNewer() != null && diff.getNewer().getType().isTypeOf(field))); }
protected void updateInternal(@Nonnull SIComposite instance, SIComposite previousPersistedInstance, Integer inclusionActor) { for (SInstance field : instance.getAllChildren()) { if (RelationalSQL.isListWithTableBound(field.getType())) { updateFieldInternal(instance, previousPersistedInstance, inclusionActor, field); } } if (execScript(RelationalSQL.update(instance, previousPersistedInstance).toSQLScript()) == 0) { throw new SingularFormNotFoundException(FormKey.fromInstance(instance)); } }
private void buildHeader(BSContainer<?> header, Form<?> form, IModel<SIList<SInstance>> list, WicketBuildContext ctx, SViewListByTable view, boolean isEdition) { final IModel<String> label = $m.ofValue(ctx.getCurrentInstance().getType().asAtr().getLabel()); final Label title = new Label("_title", label); ctx.configureContainer(label); header.appendTag("span", title); // header.add($b.visibleIf($m.get(() -> !Strings.isNullOrEmpty(label.getObject())))); final SType<SInstance> elementsType = list.getObject().getElementsType(); if (!elementsType.isComposite() && elementsType.asAtr().isRequired()) { title.add($b.classAppender("singular-form-required")); } }
private TableListPanel buildPanel(WicketBuildContext ctx, ConfirmationModal confirmationModal, String id) { final IModel<SIList<SInstance>> list = new ReadOnlyCurrentInstanceModel<>(ctx); final ViewMode viewMode = ctx.getViewMode(); final Boolean isEdition = viewMode == null || viewMode.isEdition(); final SIList<SInstance> iList = list.getObject(); final SType<?> currentType = ctx.getCurrentInstance().getType(); addInitialNumberOfLines(currentType, iList, ctx.getViewSupplier(SViewListByTable.class)); return TableListPanel.TableListPanelBuilder.build(id, (h, form) -> buildHeader(h, form, list, ctx, isEdition), (c, form) -> builContent(c, form, list, ctx, isEdition, confirmationModal), (f, form) -> buildFooter(f, form, ctx)); }