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
.databaseAdmin
.preferencePage
;
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
.api
.application
.ICdmRepository
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IPreferenceService
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
25 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
26 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
27 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
28 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 public class ChecklistEditorGeneralPreference
extends CdmPreferencePage
implements IE4AdminPreferencePage
{
38 boolean isEditorActivated
;
39 boolean allowOverride
;
41 boolean isSortByVocabularyOrder
;
43 boolean isShowIdInVocabulary
;
44 boolean isShowSymbol1
;
45 boolean isShowSymbol2
;
51 protected Control
createContents(Composite parent
) {
53 Composite composite
= new Composite(parent
, SWT
.NULL
);
54 composite
.setLayout(new GridLayout());
55 CdmPreference pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DistributionEditorActivated
);
57 isEditorActivated
= Boolean
.valueOf(pref
.getValue());
58 allowOverride
= pref
.isAllowOverride();
60 isEditorActivated
= false;
63 final Button activateCheckButton
= new Button(composite
, SWT
.CHECK
);
64 activateCheckButton
.setText(Messages
.ChecklistEditorGeneralPreference_enable
);
65 activateCheckButton
.setSelection(isEditorActivated
);
66 activateCheckButton
.addSelectionListener(new SelectionAdapter(){
68 public void widgetSelected(SelectionEvent e
) {
69 isEditorActivated
= activateCheckButton
.getSelection();
71 if(isEditorActivated
){
72 child
.setVisible(true);
73 child
.setEnabled(true);
75 child
.setVisible(false);
76 child
.setEnabled(false);
81 final Button allowOverrideCheckButton
= new Button(composite
, SWT
.CHECK
);
82 allowOverrideCheckButton
.setText(Messages
.ChecklistEditorGeneralPreference_allowOverride
);
83 allowOverrideCheckButton
.setSelection(allowOverride
);
84 allowOverrideCheckButton
.addSelectionListener(new SelectionAdapter(){
86 public void widgetSelected(SelectionEvent e
) {
87 allowOverride
= allowOverrideCheckButton
.getSelection();
92 child
= new Composite(composite
, SWT
.NULL
);
93 child
.setLayout(new GridLayout());
94 child
.setVisible(isEditorActivated
);
102 // final CommandHandlerButton button_openWizard = new CommandHandlerButton(child, SWT.PUSH,
103 // "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardAdminHandler");
105 // button_openWizard.setText(Messages.ChecklistEditorGeneralPreference_open_distribution_selection);
107 // Table table = new Table
108 final CLabel description
= new CLabel(child
, SWT
.NULL
);
109 description
.setText(Messages
.ChecklistEditorGeneralPreference_Configure_display_of_Areas
);
111 final Button showIdInVocabulary
= new Button(child
, SWT
.RADIO
);
112 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowIdInVocabulary
);
114 isShowIdInVocabulary
= Boolean
.valueOf(pref
.getValue());
116 isShowIdInVocabulary
= false;
118 showIdInVocabulary
.setText(Messages
.ChecklistEditorGeneralPreference_show_id_in_voc
);
119 showIdInVocabulary
.setSelection(isShowIdInVocabulary
);
120 showIdInVocabulary
.addSelectionListener(new SelectionAdapter(){
122 public void widgetSelected(SelectionEvent e
) {
123 isShowIdInVocabulary
= showIdInVocabulary
.getSelection();
127 final Button showSymbol1
= new Button(child
, SWT
.RADIO
);
128 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowSymbol1
);
130 isShowSymbol1
= Boolean
.valueOf(pref
.getValue());
132 isShowSymbol1
= false;
134 showSymbol1
.setText(Messages
.ChecklistEditorGeneralPreference_show_symbol1
);
135 showSymbol1
.setSelection(isShowSymbol1
);
136 showSymbol1
.addSelectionListener(new SelectionAdapter(){
138 public void widgetSelected(SelectionEvent e
) {
139 isShowSymbol1
= showSymbol1
.getSelection();
143 final Button showSymbol2
= new Button(child
, SWT
.RADIO
);
144 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowSymbol2
);
146 isShowSymbol2
= Boolean
.valueOf(pref
.getValue());
148 isShowSymbol2
= false;
150 showSymbol2
.setText(Messages
.ChecklistEditorGeneralPreference_show_symbol2
);
151 showSymbol2
.setSelection(isShowSymbol2
);
152 showSymbol2
.addSelectionListener(new SelectionAdapter(){
154 public void widgetSelected(SelectionEvent e
) {
155 isShowSymbol2
= showSymbol2
.getSelection();
159 final Button showTitle
= new Button(child
, SWT
.RADIO
);
160 isShowTitle
= !(isShowIdInVocabulary
|| isShowSymbol1
|| isShowSymbol2
);
162 showTitle
.setText(Messages
.ChecklistEditorGeneralPreference_show_title
);
163 showTitle
.setSelection(isShowTitle
);
164 showTitle
.addSelectionListener(new SelectionAdapter(){
166 public void widgetSelected(SelectionEvent e
) {
167 isShowTitle
= showTitle
.getSelection();
172 final Label seperator1
= new Label(child
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
173 final Button sortNamedAreaByVocabularyOrder
= new Button(child
, SWT
.CHECK
);
175 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AreasSortedByIdInVocabulary
);
177 isSortByVocabularyOrder
= Boolean
.valueOf(pref
.getValue());
179 isSortByVocabularyOrder
= false;
182 sortNamedAreaByVocabularyOrder
.setText(Messages
.ChecklistEditorGeneralPreference_sort_areas
);
183 sortNamedAreaByVocabularyOrder
.setSelection(isSortByVocabularyOrder
);
184 sortNamedAreaByVocabularyOrder
.addSelectionListener(new SelectionAdapter(){
186 public void widgetSelected(SelectionEvent e
) {
187 isSortByVocabularyOrder
= sortNamedAreaByVocabularyOrder
.getSelection();
190 final Label seperator2
= new Label(child
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
191 final CLabel descriptionStatus
= new CLabel(child
, SWT
.NULL
);
192 descriptionStatus
.setText("Configure how the status should be displayed");
193 final Button showSymbol
= new Button(child
, SWT
.CHECK
);
194 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowSymbolForStatus
);
196 isShowSymbol
= Boolean
.valueOf(pref
.getValue());
198 isShowSymbol
= false;
201 showSymbol
.setText(Messages
.ChecklistEditorGeneralPreference_show_symbol
);
202 showSymbol
.setSelection(isShowSymbol
);
203 showSymbol
.addSelectionListener(new SelectionAdapter(){
205 public void widgetSelected(SelectionEvent e
) {
206 isShowSymbol
= showSymbol
.getSelection();
209 // PreferencesUtil.recursiveSetEnabled(button_openWizard, CdmStore.isActive());
210 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowRankInDistributionEditor
);
212 isShowRank
= Boolean
.valueOf(pref
.getValue());
217 final Button activateRankButton
= new Button(child
, SWT
.CHECK
);
218 activateRankButton
.setText(Messages
.ChecklistEditorGeneralPreference_show_rank
);
219 activateRankButton
.setSelection(isShowRank
);
220 activateRankButton
.addSelectionListener(new SelectionAdapter(){
222 public void widgetSelected(SelectionEvent e
) {
223 isShowRank
= activateRankButton
.getSelection();
228 if(isEditorActivated
){
229 child
.setEnabled(true);
231 child
.setEnabled(false);
238 public boolean performOk() {
239 ICdmRepository controller
= CdmStore
.getCurrentApplicationConfiguration();
240 if (controller
== null){
243 IPreferenceService service
= controller
.getPreferenceService();
245 CdmPreference pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.DistributionEditorActivated
, Boolean
.toString(isEditorActivated
));
247 pref
.setAllowOverride(allowOverride
);
250 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowIdInVocabulary
, Boolean
.toString(isShowIdInVocabulary
));
252 pref
.setAllowOverride(true);
255 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowSymbol1
, Boolean
.toString(isShowSymbol1
));
257 pref
.setAllowOverride(true);
259 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowSymbol2
, Boolean
.toString(isShowSymbol2
));
261 pref
.setAllowOverride(true);
265 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowSymbolForStatus
, Boolean
.toString(isShowSymbol
));
267 pref
.setAllowOverride(true);
270 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowRankInDistributionEditor
, Boolean
.toString(isShowRank
));
272 pref
.setAllowOverride(true);
274 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.AreasSortedByIdInVocabulary
, Boolean
.toString(isSortByVocabularyOrder
));
276 pref
.setAllowOverride(true);
279 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
, isEditorActivated
);
280 PreferencesUtil
.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder
);
281 PreferencesUtil
.setShowRankInChecklistEditor(isShowRank
);
282 PreferencesUtil
.setShowSymbolInChecklistEditor(isShowSymbol
);
284 if (isShowIdInVocabulary
){
285 displayString
= IPreferenceKeys
.CHECKLIST_AREA_DISPLAY_ID_IN_VOCABULARY
;
286 }else if (isShowSymbol1
){
287 displayString
= IPreferenceKeys
.CHECKLIST_AREA_DISPLAY_SYMBOL1
;
288 }else if (isShowSymbol2
){
289 displayString
= IPreferenceKeys
.CHECKLIST_AREA_DISPLAY_SYMBOL2
;
291 displayString
= IPreferenceKeys
.CHECKLIST_AREA_DISPLAY_TITLE
;
293 PreferencesUtil
.setShowIdInVocabularyInChecklistEditor(displayString
);