bc51c0d98dc13a3f531a5d1ec83ef01f6185c67c
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / OrderPreferences.java
1 package eu.etaxonomy.taxeditor.preference;
2
3 import java.io.IOException;
4
5 import org.eclipse.jface.dialogs.MessageDialog;
6 import org.eclipse.jface.preference.PreferencePage;
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.jface.viewers.ArrayContentProvider;
9 import org.eclipse.jface.viewers.LabelProvider;
10 import org.eclipse.swt.SWT;
11 import org.eclipse.swt.events.SelectionAdapter;
12 import org.eclipse.swt.events.SelectionEvent;
13 import org.eclipse.swt.graphics.Image;
14 import org.eclipse.swt.graphics.Point;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.IWorkbenchPreferencePage;
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.ui.dialogs.ListSelectionDialog;
24
25 import eu.etaxonomy.taxeditor.Messages;
26
27 public class OrderPreferences extends PreferencePage implements IWorkbenchPreferencePage {
28
29
30 boolean isNaturalOrderActivated;
31 boolean isAlphabeticalOrderActivated;
32 boolean isRankAndNameOrderActivated;
33 boolean isSelectionChanged = false;
34 boolean isStrictlyAlphabeticallyOrdered;
35 /*
36 * (non-Javadoc)
37 *
38 * @see
39 * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors
40 * ()
41 */
42 @Override
43 protected Control createContents(Composite parent) {
44
45 Composite composite = new Composite(parent, SWT.NULL);
46 composite.setLayout(new GridLayout());
47 final Label description = new Label(parent, SWT.NONE);
48 description.setText(Messages.OrderPreferencePage_NewNavigatorWindowRequired);
49 isNaturalOrderActivated = PreferencesUtil.getSortNodesNaturally();
50 final Button activateNaturalOrderCheckButton = new Button(composite, SWT.RADIO);
51 activateNaturalOrderCheckButton.setText("Enable Natural Order");
52 activateNaturalOrderCheckButton.setSelection(isNaturalOrderActivated);
53
54 isRankAndNameOrderActivated = !PreferencesUtil.getSortNodesStrictlyAlphabetically() && !PreferencesUtil.getSortNodesNaturally();
55 final Button activateRankAndNameOrderActivatedCheckButton = new Button(composite, SWT.RADIO);
56 activateRankAndNameOrderActivatedCheckButton.setText("Enable Rank and Aplhabetical Order");
57 activateRankAndNameOrderActivatedCheckButton.setSelection(isRankAndNameOrderActivated);
58
59 isAlphabeticalOrderActivated = PreferencesUtil.getSortNodesStrictlyAlphabetically();
60 final Button activateAlphabeticallyOrderedCheckButton = new Button(composite, SWT.RADIO);
61 activateAlphabeticallyOrderedCheckButton.setText("Enable Alphabetical Order");
62 activateAlphabeticallyOrderedCheckButton.setSelection(isAlphabeticalOrderActivated);
63
64 activateNaturalOrderCheckButton.addSelectionListener(new SelectionAdapter(){
65 @Override
66 public void widgetSelected(SelectionEvent e) {
67 if(isNaturalOrderActivated != activateNaturalOrderCheckButton.getSelection()) {
68 isNaturalOrderActivated = activateNaturalOrderCheckButton.getSelection();
69 if (isAlphabeticalOrderActivated && isNaturalOrderActivated){
70 isAlphabeticalOrderActivated = false;
71 PreferencesUtil.setSortNodesStrictlyAlphabetically(isAlphabeticalOrderActivated);
72 }
73 if (isRankAndNameOrderActivated && isNaturalOrderActivated){
74 isRankAndNameOrderActivated = false;
75 }
76 PreferencesUtil.setSortNodesNaturally(isNaturalOrderActivated);
77 isSelectionChanged = true;
78 }else{
79 isSelectionChanged = false;
80 }
81
82 }
83 });
84 activateAlphabeticallyOrderedCheckButton.addSelectionListener(new SelectionAdapter(){
85 @Override
86 public void widgetSelected(SelectionEvent e) {
87 if(isAlphabeticalOrderActivated != activateAlphabeticallyOrderedCheckButton.getSelection()) {
88 isAlphabeticalOrderActivated = activateAlphabeticallyOrderedCheckButton.getSelection();
89 if (isNaturalOrderActivated && isAlphabeticalOrderActivated){
90 isNaturalOrderActivated = false;
91 PreferencesUtil.setSortNodesNaturally(isNaturalOrderActivated);
92 }
93 if (isRankAndNameOrderActivated && isAlphabeticalOrderActivated){
94 isRankAndNameOrderActivated = false;
95 }
96 PreferencesUtil.setSortNodesStrictlyAlphabetically(isAlphabeticalOrderActivated);
97 isSelectionChanged = true;
98 }else{
99 isSelectionChanged = false;
100 }
101
102 }
103 });
104
105 activateRankAndNameOrderActivatedCheckButton.addSelectionListener(new SelectionAdapter(){
106 @Override
107 public void widgetSelected(SelectionEvent e) {
108 if(isRankAndNameOrderActivated != activateRankAndNameOrderActivatedCheckButton.getSelection()) {
109 isRankAndNameOrderActivated = activateRankAndNameOrderActivatedCheckButton.getSelection();
110 if (isAlphabeticalOrderActivated && isRankAndNameOrderActivated){
111 isAlphabeticalOrderActivated = false;
112 }
113 if (isNaturalOrderActivated && isRankAndNameOrderActivated){
114 isNaturalOrderActivated = false;
115 }
116
117 if (isRankAndNameOrderActivated ||(!isNaturalOrderActivated && !isAlphabeticalOrderActivated)){
118 PreferencesUtil.setSortNodesStrictlyAlphabetically(false);
119 PreferencesUtil.setSortNodesNaturally(false);
120 }
121 isSelectionChanged = true;
122 }else{
123 isSelectionChanged = false;
124 }
125
126 }
127 });
128
129
130
131
132 return composite;
133 }
134
135
136 @Override
137 public void init(IWorkbench workbench) {
138 // TODO Auto-generated method stub
139
140 }
141
142 /* (non-Javadoc)
143 * @see org.eclipse.jface.preference.PreferencePage#performOk()
144 */
145 @Override
146 public boolean performOk() {
147 if(isSelectionChanged){
148 MessageDialog.openInformation(getShell(), null, Messages.OrderPreferencePage_PleaseReopenNavigator);
149 isSelectionChanged = false;
150 return super.performOk();
151 }
152 return true;
153 }
154
155
156 }