Project

General

Profile

Download (4.02 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.swt.SWT;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.events.SelectionListener;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.widgets.Shell;
25

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

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

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

    
41
    List<TermVocabulary> selectedVocabularies = new ArrayList<TermVocabulary>();
42

    
43
    Object preferenceId;
44

    
45
    /**
46
     * @param parentShell
47
     */
48
    protected FilterDialog(Shell parentShell, Object preferenceId, List<TermVocabulary> selectedVocabularies) {
49
        super(parentShell);
50
        vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
51
        this.preferenceId = preferenceId;
52
        List<TermVocabulary> tempSelectedVocabularies = new ArrayList<>();
53
        this.selectedVocabularies = selectedVocabularies;
54

    
55
    }
56

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

    
71
            btnCheckButton.addSelectionListener(new SelectionListener(){
72

    
73
                @Override
74
                public void widgetSelected(SelectionEvent e) {
75
                   if (btnCheckButton.getSelection()){
76
                       Object obj = btnCheckButton.getData();
77
                       if (!selectedVocabularies.contains(btnCheckButton.getData())){
78
                           selectedVocabularies.add((TermVocabulary)btnCheckButton.getData());
79
                       }
80
                   }else{
81
                       if (selectedVocabularies.contains(btnCheckButton.getData())){
82
                           selectedVocabularies.remove(btnCheckButton.getData());
83
                       }
84
                   }
85

    
86
                }
87

    
88
                @Override
89
                public void widgetDefaultSelected(SelectionEvent e) {
90
                    // TODO Auto-generated method stub
91

    
92
                }
93

    
94
            });
95
        }
96

    
97
        GridData gd_table = new GridData(SWT.CENTER, SWT.CENTER, true, true, 2, 1);
98
        gd_table.heightHint = 231;
99
        gd_table.widthHint = 543;
100

    
101
        return dialogArea;
102

    
103
    }
104

    
105
    @Override
106
    protected void okPressed(){
107
        for (TermVocabulary voc: vocabularies){
108
            if (selectedVocabularies.contains(voc)){
109
                PreferencesUtil.getPreferenceStore().setValue(getPrefKey(voc), false);
110
            } else{
111
                PreferencesUtil.getPreferenceStore().setValue(getPrefKey(voc), true);
112
            }
113
        }
114
        super.okPressed();
115
    }
116

    
117
    private String getPrefKey(TermVocabulary vocabulary){
118
        return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceId;
119
    }
120

    
121
}
(14-14/39)