Project

General

Profile

Download (2.51 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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.cdm.vaadin.util;
10

    
11
import java.util.concurrent.locks.Lock;
12

    
13
import org.apache.log4j.Logger;
14

    
15
import com.vaadin.server.VaadinSession;
16

    
17
import eu.etaxonomy.cdm.vaadin.session.BasicEventService;
18
import eu.etaxonomy.cdm.vaadin.session.CdmDataChangeService;
19
import eu.etaxonomy.cdm.vaadin.session.SelectionService;
20

    
21
/**
22
 * @author cmathew
23
 * @date 7 Apr 2015
24
 *
25
 */
26
public class CdmVaadinSessionUtilities {
27

    
28
    private static final Logger logger = Logger.getLogger(CdmVaadinSessionUtilities.class);
29

    
30
    public static void setCurrentAttribute(String name, Object value) {
31
        Lock sessionLock = VaadinSession.getCurrent().getLockInstance();
32
        try {
33
            if(sessionLock != null) {
34
                sessionLock.lock();
35
            }
36
            VaadinSession.getCurrent().setAttribute(name, value);
37
        } finally {
38
            if(sessionLock != null) {
39
                sessionLock.unlock();
40
            }
41
        }
42
    }
43

    
44
    public static void initCdmDataChangeService() {
45
//        if(getCurrentCdmDataChangeService() != null) {
46
//           logger.info("replacing data change service with new one");
47
//        }
48
        setCurrentAttribute(CdmDataChangeService.KEY, new CdmDataChangeService());
49
    }
50

    
51
    public static CdmDataChangeService getCurrentCdmDataChangeService() {
52
        return (CdmDataChangeService) VaadinSession.getCurrent().getAttribute(CdmDataChangeService.KEY);
53
    }
54

    
55
    public static void initSelectionService() {
56
//        if(getCurrentSelectionService() != null) {
57
//            logger.info("replacing selection service with new one");
58
//        }
59
        setCurrentAttribute(SelectionService.KEY, new SelectionService());
60
    }
61

    
62
    public static SelectionService getCurrentSelectionService() {
63
        return (SelectionService) VaadinSession.getCurrent().getAttribute(SelectionService.KEY);
64
    }
65

    
66
    public static void initBasicEventService() {
67
//        if(getCurrentBasicEventService() != null) {
68
//            logger.info("replacing basic event service with new one");
69
//        }
70
        setCurrentAttribute(BasicEventService.KEY, new BasicEventService());
71
    }
72

    
73
    public static BasicEventService getCurrentBasicEventService() {
74
        return (BasicEventService) VaadinSession.getCurrent().getAttribute(BasicEventService.KEY);
75
    }
76
}
(7-7/12)