Merge branch 'release/3.12.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 previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
50 bindNullSession();
51 }
52
53 private void bindNullSession() {
54 if(CdmStore.isActive()) {
55 CdmStore.getCurrentSessionManager().bindNullSession();
56 }
57 }
58
59 @Override
60 public boolean performOk() {
61 if(previousCdmEntitySession != null && !isApply) {
62 previousCdmEntitySession.bind();
63 }
64 return super.performOk();
65 }
66
67 @Override
68 public boolean performCancel() {
69 if(previousCdmEntitySession != null) {
70 previousCdmEntitySession.bind();
71 }
72 return super.performCancel();
73 }
74
75 @Override
76 public void performApply() {
77 isApply = true;
78 super.performApply();
79 isApply = false;
80 }
81
82 /* (non-Javadoc)
83 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
84 */
85 @Override
86 public ICdmEntitySession getCdmEntitySession() {
87 return CdmStore.getCurrentSessionManager().getNullSession();
88 }
89
90 /* (non-Javadoc)
91 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
92 */
93 @Override
94 public <T extends CdmBase> Collection<T> getRootEntities() {
95 return null;
96 }
97
98 /* (non-Javadoc)
99 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
100 */
101 @Override
102 public Map<Object, List<String>> getPropertyPathsMap() {
103 return null;
104 }
105
106 }