package eu.etaxonomy.taxeditor.preference;\r
\r
import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.jface.preference.PreferencePage;\r
import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.CLabel;\r
import org.eclipse.swt.events.SelectionAdapter;\r
import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.layout.GridData;\r
import org.eclipse.swt.widgets.Button;\r
+import org.eclipse.swt.widgets.Combo;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.ui.IWorkbench;\r
-import org.eclipse.ui.IWorkbenchPreferencePage;\r
\r
-import eu.etaxonomy.taxeditor.Messages;\r
+import eu.etaxonomy.cdm.model.metadata.CdmPreference;\r
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;\r
+import eu.etaxonomy.taxeditor.l10n.Messages;\r
+import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;\r
\r
-public class OrderPreferences extends PreferencePage implements IWorkbenchPreferencePage {\r
+public class OrderPreferences extends CdmPreferencePage implements SelectionListener{\r
\r
\r
- boolean isNaturalOrderActivated;\r
- boolean isAlphabeticalOrderActivated;\r
- boolean isRankAndNameOrderActivated;\r
+ protected NavigatorOrderEnum orderActivated;\r
+ private Combo orderSelectionCombo;\r
boolean isRestoreTaxonNavigator;\r
- boolean isSelectionChanged = false;\r
- boolean isStrictlyAlphabeticallyOrdered;\r
- /*\r
- * (non-Javadoc)\r
- *\r
- * @see\r
- * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors\r
- * ()\r
- */\r
+\r
+\r
+ Button activateRestoreNavigatorButton;\r
+ protected Button allowOverrideButton;\r
+ protected CdmPreference orderPref;\r
+ boolean override = false;\r
+ protected boolean allowOverride;\r
+\r
+\r
@Override\r
protected Control createContents(Composite parent) {\r
\r
isRestoreTaxonNavigator = PreferencesUtil.isStoreNavigatorState();\r
+ getValues();\r
+ Composite secondComposite = createComposite(parent);\r
+\r
+ if(!isAdminPreference) {\r
+ activateRestoreNavigatorButton = new Button(secondComposite, SWT.CHECK | SWT.LEFT);\r
+ activateRestoreNavigatorButton.setText(Messages.OrderPreferences_Restore);\r
+ activateRestoreNavigatorButton.setSelection(isRestoreTaxonNavigator);\r
+ activateRestoreNavigatorButton.addSelectionListener(new SelectionAdapter(){\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ setApply(true);\r
+ if(isRestoreTaxonNavigator != activateRestoreNavigatorButton.getSelection()) {\r
+ isRestoreTaxonNavigator = activateRestoreNavigatorButton.getSelection();\r
+\r
+ }\r
+ }\r
+\r
+ });\r
+ }\r
+\r
+// Composite composite = new Composite(parent, SWT.NULL);\r
+// composite.setLayout(new GridLayout());\r
+//\r
+// Label label = new Label(composite, SWT.NONE);\r
+// label.setText(Messages.OrderPreferences_Sorting);\r
\r
- Composite secondComposite = new Composite(parent, SWT.NULL);\r
- secondComposite.setLayout(new GridLayout());\r
-\r
- final Button activateRestoreNavigatorButton = new Button(secondComposite, SWT.CHECK | SWT.LEFT);\r
- activateRestoreNavigatorButton.setText("Restore the last Taxon Navigator state.");\r
- activateRestoreNavigatorButton.setSelection(isRestoreTaxonNavigator);\r
- activateRestoreNavigatorButton.addSelectionListener(new SelectionAdapter(){\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if(isRestoreTaxonNavigator != activateRestoreNavigatorButton.getSelection()) {\r
- isRestoreTaxonNavigator = activateRestoreNavigatorButton.getSelection();\r
- PreferencesUtil.setStoreNavigatorState(isRestoreTaxonNavigator);\r
+// GridData gridData = new GridData();\r
+// gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);\r
+// gridData.horizontalIndent = 5;\r
+\r
+ orderSelectionCombo = createCombo(secondComposite, NavigatorOrderEnum.values(), PreferencePredicate.TaxonNodeOrder, Messages.OrderPreferences_Sorting, isAdminPreference);\r
+// orderSelectionCombo.setLayoutData(gridData);\r
+\r
+ int index = 0;\r
+\r
+ if (orderActivated == null){\r
+ orderSelectionCombo.select(index);\r
+ }else{\r
+ for (String itemLabel : orderSelectionCombo.getItems()){\r
+ if (itemLabel.equalsIgnoreCase(orderActivated.getLabel())){\r
+ orderSelectionCombo.select(index);\r
+ break;\r
}\r
+ index++;\r
}\r
+ }\r
+\r
+\r
+ orderSelectionCombo.addSelectionListener(this);\r
+ if (isAdminPreference){\r
+ allowOverrideButton = createAllowOverrideButton(secondComposite);\r
+ allowOverrideButton.setSelection(allowOverride);\r
+ allowOverrideButton.addSelectionListener(new SelectionAdapter(){\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ allowOverride = !allowOverride;\r
+ setApply(true);\r
+ }\r
+ });\r
+ }\r
+\r
+ if (orderPref != null && !isAdminPreference){\r
+ if (!orderPref.isAllowOverride()){\r
+ orderSelectionCombo.setEnabled(false);\r
+ final CLabel description = new CLabel(secondComposite, SWT.NULL);\r
+ description.setText(Messages.OrderPreferencePage_NotAllowed);\r
+ GridData textGrid = createTextGridData();\r
+ textGrid.verticalSpan = 2;\r
+ description.setLayoutData(textGrid);\r
+ }\r
+ }\r
+\r
+// final CLabel description = new CLabel(secondComposite, SWT.NULL);\r
+// description.setText(Messages.OrderPreferencePage_NewNavigatorWindowRequired);\r
+// GridData textGrid = createTextGridData();\r
+// textGrid.verticalSpan = 2;\r
+// description.setLayoutData(textGrid);\r
+\r
+// final Label description = new Label(secondComposite, SWT.NONE);\r
+// description.setText(Messages.OrderPreferencePage_NewNavigatorWindowRequired);\r
+// GridData textGrid = createTextGridData();\r
+// textGrid.verticalSpan = 2;\r
+// description.setLayoutData(textGrid);\r
+ return secondComposite;\r
+ }\r
\r
- });\r
-\r
-\r
- Composite composite = new Composite(parent, SWT.NULL);\r
- composite.setLayout(new GridLayout());\r
-\r
- isNaturalOrderActivated = PreferencesUtil.getSortNodesNaturally();\r
- final Button activateNaturalOrderCheckButton = new Button(composite, SWT.RADIO);\r
- activateNaturalOrderCheckButton.setText("Enable Natural Order");\r
- activateNaturalOrderCheckButton.setSelection(isNaturalOrderActivated);\r
-\r
- isRankAndNameOrderActivated = !PreferencesUtil.getSortNodesStrictlyAlphabetically() && !PreferencesUtil.getSortNodesNaturally();\r
- final Button activateRankAndNameOrderActivatedCheckButton = new Button(composite, SWT.RADIO);\r
- activateRankAndNameOrderActivatedCheckButton.setText("Enable Rank and Aplhabetical Order");\r
- activateRankAndNameOrderActivatedCheckButton.setSelection(isRankAndNameOrderActivated);\r
-\r
- isAlphabeticalOrderActivated = PreferencesUtil.getSortNodesStrictlyAlphabetically();\r
- final Button activateAlphabeticallyOrderedCheckButton = new Button(composite, SWT.RADIO);\r
- activateAlphabeticallyOrderedCheckButton.setText("Enable Alphabetical Order");\r
- activateAlphabeticallyOrderedCheckButton.setSelection(isAlphabeticalOrderActivated);\r
-\r
- activateNaturalOrderCheckButton.addSelectionListener(new SelectionAdapter(){\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if(isNaturalOrderActivated != activateNaturalOrderCheckButton.getSelection()) {\r
- isNaturalOrderActivated = activateNaturalOrderCheckButton.getSelection();\r
- if (isAlphabeticalOrderActivated && isNaturalOrderActivated){\r
- isAlphabeticalOrderActivated = false;\r
- PreferencesUtil.setSortNodesStrictlyAlphabetically(isAlphabeticalOrderActivated);\r
- }\r
- if (isRankAndNameOrderActivated && isNaturalOrderActivated){\r
- isRankAndNameOrderActivated = false;\r
- }\r
- PreferencesUtil.setSortNodesNaturally(isNaturalOrderActivated);\r
- isSelectionChanged = true;\r
- }else{\r
- isSelectionChanged = false;\r
- }\r
\r
- }\r
- });\r
- activateAlphabeticallyOrderedCheckButton.addSelectionListener(new SelectionAdapter(){\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if(isAlphabeticalOrderActivated != activateAlphabeticallyOrderedCheckButton.getSelection()) {\r
- isAlphabeticalOrderActivated = activateAlphabeticallyOrderedCheckButton.getSelection();\r
- if (isNaturalOrderActivated && isAlphabeticalOrderActivated){\r
- isNaturalOrderActivated = false;\r
- PreferencesUtil.setSortNodesNaturally(isNaturalOrderActivated);\r
- }\r
- if (isRankAndNameOrderActivated && isAlphabeticalOrderActivated){\r
- isRankAndNameOrderActivated = false;\r
- }\r
- PreferencesUtil.setSortNodesStrictlyAlphabetically(isAlphabeticalOrderActivated);\r
- isSelectionChanged = true;\r
- }else{\r
- isSelectionChanged = false;\r
- }\r
+ @Override\r
+ public boolean performOk() {\r
+ if (isApply()){\r
+ PreferencesUtil.setSortNodes(this.orderActivated);\r
+ if (orderActivated != null){\r
+ PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), true);\r
+ }else{\r
+ PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), false);\r
+ }\r
+ PreferencesUtil.setStoreNavigatorState(isRestoreTaxonNavigator);\r
+ MessageDialog.openInformation(getShell(), null, Messages.OrderPreferencePage_PleaseReopenNavigator);\r
+ }\r
+ return true;\r
\r
- }\r
- });\r
-\r
- activateRankAndNameOrderActivatedCheckButton.addSelectionListener(new SelectionAdapter(){\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if(isRankAndNameOrderActivated != activateRankAndNameOrderActivatedCheckButton.getSelection()) {\r
- isRankAndNameOrderActivated = activateRankAndNameOrderActivatedCheckButton.getSelection();\r
- if (isAlphabeticalOrderActivated && isRankAndNameOrderActivated){\r
- isAlphabeticalOrderActivated = false;\r
- }\r
- if (isNaturalOrderActivated && isRankAndNameOrderActivated){\r
- isNaturalOrderActivated = false;\r
- }\r
-\r
- if (isRankAndNameOrderActivated ||(!isNaturalOrderActivated && !isAlphabeticalOrderActivated)){\r
- PreferencesUtil.setSortNodesStrictlyAlphabetically(false);\r
- PreferencesUtil.setSortNodesNaturally(false);\r
- }\r
- isSelectionChanged = true;\r
- }else{\r
- isSelectionChanged = false;\r
- }\r
+ }\r
\r
- }\r
- });\r
\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ setApply(true);\r
\r
+ for (NavigatorOrderEnum item : NavigatorOrderEnum.values()){\r
+ if (!orderSelectionCombo.getText().startsWith(Messages.Preference_Use_Default)){\r
+ orderActivated = (NavigatorOrderEnum)orderSelectionCombo.getData(orderSelectionCombo.getText());\r
+ }else{\r
+ orderActivated = null;\r
+ }\r
\r
+ }\r
+ }\r
\r
\r
- final Label description = new Label(parent, SWT.NONE);\r
- description.setText(Messages.OrderPreferencePage_NewNavigatorWindowRequired);\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ // TODO Auto-generated method stub\r
\r
- return composite;\r
- }\r
+ }\r
\r
+ @Override\r
+ protected void performDefaults() {\r
+ if (!isAdminPreference) {\r
+ activateRestoreNavigatorButton.setSelection(false);\r
+ }\r
\r
- @Override\r
- public void init(IWorkbench workbench) {\r
- // TODO Auto-generated method stub\r
+ isRestoreTaxonNavigator = false;\r
+ orderActivated = null;\r
\r
- }\r
+ orderSelectionCombo.select(0);\r
\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.preference.PreferencePage#performOk()\r
- */\r
- @Override\r
- public boolean performOk() {\r
- if(isSelectionChanged){\r
- MessageDialog.openInformation(getShell(), null, Messages.OrderPreferencePage_PleaseReopenNavigator);\r
- isSelectionChanged = false;\r
- return super.performOk();\r
- }\r
- return true;\r
- }\r
+ super.performDefaults();\r
+ }\r
+\r
+ @Override\r
+ protected void getValues(){\r
+ orderPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.TaxonNodeOrder);\r
+ override = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()));\r
+ allowOverride = orderPref != null? orderPref.isAllowOverride():true;\r
+ if (orderPref == null || (allowOverride && override)) {\r
+ orderActivated = NavigatorOrderEnum.valueOf(PreferencesUtil.getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));\r
+ }else{\r
+ orderActivated = orderPref.getValue()!= null? NavigatorOrderEnum.valueOf(orderPref.getValue()):null;\r
+ }\r
\r
+ }\r
\r
}\r