Search in sources :

Example 1 with Dialogs

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

the class ExcelAction method actionPerform.

/**
 * This method is invoked by action owner component.
 * @param component component invoking action
 */
@Override
public void actionPerform(Component component) {
    if (beforeActionPerformedHandler != null) {
        if (!beforeActionPerformedHandler.beforeActionPerformed())
            return;
    }
    if (listComponent.getSelected().isEmpty() || listComponent.getDatasource() == null || listComponent.getDatasource().size() <= 1) {
        export(ExportMode.ALL_ROWS);
    } else {
        String title = messages.getMainMessage("actions.exportSelectedTitle");
        String caption = messages.getMainMessage("actions.exportSelectedCaption");
        AbstractAction exportSelectedAction = new AbstractAction("actions.export.SELECTED_ROWS", Status.PRIMARY) {

            @Override
            public void actionPerform(Component component) {
                export(ExportMode.SELECTED_ROWS);
            }
        };
        exportSelectedAction.setCaption(messages.getMainMessage(exportSelectedAction.getId()));
        AbstractAction exportAllAction = new AbstractAction("actions.export.ALL_ROWS") {

            @Override
            public void actionPerform(Component component) {
                export(ExportMode.ALL_ROWS);
            }
        };
        exportAllAction.setCaption(messages.getMainMessage(exportAllAction.getId()));
        Dialogs dialogs = getScreenContext(listComponent).getDialogs();
        dialogs.createOptionDialog().withCaption(title).withMessage(caption).withType(Dialogs.MessageType.CONFIRMATION).withActions(exportSelectedAction, exportAllAction, new DialogAction(Type.CANCEL)).show();
    }
}
Also used : Dialogs(com.haulmont.cuba.gui.Dialogs)

Example 2 with Dialogs

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

the class RemoveAction method confirmAndRemove.

protected void confirmAndRemove(Set<Entity> selected) {
    Dialogs dialogs = ComponentsHelper.getScreenContext(target.getFrame()).getDialogs();
    dialogs.createOptionDialog().withCaption(getConfirmationTitle()).withMessage(getConfirmationMessage()).withActions(new DialogAction(Type.OK, Status.PRIMARY).withHandler(event -> {
        try {
            remove(selected);
        } finally {
            if (target instanceof Component.Focusable) {
                ((Component.Focusable) target).focus();
            }
            Set<Entity> filtered = new HashSet<>(selected);
            filtered.retainAll(target.getDatasource().getItems());
            // noinspection unchecked
            target.setSelected(filtered);
        }
    }), new DialogAction(Type.CANCEL).withHandler(event -> {
        // move focus to owner
        if (target instanceof Component.Focusable) {
            ((Component.Focusable) target).focus();
        }
    })).show();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Dialogs(com.haulmont.cuba.gui.Dialogs) DialogAction(com.haulmont.cuba.gui.components.DialogAction) HashSet(java.util.HashSet)

Example 3 with Dialogs

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

the class LocalizedTaskWrapper method showExecutionError.

protected void showExecutionError(Exception ex) {
    Screen ownerFrame = wrappedTask.getOwnerScreen();
    if (ownerFrame != null) {
        Dialogs dialogs = getScreenContext().getDialogs();
        Messages messages = AppBeans.get(Messages.class);
        dialogs.createExceptionDialog().withThrowable(ex).withCaption(messages.getMessage(LocalizedTaskWrapper.class, "backgroundWorkProgress.executionError")).withMessage(ex.getLocalizedMessage()).show();
    }
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) Dialogs(com.haulmont.cuba.gui.Dialogs) Screen(com.haulmont.cuba.gui.screen.Screen)

Example 4 with Dialogs

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

the class ExcelAction method execute.

/**
 * Executes the action.
 */
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("ExcelAction target is not set");
    }
    if (needExportAll()) {
        export(ExcelExporter.ExportMode.ALL_ROWS);
    } else {
        AbstractAction exportSelectedAction = new AbstractAction("actions.export.SELECTED_ROWS", Status.PRIMARY) {

            @Override
            public void actionPerform(Component component) {
                export(ExcelExporter.ExportMode.SELECTED_ROWS);
            }
        };
        exportSelectedAction.setCaption(messages.getMainMessage(exportSelectedAction.getId()));
        AbstractAction exportAllAction = new AbstractAction("actions.export.ALL_ROWS") {

            @Override
            public void actionPerform(Component component) {
                export(ExcelExporter.ExportMode.ALL_ROWS);
            }
        };
        exportAllAction.setCaption(messages.getMainMessage(exportAllAction.getId()));
        Action[] actions = new Action[] { exportSelectedAction, exportAllAction, new DialogAction(DialogAction.Type.CANCEL) };
        Dialogs dialogs = ComponentsHelper.getScreenContext(target).getDialogs();
        dialogs.createOptionDialog().withCaption(messages.getMainMessage("actions.exportSelectedTitle")).withMessage(messages.getMainMessage("actions.exportSelectedCaption")).withType(Dialogs.MessageType.CONFIRMATION).withActions(actions).show();
    }
}
Also used : ListAction(com.haulmont.cuba.gui.components.actions.ListAction) StudioAction(com.haulmont.cuba.gui.meta.StudioAction) Dialogs(com.haulmont.cuba.gui.Dialogs)

