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;
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
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);
+
}
@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);
+ }
}
}
@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();