X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api.cms%2Fsrc%2Forg%2Fargeo%2Fapi%2Fcms%2Fux%2FMvcProvider.java;fp=org.argeo.api.cms%2Fsrc%2Forg%2Fargeo%2Fapi%2Fcms%2Fux%2FMvcProvider.java;h=3556edecf7b7fe428f6c3b4fe962180822f2579c;hb=df60fd8de17590b8f4ab32fd0278e57aaaedbfa2;hp=0000000000000000000000000000000000000000;hpb=dc27b57704278684e72efcaf72b01c5b91df39f8;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api.cms/src/org/argeo/api/cms/ux/MvcProvider.java b/org.argeo.api.cms/src/org/argeo/api/cms/ux/MvcProvider.java new file mode 100644 index 000000000..3556edecf --- /dev/null +++ b/org.argeo.api.cms/src/org/argeo/api/cms/ux/MvcProvider.java @@ -0,0 +1,45 @@ +package org.argeo.api.cms.ux; + +import java.util.function.BiFunction; + +/** + * Stateless UI part creator. Takes a parent view (V) and a model context (M) in + * order to create a view part (W) which can then be further configured. Such + * object can be used as services and reference other part of the model which + * are relevant for all created UI part. + */ +@FunctionalInterface +@Deprecated +public interface MvcProvider extends BiFunction { + W createUiPart(V parent, M context); + + /** + * Whether this parent view is supported. + * + * @return true by default. + */ + default boolean isViewSupported(V parent) { + return true; + } + + /** + * Whether this context is supported. + * + * @return true by default. + */ + default boolean isModelSupported(M context) { + return true; + } + + default W apply(V parent, M context) { + if (!isViewSupported(parent)) + throw new IllegalArgumentException("Parent view " + parent + "is not supported."); + if (!isModelSupported(context)) + throw new IllegalArgumentException("Model context " + context + "is not supported."); + return createUiPart(parent, context); + } + + default W createUiPart(V parent) { + return createUiPart(parent, null); + } +}