protected Collection<WindowInfo> sortWindowInfos(Collection<WindowInfo> infos) { List<WindowInfo> infosContainer = new ArrayList<>(infos); infosContainer.sort((o1, o2) -> { if (o1.getId().contains("$") != o2.getId().contains("$")) { if (o1.getId().contains("$")) { return -1; } else { return 1; } } else { return o1.getId().compareTo(o2.getId()); } }); return infosContainer; }
@Nullable protected Element loadScreenXml(WindowInfo windowInfo, ScreenOptions options) { String templatePath = windowInfo.getTemplate(); if (StringUtils.isNotEmpty(templatePath)) { Map<String, Object> params = Collections.emptyMap(); if (options instanceof MapScreenOptions) { params = ((MapScreenOptions) options).getParams(); } return screenXmlLoader.load(templatePath, windowInfo.getId(), params); } return null; }
@Nullable public String getScreenCaption(WindowInfo windowInfo, Locale locale) throws FileNotFoundException { String src = windowInfo.getTemplate(); if (StringUtils.isNotEmpty(src)) { String key = getCaptionCacheKey(src, locale); String caption = captionCache.get(key); if (caption != null) { return caption; } Element window = getWindowElement(src); if (window != null) { return getScreenCaption(window, src); } } Class screenClass = windowInfo.getControllerClass(); return screenClass.getSimpleName(); }
public ResolvedWindowInfo(WindowInfo windowInfo, Type type, Class<? extends FrameOwner> controllerClass, String template) { super(windowInfo.getId(), null, windowInfo.getDescriptor(), windowInfo.getControllerClassName(), windowInfo.getRouteDefinition()); this.template = template; this.controllerClass = controllerClass; this.type = type; }
@SuppressWarnings("unchecked") public Class<? extends Screen> asScreen() { Class<? extends FrameOwner> controllerClass = getControllerClass(); if (!Screen.class.isAssignableFrom(controllerClass)) { throw new IllegalStateException("WindowInfo is not Screen - " + this.toString()); } return (Class<? extends Screen>) controllerClass; }
protected List<String> getAllLookupIds() { Collection<WindowInfo> allWindows = windowConfig.getWindows(); List<String> lookupIds = new ArrayList<>(); for (WindowInfo winInfo : allWindows) { if (isNotBlank(winInfo.getTemplate()) && isLookupWindow(winInfo)) { lookupIds.add(winInfo.getId()); } else if (winInfo.getScreenClass() != null && AbstractLookup.class.isAssignableFrom(winInfo.getScreenClass())) { lookupIds.add(winInfo.getId()); } } filterLookupFields(lookupIds); return lookupIds; }
protected <T extends ScreenFragment> T createFragment(FrameOwner parent, WindowInfo windowInfo, ScreenOptions options) { if (windowInfo.getType() != WindowInfo.Type.FRAGMENT) { throw new IllegalArgumentException( String.format("Unable to create fragment %s with type %s", windowInfo.getId(), windowInfo.getType()) ); StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId()); ScreenFragment controller = createController(windowInfo, fragment, windowInfo.asFragment()); setWindowId(controller, windowInfo.getId()); setFrame(controller, fragment); setScreenContext(controller, StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, windowInfo.getId()); loaderContext.setCurrentFrameId(windowInfo.getId()); loaderContext.setFullFrameId(windowInfo.getId()); loaderContext.setFrame(fragment); loaderContext.setParent(null); if (windowInfo.getTemplate() != null) { ComponentLoaderContext innerContext = new ComponentLoaderContext(options); innerContext.setCurrentFrameId(windowInfo.getId()); innerContext.setFullFrameId(windowInfo.getId()); innerContext.setFrame(fragment); innerContext.setParent(loaderContext); layoutLoader.setMessagesPack(getMessagePack(windowInfo.getTemplate()));
if (src == null) { windowInfo = getWindowConfig().getWindowInfo(screenId).resolve(); if (windowInfo.getTemplate() == null) { throw new GuiDevelopmentException( String.format("Screen %s doesn't have template path configured", screenId), StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId()); ScreenFragment controller = createController(windowInfo, fragment, windowInfo.asFragment()); setWindowId(controller, windowInfo.getId()); setFrame(controller, fragment); setScreenContext(controller, if (windowInfo.getTemplate() != null) { String frameId = fragmentId; if (parentContext.getFullFrameId() != null) { layoutLoader.setMessagesPack(getMessagePack(windowInfo.getTemplate())); Element windowElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getContext().getParams());
String windowId = windowInfo.getId(); String src = windowInfo.getTemplate(); if (StringUtils.isNotEmpty(src)) { try { if (windowElement != null) { if (isEntityAvailable(windowElement, windowInfo.getControllerClass(), entityClass, filterScreenType)) { String caption = getScreenCaption(windowElement, src); caption = getDetailedScreenCaption(caption, windowId);
ScreenFragment controller = createController(windowInfo, fragment, windowInfo.asFragment()); setWindowId(controller, windowInfo.getId()); setFrame(controller, fragment); setScreenContext(controller, if (windowInfo.getTemplate() != null) { String frameId = fragmentId; if (parentContext.getFullFrameId() != null) { layoutLoader.setMessagesPack(getMessagePack(windowInfo.getTemplate())); Element windowElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getContext().getParams());
@Nullable @Override public String getTemplate(WindowInfo windowInfo) { return resolveWindowInfo(windowInfo).getTemplate(); }
protected Screen createEditor(WindowInfo windowInfo, NavigationState requestedState) { Map<String, Object> screenOptions = createEditorScreenOptions(windowInfo, requestedState); if (screenOptions.isEmpty()) { return null; } Screen editor; OpenMode openMode = getScreenOpenMode(requestedState.getNestedRoute(), windowInfo); if (LegacyFrame.class.isAssignableFrom(windowInfo.getControllerClass())) { editor = getScreens().create(windowInfo.getId(), openMode, new MapScreenOptions(screenOptions)); } else { editor = getScreens().create(windowInfo.getId(), openMode); } Entity entity = (Entity) screenOptions.get(WindowParams.ITEM.name()); //noinspection unchecked ((EditorScreen<Entity>) editor).setEntityToEdit(entity); return editor; }
protected <T extends Screen> T createScreen(WindowInfo windowInfo, LaunchMode launchMode, ScreenOptions options) { if (windowInfo.getType() != WindowInfo.Type.SCREEN) { throw new IllegalArgumentException( String.format("Unable to create screen %s with type %s", windowInfo.getId(), windowInfo.getType()) ); Class<T> resolvedScreenClass = (Class<T>) windowInfo.getControllerClass(); StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId()); setWindowId(controller, windowInfo.getId()); setFrame(controller, window); setScreenContext(controller, StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, windowInfo.getId()); componentLoaderContext.setFullFrameId(windowInfo.getId()); componentLoaderContext.setCurrentFrameId(windowInfo.getId()); componentLoaderContext.setFrame(window); StopWatch injectStopWatch = createStopWatch(ScreenLifeCycle.INJECTION, windowInfo.getId()); StopWatch initStopWatch = createStopWatch(ScreenLifeCycle.INIT, windowInfo.getId());
String template; if (windowInfo.getDescriptor() != null) { String className = windowInfo.getDescriptor().attributeValue("class"); template = windowInfo.getDescriptor().attributeValue("template"); windowInfo.getId(), Collections.emptyMap()); className = screenXml.attributeValue("class"); } else { } else if (windowInfo.getControllerClassName() != null) { controllerClass = loadDefinedScreenClass(windowInfo.getControllerClassName()); throw new IllegalStateException("Neither screen class nor descriptor is set for WindowInfo " + windowInfo.getId());
protected RouteDefinition getRouteDef(Screen screen) { return screen == null ? null : getScreenContext(screen).getWindowInfo().getRouteDefinition(); }
protected boolean isEditor(WindowInfo windowInfo) { return EditorScreen.class.isAssignableFrom(windowInfo.getControllerClass()); }
@Deprecated protected Map<String, Object> createParametersMap(WindowInfo windowInfo, @Nullable Map<String, Object> params) { Map<String, Object> map; if (params != null) { map = new HashMap<>(params.size()); } else { map = new HashMap<>(); } Element element = windowInfo.getDescriptor(); if (element != null) { Element paramsElement = element.element("params") != null ? element.element("params") : element; if (paramsElement != null) { List<Element> paramElements = paramsElement.elements("param"); for (Element paramElement : paramElements) { String name = paramElement.attributeValue("name"); String value = paramElement.attributeValue("value"); if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { Boolean booleanValue = Boolean.valueOf(value); map.put(name, booleanValue); } else { map.put(name, value); } } } } if (params != null) { map.putAll(params); } return map; }
protected void registerScreen(String id, WindowInfo windowInfo) { String controllerClassName = windowInfo.getControllerClassName(); if (controllerClassName != null) { MetadataReader classMetadata = loadClassMetadata(controllerClassName); AnnotationMetadata annotationMetadata = classMetadata.getAnnotationMetadata(); registerPrimaryEditor(windowInfo, annotationMetadata); registerPrimaryLookup(windowInfo, annotationMetadata); } screens.put(id, windowInfo); RouteDefinition routeDef = windowInfo.getRouteDefinition(); if (routeDef != null) { String anotherScreenId = routes.get(routeDef.getPath()); if (anotherScreenId != null && !Objects.equals(id, anotherScreenId)) { log.debug("Multiple use of the route '{}' for different screens is detected: '{}' and '{}'. " + "The screen '{}' will be opened during navigation as the last registered screen", routeDef.getPath(), id, anotherScreenId, id); } routes.put(routeDef.getPath(), id); } }
@Override public <T extends Screen> T create(Class<T> requiredScreenClass, LaunchMode launchMode, ScreenOptions options) { checkNotNullArgument(requiredScreenClass); checkNotNullArgument(launchMode); checkNotNullArgument(options); WindowInfo windowInfo = getScreenInfo(requiredScreenClass).resolve(); return createScreen(windowInfo, launchMode, options); }
@Override public WindowInfo.Type getType(WindowInfo windowInfo) { return resolveWindowInfo(windowInfo).getType(); }