Search in sources :

Example 6 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class ScreensLinkHandlerProcessor method handle.

@Override
public void handle(ExternalLinkContext linkContext) {
    String screenName = linkContext.getRequestParams().get("screen");
    App app = linkContext.getApp();
    final WindowInfo windowInfo = windowConfig.getWindowInfo(screenName);
    if (windowInfo == null) {
        log.warn("WindowInfo not found for screen: {}", screenName);
        return;
    }
    try {
        openWindow(windowInfo, linkContext);
    } catch (EntityAccessException e) {
        entityAccessExceptionHandler.handle(e, app.getWindowManager());
    } catch (AccessDeniedException e) {
        accessDeniedHandler.handle(e, app.getWindowManager());
    } catch (NoSuchScreenException e) {
        noSuchScreenHandler.handle(e, app.getWindowManager());
    }
}
Also used : App(com.haulmont.cuba.web.App) NoSuchScreenException(com.haulmont.cuba.gui.NoSuchScreenException) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo)

Example 7 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class ScreensLinkHandlerProcessor method openWindow.

protected void openWindow(WindowInfo windowInfo, ExternalLinkContext linkContext) {
    Map<String, String> requestParams = linkContext.getRequestParams();
    App app = linkContext.getApp();
    String itemStr = requestParams.get("item");
    String openTypeParam = requestParams.get("openType");
    WindowManager.OpenType openType = WindowManager.OpenType.NEW_TAB;
    if (StringUtils.isNotEmpty(openTypeParam)) {
        try {
            openType = WindowManager.OpenType.valueOf(openTypeParam);
        } catch (IllegalArgumentException e) {
            log.warn("Unknown open type ({}) in request parameters", openTypeParam);
        }
    }
    if (itemStr == null) {
        app.getWindowManager().openWindow(windowInfo, openType, getParamsMap(requestParams));
    } else {
        EntityLoadInfo info = EntityLoadInfo.parse(itemStr);
        if (info == null) {
            log.warn("Invalid item definition: {}", itemStr);
        } else {
            Entity entity = loadEntityInstance(info);
            if (entity != null)
                app.getWindowManager().openEditor(windowInfo, entity, openType, getParamsMap(requestParams));
            else
                throw new EntityAccessException();
        }
    }
}
Also used : App(com.haulmont.cuba.web.App) Entity(com.haulmont.cuba.core.entity.Entity) WindowManager(com.haulmont.cuba.gui.WindowManager)

Example 8 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class UserSwitchLinkHandlerProcessor method substituteUserAndOpenWindow.

protected void substituteUserAndOpenWindow(ExternalLinkContext linkContext, UUID userId) {
    App app = linkContext.getApp();
    UserSession userSession = app.getConnection().getSession();
    assert userSession != null;
    final User substitutedUser = loadUser(userId, userSession.getUser());
    if (substitutedUser != null) {
        app.getWindowManager().showOptionDialog(messages.getMainMessage("toSubstitutedUser.title"), getDialogMessage(substitutedUser), Frame.MessageType.CONFIRMATION_HTML, new Action[] { new ChangeSubstUserAction(substitutedUser) {

            @Override
            public void doAfterChangeUser() {
                super.doAfterChangeUser();
                screenHandler.handle(linkContext);
            }

            @Override
            public void doRevert() {
                super.doRevert();
                JavaScript js = Page.getCurrent().getJavaScript();
                js.execute("window.close();");
            }

            @Override
            public String getCaption() {
                return messages.getMainMessage("action.switch");
            }
        }, new DoNotChangeSubstUserAction() {

            @Override
            public void actionPerform(Component component) {
                super.actionPerform(component);
                JavaScript js = Page.getCurrent().getJavaScript();
                js.execute("window.close();");
            }

            @Override
            public String getCaption() {
                return messages.getMainMessage("action.cancel");
            }
        } });
    } else {
        User user = loadUser(userId);
        app.getWindowManager().showOptionDialog(messages.getMainMessage("warning.title"), getWarningMessage(user), Frame.MessageType.WARNING_HTML, new Action[] { new DialogAction(DialogAction.Type.OK).withHandler(event -> {
            JavaScript js = Page.getCurrent().getJavaScript();
            js.execute("window.close();");
        }) });
    }
}
Also used : App(com.haulmont.cuba.web.App) LoadContext(com.haulmont.cuba.core.global.LoadContext) Frame(com.haulmont.cuba.gui.components.Frame) JavaScript(com.vaadin.ui.JavaScript) Ordered(org.springframework.core.Ordered) StringUtils(org.apache.commons.lang.StringUtils) Logger(org.slf4j.Logger) Resource(javax.annotation.Resource) DoNotChangeSubstUserAction(com.haulmont.cuba.web.actions.DoNotChangeSubstUserAction) App(com.haulmont.cuba.web.App) Messages(com.haulmont.cuba.core.global.Messages) UUID(java.util.UUID) User(com.haulmont.cuba.security.entity.User) UserSession(com.haulmont.cuba.security.global.UserSession) Inject(javax.inject.Inject) List(java.util.List) Page(com.vaadin.server.Page) TimeSource(com.haulmont.cuba.core.global.TimeSource) DialogAction(com.haulmont.cuba.gui.components.DialogAction) UserSubstitution(com.haulmont.cuba.security.entity.UserSubstitution) ChangeSubstUserAction(com.haulmont.cuba.web.actions.ChangeSubstUserAction) Component(com.haulmont.cuba.gui.components.Component) DataService(com.haulmont.cuba.core.app.DataService) Action(com.haulmont.cuba.gui.components.Action) DoNotChangeSubstUserAction(com.haulmont.cuba.web.actions.DoNotChangeSubstUserAction) ChangeSubstUserAction(com.haulmont.cuba.web.actions.ChangeSubstUserAction) User(com.haulmont.cuba.security.entity.User) DialogAction(com.haulmont.cuba.gui.components.DialogAction) UserSession(com.haulmont.cuba.security.global.UserSession) JavaScript(com.vaadin.ui.JavaScript) DoNotChangeSubstUserAction(com.haulmont.cuba.web.actions.DoNotChangeSubstUserAction) Component(com.haulmont.cuba.gui.components.Component)

