Project

General

Profile

Download (2.43 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.vaadin.mvp;
10

    
11
import eu.etaxonomy.cdm.api.util.UserHelper;
12
import eu.etaxonomy.cdm.service.UserHelperAccess;
13
import eu.etaxonomy.cdm.vaadin.event.EditorActionContextFormat;
14
import eu.etaxonomy.cdm.vaadin.event.EditorActionContextFormat.TargetInfoType;
15
import eu.etaxonomy.cdm.vaadin.event.EditorActionContextFormatter;
16

    
17
/**
18
 * @author a.kohlbecker
19
 * @since Nov 8, 2018
20
 *
21
 */
22
public class PopupEditorException extends RuntimeException {
23

    
24
    private static final long serialVersionUID = -4242789621156408545L;
25

    
26
    private String contextInfo;
27

    
28
    private String userName;
29

    
30
    /**
31
     * @param message
32
     */
33
    public PopupEditorException(String message, AbstractPopupEditor<?,?> editor, Throwable e) {
34
        super(message, e);
35

    
36
        EditorActionContextFormatter formatter = new EditorActionContextFormatter();
37
        EditorActionContextFormat format = new EditorActionContextFormat(true, true, true, true, TargetInfoType.PROPERTIES, null);
38
        format.tagName = null;
39
        format.doTargetEntity = true;
40
        contextInfo = formatter.format(editor.getEditorActionContext(), format);
41
        userName = userName();
42
    }
43

    
44
    /**
45
     * @return
46
     */
47
    public String userName() {
48
        UserHelper userHelper = UserHelperAccess.userHelper();
49
        return userHelper != null ? userHelper.userName() : null;
50
    }
51

    
52
    public PopupEditorException(String message, AbstractPopupEditor<?,?> editor) {
53
        super(message);
54

    
55
        EditorActionContextFormatter formatter = new EditorActionContextFormatter();
56
        EditorActionContextFormat format = new EditorActionContextFormat(true, true, true, true, TargetInfoType.PROPERTIES, null);
57
        format.tagName = null;
58
        format.doTargetEntity = true;
59
        contextInfo = formatter.format(editor.getEditorActionContext(), format);
60
        userName = userName();
61
    }
62

    
63

    
64

    
65
    @Override
66
    public String getMessage() {
67
        String userInfo = "";
68
        if(userName != null){
69
            userInfo = " [user=" + userName + "] ";
70
        }
71
        return super.getMessage() + " -  context" + userInfo + ":" + contextInfo;
72
    }
73

    
74

    
75
    @Override
76
    public String getLocalizedMessage() {
77
        return getMessage();
78
    }
79

    
80
}
(15-15/15)