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();
}
}
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();
}
}
}
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();
}
}
}
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);
}
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();
}
}
Aggregations