import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
import eu.etaxonomy.cdm.api.application.ICdmRepository;
import eu.etaxonomy.cdm.api.service.IPreferenceService;
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
import eu.etaxonomy.taxeditor.l10n.Messages;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
import eu.etaxonomy.taxeditor.store.CdmStore;
*
*/
public class SpecimenAdminPreferences extends CdmPreferencePage implements IE4AdminPreferencePage {
+ public SpecimenAdminPreferences() {
+ }
-
- boolean isShowCollectingAreaInGeneralSection = false;
- boolean isDeterminationOnlyForFieldUnits = false;
- boolean isShowTaxonAssociation = false;
- boolean isShowLifeForm = false;
- boolean isUseLocalPreference = false;
-
+ boolean isShowSpecimenRelatedIssues;
+ boolean isShowCollectingAreaInGeneralSection;
+ boolean isDeterminationOnlyForFieldUnits;
+ boolean isShowTaxonAssociation;
+ boolean isShowLifeForm;
+ boolean isUseLocalPreference;
+ Composite composite;
+ CdmPreference isShowSpecimenPref = null;
@Override
protected Control createContents(Composite parent) {
- Composite composite = new Composite(parent, SWT.NULL);
+
+ getValues();
+
+
+ final Button showSpecimenButton = new Button(parent, SWT.CHECK);
+
+ showSpecimenButton.setText(Messages.DatabasePreferncesPage_Show_Specimen);
+
+ showSpecimenButton.setSelection(isShowSpecimenRelatedIssues);
+ showSpecimenButton.addSelectionListener(new SelectionAdapter(){
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ isShowSpecimenRelatedIssues = showSpecimenButton.getSelection();
+ if(isShowSpecimenRelatedIssues){
+ composite.setVisible(true);
+ composite.setEnabled(true);
+ }else{
+ composite.setVisible(false);
+ composite.setEnabled(false);
+ }
+ }
+ });
+ composite = new Composite(parent, SWT.NULL);
GridLayout gridLayout = new GridLayout();
composite.setLayout(gridLayout);
+ composite.setEnabled(isShowSpecimenRelatedIssues);
+ Label separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
+ separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
final Button showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
@Override
public void widgetSelected(SelectionEvent e) {
isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
- }
+ }
});
final Button showTaxonAssociationButton = new Button(composite, SWT.CHECK);
@Override
public void widgetSelected(SelectionEvent e) {
isUseLocalPreference = useLocalPreference.getSelection();
-
+ PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SPECIMEN_ALLOW_OVERRIDE, isUseLocalPreference);
}
});
return composite;
if(!CdmStore.isActive()){
return;
}
- ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
- if (controller != null){
- IPreferenceService service = controller.getPreferenceService();
- PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
- CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
- if (isShowCollectingAreaInGeneralSectionPref != null){
- this.isShowCollectingAreaInGeneralSection = Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue());
- }
- key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
- CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
- if (isDeterminationOnlyForFieldUnitsPref != null){
- this.isDeterminationOnlyForFieldUnits = Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue());
- }
- key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowTaxonAssociations);
- CdmPreference isShowTaxonAssociationPref = service.find(key);
- if (isShowTaxonAssociationPref != null){
- this.isShowTaxonAssociation = Boolean.valueOf(isShowTaxonAssociationPref.getValue());
- isUseLocalPreference = isShowTaxonAssociationPref.isAllowOverride();
- }
- key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowLifeForm);
- CdmPreference isShowLifeFormPref = service.find(key);
- if (isShowLifeFormPref != null){
- this.isShowLifeForm = Boolean.valueOf(isShowLifeFormPref.getValue());
- }
+ }
+
+ private void getValues(){
+ ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
+ if (controller != null){
+ IPreferenceService service = controller.getPreferenceService();
+ PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
+ isShowSpecimenPref = service.find(key);
+ if (isShowSpecimenPref != null){
+ this.isShowSpecimenRelatedIssues = Boolean.valueOf(isShowSpecimenPref.getValue());
+ }else{
+ isShowSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(true));
+ this.isShowSpecimenRelatedIssues = true;
+ }
+
+
+ key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
+ CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
+ if (isShowCollectingAreaInGeneralSectionPref != null){
+ this.isShowCollectingAreaInGeneralSection = Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue());
+ }
+
+ key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
+ CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
+ if (isDeterminationOnlyForFieldUnitsPref != null){
+ this.isDeterminationOnlyForFieldUnits = Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue());
+ }
+ key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
+ CdmPreference isShowTaxonAssociationPref = service.find(key);
+ if (isShowTaxonAssociationPref != null){
+ this.isShowTaxonAssociation = Boolean.valueOf(isShowTaxonAssociationPref.getValue());
+ // isUseLocalPreference = isShowTaxonAssociationPref.isAllowOverride();
+ }
+
+ key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
+ CdmPreference isShowLifeFormPref = service.find(key);
+ if (isShowLifeFormPref != null){
+ this.isShowLifeForm = Boolean.valueOf(isShowLifeFormPref.getValue());
+ }
- }
+ }
}
@Override
public boolean performOk() {
+ if (isShowSpecimenPref == null){
+ return true;
+ }
+ ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
+ if (controller != null){
+ IPreferenceService service = controller.getPreferenceService();
+
+ CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, Boolean.toString(this.isShowCollectingAreaInGeneralSection));
+ pref.setAllowOverride(isUseLocalPreference);
+ service.set(pref);
+ pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(this.isShowSpecimenRelatedIssues));
+ pref.setAllowOverride(isUseLocalPreference);
+ service.set(pref);
+
+ pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, Boolean.toString(this.isDeterminationOnlyForFieldUnits));
+ pref.setAllowOverride(isUseLocalPreference);
+ service.set(pref);
+ pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, Boolean.toString(this.isShowTaxonAssociation));
+ pref.setAllowOverride(isUseLocalPreference);
+ service.set(pref);
+ pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, Boolean.toString(this.isShowLifeForm));
+ pref.setAllowOverride(isUseLocalPreference);
+ service.set(pref);
+ PreferencesUtil.updateDBPreferences();
+
+
+ }
return true;
}