Project

General

Profile

Download (4.64 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2017 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.ui.dialog.selection;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14

    
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.jface.dialogs.IDialogConstants;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.events.SelectionListener;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Shell;
26

    
27
import eu.etaxonomy.cdm.api.service.IVocabularyService;
28
import eu.etaxonomy.cdm.model.common.TermType;
29
import eu.etaxonomy.cdm.model.common.TermVocabulary;
30
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32

    
33
/**
34
 * @author k.luther
35
 * @date 21.11.2017
36
 *
37
 */
38
public class FilterDialog extends Dialog {
39

    
40
    List<TermVocabulary> vocabularies = new ArrayList<TermVocabulary>();
41

    
42
    List<TermVocabulary> selectedVocabularies = new ArrayList<TermVocabulary>();
43
    List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>();
44
    boolean performOk = true;
45

    
46
    Object preferenceId;
47

    
48
    /**
49
     * @param parentShell
50
     */
51
    protected FilterDialog(Shell parentShell, Object preferenceId, List<TermVocabulary> selectedVocabularies) {
52
        super(parentShell);
53
        vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
54
        this.preferenceId = preferenceId;
55
        this.selectedVocabularies = selectedVocabularies;
56
        this.tempSelectedVocabularies = new ArrayList();
57
        this.tempSelectedVocabularies.addAll(selectedVocabularies);
58
       
59
       
60
    }
61

    
62
    @Override
63
    protected Control createDialogArea(Composite parent) {
64
        Composite dialogArea = new Composite(parent, SWT.NULL);
65
        dialogArea.setLayout(new GridLayout(1, false));
66
        for (TermVocabulary voc: vocabularies){
67
            Button btnCheckButton = new Button(dialogArea, SWT.CHECK);
68
            btnCheckButton.setText(voc.getLabel());
69
            btnCheckButton.setData(voc);
70
            if (selectedVocabularies.contains(voc)){
71
                btnCheckButton.setSelection(true);
72
            }else {
73
                btnCheckButton.setSelection(false);
74
            }
75

    
76
            btnCheckButton.addSelectionListener(new SelectionListener(){
77

    
78
                @Override
79
                public void widgetSelected(SelectionEvent e) {
80
                   if (btnCheckButton.getSelection()){
81
                       if (!tempSelectedVocabularies.contains(btnCheckButton.getData())){
82
                    	   tempSelectedVocabularies.add((TermVocabulary)btnCheckButton.getData());
83
                    	   if (!tempSelectedVocabularies.isEmpty()) {
84
                    		   getButton(IDialogConstants.OK_ID).setEnabled(true);
85
                    	   }
86
                       }
87
                   }else{
88
                       if (tempSelectedVocabularies.contains(btnCheckButton.getData())){
89
                    	   tempSelectedVocabularies.remove(btnCheckButton.getData());
90
                    	   if (tempSelectedVocabularies.isEmpty()) {
91
                    		   getButton(IDialogConstants.OK_ID).setEnabled(false);
92
                    	   }
93
                       }
94
                   }
95

    
96
                }
97

    
98
                @Override
99
                public void widgetDefaultSelected(SelectionEvent e) {
100
                    // TODO Auto-generated method stub
101

    
102
                }
103

    
104
            });
105
        }
106

    
107
        GridData gd_table = new GridData(SWT.CENTER, SWT.CENTER, true, true, 2, 1);
108
        gd_table.heightHint = 231;
109
        gd_table.widthHint = 543;
110

    
111
        return dialogArea;
112

    
113
    }
114

    
115
    @Override
116
    protected void okPressed(){
117
    	
118
        for (TermVocabulary voc: vocabularies){
119
            if (tempSelectedVocabularies.contains(voc)){
120
                PreferencesUtil.getPreferenceStore().setValue(getPrefKey(voc), false);
121
                selectedVocabularies.add(voc);
122
            } else{
123
                PreferencesUtil.getPreferenceStore().setValue(getPrefKey(voc), true);
124
                selectedVocabularies.remove(voc);
125
            }
126
        }
127
        super.okPressed();
128
    }
129
    
130
    private String getPrefKey(TermVocabulary vocabulary){
131
        return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceId;
132
    }
133

    
134
}
(15-15/42)