Project

General

Profile

Download (2.34 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 org.apache.log4j.Logger;
13

    
14
import com.vaadin.server.VaadinSession;
15

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

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

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

    
29
    public static void setCurrentAttribute(String name, Object value) {
30
        try {
31
            VaadinSession.getCurrent().getLockInstance().lock();
32
            VaadinSession.getCurrent().setAttribute(name, value);
33
        } finally {
34
            VaadinSession.getCurrent().getLockInstance().unlock();
35
        }
36
    }
37

    
38
    public static void initCdmDataChangeService() {
39
        if(getCurrentCdmDataChangeService() != null) {
40
           logger.info("replacing data change service with new one");
41
        }
42
        setCurrentAttribute(CdmDataChangeService.KEY, new CdmDataChangeService());
43
    }
44

    
45
    public static CdmDataChangeService getCurrentCdmDataChangeService() {
46
        return (CdmDataChangeService) VaadinSession.getCurrent().getAttribute(CdmDataChangeService.KEY);
47
    }
48

    
49
    public static void initSelectionService() {
50
        if(getCurrentSelectionService() != null) {
51
            logger.info("replacing selection service with new one");
52
        }
53
        setCurrentAttribute(SelectionService.KEY, new SelectionService());
54
    }
55

    
56
    public static SelectionService getCurrentSelectionService() {
57
        return (SelectionService) VaadinSession.getCurrent().getAttribute(SelectionService.KEY);
58
    }
59

    
60
    public static void initBasicEventService() {
61
        if(getCurrentBasicEventService() != null) {
62
            logger.info("replacing basic event service with new one");
63
        }
64
        setCurrentAttribute(BasicEventService.KEY, new BasicEventService());
65
    }
66

    
67
    public static BasicEventService getCurrentBasicEventService() {
68
        return (BasicEventService) VaadinSession.getCurrent().getAttribute(BasicEventService.KEY);
69
    }
70
}
(5-5/7)