Search in sources :

Example 16 with Action

use of com.haulmont.cuba.gui.components.Action 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 17 with Action

use of com.haulmont.cuba.gui.components.Action in project cuba by cuba-platform.

the class ActionsHolderLoader method loadDeclarativeAction.

@Override
protected Action loadDeclarativeAction(Component.ActionsHolder actionsHolder, Element element) {
    String id = element.attributeValue("id");
    if (StringUtils.isEmpty(id)) {
        throw new GuiDevelopmentException("No action id provided", context.getFullFrameId(), "ActionsHolder ID", actionsHolder.getId());
    }
    if (StringUtils.isBlank(element.attributeValue("invoke"))) {
        // Try to create a standard list action
        for (ListActionType type : ListActionType.values()) {
            if (type.getId().equals(id)) {
                Action instance = type.createAction((ListComponent) actionsHolder);
                loadStandardActionProperties(instance, element);
                loadActionOpenType(instance, element);
                loadActionConstraint(instance, element);
                loadShortcut(instance, element);
                return instance;
            }
        }
    }
    return super.loadDeclarativeAction(actionsHolder, element);
}
Also used : Action(com.haulmont.cuba.gui.components.Action) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) ListActionType(com.haulmont.cuba.gui.components.actions.ListActionType)

Example 18 with Action

use of com.haulmont.cuba.gui.components.Action in project cuba by cuba-platform.

the class WebRelatedEntities method setOpenType.

@Override
public void setOpenType(WindowManager.OpenType openType) {
    checkNotNullArgument(openType);
    this.openType = openType;
    for (Action action : getActions()) {
        if (action instanceof RelatedAction) {
            ((RelatedAction) action).setOpenType(openType);
        }
    }
}
Also used : RelatedAction(com.haulmont.cuba.gui.components.actions.RelatedAction) Action(com.haulmont.cuba.gui.components.Action) RelatedAction(com.haulmont.cuba.gui.components.actions.RelatedAction)

Aggregations

Action (com.haulmont.cuba.gui.components.Action)18 AbstractAction (javax.swing.AbstractAction)5 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)4 Component (com.haulmont.cuba.gui.components.Component)3 Window (com.haulmont.cuba.gui.components.Window)3 ClientConfig (com.haulmont.cuba.client.ClientConfig)2 Messages (com.haulmont.cuba.core.global.Messages)2 ValidationAwareAction (com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction)2 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)2 DialogAction (com.haulmont.cuba.gui.components.DialogAction)2 CollectionDsActionsNotifier (com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier)2 WeakCollectionChangeListener (com.haulmont.cuba.gui.data.impl.WeakCollectionChangeListener)2 HierarchicalDsWrapper (com.haulmont.cuba.web.gui.data.HierarchicalDsWrapper)2 Inject (javax.inject.Inject)2 JTextComponent (javax.swing.text.JTextComponent)2 Element (org.dom4j.Element)2 BoundAction (org.jdesktop.swingx.action.BoundAction)2 Iterables (com.google.common.collect.Iterables)1 Pair (com.haulmont.bali.datastruct.Pair)1 EventRouter (com.haulmont.bali.events.EventRouter)1