Search in sources :

Example 1 with WindowInfo

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;
}
Also used : Element(org.dom4j.Element) FileNotFoundException(java.io.FileNotFoundException) WindowInfo(io.jmix.ui.WindowInfo)

Example 2 with WindowInfo

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();
        }
    }
}
Also used : Window(io.jmix.ui.component.Window) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) DsContext(com.haulmont.cuba.gui.data.DsContext) HashMap(java.util.HashMap) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) WindowInfo(io.jmix.ui.WindowInfo) WindowManager(com.haulmont.cuba.gui.WindowManager) Filter(com.haulmont.cuba.gui.components.Filter) HasTablePresentations(io.jmix.ui.component.HasTablePresentations)

Example 3 with WindowInfo

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;
}
Also used : UrlParamsChangedEvent(io.jmix.ui.navigation.UrlParamsChangedEvent) WindowImpl(io.jmix.ui.component.impl.WindowImpl) Screen(io.jmix.ui.screen.Screen) NotFoundScreen(io.jmix.ui.app.navigation.notfoundwindow.NotFoundScreen) UrlChangeHandler(io.jmix.ui.navigation.UrlChangeHandler) WindowInfo(io.jmix.ui.WindowInfo)

Example 4 with WindowInfo

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;
}
Also used : WindowInfo(io.jmix.ui.WindowInfo)

Example 5 with WindowInfo

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);
}
Also used : WindowConfig(io.jmix.ui.WindowConfig) HashMap(java.util.HashMap) Screens(io.jmix.ui.Screens) WindowInfo(io.jmix.ui.WindowInfo) WindowManager(com.haulmont.cuba.gui.WindowManager)

Aggregations

WindowInfo (io.jmix.ui.WindowInfo)24 WindowManager (com.haulmont.cuba.gui.WindowManager)7 WindowConfig (io.jmix.ui.WindowConfig)7 HashMap (java.util.HashMap)6 Element (org.dom4j.Element)5 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)3 Window (io.jmix.ui.component.Window)3 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 WindowManagerProvider (com.haulmont.cuba.gui.WindowManagerProvider)2 Filter (com.haulmont.cuba.gui.components.Filter)2 Window (com.haulmont.cuba.gui.components.Window)2 AddConditionWindow (com.haulmont.cuba.gui.components.filter.addcondition.AddConditionWindow)2 ConditionDescriptorsTreeBuilderAPI (com.haulmont.cuba.gui.components.filter.addcondition.ConditionDescriptorsTreeBuilderAPI)2 AbstractConditionDescriptor (com.haulmont.cuba.gui.components.filter.descriptor.AbstractConditionDescriptor)2 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)2 Screens (io.jmix.ui.Screens)2 NotFoundScreen (io.jmix.ui.app.navigation.notfoundwindow.NotFoundScreen)2 Fragment (io.jmix.ui.component.Fragment)2 FragmentImplementation (io.jmix.ui.component.impl.FragmentImplementation)2 FrameImplementation (io.jmix.ui.component.impl.FrameImplementation)2