/** * Recupera o Path a partir de um model * @param model o model que representa a instancia * @param <T> o tipo do model * @return o path */ private <T> Optional<String> getPath(IModel<T> model) { final T object = model.getObject(); if (object instanceof SInstance) { return Optional.of(((SInstance) object).getPathFromRoot()); } return Optional.empty(); }
/** * Recupera o Path a partir de um model * @param model o model que representa a instancia * @param <T> o tipo do model * @return o path */ private <T> Optional<String> getPath(IModel<T> model) { final T object = model.getObject(); if (object instanceof SInstance) { return Optional.of(((SInstance) object).getPathFromRoot()+ ((SInstance) object).getId()); } return Optional.empty(); }
private static void defineFocusField(SInstance instance, FormSerialized fs) { if (instance.getRoot() != instance) { fs.setFocusFieldPath(instance.getPathFromRoot()); } }
private static void defineFocusField(SInstance instance, FormSerialized fs) { if (instance.getDocument().getRoot() != instance) { fs.setFocusFieldPath(instance.getPathFromRoot()); } }
/** * Copia para o documento atual todas as anotação do documento fonte que tiverem um caminho corresponde no documento * atual. */ public void copyAnnotationsFrom(SDocument source) { Objects.requireNonNull(source); DocumentAnnotations sourceAnnotations = source.getDocumentAnnotations(); if (sourceAnnotations.hasAnnotations()) { for (SIAnnotation sourceAnnotation : sourceAnnotations.annotations) { source.findInstanceById(sourceAnnotation.getTargetId()).ifPresent(si -> { String pathFromRoot = si.getPathFromRoot(); //localiza a instancia correspondente no formulario destino SInstance targetInstance = document.getRoot(); if (pathFromRoot != null){ targetInstance = document.getRoot().getFieldOpt(pathFromRoot).orElse(targetInstance); } //Copiando todos os valores da anotação (inclusive o id na sinstance antiga) SIAnnotation targetAnnotation = getAnnotationOrCreate(targetInstance, sourceAnnotation.getClassifier()); Value.copyValues(sourceAnnotation, targetAnnotation); //Corrigindo o ID targetAnnotation.setTarget(targetInstance); }); } } }
/** * Copia para o documento atual todas as anotação do documento fonte que tiverem um caminho corresponde no documento * atual. */ public void copyAnnotationsFrom(SDocument source) { Objects.requireNonNull(source); DocumentAnnotations sourceAnnotations = source.getDocumentAnnotations(); if (sourceAnnotations.hasAnnotations()) { for (SIAnnotation sourceAnnotation : sourceAnnotations.annotations) { source.findInstanceById(sourceAnnotation.getTargetId()).ifPresent(si -> { String pathFromRoot = si.getPathFromRoot(); //localiza a instancia correspondente no formulario destino SInstance targetInstance = document.getRoot(); if (pathFromRoot != null){ targetInstance = ((SIComposite) document.getRoot()).getField(pathFromRoot); } //Copiando todos os valores da anotação (inclusive o id na sinstance antiga) SIAnnotation targetAnnotation = getAnnotationOrCreate(targetInstance, sourceAnnotation.getClassifier()); Value.copyValues(sourceAnnotation, targetAnnotation); //Corrigindo o ID targetAnnotation.setTarget(targetInstance); }); } } }
@Override public void onClick(AjaxRequestTarget target) { final SInstance si = m.getObject(); if (si instanceof SIList) { final SIList sil = (SIList) si; if (sil.getType().getMaximumSize() != null && sil.getType().getMaximumSize() == sil.size()) { target.appendJavaScript(";bootbox.alert('A quantidade máxima de valores foi atingida.');"); target.appendJavaScript(Scripts.multipleModalBackDrop()); } else { adding = true; pushStatus(); SInstance sInstance = sil.addNew(); IModel<? extends SInstance> itemModel = new SInstanceFieldModel<>(ctx.getRootContext().getModel(), sInstance.getPathFromRoot()); showCrud(ctx, target, itemModel); } } } });
@Override public void onClick(AjaxRequestTarget target) { final SInstance si = m.getObject(); if (si instanceof SIList) { final SIList sil = (SIList) si; if (sil.getType().getMaximumSize() != null && sil.getType().getMaximumSize() == sil.size()) { target.appendJavaScript(";bootbox.alert('A Quantidade máxima de valores foi atingida.');"); target.appendJavaScript(Scripts.multipleModalBackDrop()); } else { adding = true; pushStatus(); SInstance sInstance = sil.addNew(); IModel<? extends SInstance> itemModel = new SInstanceFieldModel<>(ctx.getRootContext().getModel(), sInstance.getPathFromRoot()); showCrud(ctx, target, itemModel); } } } });