mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 02:07:41 +08:00
Declarative handlers approach with @Install annotation #1280
Rename @Provide to @Install
This commit is contained in:
parent
ecd7dafcfa
commit
85eda617a1
@ -28,7 +28,7 @@ import com.haulmont.cuba.gui.NoSuchScreenException;
|
||||
import com.haulmont.cuba.gui.components.AbstractFrame;
|
||||
import com.haulmont.cuba.gui.components.Window;
|
||||
import com.haulmont.cuba.gui.screen.*;
|
||||
import com.haulmont.cuba.gui.sys.ScreenDescriptorUtils;
|
||||
import com.haulmont.cuba.gui.sys.UiDescriptorUtils;
|
||||
import com.haulmont.cuba.gui.sys.UiControllerDefinition;
|
||||
import com.haulmont.cuba.gui.sys.UiControllersConfiguration;
|
||||
import com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader;
|
||||
@ -181,7 +181,7 @@ public class WindowConfig {
|
||||
if (annotation == null) {
|
||||
return null;
|
||||
}
|
||||
String template = ScreenDescriptorUtils.getInferredTemplate(annotation, screenClass);
|
||||
String template = UiDescriptorUtils.getInferredTemplate(annotation, screenClass);
|
||||
if (!template.startsWith("/")) {
|
||||
String packageName = screenClass.getPackage().getName();
|
||||
if (StringUtils.isNotEmpty(packageName)) {
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
package com.haulmont.cuba.gui.screen;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -26,16 +24,12 @@ import java.lang.annotation.RetentionPolicy;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@java.lang.annotation.Target(ElementType.METHOD)
|
||||
public @interface Provide {
|
||||
public @interface Install {
|
||||
Target target() default Target.COMPONENT;
|
||||
|
||||
@AliasFor("to")
|
||||
String value() default "";
|
||||
|
||||
@AliasFor("value")
|
||||
String to() default "";
|
||||
|
||||
Class type() default Object.class;
|
||||
|
||||
String subject() default "";
|
||||
|
||||
String to() default "";
|
||||
}
|
@ -20,13 +20,13 @@ import java.lang.annotation.*;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Sets primary subject for {@link Provide} target classes.
|
||||
* Sets primary subject for {@link Install} target classes.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface ProvideSubject {
|
||||
public @interface InstallSubject {
|
||||
|
||||
String value();
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
package com.haulmont.cuba.gui.screen;
|
||||
|
||||
/**
|
||||
* {@link Subscribe} and {@link Provide} target type.
|
||||
* {@link Subscribe} and {@link Install} target type.
|
||||
*/
|
||||
public enum Target {
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.hash.Hashing.md5;
|
||||
import static com.google.common.hash.Hashing.goodFastHash;
|
||||
|
||||
public class TestIdManager {
|
||||
|
||||
@ -47,7 +47,7 @@ public class TestIdManager {
|
||||
id = id + number;
|
||||
}
|
||||
|
||||
return md5().hashString(id, StandardCharsets.UTF_8).toString();
|
||||
return goodFastHash(128).hashString(id, StandardCharsets.UTF_8).toString();
|
||||
}
|
||||
|
||||
public String reserveId(String id) {
|
||||
@ -55,7 +55,7 @@ public class TestIdManager {
|
||||
ids.put(id, 0);
|
||||
}
|
||||
|
||||
return md5().hashString(id, StandardCharsets.UTF_8).toString();
|
||||
return goodFastHash(128).hashString(id, StandardCharsets.UTF_8).toString();
|
||||
}
|
||||
|
||||
public String normalize(String id) {
|
||||
|
@ -104,51 +104,51 @@ public class UiControllerDependencyInjector {
|
||||
|
||||
initSubscribeListeners(frameOwner);
|
||||
|
||||
initProvideObjects(frameOwner);
|
||||
initInstallMethods(frameOwner);
|
||||
|
||||
initUiEventListeners(frameOwner);
|
||||
}
|
||||
|
||||
protected void initProvideObjects(FrameOwner frameOwner) {
|
||||
protected void initInstallMethods(FrameOwner frameOwner) {
|
||||
Class<? extends FrameOwner> clazz = frameOwner.getClass();
|
||||
|
||||
List<AnnotatedMethod<Provide>> provideMethods = reflectionInspector.getAnnotatedProvideMethods(clazz);
|
||||
List<AnnotatedMethod<Install>> installMethods = reflectionInspector.getAnnotatedInstallMethods(clazz);
|
||||
|
||||
for (AnnotatedMethod<Provide> annotatedMethod : provideMethods) {
|
||||
Provide annotation = annotatedMethod.getAnnotation();
|
||||
for (AnnotatedMethod<Install> annotatedMethod : installMethods) {
|
||||
Install annotation = annotatedMethod.getAnnotation();
|
||||
|
||||
Frame frame = UiControllerUtils.getFrame(frameOwner);
|
||||
|
||||
Object targetInstance = getProvideTargetInstance(frameOwner, annotation, frame);
|
||||
Object targetInstance = getInstallTargetInstance(frameOwner, annotation, frame);
|
||||
|
||||
Class<?> instanceClass = targetInstance.getClass();
|
||||
Method provideMethod = annotatedMethod.getMethod();
|
||||
Method installMethod = annotatedMethod.getMethod();
|
||||
|
||||
MethodHandle targetSetterMethod = getProvideTargetSetterMethod(annotation, frame, instanceClass, provideMethod);
|
||||
MethodHandle targetSetterMethod = getInstallTargetSetterMethod(annotation, frame, instanceClass, installMethod);
|
||||
Class<?> targetParameterType = targetSetterMethod.type().parameterList().get(1);
|
||||
|
||||
Object handler = createProvideHandler(frameOwner, provideMethod, targetParameterType);
|
||||
Object handler = createInstallHandler(frameOwner, installMethod, targetParameterType);
|
||||
|
||||
try {
|
||||
targetSetterMethod.invoke(targetInstance, handler);
|
||||
} catch (Error e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Unable to set declarative @Provide handler for " + provideMethod, e);
|
||||
throw new RuntimeException("Unable to set declarative @Install handler for " + installMethod, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected MethodHandle getProvideTargetSetterMethod(Provide annotation, Frame frame, Class<?> instanceClass,
|
||||
protected MethodHandle getInstallTargetSetterMethod(Install annotation, Frame frame, Class<?> instanceClass,
|
||||
Method provideMethod) {
|
||||
String subjectProperty;
|
||||
if (Strings.isNullOrEmpty(annotation.subject()) && annotation.type() == Object.class) {
|
||||
ProvideSubject provideSubjectAnnotation = findMergedAnnotation(instanceClass, ProvideSubject.class);
|
||||
if (provideSubjectAnnotation != null) {
|
||||
subjectProperty = provideSubjectAnnotation.value();
|
||||
InstallSubject installSubjectAnnotation = findMergedAnnotation(instanceClass, InstallSubject.class);
|
||||
if (installSubjectAnnotation != null) {
|
||||
subjectProperty = installSubjectAnnotation.value();
|
||||
} else {
|
||||
throw new DevelopmentException(
|
||||
String.format("Unable to determine @Provide subject of %s in %s", provideMethod, frame.getId())
|
||||
String.format("Unable to determine @Install subject of %s in %s", provideMethod, frame.getId())
|
||||
);
|
||||
}
|
||||
} else if (annotation.type() != Object.class) {
|
||||
@ -158,20 +158,20 @@ public class UiControllerDependencyInjector {
|
||||
}
|
||||
|
||||
String subjectSetterName = "set" + StringUtils.capitalize(subjectProperty);
|
||||
MethodHandle targetSetterMethod = reflectionInspector.getProvideTargetMethod(instanceClass, subjectSetterName);
|
||||
MethodHandle targetSetterMethod = reflectionInspector.getInstallTargetMethod(instanceClass, subjectSetterName);
|
||||
|
||||
if (targetSetterMethod == null) {
|
||||
throw new DevelopmentException(
|
||||
String.format("Unable to find @Provide target method %s in %s", subjectProperty, instanceClass)
|
||||
String.format("Unable to find @Install target method %s in %s", subjectProperty, instanceClass)
|
||||
);
|
||||
}
|
||||
|
||||
return targetSetterMethod;
|
||||
}
|
||||
|
||||
protected Object getProvideTargetInstance(FrameOwner frameOwner, Provide annotation, Frame frame) {
|
||||
protected Object getInstallTargetInstance(FrameOwner frameOwner, Install annotation, Frame frame) {
|
||||
Object targetInstance;
|
||||
String target = ScreenDescriptorUtils.getInferredProvideId(annotation);
|
||||
String target = UiDescriptorUtils.getInferredProvideId(annotation);
|
||||
if (Strings.isNullOrEmpty(target)) {
|
||||
|
||||
switch (annotation.target()) {
|
||||
@ -188,7 +188,7 @@ public class UiControllerDependencyInjector {
|
||||
case PARENT_CONTROLLER:
|
||||
if (frameOwner instanceof Screen) {
|
||||
throw new DevelopmentException(
|
||||
String.format("Screen %s cannot use @Provide with target = PARENT_CONTROLLER",
|
||||
String.format("Screen %s cannot use @Install with target = PARENT_CONTROLLER",
|
||||
frame.getId())
|
||||
);
|
||||
}
|
||||
@ -196,24 +196,24 @@ public class UiControllerDependencyInjector {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unsupported @Provide target " + annotation.target());
|
||||
throw new UnsupportedOperationException("Unsupported @Install target " + annotation.target());
|
||||
}
|
||||
} else {
|
||||
if (annotation.target() == Target.DATA_LOADER) {
|
||||
targetInstance = UiControllerUtils.getScreenData(frameOwner).getLoader(target);
|
||||
} else {
|
||||
targetInstance = findProvideTarget(target, frame);
|
||||
targetInstance = findInstallTarget(target, frame);
|
||||
|
||||
if (targetInstance == null) {
|
||||
throw new DevelopmentException(
|
||||
String.format("Unable to find @Provide target %s in %s", target, frame.getId()));
|
||||
String.format("Unable to find @Install target %s in %s", target, frame.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return targetInstance;
|
||||
}
|
||||
|
||||
protected Object findProvideTarget(String target, Frame frame) {
|
||||
protected Object findInstallTarget(String target, Frame frame) {
|
||||
String[] elements = ValuePathHelper.parse(target);
|
||||
if (elements.length == 1) {
|
||||
Object part = frame.getSubPart(target);
|
||||
@ -248,22 +248,22 @@ public class UiControllerDependencyInjector {
|
||||
}
|
||||
}
|
||||
|
||||
throw new DevelopmentException(String.format("Unable to find @Provide target %s in %s", target, frame.getId()));
|
||||
throw new DevelopmentException(String.format("Unable to find @Install target %s in %s", target, frame.getId()));
|
||||
}
|
||||
|
||||
protected Object createProvideHandler(FrameOwner frameOwner, Method method, Class<?> targetObjectType) {
|
||||
protected Object createInstallHandler(FrameOwner frameOwner, Method method, Class<?> targetObjectType) {
|
||||
if (targetObjectType == Function.class) {
|
||||
return new ProvideInvocationFunction(frameOwner, method);
|
||||
return new InstallInvocationFunction(frameOwner, method);
|
||||
} else if (targetObjectType == Consumer.class) {
|
||||
return new ProvideInvocationConsumer(frameOwner, method);
|
||||
return new InstallInvocationConsumer(frameOwner, method);
|
||||
} else if (targetObjectType == Supplier.class) {
|
||||
return new ProvideInvocationSupplier(frameOwner, method);
|
||||
return new InstallInvocationSupplier(frameOwner, method);
|
||||
} else if (targetObjectType == BiFunction.class) {
|
||||
return new ProvideInvocationBiFunction(frameOwner, method);
|
||||
return new InstallInvocationBiFunction(frameOwner, method);
|
||||
} else {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
return newProxyInstance(classLoader, new Class[]{targetObjectType},
|
||||
new ProvideInvocationProxyHandler(frameOwner, method)
|
||||
new InstallInvocationProxyHandler(frameOwner, method)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -286,7 +286,7 @@ public class UiControllerDependencyInjector {
|
||||
Method method = annotatedMethod.getMethod();
|
||||
Subscribe annotation = annotatedMethod.getAnnotation();
|
||||
|
||||
String target = ScreenDescriptorUtils.getInferredSubscribeId(annotation);
|
||||
String target = UiDescriptorUtils.getInferredSubscribeId(annotation);
|
||||
|
||||
Parameter parameter = method.getParameters()[0];
|
||||
Class<?> eventType = parameter.getType();
|
||||
@ -673,11 +673,11 @@ public class UiControllerDependencyInjector {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProvideInvocationFunction implements Function {
|
||||
public static class InstallInvocationFunction implements Function {
|
||||
private final FrameOwner frameOwner;
|
||||
private final Method method;
|
||||
|
||||
public ProvideInvocationFunction(FrameOwner frameOwner, Method method) {
|
||||
public InstallInvocationFunction(FrameOwner frameOwner, Method method) {
|
||||
this.frameOwner = frameOwner;
|
||||
this.method = method;
|
||||
}
|
||||
@ -687,24 +687,24 @@ public class UiControllerDependencyInjector {
|
||||
try {
|
||||
return method.invoke(frameOwner, o);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException("Exception on @Provide invocation", e);
|
||||
throw new RuntimeException("Exception on @Install invocation", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProvideInvocationFunction{" +
|
||||
return "InstallInvocationFunction{" +
|
||||
"frameOwner=" + frameOwner.getClass() +
|
||||
", method=" + method +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProvideInvocationConsumer implements Consumer {
|
||||
public static class InstallInvocationConsumer implements Consumer {
|
||||
private final FrameOwner frameOwner;
|
||||
private final Method method;
|
||||
|
||||
public ProvideInvocationConsumer(FrameOwner frameOwner, Method method) {
|
||||
public InstallInvocationConsumer(FrameOwner frameOwner, Method method) {
|
||||
this.frameOwner = frameOwner;
|
||||
this.method = method;
|
||||
}
|
||||
@ -714,24 +714,24 @@ public class UiControllerDependencyInjector {
|
||||
try {
|
||||
method.invoke(frameOwner, o);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException("Exception on @Provide invocation", e);
|
||||
throw new RuntimeException("Exception on @Install invocation", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProvideInvocationConsumer{" +
|
||||
return "InstallInvocationConsumer{" +
|
||||
"frameOwner=" + frameOwner.getClass() +
|
||||
", method=" + method +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProvideInvocationSupplier implements Supplier {
|
||||
public static class InstallInvocationSupplier implements Supplier {
|
||||
private final FrameOwner frameOwner;
|
||||
private final Method method;
|
||||
|
||||
public ProvideInvocationSupplier(FrameOwner frameOwner, Method method) {
|
||||
public InstallInvocationSupplier(FrameOwner frameOwner, Method method) {
|
||||
this.frameOwner = frameOwner;
|
||||
this.method = method;
|
||||
}
|
||||
@ -741,24 +741,24 @@ public class UiControllerDependencyInjector {
|
||||
try {
|
||||
return method.invoke(frameOwner);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException("Exception on @Provide invocation", e);
|
||||
throw new RuntimeException("Exception on @Install invocation", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProvideInvocationSupplier{" +
|
||||
return "InstallInvocationSupplier{" +
|
||||
"target=" + frameOwner.getClass() +
|
||||
", method=" + method +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProvideInvocationBiFunction implements BiFunction {
|
||||
public static class InstallInvocationBiFunction implements BiFunction {
|
||||
private final FrameOwner frameOwner;
|
||||
private final Method method;
|
||||
|
||||
public ProvideInvocationBiFunction(FrameOwner frameOwner, Method method) {
|
||||
public InstallInvocationBiFunction(FrameOwner frameOwner, Method method) {
|
||||
this.frameOwner = frameOwner;
|
||||
this.method = method;
|
||||
}
|
||||
@ -768,24 +768,24 @@ public class UiControllerDependencyInjector {
|
||||
try {
|
||||
return method.invoke(frameOwner, o1, o2);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException("Exception on @Provide invocation", e);
|
||||
throw new RuntimeException("Exception on @Install invocation", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProvideInvocationBiFunction{" +
|
||||
return "InstallInvocationBiFunction{" +
|
||||
"frameOwner=" + frameOwner.getClass() +
|
||||
", method=" + method +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProvideInvocationProxyHandler implements InvocationHandler {
|
||||
public static class InstallInvocationProxyHandler implements InvocationHandler {
|
||||
private final FrameOwner frameOwner;
|
||||
private final Method method;
|
||||
|
||||
public ProvideInvocationProxyHandler(FrameOwner frameOwner, Method method) {
|
||||
public InstallInvocationProxyHandler(FrameOwner frameOwner, Method method) {
|
||||
this.frameOwner = frameOwner;
|
||||
this.method = method;
|
||||
}
|
||||
@ -811,12 +811,12 @@ public class UiControllerDependencyInjector {
|
||||
}
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException("ProvideInvocationProxyHandler does not support method " + invokedMethod);
|
||||
throw new UnsupportedOperationException("InstallInvocationProxyHandler does not support method " + invokedMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProvideInvocationProxyHandler{" +
|
||||
return "InstallInvocationProxyHandler{" +
|
||||
"frameOwner=" + frameOwner.getClass() +
|
||||
", method=" + method +
|
||||
'}';
|
||||
|
@ -28,7 +28,7 @@ import com.haulmont.cuba.gui.components.AbstractEditor;
|
||||
import com.haulmont.cuba.gui.components.AbstractFrame;
|
||||
import com.haulmont.cuba.gui.components.AbstractLookup;
|
||||
import com.haulmont.cuba.gui.components.AbstractWindow;
|
||||
import com.haulmont.cuba.gui.screen.Provide;
|
||||
import com.haulmont.cuba.gui.screen.Install;
|
||||
import com.haulmont.cuba.gui.screen.Screen;
|
||||
import com.haulmont.cuba.gui.screen.ScreenFragment;
|
||||
import com.haulmont.cuba.gui.screen.Subscribe;
|
||||
@ -98,23 +98,23 @@ public class UiControllerReflectionInspector {
|
||||
}
|
||||
});
|
||||
|
||||
protected final LoadingCache<Class<?>, List<AnnotatedMethod<Provide>>> provideMethodsCache =
|
||||
protected final LoadingCache<Class<?>, List<AnnotatedMethod<Install>>> installMethodsCache =
|
||||
CacheBuilder.newBuilder()
|
||||
.weakKeys()
|
||||
.build(new CacheLoader<Class<?>, List<AnnotatedMethod<Provide>>>() {
|
||||
.build(new CacheLoader<Class<?>, List<AnnotatedMethod<Install>>>() {
|
||||
@Override
|
||||
public List<AnnotatedMethod<Provide>> load(@Nonnull Class<?> concreteClass) {
|
||||
return getAnnotatedProvideMethodsNotCached(concreteClass);
|
||||
public List<AnnotatedMethod<Install>> load(@Nonnull Class<?> concreteClass) {
|
||||
return getAnnotatedInstallMethodsNotCached(concreteClass);
|
||||
}
|
||||
});
|
||||
|
||||
protected final LoadingCache<Class<?>, Map<String, MethodHandle>> provideTargetMethodsCache =
|
||||
protected final LoadingCache<Class<?>, Map<String, MethodHandle>> installTargetMethodsCache =
|
||||
CacheBuilder.newBuilder()
|
||||
.weakKeys()
|
||||
.build(new CacheLoader<Class<?>, Map<String, MethodHandle>>() {
|
||||
@Override
|
||||
public Map<String, MethodHandle> load(@Nonnull Class<?> concreteClass) {
|
||||
return getProvideTargetMethodsNotCached(concreteClass);
|
||||
return getInstallTargetMethodsNotCached(concreteClass);
|
||||
}
|
||||
});
|
||||
|
||||
@ -141,8 +141,8 @@ public class UiControllerReflectionInspector {
|
||||
this.trustedLambdaLookup = trusted;
|
||||
}
|
||||
|
||||
public List<AnnotatedMethod<Provide>> getAnnotatedProvideMethods(Class<?> clazz) {
|
||||
return provideMethodsCache.getUnchecked(clazz);
|
||||
public List<AnnotatedMethod<Install>> getAnnotatedInstallMethods(Class<?> clazz) {
|
||||
return installMethodsCache.getUnchecked(clazz);
|
||||
}
|
||||
|
||||
public List<AnnotatedMethod<Subscribe>> getAnnotatedSubscribeMethods(Class<?> clazz) {
|
||||
@ -171,8 +171,8 @@ public class UiControllerReflectionInspector {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MethodHandle getProvideTargetMethod(Class<?> clazz, String methodName) {
|
||||
Map<String, MethodHandle> targetMethodsCache = provideTargetMethodsCache.getUnchecked(clazz);
|
||||
public MethodHandle getInstallTargetMethod(Class<?> clazz, String methodName) {
|
||||
Map<String, MethodHandle> targetMethodsCache = installTargetMethodsCache.getUnchecked(clazz);
|
||||
return targetMethodsCache.get(methodName);
|
||||
}
|
||||
|
||||
@ -219,8 +219,8 @@ public class UiControllerReflectionInspector {
|
||||
subscribeMethodsCache.invalidateAll();
|
||||
addListenerMethodsCache.invalidateAll();
|
||||
|
||||
provideMethodsCache.invalidateAll();
|
||||
provideTargetMethodsCache.invalidateAll();
|
||||
installMethodsCache.invalidateAll();
|
||||
installTargetMethodsCache.invalidateAll();
|
||||
|
||||
lambdaMethodsCache.invalidateAll();
|
||||
}
|
||||
@ -309,16 +309,16 @@ public class UiControllerReflectionInspector {
|
||||
.collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
|
||||
protected List<AnnotatedMethod<Provide>> getAnnotatedProvideMethodsNotCached(Class<?> clazz) {
|
||||
protected List<AnnotatedMethod<Install>> getAnnotatedInstallMethodsNotCached(Class<?> clazz) {
|
||||
Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz);
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
|
||||
List<AnnotatedMethod<Provide>> annotatedMethods = new ArrayList<>();
|
||||
List<AnnotatedMethod<Install>> annotatedMethods = new ArrayList<>();
|
||||
|
||||
for (Method m : methods) {
|
||||
if (m.getParameterCount() > 0 || m.getReturnType() != Void.TYPE) {
|
||||
Provide provideAnnotation = findMergedAnnotation(m, Provide.class);
|
||||
if (provideAnnotation != null) {
|
||||
Install installAnnotation = findMergedAnnotation(m, Install.class);
|
||||
if (installAnnotation != null) {
|
||||
if (!m.isAccessible()) {
|
||||
m.setAccessible(true);
|
||||
}
|
||||
@ -328,7 +328,7 @@ public class UiControllerReflectionInspector {
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException("unable to get method handle " + m);
|
||||
}
|
||||
annotatedMethods.add(new AnnotatedMethod<>(provideAnnotation, m, methodHandle));
|
||||
annotatedMethods.add(new AnnotatedMethod<>(installAnnotation, m, methodHandle));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -533,7 +533,7 @@ public class UiControllerReflectionInspector {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Map<String, MethodHandle> getProvideTargetMethodsNotCached(Class<?> clazz) {
|
||||
protected Map<String, MethodHandle> getInstallTargetMethodsNotCached(Class<?> clazz) {
|
||||
Map<String, MethodHandle> handlesMap = new HashMap<>();
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class UiControllersConfiguration {
|
||||
}
|
||||
|
||||
String className = metadataReader.getClassMetadata().getClassName();
|
||||
String controllerId = ScreenDescriptorUtils.getInferredScreenId(idAttr, valueAttr, className);
|
||||
String controllerId = UiDescriptorUtils.getInferredScreenId(idAttr, valueAttr, className);
|
||||
|
||||
return new UiControllerDefinition(controllerId, className);
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ import com.haulmont.cuba.gui.screen.*;
|
||||
|
||||
import static com.haulmont.bali.util.Preconditions.checkNotNullArgument;
|
||||
|
||||
public final class ScreenDescriptorUtils {
|
||||
public final class UiDescriptorUtils {
|
||||
|
||||
private ScreenDescriptorUtils() {
|
||||
private UiDescriptorUtils() {
|
||||
}
|
||||
|
||||
public static String getInferredScreenId(UiController uiController,
|
||||
@ -64,14 +64,9 @@ public final class ScreenDescriptorUtils {
|
||||
return target;
|
||||
}
|
||||
|
||||
public static String getInferredProvideId(Provide provide) {
|
||||
checkNotNullArgument(provide);
|
||||
public static String getInferredProvideId(Install install) {
|
||||
checkNotNullArgument(install);
|
||||
|
||||
String target = provide.value();
|
||||
if (Strings.isNullOrEmpty(target)) {
|
||||
target = provide.to();
|
||||
}
|
||||
|
||||
return target;
|
||||
return install.to();
|
||||
}
|
||||
}
|
@ -189,7 +189,7 @@ class UiControllerDependencyInjectorTest extends Specification {
|
||||
screen.eventHub.hasSubscriptions(Screen.InitEvent)
|
||||
}
|
||||
|
||||
def "Injector supports @Provide methods"() {
|
||||
def "Injector supports @Install methods"() {
|
||||
def screen = new ScreenBindProvide()
|
||||
|
||||
def injector = new UiControllerDependencyInjector(screen, FrameOwner.NO_OPTIONS)
|
||||
|
@ -175,12 +175,12 @@ class UiControllerReflectionInspectorTest extends Specification {
|
||||
methods.find({ it.name == 'onInitMixin' }) != null
|
||||
}
|
||||
|
||||
def "Get annotated @Provide methods"() {
|
||||
def "Get annotated @Install methods"() {
|
||||
def inspector = new UiControllerReflectionInspector()
|
||||
|
||||
when:
|
||||
|
||||
def methods = inspector.getAnnotatedProvideMethods(ScreenWithProvide).collect({ it.method })
|
||||
def methods = inspector.getAnnotatedInstallMethods(ScreenWithProvide).collect({ it.method })
|
||||
|
||||
then:
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
package spec.cuba.web.screens.injection;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Table;
|
||||
import com.haulmont.cuba.gui.screen.Provide;
|
||||
import com.haulmont.cuba.gui.screen.Install;
|
||||
import com.haulmont.cuba.gui.screen.Screen;
|
||||
import com.haulmont.cuba.security.entity.User;
|
||||
|
||||
@ -14,22 +14,22 @@ import java.util.Date;
|
||||
|
||||
public class ScreenBindProvide extends Screen {
|
||||
|
||||
@Provide(subject = "formatter", to = "label1")
|
||||
@Install(subject = "formatter", to = "label1")
|
||||
private String format(Date date) {
|
||||
return "formatted-date";
|
||||
}
|
||||
|
||||
@Provide(subject = "styleProvider", to = "usersTable")
|
||||
@Install(subject = "styleProvider", to = "usersTable")
|
||||
private String getStyleName(User user, String columnId) {
|
||||
return "awesome-style";
|
||||
}
|
||||
|
||||
@Provide(type = Table.StyleProvider.class, to = "groupTable")
|
||||
@Install(type = Table.StyleProvider.class, to = "groupTable")
|
||||
public String getGroupStyle(User user, String columnId){
|
||||
return "ok-style";
|
||||
}
|
||||
|
||||
@Provide(subject = "iconProvider", to = "tree")
|
||||
@Install(subject = "iconProvider", to = "tree")
|
||||
public String getIcon(User user) {
|
||||
return "ok.png";
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ package spec.cuba.web.screens.inspection;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Button;
|
||||
import com.haulmont.cuba.gui.components.Table;
|
||||
import com.haulmont.cuba.gui.screen.Provide;
|
||||
import com.haulmont.cuba.gui.screen.Install;
|
||||
import com.haulmont.cuba.gui.screen.Screen;
|
||||
import com.haulmont.cuba.security.entity.User;
|
||||
|
||||
@ -15,26 +15,26 @@ import java.util.Date;
|
||||
|
||||
public class ScreenWithProvide extends Screen {
|
||||
|
||||
@Provide(subject = "formatter", to = "label1")
|
||||
@Install(subject = "formatter", to = "label1")
|
||||
public String format(Date date) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Provide(type = Table.StyleProvider.class, to = "usersTable")
|
||||
@Install(type = Table.StyleProvider.class, to = "usersTable")
|
||||
protected String getCellStyleName(User user, String property) {
|
||||
return "red";
|
||||
}
|
||||
|
||||
@Provide
|
||||
@Install
|
||||
private String getData() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Provide
|
||||
@Install
|
||||
protected void ignoredMethod() {
|
||||
}
|
||||
|
||||
@Provide("button1")
|
||||
@Install(to = "button1")
|
||||
protected void consumeEvent(Button.ClickEvent event) {
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ import com.haulmont.cuba.gui.screen.compatibility.LegacyFrame;
|
||||
import com.haulmont.cuba.gui.sys.FragmentContextImpl;
|
||||
import com.haulmont.cuba.gui.sys.FrameContextImpl;
|
||||
import com.haulmont.cuba.gui.sys.ScreenContextImpl;
|
||||
import com.haulmont.cuba.gui.sys.ScreenDescriptorUtils;
|
||||
import com.haulmont.cuba.gui.sys.UiDescriptorUtils;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader;
|
||||
@ -93,7 +93,7 @@ public class WebFragments implements Fragments {
|
||||
throw new IllegalArgumentException("No @UiController annotation for class " + fragmentClass);
|
||||
}
|
||||
|
||||
String screenId = ScreenDescriptorUtils.getInferredScreenId(uiController, fragmentClass);
|
||||
String screenId = UiDescriptorUtils.getInferredScreenId(uiController, fragmentClass);
|
||||
|
||||
return windowConfig.getWindowInfo(screenId);
|
||||
}
|
||||
|
@ -972,7 +972,7 @@ public class WebScreens implements Screens, WindowManager {
|
||||
throw new IllegalArgumentException("No @UiController annotation for class " + screenClass);
|
||||
}
|
||||
|
||||
String screenId = ScreenDescriptorUtils.getInferredScreenId(uiController, screenClass);
|
||||
String screenId = UiDescriptorUtils.getInferredScreenId(uiController, screenClass);
|
||||
|
||||
return windowConfig.getWindowInfo(screenId);
|
||||
}
|
||||
|
@ -97,10 +97,10 @@ public class DcScreen5 extends Screen {
|
||||
}
|
||||
}
|
||||
|
||||
@Provide(to = "usersLoader", subject = "loadDelegate", target = Target.DATA_LOADER)
|
||||
@Install(subject = "loadDelegate", to = "usersLoader", target = Target.DATA_LOADER)
|
||||
private List<User> loadUsers(LoadContext<User> loadContext) {
|
||||
List<User> users = dataManager.loadList(loadContext);
|
||||
System.out.println("Loaded users: " + users.size());
|
||||
return users;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user