Example 5 with Dialogs

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

the class ScreenValidation method showUnsavedChangesDialog.

/**
 * Shows standard unsaved changes dialog with Discard and Cancel actions.
 *
 * @param origin screen controller
 * @param closeAction close action
 * @return result
 */
public UnsavedChangesDialogResult showUnsavedChangesDialog(FrameOwner origin, @SuppressWarnings("unused") CloseAction closeAction) {
    UnsavedChangesDialogResult result = new UnsavedChangesDialogResult();
    Dialogs dialogs = getScreenContext(origin).getDialogs();
    dialogs.createOptionDialog().withCaption(messages.getMainMessage("closeUnsaved.caption")).withMessage(messages.getMainMessage("closeUnsaved")).withType(Dialogs.MessageType.WARNING).withActions(new DialogAction(DialogAction.Type.YES).withHandler(e -> {
        result.discard();
    }), new DialogAction(DialogAction.Type.NO, Action.Status.PRIMARY).withHandler(e -> {
        Frame frame = UiControllerUtils.getFrame(origin);
        ComponentsHelper.focusChildComponent(frame);
        result.cancel();
    })).show();
    return result;
}
Also used : Dialogs(com.haulmont.cuba.gui.Dialogs)

Aggregations

Dialogs (com.haulmont.cuba.gui.Dialogs)9 DialogAction (com.haulmont.cuba.gui.components.DialogAction)3 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)3 Messages (com.haulmont.cuba.core.global.Messages)2 Entity (com.haulmont.cuba.core.entity.Entity)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 Screens (com.haulmont.cuba.gui.Screens)1 RootWindow (com.haulmont.cuba.gui.components.RootWindow)1 ListAction (com.haulmont.cuba.gui.components.actions.ListAction)1 IllegalConcurrentAccessException (com.haulmont.cuba.gui.executors.IllegalConcurrentAccessException)1 Icons (com.haulmont.cuba.gui.icons.Icons)1 StudioAction (com.haulmont.cuba.gui.meta.StudioAction)1 Screen (com.haulmont.cuba.gui.screen.Screen)1 UnknownOperationResult (com.haulmont.cuba.gui.util.UnknownOperationResult)1 User (com.haulmont.cuba.security.entity.User)1 LoginException (com.haulmont.cuba.security.global.LoginException)1 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 AppUI (com.haulmont.cuba.web.AppUI)1 ChangeSubstUserAction (com.haulmont.cuba.web.actions.ChangeSubstUserAction)1