1 package eu
.etaxonomy
.taxeditor
.preference
;
3 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
4 import org
.eclipse
.jface
.preference
.PreferencePage
;
5 import org
.eclipse
.swt
.SWT
;
6 import org
.eclipse
.swt
.events
.SelectionAdapter
;
7 import org
.eclipse
.swt
.events
.SelectionEvent
;
8 import org
.eclipse
.swt
.layout
.GridLayout
;
9 import org
.eclipse
.swt
.widgets
.Button
;
10 import org
.eclipse
.swt
.widgets
.Composite
;
11 import org
.eclipse
.swt
.widgets
.Control
;
12 import org
.eclipse
.swt
.widgets
.Label
;
13 import org
.eclipse
.ui
.IWorkbench
;
14 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
16 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
18 public class OrderPreferences
extends PreferencePage
implements IWorkbenchPreferencePage
{
21 boolean isNaturalOrderActivated
;
22 boolean isAlphabeticalOrderActivated
;
23 boolean isRankAndNameOrderActivated
;
24 boolean isRestoreTaxonNavigator
;
25 boolean isSelectionChanged
= false;
26 boolean isStrictlyAlphabeticallyOrdered
;
31 * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors
35 protected Control
createContents(Composite parent
) {
37 isRestoreTaxonNavigator
= PreferencesUtil
.isStoreNavigatorState();
39 Composite secondComposite
= new Composite(parent
, SWT
.NULL
);
40 secondComposite
.setLayout(new GridLayout());
42 final Button activateRestoreNavigatorButton
= new Button(secondComposite
, SWT
.CHECK
| SWT
.LEFT
);
43 activateRestoreNavigatorButton
.setText("Restore the last Taxon Navigator state.");
44 activateRestoreNavigatorButton
.setSelection(isRestoreTaxonNavigator
);
45 activateRestoreNavigatorButton
.addSelectionListener(new SelectionAdapter(){
47 public void widgetSelected(SelectionEvent e
) {
48 if(isRestoreTaxonNavigator
!= activateRestoreNavigatorButton
.getSelection()) {
49 isRestoreTaxonNavigator
= activateRestoreNavigatorButton
.getSelection();
50 PreferencesUtil
.setStoreNavigatorState(isRestoreTaxonNavigator
);
57 Composite composite
= new Composite(parent
, SWT
.NULL
);
58 composite
.setLayout(new GridLayout());
60 Label label
= new Label(composite
, SWT
.NONE
);
61 label
.setText("Sorting");
64 isNaturalOrderActivated
= PreferencesUtil
.getSortNodesNaturally();
65 final Button activateNaturalOrderCheckButton
= new Button(composite
, SWT
.RADIO
);
66 activateNaturalOrderCheckButton
.setText("Natural order");
67 activateNaturalOrderCheckButton
.setSelection(isNaturalOrderActivated
);
69 isRankAndNameOrderActivated
= !PreferencesUtil
.getSortNodesStrictlyAlphabetically() && !PreferencesUtil
.getSortNodesNaturally();
70 final Button activateRankAndNameOrderActivatedCheckButton
= new Button(composite
, SWT
.RADIO
);
71 activateRankAndNameOrderActivatedCheckButton
.setText("Rank and alphabetical Order");
72 activateRankAndNameOrderActivatedCheckButton
.setSelection(isRankAndNameOrderActivated
);
74 isAlphabeticalOrderActivated
= PreferencesUtil
.getSortNodesStrictlyAlphabetically();
75 final Button activateAlphabeticallyOrderedCheckButton
= new Button(composite
, SWT
.RADIO
);
76 activateAlphabeticallyOrderedCheckButton
.setText("Alphabetical order");
77 activateAlphabeticallyOrderedCheckButton
.setSelection(isAlphabeticalOrderActivated
);
79 activateNaturalOrderCheckButton
.addSelectionListener(new SelectionAdapter(){
81 public void widgetSelected(SelectionEvent e
) {
82 if(isNaturalOrderActivated
!= activateNaturalOrderCheckButton
.getSelection()) {
83 isNaturalOrderActivated
= activateNaturalOrderCheckButton
.getSelection();
84 if (isAlphabeticalOrderActivated
&& isNaturalOrderActivated
){
85 isAlphabeticalOrderActivated
= false;
86 PreferencesUtil
.setSortNodesStrictlyAlphabetically(isAlphabeticalOrderActivated
);
88 if (isRankAndNameOrderActivated
&& isNaturalOrderActivated
){
89 isRankAndNameOrderActivated
= false;
91 PreferencesUtil
.setSortNodesNaturally(isNaturalOrderActivated
);
92 isSelectionChanged
= true;
94 isSelectionChanged
= false;
99 activateAlphabeticallyOrderedCheckButton
.addSelectionListener(new SelectionAdapter(){
101 public void widgetSelected(SelectionEvent e
) {
102 if(isAlphabeticalOrderActivated
!= activateAlphabeticallyOrderedCheckButton
.getSelection()) {
103 isAlphabeticalOrderActivated
= activateAlphabeticallyOrderedCheckButton
.getSelection();
104 if (isNaturalOrderActivated
&& isAlphabeticalOrderActivated
){
105 isNaturalOrderActivated
= false;
106 PreferencesUtil
.setSortNodesNaturally(isNaturalOrderActivated
);
108 if (isRankAndNameOrderActivated
&& isAlphabeticalOrderActivated
){
109 isRankAndNameOrderActivated
= false;
111 PreferencesUtil
.setSortNodesStrictlyAlphabetically(isAlphabeticalOrderActivated
);
112 isSelectionChanged
= true;
114 isSelectionChanged
= false;
120 activateRankAndNameOrderActivatedCheckButton
.addSelectionListener(new SelectionAdapter(){
122 public void widgetSelected(SelectionEvent e
) {
123 if(isRankAndNameOrderActivated
!= activateRankAndNameOrderActivatedCheckButton
.getSelection()) {
124 isRankAndNameOrderActivated
= activateRankAndNameOrderActivatedCheckButton
.getSelection();
125 if (isAlphabeticalOrderActivated
&& isRankAndNameOrderActivated
){
126 isAlphabeticalOrderActivated
= false;
128 if (isNaturalOrderActivated
&& isRankAndNameOrderActivated
){
129 isNaturalOrderActivated
= false;
132 if (isRankAndNameOrderActivated
||(!isNaturalOrderActivated
&& !isAlphabeticalOrderActivated
)){
133 PreferencesUtil
.setSortNodesStrictlyAlphabetically(false);
134 PreferencesUtil
.setSortNodesNaturally(false);
136 isSelectionChanged
= true;
138 isSelectionChanged
= false;
148 final Label description
= new Label(parent
, SWT
.NONE
);
149 description
.setText(Messages
.OrderPreferencePage_NewNavigatorWindowRequired
);
156 public void init(IWorkbench workbench
) {
157 // TODO Auto-generated method stub
162 * @see org.eclipse.jface.preference.PreferencePage#performOk()
165 public boolean performOk() {
166 if(isSelectionChanged
){
167 MessageDialog
.openInformation(getShell(), null, Messages
.OrderPreferencePage_PleaseReopenNavigator
);
168 isSelectionChanged
= false;
169 return super.performOk();