fix #8034: preselected references should have correct type
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / FilterDialog.java
index eb402edf13e24ced5970887d377c8260a0ab961f..bfbc457ff3c5021bfe84e7a475ecc8890f4a128a 100644 (file)
@@ -13,6 +13,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
@@ -23,11 +24,8 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 
-import eu.etaxonomy.cdm.api.service.IVocabularyService;
-import eu.etaxonomy.cdm.model.common.TermType;
-import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * @author k.luther
@@ -39,18 +37,22 @@ public class FilterDialog extends Dialog {
     List<TermVocabulary> vocabularies = new ArrayList<TermVocabulary>();
 
     List<TermVocabulary> selectedVocabularies = new ArrayList<TermVocabulary>();
+    List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>();
+    boolean performOk = true;
 
     Object preferenceId;
 
     /**
      * @param parentShell
      */
-    protected FilterDialog(Shell parentShell, Object preferenceId, List<TermVocabulary> selectedVocabularies) {
+    protected FilterDialog(Shell parentShell, Object preferenceId, List<TermVocabulary> selectedVocabularies, List<TermVocabulary> vocabularies) {
         super(parentShell);
-        vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
+        this.vocabularies = vocabularies;
         this.preferenceId = preferenceId;
-        List<TermVocabulary> tempSelectedVocabularies = new ArrayList<>();
         this.selectedVocabularies = selectedVocabularies;
+        this.tempSelectedVocabularies = new ArrayList();
+        this.tempSelectedVocabularies.addAll(selectedVocabularies);
+
 
     }
 
@@ -73,13 +75,18 @@ public class FilterDialog extends Dialog {
                 @Override
                 public void widgetSelected(SelectionEvent e) {
                    if (btnCheckButton.getSelection()){
-                       Object obj = btnCheckButton.getData();
-                       if (!selectedVocabularies.contains(btnCheckButton.getData())){
-                           selectedVocabularies.add((TermVocabulary)btnCheckButton.getData());
+                       if (!tempSelectedVocabularies.contains(btnCheckButton.getData())){
+                          tempSelectedVocabularies.add((TermVocabulary)btnCheckButton.getData());
+                          if (!tempSelectedVocabularies.isEmpty()) {
+                                  getButton(IDialogConstants.OK_ID).setEnabled(true);
+                          }
                        }
                    }else{
-                       if (selectedVocabularies.contains(btnCheckButton.getData())){
-                           selectedVocabularies.remove(btnCheckButton.getData());
+                       if (tempSelectedVocabularies.contains(btnCheckButton.getData())){
+                          tempSelectedVocabularies.remove(btnCheckButton.getData());
+                          if (tempSelectedVocabularies.isEmpty()) {
+                                  getButton(IDialogConstants.OK_ID).setEnabled(false);
+                          }
                        }
                    }
 
@@ -104,11 +111,14 @@ public class FilterDialog extends Dialog {
 
     @Override
     protected void okPressed(){
+
         for (TermVocabulary voc: vocabularies){
-            if (selectedVocabularies.contains(voc)){
-                PreferencesUtil.getPreferenceStore().setValue(getPrefKey(voc), false);
+            if (tempSelectedVocabularies.contains(voc)){
+                PreferencesUtil.setBooleanValue(getPrefKey(voc), false);
+                selectedVocabularies.add(voc);
             } else{
-                PreferencesUtil.getPreferenceStore().setValue(getPrefKey(voc), true);
+                PreferencesUtil.setBooleanValue(getPrefKey(voc), true);
+                selectedVocabularies.remove(voc);
             }
         }
         super.okPressed();