1 package eu
.etaxonomy
.taxeditor
.preference
;
3 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
4 import org
.eclipse
.swt
.SWT
;
5 import org
.eclipse
.swt
.events
.SelectionAdapter
;
6 import org
.eclipse
.swt
.events
.SelectionEvent
;
7 import org
.eclipse
.swt
.events
.SelectionListener
;
8 import org
.eclipse
.swt
.layout
.GridData
;
9 import org
.eclipse
.swt
.layout
.GridLayout
;
10 import org
.eclipse
.swt
.widgets
.Button
;
11 import org
.eclipse
.swt
.widgets
.Combo
;
12 import org
.eclipse
.swt
.widgets
.Composite
;
13 import org
.eclipse
.swt
.widgets
.Control
;
14 import org
.eclipse
.swt
.widgets
.Label
;
16 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
17 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
19 public class OrderPreferences
extends CdmPreferencePage
implements SelectionListener
{
22 NavigatorOrderEnum orderActivated
;
23 private Combo orderSelectionCombo
;
24 boolean isRestoreTaxonNavigator
;
25 boolean isSelectionChanged
= false;
26 boolean isStrictlyAlphabeticallyOrdered
;
27 Button activateRestoreNavigatorButton
;
30 protected Control
createContents(Composite parent
) {
32 isRestoreTaxonNavigator
= PreferencesUtil
.isStoreNavigatorState();
34 Composite secondComposite
= new Composite(parent
, SWT
.NULL
);
35 secondComposite
.setLayout(new GridLayout());
37 activateRestoreNavigatorButton
= new Button(secondComposite
, SWT
.CHECK
| SWT
.LEFT
);
38 activateRestoreNavigatorButton
.setText(Messages
.OrderPreferences_Restore
);
39 activateRestoreNavigatorButton
.setSelection(isRestoreTaxonNavigator
);
40 activateRestoreNavigatorButton
.addSelectionListener(new SelectionAdapter(){
42 public void widgetSelected(SelectionEvent e
) {
44 if(isRestoreTaxonNavigator
!= activateRestoreNavigatorButton
.getSelection()) {
45 isRestoreTaxonNavigator
= activateRestoreNavigatorButton
.getSelection();
53 Composite composite
= new Composite(parent
, SWT
.NULL
);
54 composite
.setLayout(new GridLayout());
56 Label label
= new Label(composite
, SWT
.NONE
);
57 label
.setText(Messages
.OrderPreferences_Sorting
);
59 GridData gridData
= new GridData();
60 gridData
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
61 gridData
.horizontalIndent
= 5;
63 orderSelectionCombo
= new Combo(composite
, SWT
.BORDER
| SWT
.READ_ONLY
);
64 orderSelectionCombo
.setLayoutData(gridData
);
66 for(NavigatorOrderEnum display
: NavigatorOrderEnum
.values()){
67 orderSelectionCombo
.add(display
.getLabel());
71 if (PreferencesUtil
.getStringValue(IPreferenceKeys
.SORT_NODES
) != null){
72 this.orderActivated
= NavigatorOrderEnum
.valueOf(PreferencesUtil
.getStringValue(IPreferenceKeys
.SORT_NODES
));
74 for (String itemLabel
: orderSelectionCombo
.getItems()){
75 if (itemLabel
.equalsIgnoreCase(orderActivated
.getLabel())){
76 orderSelectionCombo
.select(index
);
83 // TODO remember last selection
84 orderSelectionCombo
.addSelectionListener(this);
86 final Label description
= new Label(parent
, SWT
.NONE
);
87 description
.setText(Messages
.OrderPreferencePage_NewNavigatorWindowRequired
);
94 public boolean performOk() {
95 if (this.orderActivated
!= null){
96 PreferencesUtil
.setSortNodes(this.orderActivated
);
97 PreferencesUtil
.setStoreNavigatorState(isRestoreTaxonNavigator
);
98 MessageDialog
.openInformation(getShell(), null, Messages
.OrderPreferencePage_PleaseReopenNavigator
);
100 return super.performOk();
109 public void widgetSelected(SelectionEvent e
) {
111 isSelectionChanged
= true;
112 for (NavigatorOrderEnum item
: NavigatorOrderEnum
.values()){
113 if (item
.getLabel().equalsIgnoreCase(orderSelectionCombo
.getText())){
114 this.orderActivated
= item
;
124 public void widgetDefaultSelected(SelectionEvent e
) {
125 // TODO Auto-generated method stub
130 protected void performDefaults() {
131 activateRestoreNavigatorButton
.setSelection(false);
132 isRestoreTaxonNavigator
= false;
133 orderActivated
= NavigatorOrderEnum
.RankAndNameOrder
;
135 for (String itemLabel
: orderSelectionCombo
.getItems()){
136 if (itemLabel
.equalsIgnoreCase(orderActivated
.getLabel())){
137 orderSelectionCombo
.select(index
);
142 super.performDefaults();