protected ScreenContext getScreenContext() { return UiControllerUtils.getScreenContext(screen); }
@Deprecated @Override public WindowManager getWindowManager() { return (WindowManager) UiControllerUtils.getScreenContext(getFrameOwner()).getScreens(); }
@Deprecated @Override public WindowManager getWindowManager() { return (WindowManager) UiControllerUtils.getScreenContext(getFrameOwner()).getScreens(); }
/** * Get screen context for UI component. * * @param component component * @return screen context * @throws IllegalStateException in case window cannot be inferred */ public static ScreenContext getScreenContext(Component.BelongToFrame component) { Window window = getWindowNN(component); return UiControllerUtils.getScreenContext(window.getFrameOwner()); }
protected RouteDefinition getRouteDef(Screen screen) { return screen == null ? null : getScreenContext(screen).getWindowInfo().getRouteDefinition(); }
protected int getScreenHashCode(Screen screen) { ScreenContext screenContext = UiControllerUtils.getScreenContext(screen); WindowInfo windowInfo = screenContext.getWindowInfo(); Map<String, Object> params = getFrame().getContext().getParams(); return windowInfo.hashCode() + (params != null ? params.hashCode() : 0); }
/** * @return true if screen can be opened multiple times from a navigation menu */ protected boolean isMultipleOpen() { WindowInfo windowInfo = UiControllerUtils.getScreenContext(this).getWindowInfo(); if (windowInfo.getDescriptor() != null) { String multipleOpenAttr = windowInfo.getDescriptor().attributeValue("multipleOpen"); if (multipleOpenAttr != null) { return Boolean.parseBoolean(multipleOpenAttr); } } MultipleOpen annotation = this.getClass().getAnnotation(MultipleOpen.class); if (annotation != null) { // default is false return annotation.value(); } return false; }
protected String getParentPrefix(Screen screen) { String parentPrefix = null; Route routeAnnotation = screen.getClass().getAnnotation(Route.class); if (routeAnnotation != null) { parentPrefix = routeAnnotation.parentPrefix(); } else { RouteDefinition routeDef = getScreenContext(screen) .getWindowInfo() .getRouteDefinition(); if (routeDef != null) { parentPrefix = routeDef.getParentPrefix(); } } return parentPrefix; }
/** * Show modal window with message which will last until task completes. * Optionally cancel button can be displayed. By pressing cancel button user can cancel task execution. * * @param task background task containing long operation * @param title window title, optional * @param message window message, optional * @param total total number of items, that will be processed * @param cancelAllowed show or not cancel button * @param percentProgress show progress in percents * @param <V> task result type */ public static <T extends Number, V> void show(BackgroundTask<T, V> task, @Nullable String title, @Nullable String message, Number total, boolean cancelAllowed, boolean percentProgress) { if (task.getOwnerScreen() == null) { throw new IllegalArgumentException("Task without owner cannot be run"); } Map<String, Object> params = new HashMap<>(); params.put("task", task); params.put("title", title); params.put("message", message); params.put("total", total); params.put("cancelAllowed", cancelAllowed); params.put("percentProgress", percentProgress); Screens screens = UiControllerUtils.getScreenContext(task.getOwnerScreen()).getScreens(); WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("backgroundWorkProgressWindow"); ((WindowManager)screens).openWindow(windowInfo, OpenType.DIALOG, params); }
protected void openReportParamsDialog(FrameOwner screen, Report report, @Nullable Map<String, Object> parameters, @Nullable ReportInputParameter inputParameter, @Nullable String templateCode, @Nullable String outputFileName, boolean bulkPrint) { Map<String, Object> params = ParamsMap.of( REPORT_PARAMETER, report, PARAMETERS_PARAMETER, parameters, INPUT_PARAMETER, inputParameter, TEMPLATE_CODE_PARAMETER, templateCode, OUTPUT_FILE_NAME_PARAMETER, outputFileName, BULK_PRINT, bulkPrint ); ScreenContext screenContext = UiControllerUtils.getScreenContext(screen); WindowManager wm = (WindowManager) screenContext.getScreens(); WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("report$inputParameters"); wm.openWindow(windowInfo, OpenType.DIALOG, params); }
@Override public Map<String, Object> getParams() { ScreenContext screenContext = UiControllerUtils.getScreenContext(frame.getFrameOwner()); if (screenContext.getScreenOptions() instanceof MapScreenOptions) { return ((MapScreenOptions) screenContext.getScreenOptions()).getParams(); } return Collections.emptyMap(); }
/** * Show modal window with message which will last until task completes. * Optionally cancel button can be displayed. By pressing cancel button user can cancel task execution. * * @param task background task containing long operation * @param title window title, optional * @param message window message, optional * @param cancelAllowed show or not cancel button * @param <T> task progress unit * @param <V> task result type */ public static <T, V> void show(BackgroundTask<T, V> task, @Nullable String title, @Nullable String message, boolean cancelAllowed) { if (task.getOwnerScreen() == null) { throw new IllegalArgumentException("Task without owner cannot be run"); } Map<String, Object> params = new HashMap<>(); params.put("task", task); params.put("title", title); params.put("message", message); params.put("cancelAllowed", cancelAllowed); Screens screens = UiControllerUtils.getScreenContext(task.getOwnerScreen()).getScreens(); WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("backgroundWorkWindow"); ((WindowManager)screens).openWindow(windowInfo, OpenType.DIALOG, params); }
protected void openReportParamsDialog(Report report, FrameOwner screen) { ScreenContext screenContext = UiControllerUtils.getScreenContext(screen); WindowManager wm = (WindowManager) screenContext.getScreens(); WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("report$inputParameters"); wm.openWindow(windowInfo, OpenType.DIALOG, ParamsMap.of("report", report)); }
protected void showParseErrorNotification(String message) { ScreenContext screenContext = UiControllerUtils.getScreenContext(getFrame().getFrameOwner()); screenContext.getNotifications().create(Notifications.NotificationType.TRAY) .withDescription(message) .show(); } }
/** * Show validation alert with passed errors and first problem UI component. * * @param origin screen controller * @param errors validation error */ public void showValidationErrors(FrameOwner origin, ValidationErrors errors) { checkNotNullArgument(origin); checkNotNullArgument(errors); if (errors.isEmpty()) { return; } StringBuilder buffer = new StringBuilder(); for (ValidationErrors.Item error : errors.getAll()) { buffer.append(error.description).append("\n"); } ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); String validationNotificationType = clientConfig.getValidationNotificationType(); if (validationNotificationType.endsWith("_HTML")) { // HTML validation notification types are not supported validationNotificationType = validationNotificationType.replace("_HTML", ""); } Notifications notifications = getScreenContext(origin).getNotifications(); notifications.create(NotificationType.valueOf(validationNotificationType)) .withCaption(messages.getMainMessage("validationFail.caption")) .withDescription(buffer.toString()) .show(); focusProblemComponent(errors); }
@SuppressWarnings("unchecked") protected Screen createScreen(RelatedEntitiesBuilder builder, MetaClass metaClass, MetaProperty metaProperty) { FrameOwner origin = builder.getOrigin(); Screens screens = getScreenContext(origin).getScreens(); if (builder instanceof RelatedEntitiesClassBuilder) { RelatedEntitiesClassBuilder screenClassBuilder = (RelatedEntitiesClassBuilder) builder; Class screenClass = screenClassBuilder.getScreenClass(); if (screenClass == null) { throw new IllegalArgumentException("Screen class is not set"); } return screens.create(screenClass, builder.getLaunchMode(), builder.getOptions()); } else { String screenId = builder.getScreenId(); if (StringUtils.isEmpty(screenId)) { // try to get default browse screen id screenId = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass()); if (StringUtils.isEmpty(screenId)) { String message = String.format("Can't create related entities screen: passed screen id is null and " + "there is no default browse screen for %s", metaClass.getName()); throw new IllegalArgumentException(message); } } return screens.create(builder.getScreenId(), builder.getLaunchMode(), builder.getOptions()); } }
@SuppressWarnings("unchecked") public Screen buildScreen(ScreenBuilder builder) { FrameOwner origin = builder.getOrigin(); Screens screens = getScreenContext(origin).getScreens();
@Override public void actionPerform(Component component) { if (beforeActionPerformedHandler != null) { if (!beforeActionPerformedHandler.beforeActionPerformed()) return; } Entity entity = editor.getEditedEntity(); if (entity != null) { MetaClass metaClass = entity.getMetaClass(); openRunReportScreen((Screen) editor, entity, metaClass, reportOutputName); } else { Messages messages = AppBeans.get(Messages.NAME); Notifications notifications = UiControllerUtils.getScreenContext((FrameOwner) editor).getNotifications(); notifications.create() .withCaption(messages.getMessage(ReportGuiManager.class, "notifications.noSelectedEntity")) .show(); } } }
protected void reflectTabChangeToUrl(boolean userOriginated) { if (!userOriginated) { return; } Component selectedTab = tabbedContainer.getTabSheetBehaviour().getSelectedTab(); if (selectedTab == null) { return; } Window selectedWindow = ((TabWindowContainer) selectedTab).getBreadCrumbs().getCurrentWindow(); WebWindow webWindow = (WebWindow) selectedWindow; NavigationState resolvedState = webWindow.getResolvedState(); if (resolvedState != null) { int stateMark = generateUrlStateMark(); NavigationState newState = new NavigationState( resolvedState.getRoot(), String.valueOf(stateMark), resolvedState.getNestedRoute(), resolvedState.getParams()); webWindow.setUrlStateMark(stateMark); webWindow.setResolvedState(newState); Screen screen = selectedWindow.getFrameOwner(); UrlRouting urlRouting = UiControllerUtils.getScreenContext(screen) .getUrlRouting(); urlRouting.pushState(screen, newState.getParams()); } }
@SuppressWarnings("CodeBlock2Expr") protected <E extends Entity> void performActionWithConfirmation(RemoveBuilder<E> builder, List<E> selectedItems) { ScreenContext screenContext = getScreenContext(builder.getOrigin()); Dialogs dialogs = screenContext.getDialogs(); String title = builder.getConfirmationTitle() != null ? builder.getConfirmationTitle() : messages.getMainMessage("dialogs.Confirmation"); String message = builder.getConfirmationTitle() != null ? builder.getConfirmationTitle() : messages.getMainMessage("dialogs.Confirmation.Remove"); dialogs.createOptionDialog() .withCaption(title) .withMessage(message) .withActions( new DialogAction(DialogAction.Type.YES).withHandler(e -> { performAction(builder, selectedItems); }), new DialogAction(DialogAction.Type.NO).withHandler(e -> { focusListComponent(builder); if (builder.getActionCancelledHandler() != null) { ActionCancelledEvent<E> event = new ActionCancelledEvent<>(builder.getOrigin(), selectedItems); builder.getActionCancelledHandler().accept(event); } }) ) .show(); }