/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */
package com.haulmont.cuba.web.exception;

import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.web.App;
import com.vaadin.ui.Window;

import javax.annotation.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Handles a JPA optimistic lock exception.
 *
 * @author krivopustov
 * @version $Id$
 */
public class OptimisticExceptionHandler extends AbstractExceptionHandler {

    public OptimisticExceptionHandler() {
        super("org.springframework.orm.jpa.JpaOptimisticLockingFailureException");
    }

    @Override
    protected void doHandle(App app, String className, String message, @Nullable Throwable throwable) {
        Pattern pattern = Pattern.compile("\\[([^-]*)-");
        Matcher matcher = pattern.matcher(message);
        String entityClassName = "";
        if (matcher.find()) {
            entityClassName = matcher.group(1);
        }

        Messages messages = AppBeans.get(Messages.class);

        String entityName = entityClassName.substring(entityClassName.lastIndexOf(".") + 1);
        String packageName = entityClassName.substring(0, entityClassName.lastIndexOf("."));
        String localizedEntityName = messages.getMessage(packageName, entityName);

        String msg = messages.formatMessage(messages.getMainMessagePack(),
                "optimisticException.message", "\"" + localizedEntityName + "\"");
        app.getAppWindow().showNotification(msg, Window.Notification.TYPE_ERROR_MESSAGE);
    }
}
@@ -321,45 +321,64 @@
 uba.
-web.App;%0D%0Aimport com.vaadin.ui.Window
+gui.components.IFrame;%0D%0Aimport com.haulmont.cuba.web.App
 ;%0D%0A%0D
@@ -1673,17 +1673,21 @@
 .get
-App
 Window
+Manager
 ().s
@@ -1707,22 +1707,22 @@
 on(msg, 
-Window
+IFrame
 .Notific
@@ -1730,27 +1730,18 @@
 tion
-.TYPE_ERROR_MESSAGE
+Type.ERROR
 );%0D%0A

Use WebWindowManager notification in WEB-6 module ExceptionHandler cuba-trunk #PL-3148