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
.events
.SelectionListener
;
16 import org
.eclipse
.swt
.layout
.GridData
;
17 import org
.eclipse
.swt
.layout
.GridLayout
;
18 import org
.eclipse
.swt
.widgets
.Button
;
19 import org
.eclipse
.swt
.widgets
.Combo
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.eclipse
.swt
.widgets
.Event
;
23 import org
.eclipse
.swt
.widgets
.Label
;
24 import org
.eclipse
.swt
.widgets
.Listener
;
26 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
27 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
28 import eu
.etaxonomy
.cdm
.model
.metadata
.TermDisplayEnum
;
29 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
30 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.CommandHandlerButton
;
38 public class ChecklistEditorGeneralPreference
extends CdmPreferencePage
implements SelectionListener
{
40 protected boolean isEditorActivated
;
41 protected boolean allowOverrideActivated
;
42 protected boolean overrideActivated
;
44 protected boolean isShowRank
;
45 protected boolean isSortByVocabularyOrder
;
46 protected String displayStatus
;
47 protected String displayArea
;
48 protected boolean ownDescriptionForDistributionEditor
;
49 protected boolean allowOverrideOwnDescriptionForDistributionEditor
;
50 protected boolean overrideOwnDescriptionForDistributionEditor
;
51 protected boolean allowOverrideAreaVoc
;
52 protected boolean overrideAreaVoc
;
53 protected boolean allowOverrideRank
;
54 protected boolean overrideRank
;
55 protected boolean allowOverrideOrderAreas
;
56 protected boolean overrideOrderAreas
;
57 protected boolean allowOverrideAreaDisplay
;
58 protected boolean overrideAreaDisplay
;
59 protected boolean allowOverrideStatusDisplay
;
60 protected boolean overrideStatusDisplay
;
62 protected boolean allowOverrideStatus
;
63 Combo statusDisplaySelectionCombo
;
64 Combo areaDisplaySelectionCombo
;
66 protected String commandHandlerString
;
67 protected String commandHandlerStringStatus
;
71 protected CdmPreference distributionEditorPref
;
73 protected boolean isAllowOverride
;
76 protected Control
createContents(Composite parent
) {
78 Composite composite
= new Composite(parent
, SWT
.NULL
);
79 composite
.setLayout(new GridLayout());
81 if (isAllowOverride
|| isAdminPreference
){
82 Composite activateComp
= createComposite(composite
);
83 Label separator
= new Label(activateComp
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
84 GridData sepGrid
= createTextGridData();
85 separator
.setLayoutData(sepGrid
);
86 separator
.setVisible(false);
87 final Button activateCheckButton
= new Button(activateComp
, SWT
.CHECK
);
88 activateCheckButton
.setText(Messages
.ChecklistEditorGeneralPreference_enable
);
89 activateCheckButton
.setSelection(isEditorActivated
);
90 activateCheckButton
.addSelectionListener(new SelectionAdapter(){
92 public void widgetSelected(SelectionEvent e
) {
94 isEditorActivated
= activateCheckButton
.getSelection();
95 if(!isAdminPreference
){
96 overrideActivated
= true;
99 if(isEditorActivated
){
100 child
.setVisible(true);
101 child
.setEnabled(true);
103 child
.setVisible(false);
104 child
.setEnabled(false);
109 Button allowOverrideActivatedButton
= createAllowOverrideButton(activateComp
);
110 if (isAdminPreference
){
111 allowOverrideActivatedButton
.setSelection(allowOverrideActivated
);
112 allowOverrideActivatedButton
.addSelectionListener(new SelectionAdapter(){
114 public void widgetSelected(SelectionEvent e
) {
116 allowOverrideActivated
= allowOverrideActivatedButton
.getSelection();
120 allowOverrideActivatedButton
.setSelection(overrideActivated
);
121 allowOverrideActivatedButton
.addSelectionListener(new SelectionAdapter(){
123 public void widgetSelected(SelectionEvent e
) {
125 overrideActivated
= allowOverrideActivatedButton
.getSelection();
131 child
= createComposite(composite
);
133 child
.setVisible(isEditorActivated
);
134 separator
= new Label(child
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
135 sepGrid
= createTextGridData();
137 GridData textGrid
= createTextGridData();
138 textGrid
.verticalSpan
= 2;
139 separator
.setLayoutData(sepGrid
);
142 final Button activateRankButton
= new Button(child
, SWT
.CHECK
);
143 activateRankButton
.setText(Messages
.ChecklistEditorGeneralPreference_show_rank
);
144 activateRankButton
.setSelection(isShowRank
);
145 activateRankButton
.addSelectionListener(new SelectionAdapter(){
147 public void widgetSelected(SelectionEvent e
) {
149 isShowRank
= activateRankButton
.getSelection();
152 Button allowOverrideRankButton
= createAllowOverrideButton(child
);
153 if (isAdminPreference
){
154 allowOverrideRankButton
.setSelection(allowOverrideRank
);
155 allowOverrideRankButton
.addSelectionListener(new SelectionAdapter(){
157 public void widgetSelected(SelectionEvent e
) {
159 allowOverrideRank
= allowOverrideRankButton
.getSelection();
163 allowOverrideRankButton
.setSelection(overrideRank
);
164 allowOverrideRankButton
.addSelectionListener(new SelectionAdapter(){
166 public void widgetSelected(SelectionEvent e
) {
168 overrideRank
= allowOverrideRankButton
.getSelection();
171 if (!allowOverrideRank
){
172 activateRankButton
.setEnabled(false);
173 allowOverrideRankButton
.setEnabled(false);
178 final Button sortNamedAreaByVocabularyOrder
= new Button(child
, SWT
.CHECK
);
179 sortNamedAreaByVocabularyOrder
.setText(Messages
.ChecklistEditorGeneralPreference_sort_areas
);
180 sortNamedAreaByVocabularyOrder
.setSelection(isSortByVocabularyOrder
);
181 sortNamedAreaByVocabularyOrder
.addSelectionListener(new SelectionAdapter(){
183 public void widgetSelected(SelectionEvent e
) {
185 isSortByVocabularyOrder
= sortNamedAreaByVocabularyOrder
.getSelection();
188 Button allowOverrideOrderAreasButton
= createAllowOverrideButton(child
);
189 if (isAdminPreference
){
190 allowOverrideOrderAreasButton
.setSelection(allowOverrideOrderAreas
);
191 allowOverrideOrderAreasButton
.addSelectionListener(new SelectionAdapter(){
193 public void widgetSelected(SelectionEvent e
) {
195 allowOverrideOrderAreas
= allowOverrideOrderAreasButton
.getSelection();
199 allowOverrideOrderAreasButton
.setSelection(overrideOrderAreas
);
200 allowOverrideOrderAreasButton
.addSelectionListener(new SelectionAdapter(){
202 public void widgetSelected(SelectionEvent e
) {
204 overrideOrderAreas
= allowOverrideOrderAreasButton
.getSelection();
207 if (!allowOverrideOrderAreas
){
208 sortNamedAreaByVocabularyOrder
.setEnabled(false);
209 allowOverrideOrderAreasButton
.setEnabled(false);
213 final Button ownDescription
= new Button(child
, SWT
.CHECK
);
214 ownDescription
.setText(Messages
.ChecklistEditorGeneralPreference_own_Description
);
215 ownDescription
.setToolTipText(Messages
.ChecklistEditorGeneralPreference_own_DescriptionToolTip
);
216 ownDescription
.setSelection(ownDescriptionForDistributionEditor
);
217 ownDescription
.addSelectionListener(new SelectionAdapter(){
219 public void widgetSelected(SelectionEvent e
) {
221 ownDescriptionForDistributionEditor
= ownDescription
.getSelection();
224 Button allowOverrideDescription
= createAllowOverrideButton(child
);
225 if (isAdminPreference
){
226 allowOverrideDescription
.setSelection(allowOverrideOwnDescriptionForDistributionEditor
);
227 allowOverrideDescription
.addSelectionListener(new SelectionAdapter(){
229 public void widgetSelected(SelectionEvent e
) {
231 allowOverrideOwnDescriptionForDistributionEditor
= allowOverrideDescription
.getSelection();
235 allowOverrideDescription
.setSelection(overrideOwnDescriptionForDistributionEditor
);
236 allowOverrideDescription
.addSelectionListener(new SelectionAdapter(){
238 public void widgetSelected(SelectionEvent e
) {
240 overrideOwnDescriptionForDistributionEditor
= allowOverrideDescription
.getSelection();
243 if (!allowOverrideOwnDescriptionForDistributionEditor
){
244 ownDescription
.setEnabled(false);
245 allowOverrideDescription
.setEnabled(false);
250 separator
= new Label(child
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
251 separator
.setLayoutData(sepGrid
);
255 final CLabel description
= new CLabel(child
, SWT
.NULL
);
256 description
.setText(Messages
.ChecklistEditorGeneralPreference_Configure_display_of_Areas
);
257 description
.setLayoutData(textGrid
);
259 GridData gridData
= new GridData();
260 gridData
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
261 //gridData.horizontalIndent = 5;
264 areaDisplaySelectionCombo
= new Combo(child
, SWT
.BORDER
| SWT
.READ_ONLY
);
265 areaDisplaySelectionCombo
.setLayoutData(gridData
);
267 for(TermDisplayEnum display
: TermDisplayEnum
.values()){
268 areaDisplaySelectionCombo
.add(display
.getLabel());
271 if (PreferencesUtil
.getStringValue(EditorPreferencePredicate
.DistributionEditorActivated
.getKey()) != null){
272 TermDisplayEnum areaDisplay
;
274 if (displayArea
!= null){
275 areaDisplay
= TermDisplayEnum
.valueOf(displayArea
);
277 areaDisplay
= TermDisplayEnum
.Title
;
279 }catch(IllegalArgumentException e
){
280 areaDisplay
= TermDisplayEnum
.Title
;
282 for (String itemLabel
: areaDisplaySelectionCombo
.getItems()){
283 if (itemLabel
.equalsIgnoreCase(areaDisplay
.getLabel())){
284 areaDisplaySelectionCombo
.select(index
);
290 areaDisplaySelectionCombo
.addSelectionListener(this);
291 Button allowOverrideOrderAreaDisplayButton
= createAllowOverrideButton(child
);
292 if (isAdminPreference
){
293 allowOverrideOrderAreaDisplayButton
.setSelection(allowOverrideAreaDisplay
);
294 allowOverrideOrderAreaDisplayButton
.addSelectionListener(new SelectionAdapter(){
296 public void widgetSelected(SelectionEvent e
) {
298 allowOverrideAreaDisplay
= allowOverrideOrderAreaDisplayButton
.getSelection();
302 allowOverrideOrderAreaDisplayButton
.setSelection(overrideAreaDisplay
);
303 allowOverrideOrderAreaDisplayButton
.addSelectionListener(new SelectionAdapter(){
305 public void widgetSelected(SelectionEvent e
) {
307 overrideAreaDisplay
= allowOverrideOrderAreaDisplayButton
.getSelection();
310 if (!allowOverrideAreaDisplay
){
311 areaDisplaySelectionCombo
.setEnabled(false);
312 allowOverrideOrderAreaDisplayButton
.setEnabled(false);
316 final CLabel descriptionStatus
= new CLabel(child
, SWT
.NULL
);
317 descriptionStatus
.setText(Messages
.ChecklistEditorGeneralPreference_Configure_display_of_Status
);
318 descriptionStatus
.setLayoutData(textGrid
);
322 statusDisplaySelectionCombo
= new Combo(child
, SWT
.BORDER
| SWT
.READ_ONLY
);
323 statusDisplaySelectionCombo
.setLayoutData(gridData
);
325 for(TermDisplayEnum display
: TermDisplayEnum
.values()){
326 statusDisplaySelectionCombo
.add(display
.getLabel());
329 if (displayStatus
!= null){
330 TermDisplayEnum statusDisplay
= TermDisplayEnum
.valueOf(displayStatus
);
331 for (String itemLabel
: statusDisplaySelectionCombo
.getItems()){
332 if (itemLabel
.equalsIgnoreCase(statusDisplay
.getLabel())){
333 statusDisplaySelectionCombo
.select(index
);
340 statusDisplaySelectionCombo
.addSelectionListener(this);
341 Button allowOverrideOrderStatusDisplayButton
= createAllowOverrideButton(child
);
342 if (isAdminPreference
){
343 allowOverrideOrderStatusDisplayButton
.setSelection(allowOverrideStatusDisplay
);
344 allowOverrideOrderStatusDisplayButton
.addSelectionListener(new SelectionAdapter(){
346 public void widgetSelected(SelectionEvent e
) {
348 allowOverrideStatusDisplay
= allowOverrideOrderStatusDisplayButton
.getSelection();
352 allowOverrideOrderStatusDisplayButton
.setSelection(overrideStatusDisplay
);
353 allowOverrideOrderStatusDisplayButton
.addSelectionListener(new SelectionAdapter(){
355 public void widgetSelected(SelectionEvent e
) {
357 overrideStatusDisplay
= allowOverrideOrderStatusDisplayButton
.getSelection();
360 if (!allowOverrideStatusDisplay
){
361 statusDisplaySelectionCombo
.setEnabled(false);
362 allowOverrideOrderStatusDisplayButton
.setEnabled(false);
367 final CLabel labelStatus
= new CLabel(child
, SWT
.NULL
);
368 labelStatus
.setText(Messages
.DistributionAdminPreferences_SELECT_STATUS
);
369 labelStatus
.setLayoutData(textGrid
);
371 final CommandHandlerButton button_openStatusWizard
= new CommandHandlerButton(child
, SWT
.PUSH
,
372 commandHandlerStringStatus
);
374 button_openStatusWizard
.setText(Messages
.Distribution_status_selection
);
375 button_openStatusWizard
.addListener(SWT
.Selection
, new Listener() {
377 public void handleEvent(Event e
) {
387 final CLabel label
= new CLabel(child
, SWT
.NULL
);
388 label
.setText(Messages
.ChecklistEditorGeneralPreference_open_wizard
);
389 label
.setLayoutData(textGrid
);
391 final CommandHandlerButton button_openSelectAreas
= new CommandHandlerButton(child
, SWT
.PUSH
,
392 commandHandlerString
);
393 button_openSelectAreas
.setText(Messages
.ChecklistEditorGeneralPreference_open_distribution_selection
);
398 if(isEditorActivated
){
399 child
.setEnabled(true);
401 child
.setEnabled(false);
403 if (!isAdminPreference
){
404 if (!allowOverrideAreaVoc
){
405 button_openSelectAreas
.setButtonEnabled(false);
407 if (!allowOverrideStatus
){
408 button_openStatusWizard
.setButtonEnabled(false);
412 Label label
= new Label(composite
, SWT
.NONE
);
413 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.");
429 public boolean performOk() {
430 if (isAllowOverride
){
432 PreferencesUtil
.setBooleanValue(EditorPreferencePredicate
.DistributionEditorActivated
.getKey(), isEditorActivated
);
433 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(EditorPreferencePredicate
.DistributionEditorActivated
.getKey()), overrideActivated
);
434 PreferencesUtil
.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder
);
435 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(EditorPreferencePredicate
.AreasSortedByIdInVocabulary
.getKey()), overrideOrderAreas
);
436 PreferencesUtil
.setShowRankInChecklistEditor(isShowRank
);
437 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(EditorPreferencePredicate
.ShowRankInDistributionEditor
.getKey()), overrideRank
);
438 PreferencesUtil
.setDisplayStatusInChecklistEditor(displayStatus
);
439 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(EditorPreferencePredicate
.DisplayOfStatus
.getKey()), overrideStatusDisplay
);
440 PreferencesUtil
.setAreaDisplayInChecklistEditor(displayArea
);
441 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(EditorPreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey()), overrideAreaDisplay
);
442 PreferencesUtil
.setOwnDescriptionForChecklistEditor(ownDescriptionForDistributionEditor
);
443 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(EditorPreferencePredicate
.OwnDescriptionForDistributionEditor
.getKey()), overrideOwnDescriptionForDistributionEditor
);
456 public void widgetSelected(SelectionEvent e
) {
458 if (e
.getSource().equals(statusDisplaySelectionCombo
)){
459 String text
= statusDisplaySelectionCombo
.getText();
460 for (TermDisplayEnum display
: TermDisplayEnum
.values()){
461 if (display
.getLabel().equals(text
)){
462 displayStatus
= display
.getKey();
467 if (e
.getSource().equals(areaDisplaySelectionCombo
)){
468 String text
= areaDisplaySelectionCombo
.getText();
469 for (TermDisplayEnum display
: TermDisplayEnum
.values()){
470 if (display
.getLabel().equals(text
)){
471 displayArea
= display
.getKey();
483 public void widgetDefaultSelected(SelectionEvent e
) {
484 // TODO Auto-generated method stub
493 public void getValues() {
494 isAdminPreference
= false;
495 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
496 distributionEditorPref
= PreferencesUtil
.getPreferenceFromDB(EditorPreferencePredicate
.DistributionEditorActivated
);
499 if (distributionEditorPref
!= null){
500 isAllowOverride
= distributionEditorPref
.isAllowOverride();
501 boolean test
= PreferencesUtil
.getBooleanValue(EditorPreferencePredicate
.DistributionEditorActivated
.getKey());
502 if (isAllowOverride
&& PreferencesUtil
.getBooleanValue(EditorPreferencePredicate
.DistributionEditorActivated
.getKey())){
503 isEditorActivated
= PreferencesUtil
.getBooleanValue(EditorPreferencePredicate
.DistributionEditorActivated
.getKey());
505 isEditorActivated
= Boolean
.valueOf(distributionEditorPref
.getValue());
508 isEditorActivated
= PreferencesUtil
.getBooleanValue(EditorPreferencePredicate
.DistributionEditorActivated
.getKey());
509 isAllowOverride
= true;
512 CdmPreference prefStatus
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AvailableDistributionAreaVocabularies
);
513 allowOverrideAreaVoc
= prefStatus
!= null?prefStatus
.isAllowOverride():true;
515 prefStatus
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AvailableDistributionStatus
);
516 allowOverrideStatus
= prefStatus
!= null?prefStatus
.isAllowOverride():true;
518 CdmPreference pref
= PreferencesUtil
.getPreferenceFromDB(EditorPreferencePredicate
.DisplayOfAreasInDistributionEditor
);
520 this.allowOverrideAreaDisplay
= pref
.isAllowOverride();
521 if (allowOverrideAreaDisplay
){
522 displayArea
= PreferencesUtil
.getStringValue(EditorPreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey());
524 displayArea
= pref
.getValue();
527 displayArea
= PreferencesUtil
.getStringValue(EditorPreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey());
528 this.allowOverrideAreaDisplay
= true;
531 pref
= PreferencesUtil
.getPreferenceFromDB(EditorPreferencePredicate
.DisplayOfStatus
);
533 this.allowOverrideStatusDisplay
= pref
.isAllowOverride();
534 if (allowOverrideStatusDisplay
){
535 displayStatus
= PreferencesUtil
.displayStatusInChecklistEditor();
537 this.displayStatus
= pref
.getValue();
540 displayStatus
= PreferencesUtil
.displayStatusInChecklistEditor();
541 this.allowOverrideStatusDisplay
= true;
544 pref
= PreferencesUtil
.getPreferenceFromDB(EditorPreferencePredicate
.AreasSortedByIdInVocabulary
);
547 this.allowOverrideOrderAreas
= pref
.isAllowOverride();
548 if (allowOverrideOrderAreas
){
549 isSortByVocabularyOrder
= PreferencesUtil
.isSortNamedAreaByOrderInVocabulary();
551 this.isSortByVocabularyOrder
= Boolean
.valueOf(pref
.getValue().toString());
554 isSortByVocabularyOrder
= PreferencesUtil
.isSortNamedAreaByOrderInVocabulary();
555 this.allowOverrideOrderAreas
= true;
558 pref
= PreferencesUtil
.getPreferenceFromDB(EditorPreferencePredicate
.ShowRankInDistributionEditor
);
561 allowOverrideRank
= pref
.isAllowOverride();
562 if (allowOverrideRank
){
563 isShowRank
= PreferencesUtil
.isShowRankInChecklistEditor();
565 this.isShowRank
= Boolean
.valueOf(pref
.getValue().toString());
568 isShowRank
= PreferencesUtil
.isShowRankInChecklistEditor();
569 this.allowOverrideRank
= true;
572 pref
= PreferencesUtil
.getPreferenceFromDB(EditorPreferencePredicate
.OwnDescriptionForDistributionEditor
);
575 allowOverrideOwnDescriptionForDistributionEditor
= pref
.isAllowOverride();
576 if (allowOverrideOwnDescriptionForDistributionEditor
){
577 ownDescriptionForDistributionEditor
= PreferencesUtil
.isOwnDescriptionForChecklistEditor();
579 ownDescriptionForDistributionEditor
= Boolean
.valueOf(pref
.getValue().toString());
582 ownDescriptionForDistributionEditor
= PreferencesUtil
.isShowRankInChecklistEditor();
583 ownDescriptionForDistributionEditor
= true;
587 commandHandlerString
= "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardHandler";
588 commandHandlerStringStatus
= "eu.etaxonomy.taxeditor.store.open.OpenDistributionStatusWizardHandler";