Project

General

Profile

Download (2.77 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.taxeditor.preference.menu;
10

    
11
import java.util.Collection;
12
import java.util.List;
13
import java.util.Map;
14

    
15
import org.eclipse.jface.preference.PreferencePage;
16
import org.eclipse.jface.resource.ImageDescriptor;
17

    
18
import eu.etaxonomy.cdm.model.common.CdmBase;
19
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
20
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
21
import eu.etaxonomy.taxeditor.store.CdmStore;
22

    
23
/**
24
 * @author cmathew
25
 * @date 30 Jul 2015
26
 *
27
 */
28
public abstract class CdmPreferencePage extends PreferencePage implements ICdmEntitySessionEnabled {
29

    
30
    private ICdmEntitySession previousCdmEntitySession;
31
    private boolean isApply;
32

    
33
    public CdmPreferencePage() {
34
        initSession();
35
    }
36

    
37
    public CdmPreferencePage(String title) {
38
        super(title);
39
        initSession();
40
    }
41

    
42
    public CdmPreferencePage(String title, ImageDescriptor image) {
43
        super(title, image);
44
        initSession();
45
    }
46

    
47
    private void initSession() {
48
        if (CdmStore.isActive()){
49
            previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
50
            bindNullSession();
51
        }
52

    
53
    }
54

    
55
    private void bindNullSession() {
56
        if(CdmStore.isActive()) {
57
            CdmStore.getCurrentSessionManager().bindNullSession();
58
        }
59
    }
60

    
61
    @Override
62
    public boolean performOk() {
63
        if(previousCdmEntitySession != null && !isApply) {
64
            previousCdmEntitySession.bind();
65
        }
66
        return super.performOk();
67
    }
68

    
69
    @Override
70
    public boolean performCancel() {
71
        if(previousCdmEntitySession != null) {
72
            previousCdmEntitySession.bind();
73
        }
74
        return super.performCancel();
75
    }
76

    
77
    @Override
78
    public void performApply() {
79
        isApply = true;
80
        super.performApply();
81
        isApply = false;
82
    }
83

    
84
    /* (non-Javadoc)
85
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
86
     */
87
    @Override
88
    public ICdmEntitySession getCdmEntitySession() {
89
        return CdmStore.getCurrentSessionManager().getNullSession();
90
    }
91

    
92
    /* (non-Javadoc)
93
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
94
     */
95
    @Override
96
    public <T extends CdmBase> Collection<T> getRootEntities() {
97
        return null;
98
    }
99

    
100
    /* (non-Javadoc)
101
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
102
     */
103
    @Override
104
    public Map<Object, List<String>> getPropertyPathsMap() {
105
        return null;
106
    }
107

    
108
}
(2-2/20)