Search in sources :

Example 11 with BaseAction

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

the class WebWindow method close.

@Override
public boolean close(final String actionId) {
    if (!forceClose) {
        if (!delegate.preClose(actionId))
            return false;
    }
    if (closing) {
        return true;
    }
    Configuration configuration = AppBeans.get(Configuration.NAME);
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    if (!forceClose && isModified()) {
        final Committable committable = (getWrapper() instanceof Committable) ? (Committable) getWrapper() : (this instanceof Committable) ? (Committable) this : null;
        if ((committable != null) && clientConfig.getUseSaveConfirmation()) {
            windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("saveUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.OK, Status.PRIMARY).withCaption(messages.getMainMessage("closeUnsaved.save")).withHandler(event -> {
                committable.commitAndClose();
            }), new BaseAction("discard").withIcon(icons.get(CubaIcon.DIALOG_CANCEL)).withCaption(messages.getMainMessage("closeUnsaved.discard")).withHandler(event -> {
                committable.close(actionId, true);
            }), new DialogAction(Type.CANCEL).withIcon(null).withHandler(event -> {
                doAfterClose = null;
                // try to move focus back
                findAndFocusChildComponent();
            }) });
        } else {
            windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("closeUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.YES).withHandler(event -> getWrapper().close(actionId, true)), new DialogAction(Type.NO, Status.PRIMARY).withHandler(event -> {
                doAfterClose = null;
                // try to move focus back
                findAndFocusChildComponent();
            }) });
        }
        closing = false;
        return false;
    }
    if (!clientConfig.getManualScreenSettingsSaving()) {
        if (getWrapper() != null) {
            getWrapper().saveSettings();
        } else {
            saveSettings();
        }
    }
    delegate.disposeComponents();
    windowManager.close(this);
    boolean res = onClose(actionId);
    if (res && doAfterClose != null) {
        doAfterClose.run();
    }
    closing = res;
    return res;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Datasource(com.haulmont.cuba.gui.data.Datasource) WindowMode(com.vaadin.shared.ui.window.WindowMode) LoggerFactory(org.slf4j.LoggerFactory) CubaIcon(com.haulmont.cuba.gui.icons.CubaIcon) Settings(com.haulmont.cuba.gui.settings.Settings) AppBeans(com.haulmont.cuba.core.global.AppBeans) Icons(com.haulmont.cuba.gui.icons.Icons) BooleanUtils(org.apache.commons.lang.BooleanUtils) IconResolver(com.haulmont.cuba.web.gui.icons.IconResolver) com.haulmont.cuba.gui(com.haulmont.cuba.gui) Window(com.haulmont.cuba.gui.components.Window) Configuration(com.haulmont.cuba.core.global.Configuration) Instance(com.haulmont.chile.core.model.Instance) AppUI(com.haulmont.cuba.web.AppUI) Page(com.vaadin.server.Page) EventRouter(com.haulmont.bali.events.EventRouter) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Status(com.haulmont.cuba.gui.components.Action.Status) MainTabSheetMode(com.haulmont.cuba.web.toolkit.ui.MainTabSheetMode) Messages(com.haulmont.cuba.core.global.Messages) ApplicationListener(org.springframework.context.ApplicationListener) MarginInfo(com.vaadin.shared.ui.MarginInfo) CubaSingleModeContainer(com.haulmont.cuba.web.toolkit.ui.CubaSingleModeContainer) WebWrapperUtils(com.haulmont.cuba.web.gui.components.WebWrapperUtils) TabSheet(com.vaadin.ui.TabSheet) WebConfig(com.haulmont.cuba.web.WebConfig) ClientConfig(com.haulmont.cuba.client.ClientConfig) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) WebWindowManager(com.haulmont.cuba.web.WebWindowManager) java.util(java.util) LookupSelectionChangeNotifier(com.haulmont.cuba.gui.components.LookupComponent.LookupSelectionChangeNotifier) Timer(com.haulmont.cuba.gui.components.Timer) MetaClass(com.haulmont.chile.core.model.MetaClass) CubaVerticalActionsLayout(com.haulmont.cuba.web.toolkit.ui.CubaVerticalActionsLayout) WebFrameActionsHolder(com.haulmont.cuba.web.gui.components.WebFrameActionsHolder) ClientConnector(com.vaadin.server.ClientConnector) Component(com.haulmont.cuba.gui.components.Component) DsContext(com.haulmont.cuba.gui.data.DsContext) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) Type(com.haulmont.cuba.gui.components.DialogAction.Type) Preconditions(com.haulmont.bali.util.Preconditions) Button(com.vaadin.ui.Button) UiEventsMulticaster(com.haulmont.cuba.gui.events.sys.UiEventsMulticaster) WebComponentsHelper(com.haulmont.cuba.web.gui.components.WebComponentsHelper) Element(org.dom4j.Element) Unit(com.vaadin.server.Sizeable.Unit) Entity(com.haulmont.cuba.core.entity.Entity) com.vaadin.ui(com.vaadin.ui) Configuration(com.haulmont.cuba.core.global.Configuration) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Aggregations

BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)11 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)10 Inject (javax.inject.Inject)9 java.util (java.util)7 StringUtils (org.apache.commons.lang.StringUtils)7 ParamsMap (com.haulmont.bali.util.ParamsMap)6 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)6 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 MetaClass (com.haulmont.chile.core.model.MetaClass)4 ClientConfig (com.haulmont.cuba.client.ClientConfig)4 Metadata (com.haulmont.cuba.core.global.Metadata)4 Window (com.haulmont.cuba.gui.components.Window)4 Map (java.util.Map)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 EventRouter (com.haulmont.bali.events.EventRouter)3 Preconditions (com.haulmont.bali.util.Preconditions)3 Entity (com.haulmont.cuba.core.entity.Entity)3 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)3 WindowManager (com.haulmont.cuba.gui.WindowManager)3