2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.preference
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.events
.SelectionAdapter
;
13 import org
.eclipse
.swt
.events
.SelectionEvent
;
14 import org
.eclipse
.swt
.events
.SelectionListener
;
15 import org
.eclipse
.swt
.layout
.GridData
;
16 import org
.eclipse
.swt
.widgets
.Button
;
17 import org
.eclipse
.swt
.widgets
.Combo
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Control
;
20 import org
.eclipse
.swt
.widgets
.Label
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
.PrefKey
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
25 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
26 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
27 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
34 public class GeneralPreferencePage
extends CdmPreferencePage
implements SelectionListener
{
36 protected Boolean isShowCheckListPerspective
;
38 protected boolean isAllowOverrideShowMediaView
;
39 protected boolean isAllowOverrideShowCheckListPerspective
;
41 protected boolean isOverrideShowMediaView
;
42 protected boolean isOverrideShowCheckListPerspective
;
44 protected Combo showChecklistPerspectiveButton
;
45 protected Button allowOverrideShowChecklistButton
;
48 protected Control
createContents(Composite parent
) {
50 final Composite composite
= createComposite(parent
);
52 GridData gridData
= createTextGridData();
54 Label separator
= new Label(composite
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
55 separator
.setLayoutData(gridData
);
56 separator
.setVisible(false);
60 showChecklistPerspectiveButton
= createBooleanCombo(composite
, SHOW
, DO_NOT_SHOW
, PreferencePredicate
.ShowChecklistPerspective
, "Set Checklist Perspective as Default Perspective",
63 showChecklistPerspectiveButton
.addSelectionListener(this);
66 if (isAdminPreference
){
67 allowOverrideShowChecklistButton
= createAllowOverrideButton(composite
);
68 allowOverrideShowChecklistButton
.addSelectionListener(new SelectionAdapter(){
70 public void widgetSelected(SelectionEvent e
) {
71 isAllowOverrideShowCheckListPerspective
= allowOverrideShowChecklistButton
.getSelection();
84 public boolean performOk() {
88 if (isAllowOverrideShowCheckListPerspective
){
89 if (isShowCheckListPerspective
!= null){
90 PreferencesUtil
.setBooleanValue(PreferencePredicate
.ShowChecklistPerspective
.getKey(), isShowCheckListPerspective
);
92 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowChecklistPerspective
.getKey()), isOverrideShowCheckListPerspective
);
100 protected void getValues(){
101 isAdminPreference
= false;
103 CdmPreferenceCache cache
= CdmPreferenceCache
.instance();
104 isOverrideShowCheckListPerspective
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowChecklistPerspective
.getKey()), true) != null? PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowChecklistPerspective
.getKey()), true): false;
105 if (isOverrideShowCheckListPerspective
){
106 isShowCheckListPerspective
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowChecklistPerspective
.getKey(), true);
109 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowChecklistPerspective
);
110 CdmPreference pref
= cache
.findBestMatching(key
);
112 isAllowOverrideShowCheckListPerspective
= pref
.isAllowOverride();
114 isAllowOverrideShowCheckListPerspective
= true;
121 public void widgetSelected(SelectionEvent e
) {
122 if (e
.getSource().equals(this.showChecklistPerspectiveButton
)) {
123 String text
= showChecklistPerspectiveButton
.getText();
124 if (text
.startsWith(Messages
.Preference_Use_Default
)){
125 isOverrideShowCheckListPerspective
= false;
126 isShowCheckListPerspective
= null;
128 }else if (text
.equals(SHOW
)){
129 isShowCheckListPerspective
= true;
130 isOverrideShowCheckListPerspective
= true;
132 isShowCheckListPerspective
= false;
133 isOverrideShowCheckListPerspective
= true;
137 this.setSelections();
149 public void widgetDefaultSelected(SelectionEvent e
) {
150 // TODO Auto-generated method stub
155 protected void performDefaults() {
156 isOverrideShowCheckListPerspective
= false;
157 isShowCheckListPerspective
= null;
163 protected void setSelections(){
164 if (isShowCheckListPerspective
== null || (!isOverrideShowCheckListPerspective
&& !isAdminPreference
)){
165 showChecklistPerspectiveButton
.select(0);
167 if (isShowCheckListPerspective
){
168 showChecklistPerspectiveButton
.select(1);
170 showChecklistPerspectiveButton
.select(2);
174 if (isAdminPreference
){
175 allowOverrideShowChecklistButton
.setSelection(isAllowOverrideShowCheckListPerspective
);