package eu.etaxonomy.taxeditor.preference;\r
\r
-import org.apache.commons.lang.StringUtils;\r
import org.eclipse.jface.dialogs.MessageDialog;\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.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
\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
public class OrderPreferences extends CdmPreferencePage implements SelectionListener{\r
\r
\r
- NavigatorOrderEnum orderActivated;\r
+ protected NavigatorOrderEnum orderActivated;\r
private Combo orderSelectionCombo;\r
boolean isRestoreTaxonNavigator;\r
- boolean isSelectionChanged = false;\r
- boolean isStrictlyAlphabeticallyOrdered;\r
- Button activateRestoreNavigatorButton;\r
-\r
- @Override\r
- protected Control createContents(Composite parent) {\r
-\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
+ Button activateRestoreNavigatorButton;\r
+ protected Button allowOverrideButton;\r
+ protected CdmPreference orderPref;\r
+ protected CdmPreference nodePref;\r
+ boolean override = false;\r
+ protected boolean allowOverride;\r
\r
+ protected Combo showTaxonNodeWizardButton;\r
+ protected Button allowOverrideShowTaxonNodeWizardButton;\r
+ protected boolean isOverrideShowTaxonNodeWizard;\r
+ protected boolean isAllowOverrideShowTaxonNodeWizard;\r
+ protected Boolean isShowTaxonNodeWizard;\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
- GridData gridData = new GridData();\r
- gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);\r
- gridData.horizontalIndent = 5;\r
+ @Override\r
+ protected Control createContents(Composite parent) {\r
\r
- orderSelectionCombo = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);\r
- orderSelectionCombo.setLayoutData(gridData);\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
- for(NavigatorOrderEnum display: NavigatorOrderEnum.values()){\r
- orderSelectionCombo.add(display.getLabel());\r
+ });\r
}\r
\r
- int index = 0;\r
+ orderSelectionCombo = createCombo(secondComposite, NavigatorOrderEnum.values(), PreferencePredicate.TaxonNodeOrder, Messages.OrderPreferences_Sorting, isAdminPreference);\r
\r
- if (!StringUtils.isBlank(PreferencesUtil.getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()))){\r
- this.orderActivated = NavigatorOrderEnum.valueOf(PreferencesUtil.getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));\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
}\r
}\r
\r
- // TODO remember last selection\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
+ showTaxonNodeWizardButton = createBooleanCombo(secondComposite, SHOW, DO_NOT_SHOW, PreferencePredicate.ShowTaxonNodeWizard, "Show Taxonnode Wizard",\r
+ isAdminPreference);\r
+ showTaxonNodeWizardButton.setText(Messages.DatabasePreferncesPage_Show_TaxonNodeWizard);\r
+ showTaxonNodeWizardButton.addSelectionListener(this);\r
+\r
+\r
+ if (isAdminPreference){\r
+ allowOverrideShowTaxonNodeWizardButton = createAllowOverrideButton(secondComposite);\r
+ allowOverrideShowTaxonNodeWizardButton.addSelectionListener(new SelectionAdapter(){\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ isAllowOverrideShowTaxonNodeWizard = allowOverrideShowTaxonNodeWizardButton.getSelection();\r
+ setApply(true);\r
+ }\r
+ });\r
+ allowOverrideShowTaxonNodeWizardButton.setSelection(isAllowOverrideShowTaxonNodeWizard);\r
+ }else{\r
+ if (!isAllowOverrideShowTaxonNodeWizard){\r
+ showTaxonNodeWizardButton.setEnabled(false);\r
+\r
+ }\r
+ }\r
\r
- final Label description = new Label(parent, SWT.NONE);\r
- description.setText(Messages.OrderPreferencePage_NewNavigatorWindowRequired);\r
+ if (isShowTaxonNodeWizard == null || (!isOverrideShowTaxonNodeWizard && !isAdminPreference)){\r
+ showTaxonNodeWizardButton.select(0);\r
+ }else{\r
+ if (isShowTaxonNodeWizard){\r
+ showTaxonNodeWizardButton.select(1);\r
+ }else{\r
+ showTaxonNodeWizardButton.select(2);\r
+ }\r
+ }\r
\r
- return composite;\r
+ return secondComposite;\r
}\r
\r
\r
public boolean performOk() {\r
if (isApply()){\r
PreferencesUtil.setSortNodes(this.orderActivated);\r
- PreferencesUtil.setStoreNavigatorState(isRestoreTaxonNavigator);\r
- MessageDialog.openInformation(getShell(), null, Messages.OrderPreferencePage_PleaseReopenNavigator);\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
+\r
+\r
+ if (isAllowOverrideShowTaxonNodeWizard){\r
+ if (isShowTaxonNodeWizard != null){\r
+ PreferencesUtil.setBooleanValue(PreferencePredicate.ShowTaxonNodeWizard.getKey(), isShowTaxonNodeWizard);\r
+ }\r
+ PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonNodeWizard.getKey()), isOverrideShowTaxonNodeWizard);\r
+ }\r
+\r
}\r
- return super.performOk();\r
+ return true;\r
\r
}\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
+ if (e.getSource().equals(orderSelectionCombo)){\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
+ MessageDialog.openInformation(getShell(), null, Messages.OrderPreferencePage_PleaseReopenNavigator);\r
+ }\r
+ if (e.getSource().equals(this.showTaxonNodeWizardButton)) {\r
+ String text = showTaxonNodeWizardButton.getText();\r
+ if (text.startsWith(Messages.Preference_Use_Default)){\r
+ isOverrideShowTaxonNodeWizard = false;\r
+ isShowTaxonNodeWizard = null;\r
+\r
+ }else if (text.equals(SHOW)){\r
+ isShowTaxonNodeWizard = true;\r
+ isOverrideShowTaxonNodeWizard = true;\r
+ }else{\r
+ isShowTaxonNodeWizard = false;\r
+ isOverrideShowTaxonNodeWizard = true;\r
}\r
+\r
}\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
+ if (!isAdminPreference) {\r
+ activateRestoreNavigatorButton.setSelection(false);\r
}\r
+\r
+ isRestoreTaxonNavigator = false;\r
+ orderActivated = null;\r
+\r
+ orderSelectionCombo.select(0);\r
+ isOverrideShowTaxonNodeWizard = false;\r
+ isShowTaxonNodeWizard = null;\r
+ showTaxonNodeWizardButton.select(0);\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 ){\r
+ if (override){\r
+ orderActivated = NavigatorOrderEnum.valueOf(PreferencesUtil.getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));\r
+ }\r
+ }else{\r
+ orderActivated = orderPref.getValue()!= null? NavigatorOrderEnum.valueOf(orderPref.getValue()):null;\r
+ }\r
+\r
+ isOverrideShowTaxonNodeWizard = PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonNodeWizard.getKey()), true) != null? PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonNodeWizard.getKey()), true): false;\r
+ if (isOverrideShowTaxonNodeWizard){\r
+ isShowTaxonNodeWizard = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonNodeWizard.getKey(), true);\r
+ }\r
+\r
+\r
+ nodePref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowTaxonNodeWizard);\r
+ if (nodePref != null){\r
+ isAllowOverrideShowTaxonNodeWizard = nodePref.isAllowOverride();\r
+ }else{\r
+ isAllowOverrideShowTaxonNodeWizard = true;\r
+ }\r
+\r
+ }\r
\r
}\r