1 package eu
.etaxonomy
.taxeditor
.preference
;
4 import org
.eclipse
.jface
.layout
.GridLayoutFactory
;
5 import org
.eclipse
.swt
.SWT
;
6 import org
.eclipse
.swt
.custom
.CLabel
;
7 import org
.eclipse
.swt
.events
.SelectionAdapter
;
8 import org
.eclipse
.swt
.events
.SelectionEvent
;
9 import org
.eclipse
.swt
.events
.SelectionListener
;
10 import org
.eclipse
.swt
.layout
.GridData
;
11 import org
.eclipse
.swt
.layout
.GridLayout
;
12 import org
.eclipse
.swt
.widgets
.Button
;
13 import org
.eclipse
.swt
.widgets
.Combo
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Control
;
16 import org
.eclipse
.swt
.widgets
.Label
;
18 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
19 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
20 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
21 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
24 public class NameDetailsViewConfiguration
extends CdmPreferencePage
implements SelectionListener
{
29 private static final String DISABLE
= "Disable";
33 private static final String ENABLE
= "Enable";
34 protected Boolean isSimpleDetailsViewActivated
;
35 boolean isUseLocalSettings
;
36 protected NameDetailsConfigurator nameDetailsConfig
;
37 Composite localSettings
;
39 CdmPreference nameDetailsPref
;
41 protected boolean isShowTaxon
;
42 protected boolean isShowNameApprobiation
;
43 protected boolean isShowHybrid
;
44 protected boolean isShowNameRelationship
;
45 protected boolean isShowTypeDesignation
;
46 protected boolean isShowProtologue
;
47 protected boolean isShowNomenclaturalStatus
;
48 protected boolean isShowNomenclaturalRef
;
49 protected boolean isShowAuthorship
;
50 protected boolean isShowAuthorCache
;
51 protected boolean isShowEpithets
;
52 protected boolean isShowRank
;
53 protected boolean isShowAppendedPhrase
;
54 protected boolean isShowNameCache
;
55 protected boolean isShowNomenclaturalCode
;
56 protected boolean isShowLSID
;
57 protected boolean isSecEnabled
;
58 protected boolean isSecDetailsActivated
;
60 protected boolean isAllowOverride
;
61 private boolean isOverride
;
62 private Button showSecDetail
;
63 private Button secEnabled
;
65 protected Combo activateCheckButton
;
66 protected Button allowLocalPreference
;
67 protected Button showTaxon
;
68 protected Button showLsid
;
69 protected Button showNomenclaturalCode
;
70 protected Button showNameCache
;
71 protected Button showAppendedPhrase
;
72 protected Button showRank
;
73 protected Button showEpithets
;
74 protected Button showAuthorCache
;
75 protected Button showAuthorship
;
76 protected Button showNomenclaturalRef
;
77 protected Button showNomenclaturalStatus
;
78 protected Button showProtologue
;
79 protected Button showTypeDesignation
;
80 protected Button showNameRelationship
;
81 protected Button showHybrid
;
82 protected Button showNameApprobiation
;
87 protected Control
createContents(Composite parent
) {
89 if (isAllowOverride
|| isAdminPreference
){
91 final CLabel description
= new CLabel(parent
, SWT
.NULL
);
92 description
.setText(Messages
.NameDetailsViewConfiguration_description
);
94 Composite title
= createComposite(parent
);
95 // nameDetailsConfig = PreferencesUtil.getPreferredNameDetailsConfiguration(!isAdminPreference);
98 activateCheckButton
= createBooleanCombo(title
, ENABLE
, DISABLE
, PreferencePredicate
.SimpleDetailsViewActivated
, Messages
.NameDetailsViewConfiguration_activateSimpleDetailsView
, isAdminPreference
);
99 if (isAdminPreference
){
100 allowLocalPreference
= createAllowOverrideButton(title
);
102 allowLocalPreference
.addSelectionListener(new SelectionAdapter(){
104 public void widgetSelected(SelectionEvent e
) {
106 if (isAdminPreference
){
107 isAllowOverride
= allowLocalPreference
.getSelection();
109 isOverride
= allowLocalPreference
.getSelection();
116 dbSettings
= new Composite(parent
, SWT
.NONE
);
118 // activateCheckButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
119 // activateCheckButton.setText(Messages.NameDetailsViewConfiguration_activateSimpleDetailsView);
120 if (nameDetailsConfig
!= null){
121 isSimpleDetailsViewActivated
= nameDetailsConfig
.isSimpleDetailsViewActivated();
123 if (nameDetailsConfig
== null){
124 nameDetailsConfig
= new NameDetailsConfigurator(false);
126 activateCheckButton
.addSelectionListener(this);
127 // new SelectionAdapter(){
129 // public void widgetSelected(SelectionEvent e) {
131 // isSimpleDetailsViewActivated = activateCheckButton.getSelectionIndex() == 0? true:false;
132 // nameDetailsConfig.setSimpleDetailsViewActivated(isSimpleDetailsViewActivated);
133 // dbSettings.setEnabled(isSimpleDetailsViewActivated);
134 // PreferencesUtil.recursiveSetEnabled(dbSettings, isSimpleDetailsViewActivated);
135 // if (isSimpleDetailsViewActivated){
136 // showSecDetail.setEnabled(isShowTaxon);
137 // secEnabled.setEnabled(isShowTaxon);
144 dbSettings
.setLayout(new GridLayout());
145 if (isSimpleDetailsViewActivated
!= null){
146 dbSettings
.setEnabled(isSimpleDetailsViewActivated
);
148 dbSettings
.setEnabled(false);
152 Label separator
= new Label(dbSettings
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
153 separator
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
154 showTaxon
= new Button(dbSettings
, SWT
.CHECK
);
155 showTaxon
.setText(Messages
.NameDetailsViewComposite_Show_Taxon
);
156 isShowTaxon
= nameDetailsConfig
.isTaxonSectionActivated();
158 showTaxon
.addSelectionListener(new SelectionAdapter(){
160 public void widgetSelected(SelectionEvent e
) {
162 isShowTaxon
= showTaxon
.getSelection();
163 nameDetailsConfig
.setTaxonSectionActivated(isShowTaxon
);
164 if (isSimpleDetailsViewActivated
!= null? isSimpleDetailsViewActivated
:false){
165 showSecDetail
.setEnabled(isShowTaxon
);
166 secEnabled
.setEnabled(isShowTaxon
);
172 Composite taxonComp
= new Composite(dbSettings
, SWT
.NULL
);
174 GridLayoutFactory
.fillDefaults().applyTo(taxonComp
);
176 GridData data
= new GridData();
177 data
.horizontalIndent
= 5;
178 data
.horizontalSpan
= 2;
179 taxonComp
.setLayoutData(data
);
181 secEnabled
= new Button(taxonComp
, SWT
.CHECK
);
182 secEnabled
.setText(Messages
.NameDetailsViewComposite_SecEnabled
);
184 isSecEnabled
= nameDetailsConfig
.isSecEnabled();
186 secEnabled
.addSelectionListener(new SelectionAdapter(){
188 public void widgetSelected(SelectionEvent e
) {
190 isSecEnabled
= secEnabled
.getSelection();
191 nameDetailsConfig
.setSecEnabled(isSecEnabled
);
194 showSecDetail
= new Button(taxonComp
, SWT
.CHECK
);
195 showSecDetail
.setText(Messages
.NameDetailsViewComposite_Show_SecDetail
);
197 isSecDetailsActivated
= nameDetailsConfig
.isSecDetailsActivated();
199 showSecDetail
.addSelectionListener(new SelectionAdapter(){
201 public void widgetSelected(SelectionEvent e
) {
203 isSecDetailsActivated
= showSecDetail
.getSelection();
204 nameDetailsConfig
.setSecDetailsActivated(isSecDetailsActivated
);
208 showLsid
= new Button(dbSettings
, SWT
.CHECK
);
209 showLsid
.setText(Messages
.NameDetailsViewComposite_Show_LSID
);
210 isShowLSID
= nameDetailsConfig
.isLSIDActivated();
212 showLsid
.addSelectionListener(new SelectionAdapter(){
214 public void widgetSelected(SelectionEvent e
) {
216 isShowLSID
= showLsid
.getSelection();
217 nameDetailsConfig
.setLSIDActivated(isShowLSID
);
221 showNomenclaturalCode
= new Button(dbSettings
, SWT
.CHECK
);
222 showNomenclaturalCode
.setText(Messages
.NameDetailsViewComposite_Show_NomenclaturalCode
);
223 isShowNomenclaturalCode
= nameDetailsConfig
.isNomenclaturalCodeActived();
225 showNomenclaturalCode
.addSelectionListener(new SelectionAdapter(){
227 public void widgetSelected(SelectionEvent e
) {
229 isShowNomenclaturalCode
= showNomenclaturalCode
.getSelection();
230 nameDetailsConfig
.setNomenclaturalCodeActived(isShowNomenclaturalCode
);
234 showNameCache
= new Button(dbSettings
, SWT
.CHECK
);
235 showNameCache
.setText(Messages
.NameDetailsViewComposite_Show_NameCache
);
236 isShowNameCache
= nameDetailsConfig
.isNameCacheActivated();
238 showNameCache
.addSelectionListener(new SelectionAdapter(){
240 public void widgetSelected(SelectionEvent e
) {
242 isShowNameCache
= showNameCache
.getSelection();
243 nameDetailsConfig
.setNameCacheActivated(isShowNameCache
);
246 showAppendedPhrase
= new Button(dbSettings
, SWT
.CHECK
);
247 isShowAppendedPhrase
= nameDetailsConfig
.isAppendedPhraseActivated();
248 showAppendedPhrase
.setText(Messages
.NameDetailsViewComposite_Show_AppendedPhrase
);
250 showAppendedPhrase
.addSelectionListener(new SelectionAdapter(){
252 public void widgetSelected(SelectionEvent e
) {
254 isShowAppendedPhrase
= showAppendedPhrase
.getSelection();
255 nameDetailsConfig
.setAppendedPhraseActivated(isShowAppendedPhrase
);
259 showRank
= new Button(dbSettings
, SWT
.CHECK
);
260 isShowRank
= nameDetailsConfig
.isRankActivated();
261 showRank
.setText(Messages
.NameDetailsViewComposite_Show_Rank
);
263 showRank
.addSelectionListener(new SelectionAdapter(){
265 public void widgetSelected(SelectionEvent e
) {
267 isShowRank
= showRank
.getSelection();
268 nameDetailsConfig
.setRankActivated(isShowRank
);
271 showEpithets
= new Button(dbSettings
, SWT
.CHECK
);
272 isShowEpithets
= nameDetailsConfig
.isAtomisedEpithetsActivated();
273 showEpithets
.setText(Messages
.NameDetailsViewComposite_Show_AtomisedEpithets
);
275 showEpithets
.addSelectionListener(new SelectionAdapter(){
277 public void widgetSelected(SelectionEvent e
) {
279 isShowEpithets
= showEpithets
.getSelection();
280 nameDetailsConfig
.setAtomisedEpithetsActivated(isShowEpithets
);
284 showAuthorCache
= new Button(dbSettings
, SWT
.CHECK
);
285 isShowAuthorCache
= nameDetailsConfig
.isAuthorCacheActivated();
286 showAuthorCache
.setText(Messages
.NameDetailsViewComposite_Show_AuthorCache
);
288 showAuthorCache
.addSelectionListener(new SelectionAdapter(){
290 public void widgetSelected(SelectionEvent e
) {
292 isShowAuthorCache
= showAuthorCache
.getSelection();
293 nameDetailsConfig
.setAuthorCacheActivated(isShowAuthorCache
);
297 showAuthorship
= new Button(dbSettings
, SWT
.CHECK
);
298 isShowAuthorship
= nameDetailsConfig
.isAuthorshipSectionActivated();
299 showAuthorship
.setText(Messages
.NameDetailsViewComposite_Show_Author
);
301 showAuthorship
.addSelectionListener(new SelectionAdapter(){
303 public void widgetSelected(SelectionEvent e
) {
305 isShowAuthorship
= showAuthorship
.getSelection();
306 nameDetailsConfig
.setAuthorshipSectionActivated(isShowAuthorship
);
310 showNomenclaturalRef
= new Button(dbSettings
, SWT
.CHECK
);
311 isShowNomenclaturalRef
= nameDetailsConfig
.isNomenclaturalReferenceSectionActivated();
312 showNomenclaturalRef
.setText(Messages
.NameDetailsViewComposite_Show_NomenclaturalReference
);
314 showNomenclaturalRef
.addSelectionListener(new SelectionAdapter(){
316 public void widgetSelected(SelectionEvent e
) {
318 isShowNomenclaturalRef
= showNomenclaturalRef
.getSelection();
319 nameDetailsConfig
.setNomenclaturalReferenceSectionActivated(isShowNomenclaturalRef
);
323 showNomenclaturalStatus
= new Button(dbSettings
, SWT
.CHECK
);
324 isShowNomenclaturalStatus
= nameDetailsConfig
.isNomenclaturalStatusSectionActivated();
325 showNomenclaturalStatus
.setText(Messages
.NameDetailsViewComposite_Show_NomenclaturalStatus
);
327 showNomenclaturalStatus
.addSelectionListener(new SelectionAdapter(){
329 public void widgetSelected(SelectionEvent e
) {
331 isShowNomenclaturalStatus
= showNomenclaturalStatus
.getSelection();
332 nameDetailsConfig
.setNomenclaturalStatusSectionActivated(isShowNomenclaturalStatus
);
336 showProtologue
= new Button(dbSettings
, SWT
.CHECK
);
337 isShowProtologue
= nameDetailsConfig
.isProtologueActivated();
338 showProtologue
.setText(Messages
.NameDetailsViewComposite_Show_Protologue
);
340 showProtologue
.addSelectionListener(new SelectionAdapter(){
342 public void widgetSelected(SelectionEvent e
) {
344 isShowProtologue
= showProtologue
.getSelection();
345 nameDetailsConfig
.setProtologueActivated(isShowProtologue
);
349 showTypeDesignation
= new Button(dbSettings
, SWT
.CHECK
);
350 isShowTypeDesignation
= nameDetailsConfig
.isTypeDesignationSectionActivated();
351 showTypeDesignation
.setText(Messages
.NameDetailsViewComposite_Show_TypeDesignation
);
353 showTypeDesignation
.addSelectionListener(new SelectionAdapter(){
355 public void widgetSelected(SelectionEvent e
) {
357 isShowTypeDesignation
= showTypeDesignation
.getSelection();
358 nameDetailsConfig
.setTypeDesignationSectionActivated(isShowTypeDesignation
);
363 showNameRelationship
= new Button(dbSettings
, SWT
.CHECK
);
364 isShowNameRelationship
= nameDetailsConfig
.isNameRelationsSectionActivated();
365 showNameRelationship
.setText(Messages
.NameDetailsViewComposite_Show_Namerelationships
);
367 showNameRelationship
.addSelectionListener(new SelectionAdapter(){
369 public void widgetSelected(SelectionEvent e
) {
371 isShowNameRelationship
= showNameRelationship
.getSelection();
372 nameDetailsConfig
.setNameRelationsSectionActivated(isShowNameRelationship
);
376 showHybrid
= new Button(dbSettings
, SWT
.CHECK
);
377 isShowHybrid
= nameDetailsConfig
.isHybridActivated();
378 showHybrid
.setText(Messages
.NameDetailsViewComposite_Show_Hybrid
);
380 showHybrid
.addSelectionListener(new SelectionAdapter(){
382 public void widgetSelected(SelectionEvent e
) {
384 isShowHybrid
= showHybrid
.getSelection();
385 nameDetailsConfig
.setHybridActivated(isShowHybrid
);
388 showNameApprobiation
= new Button(dbSettings
, SWT
.CHECK
);
389 isShowNameApprobiation
= nameDetailsConfig
.isNameApprobiationActivated();
390 showNameApprobiation
.setText(Messages
.NameDetailsViewComposite_Show_NameApprobiation
);
391 showNameApprobiation
.addSelectionListener(new SelectionAdapter(){
393 public void widgetSelected(SelectionEvent e
) {
395 isShowNameApprobiation
= showNameApprobiation
.getSelection();
396 nameDetailsConfig
.setNameApprobiationActivated(isShowNameApprobiation
);
399 PreferencesUtil
.recursiveSetEnabled(dbSettings
, isSimpleDetailsViewActivated
!= null? isSimpleDetailsViewActivated
:false);
400 if (isSimpleDetailsViewActivated
!= null? isSimpleDetailsViewActivated
:false){
401 showSecDetail
.setEnabled(isShowTaxon
);
402 secEnabled
.setEnabled(isShowTaxon
);
404 showSecDetail
.setEnabled(false);
405 secEnabled
.setEnabled(false);
407 setButtonSelections();
410 final CLabel description
= new CLabel(parent
, SWT
.NULL
);
411 description
.setText(Messages
.NameDetailsViewConfiguration_description_not_available
);
412 this.setDefaultButtonActivated(false);
422 public boolean performOk() {
423 if (nameDetailsConfig
!= null){
424 PreferencesUtil
.setStringValue(PreferencePredicate
.NameDetailsView
.getKey(), nameDetailsConfig
.toString());
425 if (nameDetailsPref
== null || !nameDetailsConfig
.toString().equals(nameDetailsPref
.getValue())) {
426 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.NameDetailsView
.getKey()), true);
435 public void getValues(){
436 if (nameDetailsConfig
== null){
437 nameDetailsPref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.NameDetailsView
);
438 isAdminPreference
= false;
439 isAllowOverride
= true;
440 if (nameDetailsPref
!= null){
441 isAllowOverride
= nameDetailsPref
.isAllowOverride();
444 isOverride
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.NameDetailsView
.getKey()), true) != null? PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.NameDetailsView
.getKey()), true): false;
445 nameDetailsConfig
= PreferencesUtil
.getPreferredNameDetailsConfiguration(true);
449 protected void setButtonSelections(){
452 if (isSimpleDetailsViewActivated
!= null){
453 if (isSimpleDetailsViewActivated
){
459 activateCheckButton
.select(index
);
460 if (isAdminPreference
){
461 allowLocalPreference
.setSelection(isAllowOverride
);
463 showTaxon
.setSelection(isShowTaxon
);
464 showLsid
.setSelection(isShowLSID
);
465 showNomenclaturalCode
.setSelection(isShowNomenclaturalCode
);
466 showNameCache
.setSelection(isShowNameCache
);
467 showAppendedPhrase
.setSelection(isShowAppendedPhrase
);
468 showRank
.setSelection(isShowRank
);
469 showEpithets
.setSelection(isShowEpithets
);
470 showAuthorCache
.setSelection(isShowAuthorCache
);
471 showAuthorship
.setSelection(isShowAuthorship
);
472 showNomenclaturalRef
.setSelection(isShowNomenclaturalRef
);
473 showNomenclaturalStatus
.setSelection(isShowNomenclaturalStatus
);
474 showProtologue
.setSelection(isShowProtologue
);
475 showTypeDesignation
.setSelection(isShowTypeDesignation
);
476 showNameRelationship
.setSelection(isShowNameRelationship
);
477 showHybrid
.setSelection(isShowHybrid
);
478 showNameApprobiation
.setSelection(isShowNameApprobiation
);
479 secEnabled
.setSelection(isSecEnabled
);
480 secEnabled
.setEnabled(isShowTaxon
);
481 showSecDetail
.setSelection(isSecDetailsActivated
);
482 showSecDetail
.setEnabled(isShowTaxon
);
487 protected void performDefaults() {
488 nameDetailsConfig
= new NameDetailsConfigurator(false);
489 isShowAppendedPhrase
= nameDetailsConfig
.isAppendedPhraseActivated();
490 isShowEpithets
= nameDetailsConfig
.isAtomisedEpithetsActivated();
491 isShowAuthorship
= nameDetailsConfig
.isAuthorshipSectionActivated();
492 isShowAuthorCache
= nameDetailsConfig
.isAuthorCacheActivated();
493 isShowLSID
= nameDetailsConfig
.isLSIDActivated();
494 isShowNameApprobiation
= nameDetailsConfig
.isNameApprobiationActivated();
495 isShowNameCache
= nameDetailsConfig
.isNameCacheActivated();
496 isShowNameRelationship
= nameDetailsConfig
.isNameRelationsSectionActivated();
497 isShowNomenclaturalCode
= nameDetailsConfig
.isNomenclaturalCodeActived();
498 isShowNomenclaturalStatus
= nameDetailsConfig
.isNomenclaturalStatusSectionActivated();
499 isShowNomenclaturalRef
= nameDetailsConfig
.isNomenclaturalReferenceSectionActivated();
500 isShowProtologue
= nameDetailsConfig
.isProtologueActivated();
501 isShowRank
= nameDetailsConfig
.isRankActivated();
502 isShowTaxon
= nameDetailsConfig
.isTaxonSectionActivated();
503 isSecDetailsActivated
= nameDetailsConfig
.isSecDetailsActivated();
504 isSecEnabled
= nameDetailsConfig
.isSecEnabled();
505 isShowTypeDesignation
= nameDetailsConfig
.isTypeDesignationSectionActivated();
506 isShowHybrid
= nameDetailsConfig
.isHybridActivated();
507 isSimpleDetailsViewActivated
= null;
508 this.setButtonSelections();
509 // activateCheckButton.select(0);
510 super.performDefaults();
517 public void widgetSelected(SelectionEvent e
) {
519 if (e
.getSource().equals(activateCheckButton
)){
520 String text
= activateCheckButton
.getText();
521 if(text
.startsWith(Messages
.Preference_Use_Default
)){
522 isSimpleDetailsViewActivated
= null;
523 if (isAdminPreference
){
524 nameDetailsPref
.setAllowOverride(true);
525 allowLocalPreference
.setSelection(true);
529 if (text
.equals(ENABLE
)){
530 isSimpleDetailsViewActivated
= true;
533 isSimpleDetailsViewActivated
= false;
535 nameDetailsConfig
.setSimpleDetailsViewActivated(isSimpleDetailsViewActivated
);
536 dbSettings
.setEnabled(isSimpleDetailsViewActivated
);
537 PreferencesUtil
.recursiveSetEnabled(dbSettings
, isSimpleDetailsViewActivated
);
538 if (isSimpleDetailsViewActivated
){
539 showSecDetail
.setEnabled(isShowTaxon
);
540 secEnabled
.setEnabled(isShowTaxon
);
552 public void widgetDefaultSelected(SelectionEvent e
) {
553 // TODO Auto-generated method stub