use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class WebFileUploadField method initUploadButton.
protected void initUploadButton(CubaFileUpload impl) {
impl.setProgressWindowCaption(messages.getMainMessage("upload.uploadingProgressTitle"));
impl.setUnableToUploadFileMessage(messages.getMainMessage("upload.unableToUploadFile"));
impl.setCancelButtonCaption(messages.getMainMessage("upload.cancel"));
impl.setCaption(messages.getMainMessage("upload.submit"));
impl.setDropZonePrompt(messages.getMainMessage("upload.singleDropZonePrompt"));
impl.setDescription(null);
impl.setFileSizeLimit(getActualFileSizeLimit());
impl.setReceiver(this::receiveUpload);
impl.addStartedListener(event -> fireFileUploadStart(event.getFileName(), event.getContentLength()));
impl.addFinishedListener(event -> fireFileUploadFinish(event.getFileName(), event.getContentLength()));
impl.addSucceededListener(event -> {
fileName = event.getFileName();
fileId = tempFileId;
saveFile(getFileDescriptor());
component.setFileNameButtonCaption(fileName);
fireFileUploadSucceed(event.getFileName(), event.getContentLength());
});
impl.addFailedListener(event -> {
try {
fileUploading.deleteFile(tempFileId);
tempFileId = null;
} catch (Exception e) {
if (e instanceof FileStorageException) {
FileStorageException fse = (FileStorageException) e;
if (fse.getType() != FileStorageException.Type.FILE_NOT_FOUND) {
log.warn(String.format("Could not remove temp file %s after broken uploading", tempFileId));
}
}
log.warn(String.format("Error while delete temp file %s", tempFileId));
}
fireFileUploadError(event.getFileName(), event.getContentLength(), event.getReason());
});
impl.addFileSizeLimitExceededListener(e -> {
Notifications notifications = getScreenContext(this).getNotifications();
notifications.create(NotificationType.WARNING).withCaption(messages.formatMainMessage("upload.fileTooBig.message", e.getFileName(), getFileSizeLimitString())).show();
});
impl.addFileExtensionNotAllowedListener(e -> {
Notifications notifications = getScreenContext(this).getNotifications();
notifications.create(NotificationType.WARNING).withCaption(messages.formatMainMessage("upload.fileIncorrectExtension.message", e.getFileName())).show();
});
}
use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class WebDateField method handleDateOutOfRange.
protected void handleDateOutOfRange(V value) {
if (getFrame() != null) {
Messages messages = beanLocator.get(Messages.NAME);
Notifications notifications = ComponentsHelper.getScreenContext(this).getNotifications();
notifications.create().withCaption(messages.getMainMessage("datePicker.dateOutOfRangeMessage")).withType(Notifications.NotificationType.TRAY).show();
}
setValueToPresentation(convertToLocalDateTime(value, zoneId));
}
use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class MasterDetailScreen method lockIfNeeded.
/**
* Pessimistic lock before start of editing, if it is configured for the entity.
*/
protected boolean lockIfNeeded(Entity entity) {
LockService lockService = getBeanLocator().get(LockService.class);
LockInfo lockInfo = lockService.lock(getLockName(), entity.getId().toString());
if (lockInfo == null) {
justLocked = true;
} else if (!(lockInfo instanceof LockNotSupported)) {
Messages messages = getBeanLocator().get(Messages.class);
DatatypeFormatter datatypeFormatter = getBeanLocator().get(DatatypeFormatter.class);
Notifications notifications = getScreenContext().getNotifications();
notifications.create(NotificationType.HUMANIZED).withCaption(messages.getMainMessage("entityLocked.msg")).withDescription(String.format(messages.getMainMessage("entityLocked.desc"), lockInfo.getUser().getLogin(), datatypeFormatter.formatDateTime(lockInfo.getSince()))).show();
return false;
}
return true;
}
use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class OpenAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
if (!checkFieldValue())
return;
Entity entity = pickerField.getValue();
if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
ScreenContext screenContext = ComponentsHelper.getScreenContext(pickerField);
Notifications notifications = screenContext.getNotifications();
notifications.create(NotificationType.HUMANIZED).withDescription(messages.getMainMessage("OpenAction.objectIsDeleted")).show();
return;
}
MetaClass metaClass = pickerField.getMetaClass();
if (metaClass == null) {
throw new DevelopmentException("Neither metaClass nor datasource/property is specified " + "for the PickerField", "action ID", getId());
}
EditorBuilder builder = screenBuilders.editor(pickerField);
builder = screenInitializer.initBuilder(builder);
if (transformation != null) {
builder.withTransformation(transformation);
}
Screen editor = builder.build();
if (afterCommitHandler != null) {
editor.addAfterCloseListener(afterCloseEvent -> {
CloseAction closeAction = afterCloseEvent.getCloseAction();
if (closeAction.equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
Entity committedEntity = ((EditorScreen) editor).getEditedEntity();
afterCommitHandler.accept((E) committedEntity);
}
});
}
screenInitializer.initScreen(editor);
editor.show();
}
use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class BulkEditAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings("unchecked")
@Override
public void execute() {
if (!(target.getItems() instanceof EntityDataUnit)) {
throw new IllegalStateException("BulkEditAction target Items is null " + "or does not implement EntityDataUnit");
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
throw new IllegalStateException("Target is not bound to entity");
}
if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMainMessage("accessDenied.message")).show();
return;
}
if (target.getSelected().isEmpty()) {
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMainMessage("actions.BulkEdit.emptySelection")).show();
return;
}
Window window = ComponentsHelper.getWindowNN(target);
BulkEditors.EditorBuilder builder = bulkEditors.builder(metaClass, target.getSelected(), window.getFrameOwner()).withListComponent(target);
if (columnsMode != null) {
builder = builder.withColumnsMode(columnsMode);
}
if (exclude != null) {
builder = builder.withExclude(exclude);
}
if (fieldSorter != null) {
builder = builder.withFieldSorter(fieldSorter);
}
if (includeProperties != null) {
builder = builder.withIncludeProperties(includeProperties);
}
if (openMode != null) {
builder = builder.withLaunchMode(openMode);
}
if (loadDynamicAttributes != null) {
builder = builder.withLoadDynamicAttributes(loadDynamicAttributes);
}
if (useConfirmDialog != null) {
builder = builder.withUseConfirmDialog(useConfirmDialog);
}
builder.create().show();
}
Aggregations