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
;
20 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IPreferenceService
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
24 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
25 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
26 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
27 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CommandHandlerButton
;
36 public class ChecklistEditorGeneralPreference
extends CdmPreferencePage
implements IE4AdminPreferencePage
{
38 boolean isEditorActivated
;
40 boolean isSortByVocabularyOrder
;
42 boolean isShowIdInVocabulary
;
46 protected Control
createContents(Composite parent
) {
48 Composite composite
= new Composite(parent
, SWT
.NULL
);
49 composite
.setLayout(new GridLayout());
50 CdmPreference pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DistributionEditorActivated
);
52 isEditorActivated
= Boolean
.valueOf(pref
.getValue());
54 isEditorActivated
= false;
56 final Button activateCheckButton
= new Button(composite
, SWT
.CHECK
);
57 activateCheckButton
.setText(Messages
.ChecklistEditorGeneralPreference_enable
);
58 activateCheckButton
.setSelection(isEditorActivated
);
59 activateCheckButton
.addSelectionListener(new SelectionAdapter(){
61 public void widgetSelected(SelectionEvent e
) {
62 isEditorActivated
= activateCheckButton
.getSelection();
64 if(isEditorActivated
){
65 child
.setVisible(true);
66 child
.setEnabled(true);
68 child
.setVisible(false);
69 child
.setEnabled(false);
75 child
= new Composite(composite
, SWT
.NULL
);
76 child
.setLayout(new GridLayout());
77 child
.setVisible(isEditorActivated
);
78 final CLabel label
= new CLabel(child
, SWT
.NULL
);
79 label
.setText(Messages
.ChecklistEditorGeneralPreference_open_wizard
+ Messages
.ChecklistEditorGeneralPreference_2
);
80 final CommandHandlerButton button_openWizard
= new CommandHandlerButton(child
, SWT
.PUSH
,
81 Messages
.ChecklistEditorGeneralPreference_3
);
83 button_openWizard
.setText(Messages
.ChecklistEditorGeneralPreference_open_distribution_selection
);
84 final Button showIdInVocabulary
= new Button(child
, SWT
.CHECK
);
85 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowIdInVocabulary
);
87 isShowIdInVocabulary
= Boolean
.valueOf(pref
.getValue());
89 isShowIdInVocabulary
= false;
91 showIdInVocabulary
.setText(Messages
.ChecklistEditorGeneralPreference_show_id_in_voc
);
92 showIdInVocabulary
.setSelection(isShowIdInVocabulary
);
93 showIdInVocabulary
.addSelectionListener(new SelectionAdapter(){
95 public void widgetSelected(SelectionEvent e
) {
96 isShowIdInVocabulary
= showIdInVocabulary
.getSelection();
101 final Button showSymbol
= new Button(child
, SWT
.CHECK
);
102 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowSymbol
);
104 isShowSymbol
= Boolean
.valueOf(pref
.getValue());
106 isShowSymbol
= false;
109 showSymbol
.setText(Messages
.ChecklistEditorGeneralPreference_show_symbol
);
110 showSymbol
.setSelection(isShowSymbol
);
111 showSymbol
.addSelectionListener(new SelectionAdapter(){
113 public void widgetSelected(SelectionEvent e
) {
114 isShowSymbol
= showSymbol
.getSelection();
117 // PreferencesUtil.recursiveSetEnabled(button_openWizard, CdmStore.isActive());
118 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowRankInDistributionEditor
);
120 isShowRank
= Boolean
.valueOf(pref
.getValue());
125 final Button activateRankButton
= new Button(child
, SWT
.CHECK
);
126 activateRankButton
.setText(Messages
.ChecklistEditorGeneralPreference_show_rank
);
127 activateRankButton
.setSelection(isShowRank
);
128 activateRankButton
.addSelectionListener(new SelectionAdapter(){
130 public void widgetSelected(SelectionEvent e
) {
131 isShowRank
= activateRankButton
.getSelection();
134 final Button sortNamedAreaByVocabularyOrder
= new Button(child
, SWT
.CHECK
);
136 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AreasSortedByIdInVocabulary
);
138 isSortByVocabularyOrder
= Boolean
.valueOf(pref
.getValue());
140 isSortByVocabularyOrder
= false;
143 sortNamedAreaByVocabularyOrder
.setText(Messages
.ChecklistEditorGeneralPreference_sort_areas
);
144 sortNamedAreaByVocabularyOrder
.setSelection(isSortByVocabularyOrder
);
145 sortNamedAreaByVocabularyOrder
.addSelectionListener(new SelectionAdapter(){
147 public void widgetSelected(SelectionEvent e
) {
148 isSortByVocabularyOrder
= sortNamedAreaByVocabularyOrder
.getSelection();
152 if(isEditorActivated
){
153 child
.setEnabled(true);
155 child
.setEnabled(false);
162 public boolean performOk() {
163 ICdmRepository controller
= CdmStore
.getCurrentApplicationConfiguration();
164 if (controller
== null){
167 IPreferenceService service
= controller
.getPreferenceService();
169 CdmPreference pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.DistributionEditorActivated
, Boolean
.toString(isEditorActivated
));
171 pref
.setAllowOverride(false);
174 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowIdInVocabulary
, Boolean
.toString(isShowIdInVocabulary
));
176 pref
.setAllowOverride(false);
179 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowSymbol
, Boolean
.toString(isShowSymbol
));
181 pref
.setAllowOverride(false);
184 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowRankInDistributionEditor
, Boolean
.toString(isShowRank
));
186 pref
.setAllowOverride(false);
188 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.AreasSortedByIdInVocabulary
, Boolean
.toString(isSortByVocabularyOrder
));
190 pref
.setAllowOverride(false);
193 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
, isEditorActivated
);
194 PreferencesUtil
.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder
);
195 PreferencesUtil
.setShowRankInChecklistEditor(isShowRank
);
196 PreferencesUtil
.setShowSymbolInChecklistEditor(isShowSymbol
);
197 PreferencesUtil
.setShowIdInVocabularyInChecklistEditor(isShowIdInVocabulary
);