Merge branch 'release/4.4.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / menu / CdmPreferencePage.java
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.taxeditor.preference.menu;
11
12 import java.util.Collection;
13 import java.util.List;
14 import java.util.Map;
15
16 import org.eclipse.jface.preference.PreferencePage;
17 import org.eclipse.jface.resource.ImageDescriptor;
18
19 import eu.etaxonomy.cdm.model.common.CdmBase;
20 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
21 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23
24 /**
25 * @author cmathew
26 * @date 30 Jul 2015
27 *
28 */
29 public abstract class CdmPreferencePage extends PreferencePage implements ICdmEntitySessionEnabled {
30
31 private ICdmEntitySession previousCdmEntitySession;
32 private boolean isApply;
33
34 public CdmPreferencePage() {
35 initSession();
36 }
37
38 public CdmPreferencePage(String title) {
39 super(title);
40 initSession();
41 }
42
43 public CdmPreferencePage(String title, ImageDescriptor image) {
44 super(title, image);
45 initSession();
46 }
47
48 private void initSession() {
49 if (CdmStore.isActive()){
50 previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
51 bindNullSession();
52 }
53
54 }
55
56 private void bindNullSession() {
57 if(CdmStore.isActive()) {
58 CdmStore.getCurrentSessionManager().bindNullSession();
59 }
60 }
61
62 @Override
63 public boolean performOk() {
64 if(previousCdmEntitySession != null && !isApply) {
65 previousCdmEntitySession.bind();
66 }
67 return super.performOk();
68 }
69
70 @Override
71 public boolean performCancel() {
72 if(previousCdmEntitySession != null) {
73 previousCdmEntitySession.bind();
74 }
75 return super.performCancel();
76 }
77
78 @Override
79 public void performApply() {
80 isApply = true;
81 super.performApply();
82 isApply = false;
83 }
84
85 /* (non-Javadoc)
86 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
87 */
88 @Override
89 public ICdmEntitySession getCdmEntitySession() {
90 return CdmStore.getCurrentSessionManager().getNullSession();
91 }
92
93 /* (non-Javadoc)
94 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
95 */
96 @Override
97 public <T extends CdmBase> Collection<T> getRootEntities() {
98 return null;
99 }
100
101 /* (non-Javadoc)
102 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
103 */
104 @Override
105 public Map<Object, List<String>> getPropertyPathsMap() {
106 return null;
107 }
108
109 }