Project

General

Profile

Download (3 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.preference.IE4PreferencePage;
20
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
22
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

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

    
32
    private ICdmEntitySession previousCdmEntitySession;
33
    private boolean isApply;
34

    
35
    public CdmPreferencePage() {
36
        this(null, null);
37
    }
38

    
39
    public CdmPreferencePage(String title) {
40
        this(title, null);
41
    }
42

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

    
49
    public void init() {
50
        setPreferenceStore(PreferencesUtil.getPreferenceStore());
51
    }
52

    
53
    private void initSession() {
54
        if (CdmStore.isActive()){
55
            previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
56
            bindNullSession();
57
        }
58

    
59
    }
60

    
61
    private void bindNullSession() {
62
        if(CdmStore.isActive()) {
63
            CdmStore.getCurrentSessionManager().bindNullSession();
64
        }
65
    }
66

    
67
    @Override
68
    public boolean performOk() {
69
        if(previousCdmEntitySession != null && !isApply) {
70
            previousCdmEntitySession.bind();
71
        }
72
        return super.performOk();
73
    }
74

    
75
    @Override
76
    public boolean performCancel() {
77
        if(previousCdmEntitySession != null) {
78
            previousCdmEntitySession.bind();
79
        }
80
        return super.performCancel();
81
    }
82

    
83
    @Override
84
    public void performApply() {
85
        isApply = true;
86
        super.performApply();
87
        isApply = false;
88
    }
89

    
90
    /* (non-Javadoc)
91
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
92
     */
93
    @Override
94
    public ICdmEntitySession getCdmEntitySession() {
95
        return CdmStore.getCurrentSessionManager().getNullSession();
96
    }
97

    
98
    /* (non-Javadoc)
99
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
100
     */
101
    @Override
102
    public <T extends CdmBase> Collection<T> getRootEntities() {
103
        return null;
104
    }
105

    
106
    /* (non-Javadoc)
107
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
108
     */
109
    @Override
110
    public Map<Object, List<String>> getPropertyPathsMap() {
111
        return null;
112
    }
113

    
114
}
(2-2/21)