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
;
39 boolean allowOverride
;
41 boolean isSortByVocabularyOrder
;
43 boolean isShowIdInVocabulary
;
47 protected Control
createContents(Composite parent
) {
49 Composite composite
= new Composite(parent
, SWT
.NULL
);
50 composite
.setLayout(new GridLayout());
51 CdmPreference pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DistributionEditorActivated
);
53 isEditorActivated
= Boolean
.valueOf(pref
.getValue());
54 allowOverride
= pref
.isAllowOverride();
56 isEditorActivated
= false;
59 final Button activateCheckButton
= new Button(composite
, SWT
.CHECK
);
60 activateCheckButton
.setText(Messages
.ChecklistEditorGeneralPreference_enable
);
61 activateCheckButton
.setSelection(isEditorActivated
);
62 activateCheckButton
.addSelectionListener(new SelectionAdapter(){
64 public void widgetSelected(SelectionEvent e
) {
65 isEditorActivated
= activateCheckButton
.getSelection();
67 if(isEditorActivated
){
68 child
.setVisible(true);
69 child
.setEnabled(true);
71 child
.setVisible(false);
72 child
.setEnabled(false);
77 final Button allowOverrideCheckButton
= new Button(composite
, SWT
.CHECK
);
78 allowOverrideCheckButton
.setText(Messages
.ChecklistEditorGeneralPreference_allowOverride
);
79 allowOverrideCheckButton
.setSelection(allowOverride
);
80 allowOverrideCheckButton
.addSelectionListener(new SelectionAdapter(){
82 public void widgetSelected(SelectionEvent e
) {
83 allowOverride
= allowOverrideCheckButton
.getSelection();
88 child
= new Composite(composite
, SWT
.NULL
);
89 child
.setLayout(new GridLayout());
90 child
.setVisible(isEditorActivated
);
94 final CLabel label
= new CLabel(child
, SWT
.NULL
);
95 label
.setText(Messages
.ChecklistEditorGeneralPreference_open_wizard
);
99 final CommandHandlerButton button_openWizard
= new CommandHandlerButton(child
, SWT
.PUSH
,
100 "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardAdminHandler");
102 button_openWizard
.setText(Messages
.ChecklistEditorGeneralPreference_open_distribution_selection
);
104 // Table table = new Table
106 final Button showIdInVocabulary
= new Button(child
, SWT
.CHECK
);
107 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowIdInVocabulary
);
109 isShowIdInVocabulary
= Boolean
.valueOf(pref
.getValue());
111 isShowIdInVocabulary
= false;
113 showIdInVocabulary
.setText(Messages
.ChecklistEditorGeneralPreference_show_id_in_voc
);
114 showIdInVocabulary
.setSelection(isShowIdInVocabulary
);
115 showIdInVocabulary
.addSelectionListener(new SelectionAdapter(){
117 public void widgetSelected(SelectionEvent e
) {
118 isShowIdInVocabulary
= showIdInVocabulary
.getSelection();
123 final Button showSymbol
= new Button(child
, SWT
.CHECK
);
124 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowSymbol
);
126 isShowSymbol
= Boolean
.valueOf(pref
.getValue());
128 isShowSymbol
= false;
131 showSymbol
.setText(Messages
.ChecklistEditorGeneralPreference_show_symbol
);
132 showSymbol
.setSelection(isShowSymbol
);
133 showSymbol
.addSelectionListener(new SelectionAdapter(){
135 public void widgetSelected(SelectionEvent e
) {
136 isShowSymbol
= showSymbol
.getSelection();
139 // PreferencesUtil.recursiveSetEnabled(button_openWizard, CdmStore.isActive());
140 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowRankInDistributionEditor
);
142 isShowRank
= Boolean
.valueOf(pref
.getValue());
147 final Button activateRankButton
= new Button(child
, SWT
.CHECK
);
148 activateRankButton
.setText(Messages
.ChecklistEditorGeneralPreference_show_rank
);
149 activateRankButton
.setSelection(isShowRank
);
150 activateRankButton
.addSelectionListener(new SelectionAdapter(){
152 public void widgetSelected(SelectionEvent e
) {
153 isShowRank
= activateRankButton
.getSelection();
156 final Button sortNamedAreaByVocabularyOrder
= new Button(child
, SWT
.CHECK
);
158 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AreasSortedByIdInVocabulary
);
160 isSortByVocabularyOrder
= Boolean
.valueOf(pref
.getValue());
162 isSortByVocabularyOrder
= false;
165 sortNamedAreaByVocabularyOrder
.setText(Messages
.ChecklistEditorGeneralPreference_sort_areas
);
166 sortNamedAreaByVocabularyOrder
.setSelection(isSortByVocabularyOrder
);
167 sortNamedAreaByVocabularyOrder
.addSelectionListener(new SelectionAdapter(){
169 public void widgetSelected(SelectionEvent e
) {
170 isSortByVocabularyOrder
= sortNamedAreaByVocabularyOrder
.getSelection();
174 if(isEditorActivated
){
175 child
.setEnabled(true);
177 child
.setEnabled(false);
184 public boolean performOk() {
185 ICdmRepository controller
= CdmStore
.getCurrentApplicationConfiguration();
186 if (controller
== null){
189 IPreferenceService service
= controller
.getPreferenceService();
191 CdmPreference pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.DistributionEditorActivated
, Boolean
.toString(isEditorActivated
));
193 pref
.setAllowOverride(allowOverride
);
196 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowIdInVocabulary
, Boolean
.toString(isShowIdInVocabulary
));
198 pref
.setAllowOverride(true);
201 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowSymbol
, Boolean
.toString(isShowSymbol
));
203 pref
.setAllowOverride(true);
206 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.ShowRankInDistributionEditor
, Boolean
.toString(isShowRank
));
208 pref
.setAllowOverride(true);
210 pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.AreasSortedByIdInVocabulary
, Boolean
.toString(isSortByVocabularyOrder
));
212 pref
.setAllowOverride(true);
215 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
, isEditorActivated
);
216 PreferencesUtil
.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder
);
217 PreferencesUtil
.setShowRankInChecklistEditor(isShowRank
);
218 PreferencesUtil
.setShowSymbolInChecklistEditor(isShowSymbol
);
219 PreferencesUtil
.setShowIdInVocabularyInChecklistEditor(isShowIdInVocabulary
);