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; }
/** * Sorts window infos alphabetically, takes into account $ mark. * * @param windowInfoCollection mutable list of window infos */ public void sortWindowInfos(List<WindowInfo> windowInfoCollection) { windowInfoCollection.sort((w1, w2) -> { int w1DollarIndex = w1.getId().indexOf("$"); int w2DollarIndex = w2.getId().indexOf("$"); if ((w1DollarIndex > 0 && w2DollarIndex > 0) || (w1DollarIndex < 0 && w2DollarIndex < 0)) { return w1.getId().compareTo(w2.getId()); } else if (w1DollarIndex > 0) { return -1; } else { return 1; } }); }
protected WindowInfo.Type extractWindowInfoType(WindowInfo windowInfo, Class<? extends FrameOwner> controllerClass) { if (Screen.class.isAssignableFrom(controllerClass)) { return WindowInfo.Type.SCREEN; } if (ScreenFragment.class.isAssignableFrom(controllerClass)) { return WindowInfo.Type.FRAGMENT; } throw new IllegalStateException("Unknown type of screen " + windowInfo.getId()); }
protected OpenMode getScreenOpenMode(String route, WindowInfo windowInfo) { String screenRoute = windowConfig.findRoute(windowInfo.getId()); //noinspection ConstantConditions return route.startsWith(screenRoute) ? OpenMode.NEW_TAB : OpenMode.THIS_TAB; }
protected void checkPermissions(LaunchMode launchMode, WindowInfo windowInfo) { // ROOT windows are always permitted if (launchMode != OpenMode.ROOT) { boolean permitted = security.isScreenPermitted(windowInfo.getId()); if (!permitted) { throw new AccessDeniedException(PermissionType.SCREEN, windowInfo.getId()); } } }
@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; }
protected boolean isLookupWindow(WindowInfo winInfo) { Element element = screenXmlLoader.load(winInfo.getTemplate(), winInfo.getId(), ParamsMap.empty()); String screenClassName = element.attributeValue("class"); try { Class<?> screenClass = Class.forName(screenClassName); if (AbstractLookup.class.isAssignableFrom(screenClass)) { return true; } } catch (NullPointerException | ClassNotFoundException e) { return false; } return false; }
public String getDetailedScreenCaption(WindowInfo windowInfo, Locale locale) throws FileNotFoundException { String caption = getScreenCaption(windowInfo, locale); return getDetailedScreenCaption(caption, windowInfo.getId()); }
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; }
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; }
protected String getLookupScreenInternal() { return StringUtils.isNotEmpty(getLookupScreen()) ? getLookupScreen() : windowConfig.getLookupScreen(getLookupEntityClass()).getId(); }
public String getLookupScreenId(MetaClass metaClass) { MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalOrThisMetaClass(metaClass); WindowInfo windowInfo = primaryLookups.get(originalMetaClass.getJavaClass()); if (windowInfo != null) { return windowInfo.getId(); } return getMetaClassScreenId(metaClass, Window.LOOKUP_WINDOW_SUFFIX); }
public String getEditorScreenId(MetaClass metaClass) { MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalOrThisMetaClass(metaClass); WindowInfo windowInfo = primaryEditors.get(originalMetaClass.getJavaClass()); if (windowInfo != null) { return windowInfo.getId(); } return getMetaClassScreenId(metaClass, Window.EDITOR_WINDOW_SUFFIX); }
@Nullable public WindowInfo getDefaultBrowseScreen(MetaClass metaClass) { WindowInfo browseWindow = windowConfig.findWindowInfo(windowConfig.getBrowseScreenId(metaClass)); if (browseWindow != null && userSessionSource.getUserSession().isScreenPermitted(browseWindow.getId())) { return browseWindow; } WindowInfo lookupWindow = windowConfig.findWindowInfo(windowConfig.getLookupScreenId(metaClass)); if (lookupWindow != null && userSessionSource.getUserSession().isScreenPermitted(lookupWindow.getId())) { return lookupWindow; } return null; }
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 void addNavigationAction(MetaClass metaClass, MetaProperty metaProperty) { // check if browse screen available PropertyOption propertyOption = propertyOptions.get(metaProperty.getName()); WindowInfo defaultScreen = screensHelper.getDefaultBrowseScreen(metaProperty.getRange().asClass()); if (defaultScreen != null || (propertyOption != null && StringUtils.isNotEmpty(propertyOption.getScreen()))) { RelatedAction relatedAction = RelatedAction.create("related" + actionOrder.size(), listComponent, metaClass, metaProperty); relatedAction.setOpenType(openType); if (defaultScreen != null) { relatedAction.setScreen(defaultScreen.getId()); } if (propertyOption != null) { if (StringUtils.isNotEmpty(propertyOption.getCaption())) { relatedAction.setCaption(propertyOption.getCaption()); } if (StringUtils.isNotEmpty(propertyOption.getFilterCaption())) { relatedAction.setFilterCaption(propertyOption.getFilterCaption()); } if (StringUtils.isNotEmpty(propertyOption.getScreen())) { relatedAction.setScreen(propertyOption.getScreen()); } } addAction(relatedAction); } }
protected <E extends Entity> Screen createScreen(LookupBuilder<E> builder, Screens screens) { Screen screen; if (builder instanceof LookupClassBuilder) { LookupClassBuilder lookupClassBuilder = (LookupClassBuilder) builder; @SuppressWarnings("unchecked") Class<? extends Screen> screenClass = lookupClassBuilder.getScreenClass(); if (screenClass == null) { throw new IllegalArgumentException("Screen class is not set"); } screen = screens.create(screenClass, builder.getLaunchMode(), builder.getOptions()); } else { String lookupScreenId; if (builder.getScreenId() != null) { lookupScreenId = builder.getScreenId(); } else { lookupScreenId = windowConfig.getLookupScreen(builder.getEntityClass()).getId(); } if (lookupScreenId == null) { throw new IllegalArgumentException("Screen id is not set"); } screen = screens.create(lookupScreenId, builder.getLaunchMode(), builder.getOptions()); } return screen; }
protected void initScreenFilter() { WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME); Collection<WindowInfo> windows = sortWindowInfos(windowConfig.getWindows()); Map<String, String> screens = new LinkedHashMap<>(); for (WindowInfo windowInfo : windows) { String id = windowInfo.getId(); String menuId = "menu-config." + id; String localeMsg = messages.getMessage(AppConfig.getMessagesPack(), menuId); String title = menuId.equals(localeMsg) ? id : localeMsg + " (" + id + ")"; screens.put(title, id); } screenFilter.setOptionsMap(screens); componentsTreeBtn.setEnabled(screenFilter.getValue() != null); screenFilter.addValueChangeListener(e -> { componentsTreeBtn.setEnabled(screenFilter.getValue() != null); componentDescriptorsDs.setScreenId(screenFilter.getValue()); componentDescriptorsDs.refresh(); componentsTree.expandTree(); }); }
protected <T extends Screen> void loadWindowFromXml(Element element, WindowInfo windowInfo, Window window, T controller, ComponentLoaderContext componentLoaderContext) { LayoutLoader layoutLoader = beanLocator.getPrototype(LayoutLoader.NAME, componentLoaderContext); layoutLoader.setLocale(getLocale()); layoutLoader.setMessagesPack(getMessagePack(windowInfo.getTemplate())); ComponentLoader<Window> windowLoader = layoutLoader.createWindowContent(window, element, windowInfo.getId()); if (controller instanceof LegacyFrame) { screenViewsLoader.deployViews(element); initDsContext(window, element, componentLoaderContext); DsContext dsContext = ((LegacyFrame) controller).getDsContext(); if (dsContext != null) { dsContext.setFrameContext(window.getContext()); } } windowLoader.loadComponent(); }
/** * Adds a listener that reloads the selected record and sets it to editCt. */ protected void initBrowseItemChangeListener() { getBrowseContainer().addItemChangeListener(e -> { if (e.getItem() != null) { InstanceLoader<T> editLoader = getEditLoader(); DynamicAttributesGuiTools tools = getBeanLocator().get(DynamicAttributesGuiTools.NAME); String screenId = getScreenContext().getWindowInfo().getId(); if (tools.screenContainsDynamicAttributes(getEditContainer().getView(), screenId)) { editLoader.setLoadDynamicAttributes(true); } editLoader.setEntityId(e.getItem().getId()); editLoader.load(); } else { if (!editing) { getEditContainer().setItem(null); } } }); }