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