package eu.etaxonomy.taxeditor.preference;\r
\r
-import java.io.IOException;\r
-\r
import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.jface.preference.PreferencePage;\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.events.SelectionAdapter;\r
import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.layout.GridData;\r
import org.eclipse.swt.layout.GridLayout;\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
-import org.eclipse.ui.PlatformUI;\r
\r
-import eu.etaxonomy.taxeditor.Messages;\r
+import eu.etaxonomy.taxeditor.l10n.Messages;\r
+import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;\r
+\r
+public class OrderPreferences extends CdmPreferencePage implements SelectionListener{\r
\r
-public class OrderPreferences extends PreferencePage implements IWorkbenchPreferencePage {\r
- \r
\r
- boolean isNaturalOrderActivated;\r
+ NavigatorOrderEnum orderActivated;\r
+ private Combo orderSelectionCombo;\r
+ boolean isRestoreTaxonNavigator;\r
boolean isSelectionChanged = false;\r
- /*\r
- * (non-Javadoc)\r
- *\r
- * @see\r
- * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors\r
- * ()\r
- */\r
+ boolean isStrictlyAlphabeticallyOrdered;\r
+ Button activateRestoreNavigatorButton;\r
+\r
@Override\r
protected Control createContents(Composite parent) {\r
\r
- Composite composite = new Composite(parent, SWT.NULL);\r
+ isRestoreTaxonNavigator = PreferencesUtil.isStoreNavigatorState();\r
+\r
+ Composite secondComposite = new Composite(parent, SWT.NULL);\r
+ secondComposite.setLayout(new GridLayout());\r
+\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
- final Label description = new Label(parent, SWT.NONE);\r
- description.setText(Messages.OrderPreferencePage_NewNavigatorWindowRequired);\r
- isNaturalOrderActivated = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SORT_NODES_NATURALLY);\r
- final Button activateCheckButton = new Button(composite, SWT.CHECK);\r
- activateCheckButton.setText("Enable Natural Order");\r
- activateCheckButton.setSelection(isNaturalOrderActivated);\r
- activateCheckButton.addSelectionListener(new SelectionAdapter(){\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if(isNaturalOrderActivated != activateCheckButton.getSelection()) {\r
- isNaturalOrderActivated = activateCheckButton.getSelection();\r
- PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SORT_NODES_NATURALLY, isNaturalOrderActivated);\r
- isSelectionChanged = true;\r
- }else{\r
- isSelectionChanged = false;\r
+\r
+ Label label = new Label(composite, SWT.NONE);\r
+ label.setText(Messages.OrderPreferences_Sorting);\r
+\r
+ GridData gridData = new GridData();\r
+ gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);\r
+ gridData.horizontalIndent = 5;\r
+\r
+ orderSelectionCombo = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);\r
+ orderSelectionCombo.setLayoutData(gridData);\r
+\r
+ for(NavigatorOrderEnum display: NavigatorOrderEnum.values()){\r
+ orderSelectionCombo.add(display.getLabel());\r
+ }\r
+\r
+ int index = 0;\r
+ if (PreferencesUtil.getStringValue(IPreferenceKeys.SORT_NODES) != null){\r
+ this.orderActivated = NavigatorOrderEnum.valueOf(PreferencesUtil.getStringValue(IPreferenceKeys.SORT_NODES));\r
+\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
- });\r
+ // TODO remember last selection\r
+ orderSelectionCombo.addSelectionListener(this);\r
\r
- \r
+ final Label description = new Label(parent, SWT.NONE);\r
+ description.setText(Messages.OrderPreferencePage_NewNavigatorWindowRequired);\r
\r
return composite;\r
}\r
\r
- \r
- @Override\r
- public void init(IWorkbench workbench) {\r
- // TODO Auto-generated method stub\r
- \r
- }\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
+ if (this.orderActivated != null){\r
+ PreferencesUtil.setSortNodes(this.orderActivated);\r
+ PreferencesUtil.setStoreNavigatorState(isRestoreTaxonNavigator);\r
+ MessageDialog.openInformation(getShell(), null, Messages.OrderPreferencePage_PleaseReopenNavigator);\r
+ }\r
return super.performOk();\r
- }\r
- return true;\r
+\r
}\r
\r
\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ setApply(true);\r
+ isSelectionChanged = true;\r
+ for (NavigatorOrderEnum item : NavigatorOrderEnum.values()){\r
+ if (item.getLabel().equalsIgnoreCase(orderSelectionCombo.getText())){\r
+ this.orderActivated = item;\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ @Override\r
+ protected void performDefaults() {\r
+ activateRestoreNavigatorButton.setSelection(false);\r
+ isRestoreTaxonNavigator = false;\r
+ orderActivated = NavigatorOrderEnum.RankAndNameOrder;\r
+ int index = 0;\r
+ for (String itemLabel : orderSelectionCombo.getItems()){\r
+ if (itemLabel.equalsIgnoreCase(orderActivated.getLabel())){\r
+ orderSelectionCombo.select(index);\r
+ break;\r
+ }\r
+ index++;\r
+ }\r
+ super.performDefaults();\r
+ }\r
+\r
+\r
}\r