Example 9 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class WebBackgroundWorker method handle.

@Override
public <T, V> BackgroundTaskHandler<V> handle(final BackgroundTask<T, V> task) {
    checkNotNull(task);
    checkUIAccess();
    App appInstance;
    try {
        appInstance = App.getInstance();
    } catch (IllegalStateException ex) {
        log.error("Couldn't handle task", ex);
        throw ex;
    }
    // create task executor
    final WebTaskExecutor<T, V> taskExecutor = new WebTaskExecutor<>(appInstance.getAppUI(), task);
    // add thread to taskSet
    appInstance.addBackgroundTask(taskExecutor.getFuture());
    // create task handler
    TaskHandlerImpl<T, V> taskHandler = new TaskHandlerImpl<>(getUIAccessor(), taskExecutor, watchDog);
    taskExecutor.setTaskHandler(taskHandler);
    return taskHandler;
}
Also used : App(com.haulmont.cuba.web.App) TaskHandlerImpl(com.haulmont.cuba.gui.executors.impl.TaskHandlerImpl)

Example 10 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class ExceptionDialog method logoutPrompt.

protected void logoutPrompt() {
    App app = AppUI.getCurrent().getApp();
    final WebWindowManager wm = app.getWindowManager();
    wm.showOptionDialog(messages.getMainMessage("exceptionDialog.logoutCaption"), messages.getMainMessage("exceptionDialog.logoutMessage"), Frame.MessageType.WARNING, new Action[] { new AbstractAction(messages.getMainMessage("closeApplication")) {

        @Override
        public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
            forceLogout();
        }

        @Override
        public String getIcon() {
            return "icons/ok.png";
        }
    }, new DialogAction(Type.CANCEL, Status.PRIMARY) });
}
Also used : App(com.haulmont.cuba.web.App) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) WebWindowManager(com.haulmont.cuba.web.WebWindowManager)

Aggregations

App (com.haulmont.cuba.web.App)12 Connection (com.haulmont.cuba.web.Connection)4 WebWindowManager (com.haulmont.cuba.web.WebWindowManager)3 Messages (com.haulmont.cuba.core.global.Messages)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 User (com.haulmont.cuba.security.entity.User)2 Page (com.vaadin.server.Page)2 List (java.util.List)2 Locale (java.util.Locale)2 Logger (org.slf4j.Logger)2 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 DataService (com.haulmont.cuba.core.app.DataService)1 Entity (com.haulmont.cuba.core.entity.Entity)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 LoadContext (com.haulmont.cuba.core.global.LoadContext)1 TimeSource (com.haulmont.cuba.core.global.TimeSource)1 SecurityContext (com.haulmont.cuba.core.sys.SecurityContext)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 NoSuchScreenException (com.haulmont.cuba.gui.NoSuchScreenException)1