import eu.etaxonomy.cdm.api.application.ICdmRepository;
import eu.etaxonomy.cdm.api.service.IPreferenceService;
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
-import eu.etaxonomy.taxeditor.l10n.Messages;
+import eu.etaxonomy.cdm.model.metadata.DistributionDescription;
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
+import eu.etaxonomy.cdm.model.metadata.TermComboEnum;
+import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
+import eu.etaxonomy.cdm.model.metadata.TermOrder;
import eu.etaxonomy.taxeditor.preference.ChecklistEditorGeneralPreference;
-import eu.etaxonomy.taxeditor.preference.EditorPreferencePredicate;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
*/
public class ChecklistEditorGeneralAdminPreference extends ChecklistEditorGeneralPreference implements IE4AdminPreferencePage {
+ Composite parent;
+
@Override
protected Control createContents(Composite parent) {
+ this.parent = parent;
return super.createContents(parent);
}
@Override
public boolean performOk() {
- if (!isValid()){
+ if (!isApply()){
return true;
}
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
return false;
}
IPreferenceService service = controller.getPreferenceService();
+ CdmPreference pref;
+ if (isEditorActivated == null && allowOverrideActivatedButton.getSelection()){
+ service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DistributionEditorActivated));
+ }else{
+ pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DistributionEditorActivated, isEditorActivated != null? Boolean.toString(isEditorActivated): null);
+ pref.setAllowOverride(allowOverrideActivatedButton.getSelection());
+ service.set(pref);
+ }
+ if(displayArea == null && allowOverrideAreaDisplayButton.getSelection()){
+ service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfAreasInDistributionEditor));
+ }else{
+ pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfAreasInDistributionEditor, displayArea != null ?this.displayArea.getKey(): null);
+ pref.setAllowOverride(allowOverrideAreaDisplayButton.getSelection());
+ service.set(pref);
+ }
- CdmPreference pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.DistributionEditorActivated, Boolean.toString(isEditorActivated));
- pref.setAllowOverride(this.allowOverrideActivated);
- service.set(pref);
+ if (displayStatus == null && allowOverrideStatusDisplayButton.getSelection()){
+ service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfStatus));
+ }else{
+ pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfStatus, displayStatus != null? this.displayStatus.getKey(): null);
+ pref.setAllowOverride(allowOverrideStatusDisplayButton.getSelection());
+ service.set(pref);
+ }
- pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.DisplayOfAreasInDistributionEditor, this.displayArea);
- pref.setAllowOverride(this.allowOverrideAreaDisplay);
- service.set(pref);
+ if (isShowRank == null && allowOverrideRankButton.getSelection()){
+ service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowRankInDistributionEditor));
+ }else{
+ pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.ShowRankInDistributionEditor, isShowRank != null? Boolean.toString(isShowRank): null);
+ pref.setAllowOverride(allowOverrideRankButton.getSelection());
+ service.set(pref);
+ }
+ if (orderAreas == null && allowOverrideOrderAreasButton.getSelection()){
+ service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AreasSortedInDistributionEditor));
+ }else{
+ pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.AreasSortedInDistributionEditor, orderAreas != null? this.orderAreas.getKey(): null);
+ pref.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
+ service.set(pref);
+ }
- pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.DisplayOfStatus, this.displayStatus);
- pref.setAllowOverride(this.allowOverrideStatusDisplay);
- service.set(pref);
+ if (orderStatus == null && allowOverrideStatusSortButton.getSelection()){
+ service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.StatusSortedInDistributionEditor));
+ }else{
+ pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.StatusSortedInDistributionEditor, orderStatus != null? this.orderStatus.getKey(): null);
+ pref.setAllowOverride(allowOverrideStatusSortButton.getSelection());
+ service.set(pref);
+ }
- pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.ShowRankInDistributionEditor, Boolean.toString(isShowRank));
- pref.setAllowOverride(this.allowOverrideRank);
- service.set(pref);
- pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.AreasSortedByIdInVocabulary, Boolean.toString(isSortByVocabularyOrder));
- pref.setAllowOverride(this.allowOverrideOrderAreas);
- service.set(pref);
+ if (displayStatusCombo == null && allowOverrideStatusDisplayInComboButton.getSelection()){
+ service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfStatusInCombo));
+ }else{
+ pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfStatusInCombo, displayStatusCombo != null? displayStatusCombo.getKey(): null);
+ if (prefStatusDisplayInCombo == null){
+ prefStatusDisplayInCombo = pref;
+ }
+ pref.setAllowOverride(prefStatusDisplayInCombo.isAllowOverride());
+ service.set(pref);
+ }
- pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.OwnDescriptionForDistributionEditor, Boolean.toString(ownDescriptionForDistributionEditor));
- pref.setAllowOverride(this.allowOverrideOwnDescriptionForDistributionEditor);
- service.set(pref);
+ if (numberOfStatus == null && allowOverrideNumberOfStatusButton.getSelection()){
+ service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NumberOfVisibleStatusInDropDown));
+ }else{
+ pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.NumberOfVisibleStatusInDropDown, numberOfStatus != null? numberOfStatus.toString(): null);
+ if (prefNumberStatus == null){
+ prefNumberStatus = pref;
+ }
+ pref.setAllowOverride(prefNumberStatus.isAllowOverride());
+ service.set(pref);
+ }
+
+ if (descriptionForDistributionEditor == null && allowOverrideDescriptionSelectionButton.getSelection()){
+ service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DescriptionForDistributionEditor));
+ }else{
+ pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DescriptionForDistributionEditor, descriptionForDistributionEditor != null? descriptionForDistributionEditor.getKey(): null);
+ if (prefDescription == null){
+ prefDescription = pref;
+ }
+ pref.setAllowOverride(prefDescription.isAllowOverride());
+ service.set(pref);
+ }
PreferencesUtil.updateDBPreferences();
@Override
public void getValues() {
-
- distributionEditorPref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.DistributionEditorActivated);
- if (distributionEditorPref == null){
- distributionEditorPref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.DistributionEditorActivated, EditorPreferencePredicate.DistributionEditorActivated.getDefaultValue().toString());
+ super.getValues();
+ distributionEditorPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
+ if (distributionEditorPref != null){
+ isEditorActivated = distributionEditorPref.getValue() != null? Boolean.valueOf(distributionEditorPref.getValue()): null;
+ }else{
+ isEditorActivated = null;
}
- isEditorActivated = Boolean.valueOf(distributionEditorPref.getValue());
- allowOverrideActivated = distributionEditorPref.isAllowOverride();
+
+
isAdminPreference = true;
- CdmPreference pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor);
- if (pref != null){
- this.displayArea = pref.getValue();
- this.allowOverrideAreaDisplay = pref.isAllowOverride();
+ if (prefAreaDisplay != null){
+ this.displayArea = prefAreaDisplay.getValue()!= null?TermDisplayEnum.byKey(prefAreaDisplay.getValue()): null;
}else{
- this.displayArea = EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString();
- this.allowOverrideAreaDisplay = true;
+ this.displayArea = null;
}
- pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.DisplayOfStatus);
- if (pref != null){
- this.displayStatus = pref.getValue();
- this.allowOverrideStatusDisplay = pref.isAllowOverride();
+
+ if (prefStatusDisplay != null){
+ this.displayStatus = prefStatusDisplay.getValue() != null? TermDisplayEnum.byKey(prefStatusDisplay.getValue()): null;
+ }else{
+ this.displayStatus = null;
+ }
+
+ if (prefStatusDisplayInCombo != null){
+ this.displayStatusCombo = prefStatusDisplayInCombo.getValue() != null? TermComboEnum.byKey(prefStatusDisplayInCombo.getValue()): null;
+ }else{
+ this.displayStatusCombo = null;
+ }
+
+
+ if (prefAreaSort != null){
+ if (prefAreaSort.getValue() != null){
+ this.orderAreas = prefAreaSort.getValue() != null? TermOrder.valueOf(prefAreaSort.getValue().toString()): null;
+ }else{
+ this.orderAreas = null;
+ }
+
+ }else{
+ this.orderAreas = null;
+
+ }
+
+ if (prefStatusSort != null){
+ if (prefStatusSort.getValue() != null){
+ this.orderStatus = prefStatusSort.getValue() != null? TermOrder.valueOf(prefStatusSort.getValue().toString()): null;
+ }else{
+ this.orderStatus = null;
+ }
+
}else{
- this.displayStatus = EditorPreferencePredicate.DisplayOfStatus.getDefaultValue().toString();
- this.allowOverrideStatusDisplay = true;
+ this.orderStatus = null;
+
}
- pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.AreasSortedByIdInVocabulary);
- if (pref != null){
- this.isSortByVocabularyOrder = Boolean.valueOf(pref.getValue().toString());
- this.allowOverrideOrderAreas = pref.isAllowOverride();
+
+ if (prefRank != null){
+ this.isShowRank = prefRank.getValue() != null?Boolean.valueOf(prefRank.getValue().toString()): null;
+
}else{
- this.isSortByVocabularyOrder = Boolean.valueOf(EditorPreferencePredicate.AreasSortedByIdInVocabulary.getDefaultValue().toString());
- this.allowOverrideOrderAreas = true;
+ this.isShowRank = null;
}
- pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.ShowRankInDistributionEditor);
- if (pref != null){
- this.isShowRank = Boolean.valueOf(pref.getValue().toString());
- this.allowOverrideRank = pref.isAllowOverride();
+ if (prefNumberStatus != null){
+ this.numberOfStatus = prefNumberStatus.getValue() != null?Integer.valueOf(prefNumberStatus.getValue().toString()): null;
+
}else{
- this.isShowRank = Boolean.valueOf(EditorPreferencePredicate.ShowRankInDistributionEditor.getDefaultValue().toString());
- this.allowOverrideRank = true;
+ this.numberOfStatus = null;
}
- pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.OwnDescriptionForDistributionEditor);
- if (pref != null){
- this.ownDescriptionForDistributionEditor = Boolean.valueOf(pref.getValue().toString());
- this.allowOverrideOwnDescriptionForDistributionEditor= pref.isAllowOverride();
+ if (prefDescription != null){
+ this.descriptionForDistributionEditor = prefDescription.getValue() != null? DistributionDescription.byKey(prefDescription.getValue().toString()): null;
}else{
- this.ownDescriptionForDistributionEditor = Boolean.valueOf(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString());
- this.allowOverrideOwnDescriptionForDistributionEditor = true;
+ this.descriptionForDistributionEditor = null;
}
- commandHandlerString = "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardAdminHandler";
- commandHandlerStringStatus = "eu.etaxonomy.taxeditor.store.open.OpenDistributionStatusWizardAdminHandler";
- overrideString = Messages.GeneralPreference_allowOverride;
+
+
setValid(false);
}
+
+
}