Search in sources :

Example 1 with EditorScreen

use of com.haulmont.cuba.gui.screen.EditorScreen in project cuba by cuba-platform.

the class ScreenNavigationHandler method createEditor.

protected Screen createEditor(WindowInfo windowInfo, String screenRoute, NavigationState requestedState, AppUI ui) {
    Map<String, Object> options = createEditorScreenOptions(windowInfo, requestedState, ui);
    if (MapUtils.isEmpty(options)) {
        log.info("Unable to load entity for editor: '{}'. " + "Subscribe for 'UrlParamsChangedEvent' to obtain its serialized id", windowInfo.getId());
    }
    Screen editor;
    OpenMode openMode = getScreenOpenMode(requestedState.getNestedRoute(), screenRoute, ui);
    if (isLegacyScreen(windowInfo.getControllerClass())) {
        editor = ui.getScreens().create(windowInfo.getId(), openMode, new MapScreenOptions(options));
    } else {
        editor = ui.getScreens().create(windowInfo.getId(), openMode);
    }
    if (MapUtils.isNotEmpty(options)) {
        Entity entity = (Entity) options.get(WindowParams.ITEM.name());
        // noinspection unchecked
        ((EditorScreen<Entity>) editor).setEntityToEdit(entity);
    }
    return editor;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) Screen(com.haulmont.cuba.gui.screen.Screen) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) NotFoundScreen(com.haulmont.cuba.web.app.ui.navigation.notfoundwindow.NotFoundScreen) MapScreenOptions(com.haulmont.cuba.gui.screen.MapScreenOptions) OpenMode(com.haulmont.cuba.gui.screen.OpenMode)

Example 2 with EditorScreen

use of com.haulmont.cuba.gui.screen.EditorScreen in project cuba by cuba-platform.

the class WebScreenTools method openDefaultScreen.

@Override
public void openDefaultScreen(Screens screens) {
    String defaultScreenId = webConfig.getDefaultScreenId();
    if (webConfig.getUserCanChooseDefaultScreen()) {
        String userDefaultScreen = userSettingService.loadSetting(ClientType.WEB, "userDefaultScreen");
        defaultScreenId = StringUtils.isEmpty(userDefaultScreen) ? defaultScreenId : userDefaultScreen;
    }
    if (StringUtils.isEmpty(defaultScreenId)) {
        return;
    }
    if (!windowConfig.hasWindow(defaultScreenId)) {
        log.info("Can't find default screen: {}", defaultScreenId);
        return;
    }
    Screen screen = screens.create(defaultScreenId, OpenMode.NEW_TAB);
    if (screen instanceof EditorScreen) {
        ((EditorScreen) screen).setEntityToEdit(getEntityToEdit(defaultScreenId));
    }
    screen.show();
    Window window = screen.getWindow();
    WebWindow webWindow;
    if (window instanceof Window.Wrapper) {
        webWindow = (WebWindow) ((Window.Wrapper) window).getWrappedWindow();
    } else {
        webWindow = (WebWindow) window;
    }
    webWindow.setDefaultScreenWindow(true);
    if (!webConfig.getDefaultScreenCanBeClosed()) {
        window.setCloseable(false);
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) Screen(com.haulmont.cuba.gui.screen.Screen) WebWindow(com.haulmont.cuba.web.gui.WebWindow)

Example 3 with EditorScreen

use of com.haulmont.cuba.gui.screen.EditorScreen in project cuba by cuba-platform.

the class ScreenHistorySupport method makeLink.

protected String makeLink(Screen frameOwner) {
    Window window = frameOwner.getWindow();
    Entity entity = null;
    if (window.getFrameOwner() instanceof EditorScreen) {
        entity = ((EditorScreen) frameOwner).getEditedEntity();
    }
    GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
    String url = String.format("%s/open?screen=%s", globalConfig.getWebAppUrl(), frameOwner.getId());
    Object entityId = referenceToEntitySupport.getReferenceIdForLink(entity);
    if (entity != null) {
        String item;
        if (entityId instanceof String) {
            item = metadata.getClassNN(entity.getClass()).getName() + "-{" + entityId + "}";
        } else {
            item = metadata.getClassNN(entity.getClass()).getName() + "-" + entityId;
        }
        url += String.format("&item=%s&params=item:%s", item, item);
    }
    Map<String, Object> params = getWindowParams(window);
    StringBuilder sb = new StringBuilder();
    if (params != null) {
        for (Map.Entry<String, Object> param : params.entrySet()) {
            Object value = param.getValue();
            if (value instanceof String || /*|| value instanceof Integer || value instanceof Double*/
            value instanceof Boolean) {
                sb.append(",").append(param.getKey()).append(":").append(URLEncodeUtils.encodeUtf8(value.toString()));
            }
        }
    }
    if (sb.length() > 0) {
        if (entity != null) {
            url += sb.toString();
        } else {
            url += "&params=" + sb.deleteCharAt(0).toString();
        }
    }
    return url;
}
Also used : Window(com.haulmont.cuba.gui.components.Window) ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) Entity(com.haulmont.cuba.core.entity.Entity) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen)

