use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class ScreensHelper method getAvailableScreensMap.
protected Map<String, String> getAvailableScreensMap(Class entityClass, ScreenType filterScreenType, List<String> facets, boolean useComplexSearch) {
String key = getScreensCacheKey(entityClass.getName(), currentAuthentication.getLocale(), filterScreenType, facets, useComplexSearch);
Map<String, String> screensMap = availableScreensCache.get(key);
if (screensMap != null) {
return screensMap;
}
Collection<WindowInfo> windowInfoCollection = windowConfig.getWindows();
screensMap = new TreeMap<>();
Set<String> visitedWindowIds = new HashSet<>();
for (WindowInfo windowInfo : windowInfoCollection) {
String windowId = windowInfo.getId();
// just skip for now, we assume all versions of screen can operate with the same entity
if (visitedWindowIds.contains(windowId)) {
continue;
}
String src = windowInfo.getTemplate();
if (StringUtils.isNotEmpty(src)) {
try {
Element windowElement = getWindowElement(src);
if (windowElement != null) {
if (isEntityAvailable(windowElement, windowInfo.getControllerClass(), entityClass, filterScreenType, useComplexSearch) && isFacetAvailable(windowElement, facets)) {
String caption = getScreenCaption(windowElement, src);
caption = getDetailedScreenCaption(caption, windowId);
screensMap.put(caption, windowId);
}
} else {
screensMap.put(windowId, windowId);
}
} catch (FileNotFoundException e) {
log.error("Unable to find file of screen: {}", e.getMessage());
}
}
visitedWindowIds.add(windowId);
}
screensMap = ImmutableMap.copyOf(screensMap);
cacheScreens(key, screensMap);
return screensMap;
}
use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class FoldersBean method openFolder.
@Override
public void openFolder(AbstractSearchFolder folder) {
if (StringUtils.isBlank(folder.getFilterComponentId())) {
log.warn("Unable to open folder: componentId is blank");
return;
}
String[] strings = ValuePathHelper.parse(folder.getFilterComponentId());
String screenId = strings[0];
WindowInfo windowInfo = windowConfig.getWindowInfo(screenId);
Map<String, Object> params = new HashMap<>();
WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
if (!StringUtils.isBlank(folder.getTabName())) {
WindowParams.DESCRIPTION.set(params, messages.getMainMessage(folder.getTabName()));
} else {
WindowParams.DESCRIPTION.set(params, messages.getMainMessage(folder.getName()));
}
WindowParams.FOLDER_ID.set(params, folder.getId());
WindowManager wm = windowManagerProvider.get();
Window window = wm.openWindow(windowInfo, WindowManager.OpenType.NEW_TAB, params);
Filter filterComponent = null;
if (strings.length > 1) {
String filterComponentId = StringUtils.join(Arrays.copyOfRange(strings, 1, strings.length), '.');
filterComponent = (Filter) window.getComponentNN(filterComponentId);
FilterEntity filterEntity = metadata.create(FilterEntity.class);
filterEntity.setFolder(folder);
filterEntity.setComponentId(folder.getFilterComponentId());
filterEntity.setName(folder.getLocName());
filterEntity.setXml(folder.getFilterXml());
filterEntity.setApplyDefault(BooleanUtils.isNotFalse(folder.getApplyDefault()));
if (folder instanceof SearchFolder) {
filterEntity.setIsSet(((SearchFolder) folder).getIsSet());
}
filterComponent.setFilterEntity(filterEntity);
filterComponent.switchFilterMode(FilterDelegate.FilterMode.GENERIC_MODE);
}
if (filterComponent != null && folder instanceof SearchFolder) {
SearchFolder searchFolder = (SearchFolder) folder;
if (searchFolder.getPresentationId() != null) {
((HasTablePresentations) filterComponent.getApplyTo()).applyPresentation(searchFolder.getPresentationId());
}
}
if (window.getFrameOwner() instanceof LegacyFrame) {
DsContext dsContext = ((LegacyFrame) window.getFrameOwner()).getDsContext();
if (dsContext != null) {
((DsContextImplementation) dsContext).resumeSuspended();
}
}
}
use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class RootNavigationHandler method doHandle.
@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
if (urlChangeHandler.isEmptyState(requestedState)) {
urlChangeHandler.revertNavigationState();
return false;
}
if (!rootChanged(requestedState, ui)) {
return false;
}
String rootRoute = requestedState.getRoot();
WindowInfo windowInfo = windowConfig.findWindowInfoByRoute(rootRoute);
if (windowInfo == null) {
log.info("No registered screen found for route: '{}'", rootRoute);
urlChangeHandler.revertNavigationState();
handle404(rootRoute, ui);
return true;
}
if (urlChangeHandler.shouldRedirect(windowInfo)) {
urlChangeHandler.redirect(requestedState);
return true;
}
if (!urlChangeHandler.isPermittedToNavigate(requestedState, windowInfo)) {
return true;
}
Screen screen = ui.getScreens().create(windowInfo.getId(), OpenMode.ROOT);
boolean hasNestedRoute = StringUtils.isNotEmpty(requestedState.getNestedRoute());
if (!hasNestedRoute && MapUtils.isNotEmpty(requestedState.getParams())) {
UiControllerUtils.fireEvent(screen, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(screen, requestedState.getParams()));
((WindowImpl) screen.getWindow()).setResolvedState(requestedState);
}
screen.show();
return !hasNestedRoute;
}
use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class Screen method isMultipleOpen.
/**
* @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;
}
use of io.jmix.ui.WindowInfo in project jmix by jmix-framework.
the class BackgroundWorkProgressWindow method show.
/**
* 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);
}
Aggregations