Project

General

Profile

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

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

    
14
import org.apache.log4j.Logger;
15

    
16
import com.vaadin.server.VaadinSession;
17

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

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

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

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

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

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

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

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

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

    
74
    public static BasicEventService getCurrentBasicEventService() {
75
        return (BasicEventService) VaadinSession.getCurrent().getAttribute(BasicEventService.KEY);
76
    }
77
}
(6-6/8)