Example 4 with EditorScreen

use of com.haulmont.cuba.gui.screen.EditorScreen in project cuba by cuba-platform.

the class ScreenHistorySupport method saveScreenHistory.

public void saveScreenHistory(Screen frameOwner) {
    WindowContext windowContext = frameOwner.getWindow().getContext();
    if (security.isEntityOpPermitted(ScreenHistoryEntity.class, EntityOp.CREATE) && (frameOwner instanceof EditorScreen) && windowContext.getLaunchMode() != OpenMode.DIALOG && (screenIds.contains(frameOwner.getId()))) {
        String caption = frameOwner.getWindow().getCaption();
        Object entityId = null;
        Entity entity = ((EditorScreen) frameOwner).getEditedEntity();
        if (entity != null) {
            if (PersistenceHelper.isNew(entity)) {
                return;
            }
            if (StringUtils.isBlank(caption)) {
                caption = messages.getTools().getEntityCaption(entity.getMetaClass()) + " " + metadata.getTools().getInstanceName(entity);
            }
            entityId = referenceToEntitySupport.getReferenceIdForLink(entity);
        }
        ScreenHistoryEntity screenHistoryEntity = metadata.create(ScreenHistoryEntity.class);
        screenHistoryEntity.setCaption(StringUtils.abbreviate(caption, 255));
        screenHistoryEntity.setUrl(makeLink(frameOwner));
        screenHistoryEntity.setObjectEntityId(entityId);
        addAdditionalFields(screenHistoryEntity, entity);
        CommitContext cc = new CommitContext(Collections.singleton(screenHistoryEntity));
        dataManager.commit(cc);
    }
}
Also used : ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) Entity(com.haulmont.cuba.core.entity.Entity) ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) WindowContext(com.haulmont.cuba.gui.WindowContext)

Example 5 with EditorScreen

use of com.haulmont.cuba.gui.screen.EditorScreen in project cuba by cuba-platform.

the class WebUrlRouting method buildParams.

protected Map<String, String> buildParams(Screen screen, Map<String, String> urlParams) {
    String route = getRoute(screen);
    if (StringUtils.isEmpty(route) && (isEditor(screen) || MapUtils.isNotEmpty(urlParams))) {
        log.debug("There's no route for screen \"{}\". URL params will be ignored", screen.getId());
        return Collections.emptyMap();
    }
    if (omitParams(screen)) {
        return Collections.emptyMap();
    }
    Map<String, String> params = new LinkedHashMap<>();
    if (isEditor(screen)) {
        Entity editedEntity = ((EditorScreen) screen).getEditedEntity();
        if (editedEntity != null) {
            if (PersistenceHelper.isNew(editedEntity)) {
                params.put("id", NEW_ENTITY_ID);
            } else {
                Object entityId = editedEntity.getId();
                if (entityId != null) {
                    String serializedId = UrlIdSerializer.serializeId(entityId);
                    if (!"".equals(serializedId)) {
                        params.put("id", serializedId);
                    }
                }
            }
        }
    }
    params.putAll(urlParams != null ? urlParams : Collections.emptyMap());
    return params;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) Preconditions.checkNotEmptyString(com.haulmont.bali.util.Preconditions.checkNotEmptyString)

Aggregations

EditorScreen (com.haulmont.cuba.gui.screen.EditorScreen)5 Entity (com.haulmont.cuba.core.entity.Entity)4 Window (com.haulmont.cuba.gui.components.Window)2 Screen (com.haulmont.cuba.gui.screen.Screen)2 ScreenHistoryEntity (com.haulmont.cuba.security.entity.ScreenHistoryEntity)2 Preconditions.checkNotEmptyString (com.haulmont.bali.util.Preconditions.checkNotEmptyString)1 WindowContext (com.haulmont.cuba.gui.WindowContext)1 MapScreenOptions (com.haulmont.cuba.gui.screen.MapScreenOptions)1 OpenMode (com.haulmont.cuba.gui.screen.OpenMode)1 NotFoundScreen (com.haulmont.cuba.web.app.ui.navigation.notfoundwindow.NotFoundScreen)1 WebWindow (com.haulmont.cuba.web.gui.WebWindow)1