1 package eu
.etaxonomy
.taxeditor
.preference
;
3 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
4 import org
.eclipse
.swt
.SWT
;
5 import org
.eclipse
.swt
.custom
.CLabel
;
6 import org
.eclipse
.swt
.events
.SelectionAdapter
;
7 import org
.eclipse
.swt
.events
.SelectionEvent
;
8 import org
.eclipse
.swt
.events
.SelectionListener
;
9 import org
.eclipse
.swt
.layout
.GridData
;
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
;
15 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
16 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
17 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
18 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
20 public class OrderPreferences
extends CdmPreferencePage
implements SelectionListener
{
23 protected NavigatorOrderEnum orderActivated
;
24 private Combo orderSelectionCombo
;
25 boolean isRestoreTaxonNavigator
;
28 Button activateRestoreNavigatorButton
;
29 protected Button allowOverrideButton
;
30 protected CdmPreference orderPref
;
31 boolean override
= false;
32 protected boolean allowOverride
;
36 protected Control
createContents(Composite parent
) {
38 isRestoreTaxonNavigator
= PreferencesUtil
.isStoreNavigatorState();
40 Composite secondComposite
= createComposite(parent
);
42 if(!isAdminPreference
) {
43 activateRestoreNavigatorButton
= new Button(secondComposite
, SWT
.CHECK
| SWT
.LEFT
);
44 activateRestoreNavigatorButton
.setText(Messages
.OrderPreferences_Restore
);
45 activateRestoreNavigatorButton
.setSelection(isRestoreTaxonNavigator
);
46 activateRestoreNavigatorButton
.addSelectionListener(new SelectionAdapter(){
48 public void widgetSelected(SelectionEvent e
) {
50 if(isRestoreTaxonNavigator
!= activateRestoreNavigatorButton
.getSelection()) {
51 isRestoreTaxonNavigator
= activateRestoreNavigatorButton
.getSelection();
59 // Composite composite = new Composite(parent, SWT.NULL);
60 // composite.setLayout(new GridLayout());
62 // Label label = new Label(composite, SWT.NONE);
63 // label.setText(Messages.OrderPreferences_Sorting);
65 // GridData gridData = new GridData();
66 // gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
67 // gridData.horizontalIndent = 5;
69 orderSelectionCombo
= createCombo(secondComposite
, NavigatorOrderEnum
.values(), PreferencePredicate
.TaxonNodeOrder
, Messages
.OrderPreferences_Sorting
, isAdminPreference
);
70 // orderSelectionCombo.setLayoutData(gridData);
74 if (orderActivated
== null){
75 orderSelectionCombo
.select(index
);
77 for (String itemLabel
: orderSelectionCombo
.getItems()){
78 if (itemLabel
.equalsIgnoreCase(orderActivated
.getLabel())){
79 orderSelectionCombo
.select(index
);
87 orderSelectionCombo
.addSelectionListener(this);
88 if (isAdminPreference
){
89 allowOverrideButton
= createAllowOverrideButton(secondComposite
);
90 allowOverrideButton
.setSelection(allowOverride
);
91 allowOverrideButton
.addSelectionListener(new SelectionAdapter(){
93 public void widgetSelected(SelectionEvent e
) {
94 allowOverride
= !allowOverride
;
100 if (orderPref
!= null && !isAdminPreference
){
101 if (!orderPref
.isAllowOverride()){
102 orderSelectionCombo
.setEnabled(false);
103 final CLabel description
= new CLabel(secondComposite
, SWT
.NULL
);
104 description
.setText(Messages
.OrderPreferencePage_NotAllowed
);
105 GridData textGrid
= createTextGridData();
106 textGrid
.verticalSpan
= 2;
107 description
.setLayoutData(textGrid
);
111 // final CLabel description = new CLabel(secondComposite, SWT.NULL);
112 // description.setText(Messages.OrderPreferencePage_NewNavigatorWindowRequired);
113 // GridData textGrid = createTextGridData();
114 // textGrid.verticalSpan = 2;
115 // description.setLayoutData(textGrid);
117 // final Label description = new Label(secondComposite, SWT.NONE);
118 // description.setText(Messages.OrderPreferencePage_NewNavigatorWindowRequired);
119 // GridData textGrid = createTextGridData();
120 // textGrid.verticalSpan = 2;
121 // description.setLayoutData(textGrid);
122 return secondComposite
;
127 public boolean performOk() {
129 PreferencesUtil
.setSortNodes(this.orderActivated
);
130 if (orderActivated
!= null){
131 PreferencesUtil
.setBooleanValue(PreferencesUtil
.createOverridePreferenceString(PreferencePredicate
.TaxonNodeOrder
.getKey()), true);
133 PreferencesUtil
.setBooleanValue(PreferencesUtil
.createOverridePreferenceString(PreferencePredicate
.TaxonNodeOrder
.getKey()), false);
135 PreferencesUtil
.setStoreNavigatorState(isRestoreTaxonNavigator
);
136 MessageDialog
.openInformation(getShell(), null, Messages
.OrderPreferencePage_PleaseReopenNavigator
);
147 public void widgetSelected(SelectionEvent e
) {
150 for (NavigatorOrderEnum item
: NavigatorOrderEnum
.values()){
151 if (!orderSelectionCombo
.getText().startsWith(Messages
.Preference_Use_Default
)){
152 orderActivated
= (NavigatorOrderEnum
)orderSelectionCombo
.getData(orderSelectionCombo
.getText());
154 orderActivated
= null;
165 public void widgetDefaultSelected(SelectionEvent e
) {
166 // TODO Auto-generated method stub
171 protected void performDefaults() {
172 if (!isAdminPreference
) {
173 activateRestoreNavigatorButton
.setSelection(false);
176 isRestoreTaxonNavigator
= false;
177 orderActivated
= null;
179 orderSelectionCombo
.select(0);
181 super.performDefaults();
185 protected void getValues(){
186 orderPref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.TaxonNodeOrder
);
187 override
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.createOverridePreferenceString(PreferencePredicate
.TaxonNodeOrder
.getKey()));
188 allowOverride
= orderPref
!= null? orderPref
.isAllowOverride():true;
189 if (orderPref
== null || (allowOverride
&& override
)) {
190 orderActivated
= NavigatorOrderEnum
.valueOf(PreferencesUtil
.getStringValue(PreferencePredicate
.TaxonNodeOrder
.getKey()));
192 orderActivated
= orderPref
.getValue()!= null? NavigatorOrderEnum
.valueOf(orderPref
.getValue()):null;