Search in sources :

Example 11 with Notifications

use of io.jmix.ui.Notifications in project jmix by jmix-framework.

the class EditorPrintFormAction method actionPerform.

@Override
public void actionPerform(Component component) {
    Object entity = editor.getEditedEntity();
    if (entity != null) {
        MetaClass metaClass = metadata.getClass(entity);
        openRunReportScreen((Screen) editor, entity, metaClass, reportOutputName);
    } else {
        Notifications notifications = UiControllerUtils.getScreenContext((FrameOwner) editor).getNotifications();
        notifications.create().withCaption(messages.getMessage(getClass(), "notifications.noSelectedEntity")).show();
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) FrameOwner(io.jmix.ui.screen.FrameOwner) Notifications(io.jmix.ui.Notifications)

Example 12 with Notifications

use of io.jmix.ui.Notifications in project jmix by jmix-framework.

the class ListPrintFormAction method actionPerform.

@Override
public void actionPerform(Component component) {
    DialogAction cancelAction = new DialogAction(DialogAction.Type.CANCEL);
    ScreenContext screenContext = ComponentsHelper.getScreenContext(target);
    Preconditions.checkState(screenContext != null, "Component is not attached to window");
    Dialogs dialogs = screenContext.getDialogs();
    Set selected = target.getSelected();
    if (CollectionUtils.isNotEmpty(selected)) {
        if (selected.size() > 1) {
            Action printSelectedAction = new AbstractAction("actions.printSelected", Status.PRIMARY) {

                @Override
                public void actionPerform(Component component) {
                    printSelected(selected);
                }
            };
            printSelectedAction.setIcon(JmixIcon.BARS.source());
            printSelectedAction.setCaption(messages.getMessage(getClass(), "actions.printSelected"));
            Action printAllAction = new AbstractAction("actions.printAll") {

                @Override
                public void actionPerform(Component component) {
                    printAll();
                }
            };
            printAllAction.setIcon(JmixIcon.TABLE.source());
            printAllAction.setCaption(messages.getMessage(getClass(), "actions.printAll"));
            dialogs.createOptionDialog().withCaption(messages.getMessage(getClass(), "notifications.confirmPrintSelectedHeader")).withMessage(messages.getMessage(getClass(), "notifications.confirmPrintSelected")).withActions(printAllAction, printSelectedAction, cancelAction).show();
        } else {
            printSelected(selected);
        }
    } else {
        if (isDataAvailable()) {
            Action yesAction = new DialogAction(DialogAction.Type.OK) {

                @Override
                public void actionPerform(Component component) {
                    printAll();
                }
            };
            cancelAction.setPrimary(true);
            dialogs.createOptionDialog().withCaption(messages.getMessage(getClass(), "notifications.confirmPrintAllheader")).withMessage(messages.getMessage(getClass(), "notifications.confirmPrintAll")).withActions(yesAction, cancelAction).show();
        } else {
            Notifications notifications = screenContext.getNotifications();
            notifications.create().withCaption(messages.getMessage(getClass(), "notifications.noSelectedEntity")).withType(Notifications.NotificationType.HUMANIZED).show();
        }
    }
}
Also used : Action(io.jmix.ui.action.Action) DialogAction(io.jmix.ui.action.DialogAction) AbstractPrintFormAction(io.jmix.reportsui.action.AbstractPrintFormAction) AbstractAction(io.jmix.ui.action.AbstractAction) StudioAction(io.jmix.ui.meta.StudioAction) ScreenContext(io.jmix.ui.screen.ScreenContext) HashSet(java.util.HashSet) Set(java.util.Set) Dialogs(io.jmix.ui.Dialogs) DialogAction(io.jmix.ui.action.DialogAction) ListComponent(io.jmix.ui.component.ListComponent) Component(io.jmix.ui.component.Component) AbstractAction(io.jmix.ui.action.AbstractAction) Notifications(io.jmix.ui.Notifications)

Example 13 with Notifications

use of io.jmix.ui.Notifications in project jmix-docs by jmix-framework.

the class ShowSelectedAction method actionPerform.

@Override
public void actionPerform(Component component) {
    if (getTarget() != null) {
        Object selected = getTarget().getSingleSelected();
        if (selected != null) {
            Notifications notifications = ComponentsHelper.getScreenContext(target).getNotifications();
            notifications.create().withType(Notifications.NotificationType.TRAY).withDescription(description).withCaption(metadataTools.getInstanceName(selected)).show();
        }
    }
}
Also used : Notifications(io.jmix.ui.Notifications)

Example 14 with Notifications

use of io.jmix.ui.Notifications in project jmix by jmix-framework.

the class UiReportRunnerImpl method runInBackground.

protected void runInBackground(UiReportRunContext context, Screen hostScreen) {
    Report targetReport = getReportForPrinting(context.getReport());
    long timeout = reportsClientProperties.getBackgroundReportProcessingTimeoutMs();
    BackgroundTask<Integer, ReportOutputDocument> task = new BackgroundTask<Integer, ReportOutputDocument>(timeout, TimeUnit.MILLISECONDS, hostScreen) {

        @SuppressWarnings("UnnecessaryLocalVariable")
        @Override
        public ReportOutputDocument run(TaskLifeCycle<Integer> taskLifeCycle) {
            context.setReport(targetReport);
            ReportOutputDocument result = reportRunner.run(context.getReportRunContext());
            return result;
        }

        @Override
        public boolean handleException(Exception ex) {
            if (ex instanceof ReportingException) {
                if (ex instanceof FailedToConnectToOpenOfficeException) {
                    String caption = messages.getMessage("io.jmix.reportsui.exception", "reportException.failedConnectToOffice");
                    return showErrorNotification(caption);
                } else if (ex instanceof NoOpenOfficeFreePortsException) {
                    String caption = messages.getMessage("io.jmix.reportsui.exception", "reportException.noOpenOfficeFreePorts");
                    return showErrorNotification(caption);
                }
            }
            return super.handleException(ex);
        }

        protected boolean showErrorNotification(String text) {
            Screen ownerScreen = this.getOwnerScreen();
            if (ownerScreen != null) {
                ScreenContext screenContext = ComponentsHelper.getScreenContext(ownerScreen.getWindow());
                Notifications notifications = screenContext.getNotifications();
                notifications.create().withCaption(text).withType(Notifications.NotificationType.ERROR).show();
                return true;
            }
            return false;
        }

        @Override
        public void done(ReportOutputDocument document) {
            showResult(document, context);
        }

        @Override
        public void canceled() {
            super.canceled();
        // todo https://github.com/Haulmont/jmix-reports/issues/22
        // reportService.cancelReportExecution(userSessionId, report.getId());
        }
    };
    showDialog(task);
}
Also used : TaskLifeCycle(io.jmix.ui.executor.TaskLifeCycle) ReportOutputDocument(com.haulmont.yarg.reporting.ReportOutputDocument) ReportingException(io.jmix.reports.exception.ReportingException) ShowPivotTableScreen(io.jmix.reportsui.screen.report.run.ShowPivotTableScreen) ShowReportTableScreen(io.jmix.reportsui.screen.report.run.ShowReportTableScreen) ShowChartScreen(io.jmix.reportsui.screen.report.run.ShowChartScreen) NoOpenOfficeFreePortsException(io.jmix.reports.exception.NoOpenOfficeFreePortsException) ReportingException(io.jmix.reports.exception.ReportingException) FailedToConnectToOpenOfficeException(io.jmix.reports.exception.FailedToConnectToOpenOfficeException) BackgroundTask(io.jmix.ui.executor.BackgroundTask) NoOpenOfficeFreePortsException(io.jmix.reports.exception.NoOpenOfficeFreePortsException) Notifications(io.jmix.ui.Notifications) FailedToConnectToOpenOfficeException(io.jmix.reports.exception.FailedToConnectToOpenOfficeException)

Example 15 with Notifications

use of io.jmix.ui.Notifications in project jmix by jmix-framework.

the class AbstractPrintFormAction method openRunReportScreen.

protected void openRunReportScreen(Screen screen, Object selectedValue, MetaClass inputValueMetaClass, @Nullable String outputFileName) {
    List<Report> reports = reportSecurityManager.getAvailableReports(screen.getId(), currentUserSubstitution.getEffectiveUser(), inputValueMetaClass);
    ScreenContext screenContext = UiControllerUtils.getScreenContext(screen);
    if (reports.size() > 1) {
        if (CollectionUtils.isNotEmpty(reports)) {
            ReportRun reportRunScreen = screenBuilder.lookup(Report.class, screen).withScreenClass(ReportRun.class).withOpenMode(OpenMode.DIALOG).withSelectHandler(selectedReports -> {
                if (CollectionUtils.isNotEmpty(selectedReports)) {
                    Report report = selectedReports.iterator().next();
                    runReport(report, screen, selectedValue, inputValueMetaClass, outputFileName);
                }
            }).build();
            reportRunScreen.setReports(reports);
            reportRunScreen.show();
        }
    } else if (reports.size() == 1) {
        Report report = reports.get(0);
        runReport(report, screen, selectedValue, inputValueMetaClass, outputFileName);
    } else {
        Notifications notifications = screenContext.getNotifications();
        notifications.create(Notifications.NotificationType.HUMANIZED).withCaption(messages.getMessage(AbstractPrintFormAction.class, "report.notFoundReports")).show();
    }
}
Also used : FluentUiReportRunner(io.jmix.reportsui.runner.FluentUiReportRunner) MetaClass(io.jmix.core.metamodel.model.MetaClass) ParametersDialogShowMode(io.jmix.reportsui.runner.ParametersDialogShowMode) ReportSecurityManager(io.jmix.reports.ReportSecurityManager) ParameterType(io.jmix.reports.entity.ParameterType) Autowired(org.springframework.beans.factory.annotation.Autowired) io.jmix.core(io.jmix.core) ParamsMap(io.jmix.core.common.util.ParamsMap) PrototypesLoader(io.jmix.reports.PrototypesLoader) ReportingException(io.jmix.reports.exception.ReportingException) ReportRun(io.jmix.reportsui.screen.report.run.ReportRun) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Notifications(io.jmix.ui.Notifications) ReportInputParameter(io.jmix.reports.entity.ReportInputParameter) ScreenBuilders(io.jmix.ui.ScreenBuilders) ParameterPrototype(io.jmix.reports.app.ParameterPrototype) Map(java.util.Map) Nullable(javax.annotation.Nullable) Collection(java.util.Collection) ReportsClientProperties(io.jmix.reportsui.screen.ReportsClientProperties) ReportTemplateUtils.inputParametersRequiredByTemplates(io.jmix.reports.util.ReportTemplateUtils.inputParametersRequiredByTemplates) InputParametersDialog(io.jmix.reportsui.screen.report.run.InputParametersDialog) List(java.util.List) io.jmix.ui.screen(io.jmix.ui.screen) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) UiReportRunner(io.jmix.reportsui.runner.UiReportRunner) AbstractAction(io.jmix.ui.action.AbstractAction) Screens(io.jmix.ui.Screens) CurrentUserSubstitution(io.jmix.core.usersubstitution.CurrentUserSubstitution) Collections(java.util.Collections) Report(io.jmix.reports.entity.Report) Report(io.jmix.reports.entity.Report) ReportRun(io.jmix.reportsui.screen.report.run.ReportRun) Notifications(io.jmix.ui.Notifications)

Aggregations

Notifications (io.jmix.ui.Notifications)24 MetaClass (io.jmix.core.metamodel.model.MetaClass)5 Screens (io.jmix.ui.Screens)4 Folder (com.haulmont.cuba.core.entity.Folder)2 Messages (io.jmix.core.Messages)2 ReportingException (io.jmix.reports.exception.ReportingException)2 AppUI (io.jmix.ui.AppUI)2 ScreenContext (io.jmix.ui.screen.ScreenContext)2 Nullable (javax.annotation.Nullable)2 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)1 AppFolder (com.haulmont.cuba.core.entity.AppFolder)1 Security (com.haulmont.cuba.core.global.Security)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 Filter (com.haulmont.cuba.gui.components.Filter)1 Window (com.haulmont.cuba.gui.components.Window)1 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)1 SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)1 ReportOutputDocument (com.haulmont.yarg.reporting.ReportOutputDocument)1