Search in sources :

Example 6 with Notifications

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();
    });
}
Also used : FileStorageException(com.haulmont.cuba.core.global.FileStorageException) Notifications(com.haulmont.cuba.gui.Notifications) FileStorageException(com.haulmont.cuba.core.global.FileStorageException)

Example 7 with Notifications

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));
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) Notifications(com.haulmont.cuba.gui.Notifications)

Example 8 with Notifications

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;
}
Also used : LockService(com.haulmont.cuba.core.app.LockService) Notifications(com.haulmont.cuba.gui.Notifications)

Example 9 with Notifications

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();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) MetaClass(com.haulmont.chile.core.model.MetaClass) EditorBuilder(com.haulmont.cuba.gui.builders.EditorBuilder) Notifications(com.haulmont.cuba.gui.Notifications) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 10 with Notifications

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();
}
Also used : BulkEditors(com.haulmont.cuba.gui.BulkEditors) MetaClass(com.haulmont.chile.core.model.MetaClass) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit) Notifications(com.haulmont.cuba.gui.Notifications)

Aggregations

Notifications (com.haulmont.cuba.gui.Notifications)14 Messages (com.haulmont.cuba.core.global.Messages)6 MetaClass (com.haulmont.chile.core.model.MetaClass)3 Entity (com.haulmont.cuba.core.entity.Entity)3 NotificationType (com.haulmont.cuba.gui.Notifications.NotificationType)3 ClientConfig (com.haulmont.cuba.client.ClientConfig)2 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)2 Dialogs (com.haulmont.cuba.gui.Dialogs)2 WindowManager (com.haulmont.cuba.gui.WindowManager)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 ExcelExportFormat (com.haulmont.cuba.gui.export.ExcelExportFormat)2 ExcelExporter (com.haulmont.cuba.gui.export.ExcelExporter)2 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)2 CubaIcon (com.haulmont.cuba.gui.icons.CubaIcon)2 Icons (com.haulmont.cuba.gui.icons.Icons)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Subscription (com.haulmont.bali.events.Subscription)1