From 85eda617a164bb112e420eec980fff425156daf6 Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Mon, 24 Sep 2018 16:07:55 +0400 Subject: [PATCH] Declarative handlers approach with @Install annotation #1280 Rename @Provide to @Install --- .../cuba/gui/config/WindowConfig.java | 4 +- .../gui/screen/{Provide.java => Install.java} | 12 +- ...rovideSubject.java => InstallSubject.java} | 4 +- .../com/haulmont/cuba/gui/screen/Target.java | 2 +- .../haulmont/cuba/gui/sys/TestIdManager.java | 6 +- .../sys/UiControllerDependencyInjector.java | 104 +++++++++--------- .../sys/UiControllerReflectionInspector.java | 38 +++---- .../gui/sys/UiControllersConfiguration.java | 2 +- ...iptorUtils.java => UiDescriptorUtils.java} | 15 +-- .../UiControllerDependencyInjectorTest.groovy | 2 +- ...UiControllerReflectionInspectorTest.groovy | 4 +- .../screens/injection/ScreenBindProvide.java | 10 +- .../screens/inspection/ScreenWithProvide.java | 12 +- .../haulmont/cuba/web/sys/WebFragments.java | 4 +- .../com/haulmont/cuba/web/sys/WebScreens.java | 2 +- .../com/haulmont/cuba/web/tmp/DcScreen5.java | 4 +- 16 files changed, 107 insertions(+), 118 deletions(-) rename modules/gui/src/com/haulmont/cuba/gui/screen/{Provide.java => Install.java} (86%) rename modules/gui/src/com/haulmont/cuba/gui/screen/{ProvideSubject.java => InstallSubject.java} (89%) rename modules/gui/src/com/haulmont/cuba/gui/sys/{ScreenDescriptorUtils.java => UiDescriptorUtils.java} (86%) diff --git a/modules/gui/src/com/haulmont/cuba/gui/config/WindowConfig.java b/modules/gui/src/com/haulmont/cuba/gui/config/WindowConfig.java index c319d661fc..9220229c28 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/config/WindowConfig.java +++ b/modules/gui/src/com/haulmont/cuba/gui/config/WindowConfig.java @@ -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)) { diff --git a/modules/gui/src/com/haulmont/cuba/gui/screen/Provide.java b/modules/gui/src/com/haulmont/cuba/gui/screen/Install.java similarity index 86% rename from modules/gui/src/com/haulmont/cuba/gui/screen/Provide.java rename to modules/gui/src/com/haulmont/cuba/gui/screen/Install.java index 78b2ed43b1..d671d2946c 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/screen/Provide.java +++ b/modules/gui/src/com/haulmont/cuba/gui/screen/Install.java @@ -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 ""; } \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/screen/ProvideSubject.java b/modules/gui/src/com/haulmont/cuba/gui/screen/InstallSubject.java similarity index 89% rename from modules/gui/src/com/haulmont/cuba/gui/screen/ProvideSubject.java rename to modules/gui/src/com/haulmont/cuba/gui/screen/InstallSubject.java index b6d2b749e1..5b8c94f1fc 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/screen/ProvideSubject.java +++ b/modules/gui/src/com/haulmont/cuba/gui/screen/InstallSubject.java @@ -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(); } \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/screen/Target.java b/modules/gui/src/com/haulmont/cuba/gui/screen/Target.java index d5861b4530..fd56f80276 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/screen/Target.java +++ b/modules/gui/src/com/haulmont/cuba/gui/screen/Target.java @@ -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 { /** diff --git a/modules/gui/src/com/haulmont/cuba/gui/sys/TestIdManager.java b/modules/gui/src/com/haulmont/cuba/gui/sys/TestIdManager.java index 3522e2d620..87f2ee29ac 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/sys/TestIdManager.java +++ b/modules/gui/src/com/haulmont/cuba/gui/sys/TestIdManager.java @@ -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) { diff --git a/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllerDependencyInjector.java b/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllerDependencyInjector.java index 7f1ae9ade0..61cd4497e3 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllerDependencyInjector.java +++ b/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllerDependencyInjector.java @@ -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 clazz = frameOwner.getClass(); - List> provideMethods = reflectionInspector.getAnnotatedProvideMethods(clazz); + List> installMethods = reflectionInspector.getAnnotatedInstallMethods(clazz); - for (AnnotatedMethod annotatedMethod : provideMethods) { - Provide annotation = annotatedMethod.getAnnotation(); + for (AnnotatedMethod 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 + '}'; diff --git a/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllerReflectionInspector.java b/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllerReflectionInspector.java index 3c0b0711e1..317175ff82 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllerReflectionInspector.java +++ b/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllerReflectionInspector.java @@ -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, List>> provideMethodsCache = + protected final LoadingCache, List>> installMethodsCache = CacheBuilder.newBuilder() .weakKeys() - .build(new CacheLoader, List>>() { + .build(new CacheLoader, List>>() { @Override - public List> load(@Nonnull Class concreteClass) { - return getAnnotatedProvideMethodsNotCached(concreteClass); + public List> load(@Nonnull Class concreteClass) { + return getAnnotatedInstallMethodsNotCached(concreteClass); } }); - protected final LoadingCache, Map> provideTargetMethodsCache = + protected final LoadingCache, Map> installTargetMethodsCache = CacheBuilder.newBuilder() .weakKeys() .build(new CacheLoader, Map>() { @Override public Map load(@Nonnull Class concreteClass) { - return getProvideTargetMethodsNotCached(concreteClass); + return getInstallTargetMethodsNotCached(concreteClass); } }); @@ -141,8 +141,8 @@ public class UiControllerReflectionInspector { this.trustedLambdaLookup = trusted; } - public List> getAnnotatedProvideMethods(Class clazz) { - return provideMethodsCache.getUnchecked(clazz); + public List> getAnnotatedInstallMethods(Class clazz) { + return installMethodsCache.getUnchecked(clazz); } public List> getAnnotatedSubscribeMethods(Class clazz) { @@ -171,8 +171,8 @@ public class UiControllerReflectionInspector { } @Nullable - public MethodHandle getProvideTargetMethod(Class clazz, String methodName) { - Map targetMethodsCache = provideTargetMethodsCache.getUnchecked(clazz); + public MethodHandle getInstallTargetMethod(Class clazz, String methodName) { + Map 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> getAnnotatedProvideMethodsNotCached(Class clazz) { + protected List> getAnnotatedInstallMethodsNotCached(Class clazz) { Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz); MethodHandles.Lookup lookup = MethodHandles.lookup(); - List> annotatedMethods = new ArrayList<>(); + List> 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 getProvideTargetMethodsNotCached(Class clazz) { + protected Map getInstallTargetMethodsNotCached(Class clazz) { Map handlesMap = new HashMap<>(); MethodHandles.Lookup lookup = MethodHandles.lookup(); diff --git a/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllersConfiguration.java b/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllersConfiguration.java index 329a050e61..0feb593068 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllersConfiguration.java +++ b/modules/gui/src/com/haulmont/cuba/gui/sys/UiControllersConfiguration.java @@ -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); } diff --git a/modules/gui/src/com/haulmont/cuba/gui/sys/ScreenDescriptorUtils.java b/modules/gui/src/com/haulmont/cuba/gui/sys/UiDescriptorUtils.java similarity index 86% rename from modules/gui/src/com/haulmont/cuba/gui/sys/ScreenDescriptorUtils.java rename to modules/gui/src/com/haulmont/cuba/gui/sys/UiDescriptorUtils.java index 116ffb80c7..4c426f36c3 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/sys/ScreenDescriptorUtils.java +++ b/modules/gui/src/com/haulmont/cuba/gui/sys/UiDescriptorUtils.java @@ -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(); } } \ No newline at end of file diff --git a/modules/gui/test/spec/cuba/web/screens/UiControllerDependencyInjectorTest.groovy b/modules/gui/test/spec/cuba/web/screens/UiControllerDependencyInjectorTest.groovy index 8bf7c1a604..f55a8a5f1e 100644 --- a/modules/gui/test/spec/cuba/web/screens/UiControllerDependencyInjectorTest.groovy +++ b/modules/gui/test/spec/cuba/web/screens/UiControllerDependencyInjectorTest.groovy @@ -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) diff --git a/modules/gui/test/spec/cuba/web/screens/UiControllerReflectionInspectorTest.groovy b/modules/gui/test/spec/cuba/web/screens/UiControllerReflectionInspectorTest.groovy index 59d9f02ec5..111ea40ff9 100644 --- a/modules/gui/test/spec/cuba/web/screens/UiControllerReflectionInspectorTest.groovy +++ b/modules/gui/test/spec/cuba/web/screens/UiControllerReflectionInspectorTest.groovy @@ -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: diff --git a/modules/gui/test/spec/cuba/web/screens/injection/ScreenBindProvide.java b/modules/gui/test/spec/cuba/web/screens/injection/ScreenBindProvide.java index 6ab278a1e3..c7cb9e6c10 100644 --- a/modules/gui/test/spec/cuba/web/screens/injection/ScreenBindProvide.java +++ b/modules/gui/test/spec/cuba/web/screens/injection/ScreenBindProvide.java @@ -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"; } diff --git a/modules/gui/test/spec/cuba/web/screens/inspection/ScreenWithProvide.java b/modules/gui/test/spec/cuba/web/screens/inspection/ScreenWithProvide.java index a5de34303a..fef6c9ef1d 100644 --- a/modules/gui/test/spec/cuba/web/screens/inspection/ScreenWithProvide.java +++ b/modules/gui/test/spec/cuba/web/screens/inspection/ScreenWithProvide.java @@ -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) { } diff --git a/modules/web/src/com/haulmont/cuba/web/sys/WebFragments.java b/modules/web/src/com/haulmont/cuba/web/sys/WebFragments.java index 14ff2db56c..c1550ff11b 100644 --- a/modules/web/src/com/haulmont/cuba/web/sys/WebFragments.java +++ b/modules/web/src/com/haulmont/cuba/web/sys/WebFragments.java @@ -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); } diff --git a/modules/web/src/com/haulmont/cuba/web/sys/WebScreens.java b/modules/web/src/com/haulmont/cuba/web/sys/WebScreens.java index f8004f2658..e22c0b09b0 100644 --- a/modules/web/src/com/haulmont/cuba/web/sys/WebScreens.java +++ b/modules/web/src/com/haulmont/cuba/web/sys/WebScreens.java @@ -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); } diff --git a/modules/web/src/com/haulmont/cuba/web/tmp/DcScreen5.java b/modules/web/src/com/haulmont/cuba/web/tmp/DcScreen5.java index 234b5b0133..6e16cdfce3 100644 --- a/modules/web/src/com/haulmont/cuba/web/tmp/DcScreen5.java +++ b/modules/web/src/com/haulmont/cuba/web/tmp/DcScreen5.java @@ -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 loadUsers(LoadContext loadContext) { List users = dataManager.loadList(loadContext); System.out.println("Loaded users: " + users.size()); return users; } -} +} \ No newline at end of file