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.model.term.TermVocabulary;
|
28
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
29
|
|
30
|
/**
|
31
|
* @author k.luther
|
32
|
* @date 21.11.2017
|
33
|
*
|
34
|
*/
|
35
|
public class FilterDialog extends Dialog {
|
36
|
|
37
|
List<TermVocabulary> vocabularies = new ArrayList<TermVocabulary>();
|
38
|
|
39
|
List<TermVocabulary> selectedVocabularies = new ArrayList<TermVocabulary>();
|
40
|
List<TermVocabulary> tempSelectedVocabularies = new ArrayList<TermVocabulary>();
|
41
|
boolean performOk = true;
|
42
|
|
43
|
Object preferenceId;
|
44
|
|
45
|
/**
|
46
|
* @param parentShell
|
47
|
*/
|
48
|
protected FilterDialog(Shell parentShell, Object preferenceId, List<TermVocabulary> selectedVocabularies, List<TermVocabulary> vocabularies) {
|
49
|
super(parentShell);
|
50
|
this.vocabularies = vocabularies;
|
51
|
this.preferenceId = preferenceId;
|
52
|
this.selectedVocabularies = selectedVocabularies;
|
53
|
this.tempSelectedVocabularies = new ArrayList();
|
54
|
this.tempSelectedVocabularies.addAll(selectedVocabularies);
|
55
|
|
56
|
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
protected Control createDialogArea(Composite parent) {
|
61
|
Composite dialogArea = new Composite(parent, SWT.NULL);
|
62
|
dialogArea.setLayout(new GridLayout(1, false));
|
63
|
for (TermVocabulary voc: vocabularies){
|
64
|
Button btnCheckButton = new Button(dialogArea, SWT.CHECK);
|
65
|
btnCheckButton.setText(voc.getLabel());
|
66
|
btnCheckButton.setData(voc);
|
67
|
if (selectedVocabularies.contains(voc)){
|
68
|
btnCheckButton.setSelection(true);
|
69
|
}else {
|
70
|
btnCheckButton.setSelection(false);
|
71
|
}
|
72
|
|
73
|
btnCheckButton.addSelectionListener(new SelectionListener(){
|
74
|
|
75
|
@Override
|
76
|
public void widgetSelected(SelectionEvent e) {
|
77
|
if (btnCheckButton.getSelection()){
|
78
|
if (!tempSelectedVocabularies.contains(btnCheckButton.getData())){
|
79
|
tempSelectedVocabularies.add((TermVocabulary)btnCheckButton.getData());
|
80
|
if (!tempSelectedVocabularies.isEmpty()) {
|
81
|
getButton(IDialogConstants.OK_ID).setEnabled(true);
|
82
|
}
|
83
|
}
|
84
|
}else{
|
85
|
if (tempSelectedVocabularies.contains(btnCheckButton.getData())){
|
86
|
tempSelectedVocabularies.remove(btnCheckButton.getData());
|
87
|
if (tempSelectedVocabularies.isEmpty()) {
|
88
|
getButton(IDialogConstants.OK_ID).setEnabled(false);
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
public void widgetDefaultSelected(SelectionEvent e) {
|
97
|
// TODO Auto-generated method stub
|
98
|
|
99
|
}
|
100
|
|
101
|
});
|
102
|
}
|
103
|
|
104
|
GridData gd_table = new GridData(SWT.CENTER, SWT.CENTER, true, true, 2, 1);
|
105
|
gd_table.heightHint = 231;
|
106
|
gd_table.widthHint = 543;
|
107
|
|
108
|
return dialogArea;
|
109
|
|
110
|
}
|
111
|
|
112
|
@Override
|
113
|
protected void okPressed(){
|
114
|
|
115
|
for (TermVocabulary voc: vocabularies){
|
116
|
if (tempSelectedVocabularies.contains(voc)){
|
117
|
PreferencesUtil.setBooleanValue(getPrefKey(voc), false);
|
118
|
selectedVocabularies.add(voc);
|
119
|
} else{
|
120
|
PreferencesUtil.setBooleanValue(getPrefKey(voc), true);
|
121
|
selectedVocabularies.remove(voc);
|
122
|
}
|
123
|
}
|
124
|
super.okPressed();
|
125
|
}
|
126
|
|
127
|
private String getPrefKey(TermVocabulary vocabulary){
|
128
|
return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceId;
|
129
|
}
|
130
|
|
131
|
}
|