2 * Copyright (C) 2014 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
.custom
.CLabel
;
13 import org
.eclipse
.swt
.events
.SelectionAdapter
;
14 import org
.eclipse
.swt
.events
.SelectionEvent
;
15 import org
.eclipse
.swt
.layout
.GridLayout
;
16 import org
.eclipse
.swt
.widgets
.Button
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Control
;
19 import org
.eclipse
.swt
.widgets
.Label
;
21 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
23 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CommandHandlerButton
;
33 public class ChecklistEditorGeneralPreference
extends CdmPreferencePage
{
35 boolean isEditorActivated
;
38 boolean isSortByVocabularyOrder
;
40 boolean isShowIdInVocabulary
;
41 boolean isShowSymbol1
;
42 boolean isShowSymbol2
;
45 boolean isAllowOverride
;
48 protected Control
createContents(Composite parent
) {
50 Composite composite
= new Composite(parent
, SWT
.NULL
);
51 composite
.setLayout(new GridLayout());
53 CdmPreference distributionEditorPref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DistributionEditorActivated
);
54 isAllowOverride
= false;
55 if (distributionEditorPref
!= null){
56 isAllowOverride
= distributionEditorPref
.isAllowOverride();
58 isAllowOverride
= true;
63 isEditorActivated
= PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
);
64 final Button activateCheckButton
= new Button(composite
, SWT
.CHECK
);
65 activateCheckButton
.setText("Enable Distribution Editor");
66 activateCheckButton
.setSelection(isEditorActivated
);
67 activateCheckButton
.addSelectionListener(new SelectionAdapter(){
69 public void widgetSelected(SelectionEvent e
) {
70 isEditorActivated
= activateCheckButton
.getSelection();
72 if(isEditorActivated
){
73 child
.setVisible(true);
74 child
.setEnabled(true);
76 child
.setVisible(false);
77 child
.setEnabled(false);
83 child
= new Composite(composite
, SWT
.NULL
);
84 child
.setLayout(new GridLayout());
85 child
.setVisible(isEditorActivated
);
86 final CLabel label
= new CLabel(child
, SWT
.NULL
);
87 label
.setText("Please open the wizard below, in order to \n" + "choose the area vocabularies for the Distribution Editor");
88 final CommandHandlerButton button_openFeatureTree
= new CommandHandlerButton(child
, SWT
.PUSH
,
89 "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardHandler");
91 button_openFeatureTree
.setText("Select Areas");
93 final CLabel description
= new CLabel(child
, SWT
.NULL
);
94 description
.setText(Messages
.ChecklistEditorGeneralPreference_Configure_display_of_Areas
);
96 final Button showIdInVocabulary
= new Button(child
, SWT
.RADIO
);
97 isShowIdInVocabulary
= PreferencesUtil
.isShowIdInVocabularyInChecklistEditor();
98 showIdInVocabulary
.setText("Show Id in Vocabulary instead of full title of the areas");
99 showIdInVocabulary
.setSelection(isShowIdInVocabulary
);
100 showIdInVocabulary
.addSelectionListener(new SelectionAdapter(){
102 public void widgetSelected(SelectionEvent e
) {
103 isShowIdInVocabulary
= showIdInVocabulary
.getSelection();
109 final Button showSymbol1
= new Button(child
, SWT
.RADIO
);
110 isShowSymbol1
= PreferencesUtil
.isShowSymbol1InChecklistEditor();
112 showSymbol1
.setText(Messages
.ChecklistEditorGeneralPreference_show_symbol1
);
113 showSymbol1
.setSelection(isShowSymbol1
);
114 showSymbol1
.addSelectionListener(new SelectionAdapter(){
116 public void widgetSelected(SelectionEvent e
) {
117 isShowSymbol1
= showSymbol1
.getSelection();
121 final Button showSymbol2
= new Button(child
, SWT
.RADIO
);
122 isShowSymbol2
= PreferencesUtil
.isShowSymbol2InChecklistEditor();
124 showSymbol2
.setText(Messages
.ChecklistEditorGeneralPreference_show_symbol2
);
125 showSymbol2
.setSelection(isShowSymbol2
);
126 showSymbol2
.addSelectionListener(new SelectionAdapter(){
128 public void widgetSelected(SelectionEvent e
) {
129 isShowSymbol2
= showSymbol2
.getSelection();
134 final Button showTitle
= new Button(child
, SWT
.RADIO
);
135 isShowTitle
= !(isShowIdInVocabulary
|| isShowSymbol1
|| isShowSymbol2
);
137 showTitle
.setText(Messages
.ChecklistEditorGeneralPreference_show_title
);
138 showTitle
.setSelection(isShowTitle
);
139 showTitle
.addSelectionListener(new SelectionAdapter(){
141 public void widgetSelected(SelectionEvent e
) {
142 isShowTitle
= showTitle
.getSelection();
148 final Button showSymbol
= new Button(child
, SWT
.CHECK
);
149 isShowSymbol
= PreferencesUtil
.isShowSymbolInChecklistEditor();
150 showSymbol
.setText("Show Symbol of the Status, if existing");
151 showSymbol
.setSelection(isShowSymbol
);
152 showSymbol
.addSelectionListener(new SelectionAdapter(){
154 public void widgetSelected(SelectionEvent e
) {
155 isShowSymbol
= showSymbol
.getSelection();
158 PreferencesUtil
.recursiveSetEnabled(button_openFeatureTree
, CdmStore
.isActive());
159 isShowRank
= PreferencesUtil
.isShowRankInChecklistEditor();
160 final Button activateRankButton
= new Button(child
, SWT
.CHECK
);
161 activateRankButton
.setText("Show Rank in Distribution Editor");
162 activateRankButton
.setSelection(isShowRank
);
163 activateRankButton
.addSelectionListener(new SelectionAdapter(){
165 public void widgetSelected(SelectionEvent e
) {
166 isShowRank
= activateRankButton
.getSelection();
169 final Button sortNamedAreaByVocabularyOrder
= new Button(child
, SWT
.CHECK
);
170 isSortByVocabularyOrder
= PreferencesUtil
.isSortNamedAreaByOrderInVocabulary();
171 sortNamedAreaByVocabularyOrder
.setText("Sort Areas by Order in Vocabulary");
172 sortNamedAreaByVocabularyOrder
.setSelection(isSortByVocabularyOrder
);
173 sortNamedAreaByVocabularyOrder
.addSelectionListener(new SelectionAdapter(){
175 public void widgetSelected(SelectionEvent e
) {
176 isSortByVocabularyOrder
= sortNamedAreaByVocabularyOrder
.getSelection();
180 if(isEditorActivated
){
181 child
.setEnabled(true);
183 child
.setEnabled(false);
186 Label label
= new Label(composite
, SWT
.NONE
);
187 label
.setText("The CDM settings don't allow to set the preferences for using the distribution editor locally. If you need to make local settings, please ask an administrator.");
195 public boolean performOk() {
196 if (isAllowOverride
){
197 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
, isEditorActivated
);
198 PreferencesUtil
.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder
);
199 PreferencesUtil
.setShowRankInChecklistEditor(isShowRank
);
200 PreferencesUtil
.setShowSymbolInChecklistEditor(isShowSymbol
);
201 String displayString
;
202 if (isShowIdInVocabulary
){
203 displayString
= IPreferenceKeys
.CHECKLIST_AREA_DISPLAY_TITLE
;
204 }else if (isShowSymbol1
){
205 displayString
= IPreferenceKeys
.CHECKLIST_AREA_DISPLAY_SYMBOL1
;
206 }else if (isShowSymbol2
){
207 displayString
= IPreferenceKeys
.CHECKLIST_AREA_DISPLAY_SYMBOL2
;
209 displayString
= IPreferenceKeys
.CHECKLIST_AREA_DISPLAY_TITLE
;
211 PreferencesUtil
.setShowIdInVocabularyInChecklistEditor(displayString
);