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
.TermComboEnum
;
29 import eu
.etaxonomy
.cdm
.model
.metadata
.TermDisplayEnum
;
30 import eu
.etaxonomy
.cdm
.model
.metadata
.TermOrder
;
31 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
32 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.CommandHandlerButton
;
40 public class ChecklistEditorGeneralPreference
extends CdmPreferencePage
implements SelectionListener
{
44 protected Boolean isEditorActivated
;
46 protected boolean overrideActivated
;
48 protected Boolean isShowRank
;
49 protected String orderAreas
;
50 protected String displayStatus
;
51 protected String displayStatusCombo
;
52 protected String displayArea
;
53 protected Boolean ownDescriptionForDistributionEditor
;
55 protected boolean overrideOwnDescriptionForDistributionEditor
;
56 protected boolean overrideAreaVoc
;
57 protected boolean overrideRank
;
58 protected boolean overrideOrderAreas
;
59 protected boolean overrideAreaDisplay
;
60 protected boolean overrideStatusDisplay
;
61 protected boolean overrideStatusDisplayCombo
;
63 protected Combo areaOrderSelectionCombo
;
64 protected Button allowOverrideOrderAreasButton
;
65 protected Combo statusDisplaySelectionCombo
;
66 protected Button allowOverrideStatusDisplayButton
;
67 protected Combo statusDisplayInComboSelectionCombo
;
68 protected Button allowOverrideStatusDisplayInComboButton
;
69 protected Combo areaDisplaySelectionCombo
;
70 protected Button allowOverrideAreaDisplayButton
;
71 protected String commandHandlerString
;
72 protected String commandHandlerStringStatus
;
74 protected CdmPreference distributionEditorPref
;
75 protected CdmPreference prefStatus
;
76 protected CdmPreference prefAreaVoc
;
77 protected CdmPreference prefAreaDisplay
;
78 protected CdmPreference prefStatusDisplay
;
79 protected CdmPreference prefStatusDisplayInCombo
;
80 protected CdmPreference prefAreaSort
;
81 protected CdmPreference prefRank
;
82 protected CdmPreference prefOwnDescription
;
85 protected Combo activateCombo
;
86 protected Button allowOverrideActivatedButton
;
87 final String ENABLE
= "Enable";
88 final String DISABLE
= "Disable";
90 protected Combo activateRankCombo
;
91 protected Button allowOverrideRankButton
;
92 final String SHOW_RANK
= "Show Rank";
93 final String NO_RANK
= "No Rank";
95 protected CdmPreference areaVocPref
= null;
96 protected CdmPreference statusPref
= null;
97 private CommandHandlerButton button_openSelectAreaVocabularies
;
99 private CommandHandlerButton button_openStatusWizard
;
102 protected Control
createContents(Composite parent
) {
104 Composite composite
= new Composite(parent
, SWT
.NULL
);
105 composite
.setLayout(new GridLayout());
106 if (!isAdminPreference
&& distributionEditorPref
!= null && !distributionEditorPref
.isAllowOverride()&& !isEditorActivated
) {
107 Label label
= new Label(composite
, SWT
.NONE
);
109 "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.");
110 this.setDefaultButtonActivated(false);
112 Composite activateComp
= createComposite(composite
);
113 Label separator
= new Label(activateComp
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
114 GridData sepGrid
= createTextGridData();
115 separator
.setLayoutData(sepGrid
);
116 separator
.setVisible(false);
117 CdmPreference dbPref
;
118 GridData textGrid
= createTextGridData();
119 textGrid
.verticalSpan
= 2;
120 separator
.setLayoutData(sepGrid
);
122 activateCombo
= createBooleanCombo(activateComp
, ENABLE
, DISABLE
, PreferencePredicate
.DistributionEditorActivated
, Messages
.ChecklistEditorGeneralPreference_enable
, isAdminPreference
);
125 for (String itemLabel
: activateCombo
.getItems()) {
126 if (isEditorActivated
== null && itemLabel
.equals(Messages
.Preference_Use_Default
)) {
127 activateCombo
.select(index
);
130 if (isEditorActivated
!= null && itemLabel
.equals(ENABLE
) && isEditorActivated
){
131 activateCombo
.select(index
);
134 if (isEditorActivated
!= null && itemLabel
.equals(DISABLE
) && !isEditorActivated
){
135 activateCombo
.select(index
);
142 activateCombo
.addSelectionListener(this);
143 if (isAdminPreference
) {
144 allowOverrideActivatedButton
= createAllowOverrideButton(activateComp
);
145 allowOverrideActivatedButton
.setSelection(this.distributionEditorPref
!= null?
this.distributionEditorPref
.isAllowOverride(): true);
146 allowOverrideActivatedButton
.addSelectionListener(new SelectionAdapter() {
148 public void widgetSelected(SelectionEvent e
) {
150 if (distributionEditorPref
== null){
151 distributionEditorPref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.DistributionEditorActivated
, PreferencePredicate
.DistributionEditorActivated
.getDefaultValue() != null ? PreferencePredicate
.DistributionEditorActivated
.getDefaultValue().toString(): null);
153 distributionEditorPref
.setAllowOverride(!distributionEditorPref
.isAllowOverride());
157 child
= createComposite(composite
);
159 if (!isAdminPreference
) {
160 if (isEditorActivated
!= null){
161 child
.setEnabled(isEditorActivated
);
163 child
.setEnabled(Boolean
.parseBoolean(distributionEditorPref
.getValue().toString()));
166 separator
= new Label(child
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
167 sepGrid
= createTextGridData();
168 separator
.setLayoutData(sepGrid
);
170 activateRankCombo
= createBooleanCombo(child
, SHOW_RANK
, NO_RANK
,
171 PreferencePredicate
.ShowRankInDistributionEditor
, Messages
.ChecklistEditorGeneralPreference_show_rank
, isAdminPreference
);
173 for (String itemLabel
: activateRankCombo
.getItems()) {
174 if (isShowRank
== null && itemLabel
.equals(Messages
.Preference_Use_Default
)) {
175 activateRankCombo
.select(index
);
178 if (isShowRank
!= null && itemLabel
.equals(SHOW_RANK
) && isShowRank
){
179 activateRankCombo
.select(index
);
182 if (isShowRank
!= null && itemLabel
.equals(NO_RANK
) && !isShowRank
){
183 activateRankCombo
.select(index
);
188 activateRankCombo
.addSelectionListener(this);
189 if (isAdminPreference
) {
190 allowOverrideRankButton
= createAllowOverrideButton(child
);
191 allowOverrideRankButton
.setSelection(prefRank
!= null? prefRank
.isAllowOverride():true);
192 allowOverrideRankButton
.addSelectionListener(new SelectionAdapter() {
194 public void widgetSelected(SelectionEvent e
) {
196 if (prefRank
== null){
197 prefRank
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.ShowRankInDistributionEditor
, PreferencePredicate
.ShowRankInDistributionEditor
.getDefaultValue() != null ? PreferencePredicate
.ShowRankInDistributionEditor
.getDefaultValue().toString(): null);
199 prefRank
.setAllowOverride(allowOverrideRankButton
.getSelection());
204 GridData gridData
= new GridData();
205 gridData
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
207 areaOrderSelectionCombo
= createCombo(child
, TermOrder
.values(), PreferencePredicate
.AreasSortedInDistributionEditor
, Messages
.ChecklistEditorGeneralPreference_Configure_area_order
, isAdminPreference
);
212 if (orderAreas
!= null) {
213 areaOrder
= TermOrder
.valueOf(orderAreas
);
215 areaOrder
= TermOrder
.IdInVoc
;
217 } catch (IllegalArgumentException e
) {
218 areaOrder
= TermOrder
.IdInVoc
;
220 for (String itemLabel
: areaOrderSelectionCombo
.getItems()) {
221 if (itemLabel
.equals(Messages
.Preference_Use_Default
) && orderAreas
.equals(Messages
.Preference_Use_Default
)){
222 areaOrderSelectionCombo
.select(index
);
225 if (itemLabel
.startsWith(areaOrder
.getLabel())) {
226 areaOrderSelectionCombo
.select(index
);
233 areaOrderSelectionCombo
.addSelectionListener(this);
235 if (isAdminPreference
) {
236 allowOverrideOrderAreasButton
= createAllowOverrideButton(child
);
237 allowOverrideOrderAreasButton
.setSelection(prefAreaSort
!= null? prefAreaSort
.isAllowOverride(): true);
238 allowOverrideOrderAreasButton
.addSelectionListener(new SelectionAdapter() {
240 public void widgetSelected(SelectionEvent e
) {
242 if (prefAreaSort
== null){
243 prefAreaSort
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.AreasSortedInDistributionEditor
, PreferencePredicate
.AreasSortedInDistributionEditor
.getDefaultValue() != null ? PreferencePredicate
.AreasSortedInDistributionEditor
.getDefaultValue().toString(): null);
245 prefAreaSort
.setAllowOverride(allowOverrideOrderAreasButton
.getSelection());
250 separator
= new Label(child
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
251 separator
.setLayoutData(sepGrid
);
252 areaDisplaySelectionCombo
= createCombo(child
, TermDisplayEnum
.values(), PreferencePredicate
.DisplayOfAreasInDistributionEditor
, Messages
.ChecklistEditorGeneralPreference_Configure_display_of_Areas
, isAdminPreference
);
256 TermDisplayEnum areaDisplay
;
258 if (displayArea
!= null) {
259 areaDisplay
= TermDisplayEnum
.valueOf(displayArea
);
261 areaDisplay
= TermDisplayEnum
.Title
;
263 } catch (IllegalArgumentException e
) {
264 areaDisplay
= TermDisplayEnum
.Title
;
266 for (String itemLabel
: areaDisplaySelectionCombo
.getItems()) {
267 if (itemLabel
.equals(Messages
.Preference_Use_Default
) && displayArea
.equals(Messages
.Preference_Use_Default
)){
268 areaDisplaySelectionCombo
.select(index
);
271 if (itemLabel
.startsWith(areaDisplay
.getLabel())) {
272 areaDisplaySelectionCombo
.select(index
);
278 areaDisplaySelectionCombo
.addSelectionListener(this);
280 if (isAdminPreference
) {
281 allowOverrideAreaDisplayButton
= createAllowOverrideButton(child
);
282 allowOverrideAreaDisplayButton
.setSelection(prefAreaDisplay
!= null? prefAreaDisplay
.isAllowOverride(): true);
283 allowOverrideAreaDisplayButton
.addSelectionListener(new SelectionAdapter() {
285 public void widgetSelected(SelectionEvent e
) {
287 if (prefAreaDisplay
== null){
288 prefAreaDisplay
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.DisplayOfAreasInDistributionEditor
, PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getDefaultValue() != null ? PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getDefaultValue().toString(): null);
290 prefAreaDisplay
.setAllowOverride(allowOverrideOrderAreasButton
.getSelection());
295 statusDisplaySelectionCombo
= createCombo(child
, TermDisplayEnum
.values(), PreferencePredicate
.DisplayOfStatus
, Messages
.ChecklistEditorGeneralPreference_Configure_display_of_Status
, isAdminPreference
);
298 TermDisplayEnum statusDisplay
;
300 if (displayStatus
!= null) {
301 statusDisplay
= TermDisplayEnum
.valueOf(displayStatus
);
303 statusDisplay
= TermDisplayEnum
.Title
;
305 } catch (IllegalArgumentException e
) {
306 statusDisplay
= TermDisplayEnum
.Title
;
308 for (String itemLabel
: statusDisplaySelectionCombo
.getItems()) {
309 if (itemLabel
.equals(Messages
.Preference_Use_Default
) && displayStatus
.equals(Messages
.Preference_Use_Default
)){
310 statusDisplaySelectionCombo
.select(index
);
313 if (itemLabel
.startsWith(statusDisplay
.getLabel())) {
314 statusDisplaySelectionCombo
.select(index
);
321 statusDisplaySelectionCombo
.addSelectionListener(this);
323 if (isAdminPreference
) {
324 allowOverrideStatusDisplayButton
= createAllowOverrideButton(child
);
325 allowOverrideStatusDisplayButton
.setSelection(prefStatusDisplay
!= null ? prefStatusDisplay
.isAllowOverride(): true);
326 allowOverrideStatusDisplayButton
.addSelectionListener(new SelectionAdapter() {
328 public void widgetSelected(SelectionEvent e
) {
330 if (prefStatusDisplay
== null){
331 prefStatusDisplay
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.DisplayOfStatus
, PreferencePredicate
.DisplayOfStatus
.getDefaultValue() != null ? PreferencePredicate
.DisplayOfStatus
.getDefaultValue().toString(): null);
333 prefStatusDisplay
.setAllowOverride(allowOverrideStatusDisplayButton
.getSelection());
338 statusDisplayInComboSelectionCombo
= createCombo(child
, TermComboEnum
.values(), PreferencePredicate
.DisplayOfStatusInCombo
, Messages
.ChecklistEditorGeneralPreference_Configure_display_of_Status_in_Combo
, isAdminPreference
);
341 TermComboEnum statusComboDisplay
;
343 if (displayStatusCombo
!= null) {
344 statusComboDisplay
= TermComboEnum
.byKey(displayStatusCombo
);
346 statusComboDisplay
= TermComboEnum
.Title
;
348 } catch (IllegalArgumentException e
) {
349 statusComboDisplay
= TermComboEnum
.Title
;
351 for (String itemLabel
: statusDisplayInComboSelectionCombo
.getItems()) {
352 if (itemLabel
.equals(Messages
.Preference_Use_Default
) && displayStatusCombo
.equals(Messages
.Preference_Use_Default
)){
353 statusDisplayInComboSelectionCombo
.select(index
);
356 if (itemLabel
.startsWith(statusComboDisplay
.getLabel())) {
357 statusDisplayInComboSelectionCombo
.select(index
);
364 statusDisplayInComboSelectionCombo
.addSelectionListener(this);
366 if (isAdminPreference
) {
367 allowOverrideStatusDisplayInComboButton
= createAllowOverrideButton(child
);
368 allowOverrideStatusDisplayInComboButton
.setSelection(prefStatusDisplayInCombo
!= null ? prefStatusDisplayInCombo
.isAllowOverride(): true);
369 allowOverrideStatusDisplayInComboButton
.addSelectionListener(new SelectionAdapter() {
371 public void widgetSelected(SelectionEvent e
) {
373 if (prefStatusDisplayInCombo
== null){
374 prefStatusDisplayInCombo
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.DisplayOfStatusInCombo
, PreferencePredicate
.DisplayOfStatusInCombo
.getDefaultValue() != null ? PreferencePredicate
.DisplayOfStatusInCombo
.getDefaultValue().toString(): null);
376 prefStatusDisplayInCombo
.setAllowOverride(allowOverrideStatusDisplayInComboButton
.getSelection());
382 final CLabel labelStatus
= new CLabel(child
, SWT
.NULL
);
383 labelStatus
.setText(Messages
.DistributionAdminPreferences_SELECT_STATUS
);
384 labelStatus
.setLayoutData(textGrid
);
386 button_openStatusWizard
= new CommandHandlerButton(child
, SWT
.PUSH
, commandHandlerStringStatus
);
388 button_openStatusWizard
.setText(Messages
.Distribution_status_selection
);
389 button_openStatusWizard
.addListener(SWT
.Selection
, new Listener() {
391 public void handleEvent(Event e
) {
400 final CLabel label
= new CLabel(child
, SWT
.NULL
);
401 label
.setText(Messages
.ChecklistEditorGeneralPreference_open_wizard
);
402 label
.setLayoutData(textGrid
);
404 button_openSelectAreaVocabularies
= new CommandHandlerButton(child
, SWT
.PUSH
, commandHandlerString
);
405 button_openSelectAreaVocabularies
406 .setText(Messages
.ChecklistEditorGeneralPreference_open_distribution_selection
);
408 if (!isAdminPreference
) {
410 //PreferencesUtil.recursiveSetEnabled(child, isEditorActivated);
411 if (distributionEditorPref
!= null && !distributionEditorPref
.isAllowOverride()){
412 activateComp
.setEnabled(false);
415 if (prefAreaVoc
!= null && !prefAreaVoc
.isAllowOverride()) {
416 button_openSelectAreaVocabularies
.setButtonEnabled(false);
418 if (prefStatus
!= null && !prefStatus
.isAllowOverride()) {
419 button_openStatusWizard
.setButtonEnabled(false);
421 if (prefRank
!= null && !prefRank
.isAllowOverride()) {
422 activateRankCombo
.setEnabled(false);
424 if (prefAreaSort
!= null && !prefAreaSort
.isAllowOverride()) {
425 areaOrderSelectionCombo
.setEnabled(false);
426 //allowOverrideOrderAreasButton.setEnabled(false);
428 if (prefAreaDisplay
!= null && !prefAreaDisplay
.isAllowOverride()) {
429 areaDisplaySelectionCombo
.setEnabled(false);
431 if (prefStatusDisplay
!= null && !prefStatusDisplay
.isAllowOverride()) {
432 statusDisplaySelectionCombo
.setEnabled(false);
434 if (prefStatusDisplayInCombo
!= null && !prefStatusDisplayInCombo
.isAllowOverride()) {
435 statusDisplayInComboSelectionCombo
.setEnabled(false);
445 public boolean performOk() {
449 boolean override
= false;
450 if (isEditorActivated
!= null ) {
452 PreferencesUtil
.setStringValue(PreferencePredicate
.DistributionEditorActivated
.getKey(), isEditorActivated
.toString());
454 PreferencesUtil
.setBooleanValue(
455 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DistributionEditorActivated
.getKey()),
460 if (!orderAreas
.equals(Messages
.Preference_Use_Default
) ) {
462 PreferencesUtil
.setSortNamedAreasInDistributionEditor(orderAreas
);
464 PreferencesUtil
.setBooleanValue(
465 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AreasSortedInDistributionEditor
.getKey()),
473 if (isShowRank
!= null ) {
475 PreferencesUtil
.setShowRankInChecklistEditor(isShowRank
);
477 PreferencesUtil
.setBooleanValue(
478 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowRankInDistributionEditor
.getKey()),
483 if (!displayStatus
.equals(Messages
.Preference_Use_Default
)) {
485 PreferencesUtil
.setDisplayStatusInChecklistEditor(displayStatus
);
487 PreferencesUtil
.setBooleanValue(
488 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DisplayOfStatus
.getKey()),
492 if (!displayStatusCombo
.equals(Messages
.Preference_Use_Default
)) {
494 PreferencesUtil
.setStringValue(PreferencePredicate
.DisplayOfStatusInCombo
.getKey(), displayStatusCombo
);
496 PreferencesUtil
.setBooleanValue(
497 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DisplayOfStatusInCombo
.getKey()),
503 if (!displayArea
.equals(Messages
.Preference_Use_Default
) ) {
505 PreferencesUtil
.setAreaDisplayInChecklistEditor(displayArea
);
507 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(
508 PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey()), override
);
513 PreferencesUtil
.setOwnDescriptionForChecklistEditor(ownDescriptionForDistributionEditor
);
514 PreferencesUtil
.setBooleanValue(
515 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.OwnDescriptionForDistributionEditor
.getKey()),
518 PreferencesUtil
.firePreferencesChanged(this.getClass());
527 public void widgetSelected(SelectionEvent e
) {
529 if (e
.getSource().equals(statusDisplaySelectionCombo
)) {
530 String text
= statusDisplaySelectionCombo
.getText();
531 if(text
.equals(Messages
.Preference_Use_Default
)){
532 displayStatus
= Messages
.Preference_Use_Default
;
533 if(isAdminPreference
){
534 prefStatusDisplay
.setAllowOverride(true);
535 allowOverrideStatusDisplayButton
.setSelection(true);
540 for (TermDisplayEnum display
: TermDisplayEnum
.values()) {
541 if (text
.startsWith(display
.getLabel())) {
542 displayStatus
= display
.getKey();
548 if (e
.getSource().equals(statusDisplayInComboSelectionCombo
)) {
549 String text
= statusDisplayInComboSelectionCombo
.getText();
550 if(text
.equals(Messages
.Preference_Use_Default
)){
551 displayStatusCombo
= Messages
.Preference_Use_Default
;
552 if(isAdminPreference
){
553 prefStatusDisplayInCombo
.setAllowOverride(true);
554 allowOverrideStatusDisplayInComboButton
.setSelection(true);
559 for (TermComboEnum display
: TermComboEnum
.values()) {
560 if (text
.startsWith(display
.getLabel())) {
561 displayStatusCombo
= display
.getKey();
567 if (e
.getSource().equals(areaDisplaySelectionCombo
)) {
568 String text
= areaDisplaySelectionCombo
.getText();
569 if(text
.equals(Messages
.Preference_Use_Default
)){
570 displayArea
= Messages
.Preference_Use_Default
;
571 if (isAdminPreference
){
572 prefAreaDisplay
.setAllowOverride(true);
573 allowOverrideAreaDisplayButton
.setSelection(true);
577 for (TermDisplayEnum display
: TermDisplayEnum
.values()) {
578 if (text
.startsWith(display
.getLabel())) {
579 displayArea
= display
.getKey();
584 if (e
.getSource().equals(areaOrderSelectionCombo
)) {
585 String text
= areaOrderSelectionCombo
.getText();
586 if(text
.equals(Messages
.Preference_Use_Default
)){
587 orderAreas
= Messages
.Preference_Use_Default
;
588 if (isAdminPreference
){
589 prefAreaSort
.setAllowOverride(true);
590 allowOverrideOrderAreasButton
.setSelection(true);
594 for (TermOrder display
: TermOrder
.values()) {
595 if (text
.startsWith(display
.getLabel())) {
596 orderAreas
= display
.getKey();
601 if (e
.getSource().equals(this.activateRankCombo
)) {
602 String text
= activateRankCombo
.getText();
603 if(text
.equals(Messages
.Preference_Use_Default
)){
605 if (isAdminPreference
){
606 prefRank
.setAllowOverride(true);
607 allowOverrideRankButton
.setSelection(true);
611 if (text
.equals(SHOW_RANK
)){
618 if (e
.getSource().equals(this.activateCombo
)) {
619 String text
= activateCombo
.getText();
620 if(text
.equals(Messages
.Preference_Use_Default
)){
621 isEditorActivated
= null;
622 if (isAdminPreference
){
623 if (distributionEditorPref
== null){
624 distributionEditorPref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.DistributionEditorActivated
, PreferencePredicate
.DistributionEditorActivated
.getDefaultValue() != null ? PreferencePredicate
.DistributionEditorActivated
.getDefaultValue().toString(): null);
626 distributionEditorPref
.setAllowOverride(true);
627 allowOverrideActivatedButton
.setSelection(true);
631 if (text
.equals(ENABLE
)){
632 isEditorActivated
= true;
634 isEditorActivated
= false;
638 //PreferencesUtil.recursiveSetEnabled(child, isEditorActivated);
645 public void widgetDefaultSelected(SelectionEvent e
) {
646 // TODO Auto-generated method stub
654 public void getValues() {
655 isAdminPreference
= false;
656 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
657 distributionEditorPref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DistributionEditorActivated
);
658 overrideActivated
= PreferencesUtil
.getBooleanValue(
659 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DistributionEditorActivated
.getKey()), true);
661 if (distributionEditorPref
!= null) {
662 if (distributionEditorPref
.isAllowOverride() ) {
663 if (overrideActivated
){
664 isEditorActivated
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.DistributionEditorActivated
.getKey(), true);
668 isEditorActivated
= Boolean
.valueOf(distributionEditorPref
.getValue());
673 if(!overrideActivated
){
674 isEditorActivated
= null;
676 isEditorActivated
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.DistributionEditorActivated
.getKey(), true);
678 //distributionEditorPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DistributionEditorActivated, PreferencePredicate.DistributionEditorActivated.getDefaultValue() != null ? PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString(): null);
681 prefAreaVoc
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AvailableDistributionAreaVocabularies
);
682 if (prefAreaVoc
== null){
683 prefAreaVoc
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.AvailableDistributionAreaVocabularies
, PreferencePredicate
.AvailableDistributionAreaVocabularies
.getDefaultValue() != null ? PreferencePredicate
.AvailableDistributionAreaVocabularies
.getDefaultValue().toString(): null);
687 prefStatus
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AvailableDistributionStatus
);
688 if (prefStatus
== null){
689 prefStatus
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.AvailableDistributionStatus
, PreferencePredicate
.AvailableDistributionStatus
.getDefaultValue() != null ? PreferencePredicate
.AvailableDistributionStatus
.getDefaultValue().toString(): null);
693 prefAreaDisplay
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DisplayOfAreasInDistributionEditor
);
694 overrideAreaDisplay
= PreferencesUtil
.getBooleanValue(
695 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getKey()), true);
696 if (prefAreaDisplay
!= null) {
697 if (prefAreaDisplay
.isAllowOverride()){
698 if (overrideActivated
) {
699 displayArea
= PreferencesUtil
.displayAreaInChecklistEditor();
701 displayArea
= Messages
.Preference_Use_Default
;
704 displayArea
= prefAreaDisplay
.getValue();
707 if (overrideAreaDisplay
){
708 displayArea
= PreferencesUtil
.displayAreaInChecklistEditor();
710 displayArea
= Messages
.Preference_Use_Default
;
712 //prefAreaDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfAreasInDistributionEditor, PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue() != null ? PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString(): null);
715 prefStatusDisplay
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DisplayOfStatus
);
716 overrideStatusDisplay
= PreferencesUtil
717 .getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DisplayOfStatus
.getKey()), true);
718 if (prefStatusDisplay
!= null) {
719 if (prefStatusDisplay
.isAllowOverride()){
720 if (overrideStatusDisplay
) {
721 displayStatus
= PreferencesUtil
.displayStatusInChecklistEditor();
723 displayStatus
= Messages
.Preference_Use_Default
;
726 this.displayStatus
= prefStatusDisplay
.getValue();
729 if (overrideStatusDisplay
){
730 displayStatus
= PreferencesUtil
.displayStatusInChecklistEditor();
732 displayStatus
= Messages
.Preference_Use_Default
;
734 //prefStatusDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfStatus, PreferencePredicate.DisplayOfStatus.getDefaultValue() != null ? PreferencePredicate.DisplayOfStatus.getDefaultValue().toString(): null);
737 prefStatusDisplayInCombo
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DisplayOfStatusInCombo
);
738 overrideStatusDisplayCombo
= PreferencesUtil
739 .getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DisplayOfStatusInCombo
.getKey()), true);
740 if (prefStatusDisplayInCombo
!= null) {
741 if (prefStatusDisplayInCombo
.isAllowOverride()){
742 if (overrideStatusDisplayCombo
) {
743 displayStatusCombo
= PreferencesUtil
.getStringValue(PreferencePredicate
.DisplayOfStatusInCombo
.getKey());
745 displayStatusCombo
= Messages
.Preference_Use_Default
;
748 this.displayStatusCombo
= prefStatusDisplayInCombo
.getValue();
751 if (overrideStatusDisplayCombo
){
752 displayStatusCombo
= PreferencesUtil
.getStringValue(PreferencePredicate
.DisplayOfStatusInCombo
.getKey());
754 displayStatusCombo
= Messages
.Preference_Use_Default
;
760 prefAreaSort
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AreasSortedInDistributionEditor
);
761 overrideOrderAreas
= PreferencesUtil
.getBooleanValue(
762 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AreasSortedInDistributionEditor
.getKey()), true);
763 if (prefAreaSort
!= null) {
764 if (prefAreaSort
.isAllowOverride()){
765 if(overrideOrderAreas
) {
766 orderAreas
= PreferencesUtil
.getSortNamedAreasInDistributionEditor();
768 orderAreas
= Messages
.Preference_Use_Default
;
771 if (prefAreaSort
.getValue() != null) {
772 orderAreas
= prefAreaSort
.getValue().toString();
774 orderAreas
= ((TermOrder
) PreferencePredicate
.AreasSortedInDistributionEditor
.getDefaultValue())
780 if (overrideOrderAreas
){
781 orderAreas
= PreferencesUtil
.getSortNamedAreasInDistributionEditor();
783 orderAreas
= Messages
.Preference_Use_Default
;
785 //prefAreaSort = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AreasSortedInDistributionEditor, PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue() != null ? PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue().toString(): null);
788 prefRank
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowRankInDistributionEditor
);
789 overrideRank
= PreferencesUtil
.getBooleanValue(
790 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowRankInDistributionEditor
.getKey()), true);
791 if (prefRank
!= null) {
792 if (prefRank
.isAllowOverride()){
794 isShowRank
= PreferencesUtil
.isShowRankInChecklistEditor();
798 this.isShowRank
= Boolean
.valueOf(prefRank
.getValue().toString());
802 isShowRank
= PreferencesUtil
.isShowRankInChecklistEditor();
807 //refRank = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowRankInDistributionEditor, PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue() != null ? PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue().toString(): null);
810 prefOwnDescription
= PreferencesUtil
811 .getPreferenceFromDB(PreferencePredicate
.OwnDescriptionForDistributionEditor
);
812 if (prefOwnDescription
!= null) {
813 if (prefOwnDescription
.isAllowOverride()) {
814 ownDescriptionForDistributionEditor
= PreferencesUtil
.isOwnDescriptionForChecklistEditor();
816 ownDescriptionForDistributionEditor
= Boolean
.valueOf(prefOwnDescription
.getValue().toString());
819 ownDescriptionForDistributionEditor
= PreferencesUtil
.isShowRankInChecklistEditor();
820 // allowOverrideOwnDescriptionForDistributionEditor = true;
821 overrideOwnDescriptionForDistributionEditor
= PreferencesUtil
.getBooleanValue(
822 PreferencesUtil
.prefOverrideKey(PreferencePredicate
.OwnDescriptionForDistributionEditor
.getKey()), true);
823 //prefOwnDescription = CdmPreference.NewTaxEditorInstance(PreferencePredicate.OwnDescriptionForDistributionEditor, PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue() != null ? PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString(): null);
826 commandHandlerString
= "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardHandler";
827 commandHandlerStringStatus
= "eu.etaxonomy.taxeditor.store.open.OpenDistributionStatusWizardHandler";
831 protected void performDefaults() {
832 if (isAdminPreference
){
833 isEditorActivated
= (Boolean
) PreferencePredicate
.DistributionEditorActivated
.getDefaultValue();
835 isEditorActivated
= Boolean
.parseBoolean(distributionEditorPref
.getValue().toString());
837 if (isEditorActivated
) {
838 activateCombo
.select(0);
840 activateCombo
.select(1);
843 if (isAdminPreference
){
844 displayArea
= ((TermDisplayEnum
) PreferencePredicate
.DisplayOfAreasInDistributionEditor
.getDefaultValue())
847 displayArea
= prefAreaDisplay
.getValue().toString();
850 TermDisplayEnum areaDisplay
;
852 if (displayArea
!= null) {
853 areaDisplay
= TermDisplayEnum
.byKey(displayArea
);
855 areaDisplay
= TermDisplayEnum
.Title
;
857 } catch (IllegalArgumentException e
) {
858 areaDisplay
= TermDisplayEnum
.Title
;
861 for (String itemLabel
: areaDisplaySelectionCombo
.getItems()) {
862 if (itemLabel
.equalsIgnoreCase(areaDisplay
.getLabel())) {
863 areaDisplaySelectionCombo
.select(index
);
869 if (isAdminPreference
){
870 displayStatus
= ((TermDisplayEnum
) PreferencePredicate
.DisplayOfStatus
.getDefaultValue()).getKey();
872 displayStatus
= prefStatusDisplay
.getValue().toString();
875 TermDisplayEnum statusDisplay
;
877 if (displayStatus
!= null) {
878 statusDisplay
= TermDisplayEnum
.byKey(displayStatus
);
880 statusDisplay
= TermDisplayEnum
.Title
;
882 } catch (IllegalArgumentException e
) {
883 statusDisplay
= TermDisplayEnum
.Title
;
886 for (String itemLabel
: statusDisplaySelectionCombo
.getItems()) {
887 if (itemLabel
.equalsIgnoreCase(statusDisplay
.getLabel())) {
888 statusDisplaySelectionCombo
.select(index
);
893 if (isAdminPreference
){
894 orderAreas
= ((TermOrder
) PreferencePredicate
.AreasSortedInDistributionEditor
.getDefaultValue()).getKey();
896 orderAreas
= prefAreaSort
.getValue().toString();
900 if (PreferencesUtil
.getStringValue(PreferencePredicate
.DistributionEditorActivated
.getKey()) != null) {
903 if (orderAreas
!= null) {
904 areaOrder
= TermOrder
.valueOf(orderAreas
);
906 areaOrder
= TermOrder
.IdInVoc
;
908 } catch (IllegalArgumentException e
) {
909 areaOrder
= TermOrder
.IdInVoc
;
911 for (String itemLabel
: areaOrderSelectionCombo
.getItems()) {
912 if (itemLabel
.equalsIgnoreCase(areaOrder
.getLabel())) {
913 areaOrderSelectionCombo
.select(index
);
920 if (isAdminPreference
){
921 isShowRank
= Boolean
.valueOf(PreferencePredicate
.ShowRankInDistributionEditor
.getDefaultValue().toString());
923 isShowRank
= Boolean
.parseBoolean(prefRank
.getValue().toString());
927 activateRankCombo
.select(0);
929 activateRankCombo
.select(1);
932 ownDescriptionForDistributionEditor
= Boolean
933 .valueOf(PreferencePredicate
.OwnDescriptionForDistributionEditor
.getDefaultValue().toString());
935 allowOverrideActivatedButton
.setSelection(true);
936 overrideActivated
= true;
938 overrideAreaDisplay
= true;
939 allowOverrideAreaDisplayButton
.setSelection(true);
941 overrideStatusDisplay
= true;
942 allowOverrideStatusDisplayButton
.setSelection(true);
944 overrideOrderAreas
= true;
945 allowOverrideOrderAreasButton
.setSelection(true);
948 allowOverrideRankButton
.setSelection(true);
950 overrideOwnDescriptionForDistributionEditor
= true;
952 this.statusPref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.AvailableDistributionStatus
, null);
953 this.areaVocPref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.AvailableDistributionAreaVocabularies
,
955 if (!isAdminPreference
) {
956 PreferencesUtil
.recursiveSetEnabled(child
, isEditorActivated
);
958 if (!prefAreaVoc
.isAllowOverride()) {
959 button_openSelectAreaVocabularies
.setButtonEnabled(false);
961 if (!prefStatus
.isAllowOverride()) {
962 button_openStatusWizard
.setButtonEnabled(false);
964 if (!prefRank
.isAllowOverride()) {
965 activateRankCombo
.setEnabled(false);
967 if (!prefAreaSort
.isAllowOverride()) {
968 areaOrderSelectionCombo
.setEnabled(false);
969 allowOverrideOrderAreasButton
.setEnabled(false);
971 if (!prefAreaDisplay
.isAllowOverride()) {
972 allowOverrideAreaDisplayButton
.setEnabled(false);
974 if (!prefStatusDisplay
.isAllowOverride()) {
975 allowOverrideStatusDisplayButton
.setEnabled(false);
978 super.performDefaults();