3 * Copyright (C) 2017 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
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
;
27 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
28 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
35 public class FilterDialog
extends Dialog
{
37 List
<TermVocabulary
> vocabularies
= new ArrayList
<TermVocabulary
>();
39 List
<TermVocabulary
> selectedVocabularies
= new ArrayList
<TermVocabulary
>();
40 List
<TermVocabulary
> tempSelectedVocabularies
= new ArrayList
<TermVocabulary
>();
41 boolean performOk
= true;
48 protected FilterDialog(Shell parentShell
, Object preferenceId
, List
<TermVocabulary
> selectedVocabularies
, List
<TermVocabulary
> vocabularies
) {
50 this.vocabularies
= vocabularies
;
51 this.preferenceId
= preferenceId
;
52 this.selectedVocabularies
= selectedVocabularies
;
53 this.tempSelectedVocabularies
= new ArrayList();
54 this.tempSelectedVocabularies
.addAll(selectedVocabularies
);
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);
70 btnCheckButton
.setSelection(false);
73 btnCheckButton
.addSelectionListener(new SelectionListener(){
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);
85 if (tempSelectedVocabularies
.contains(btnCheckButton
.getData())){
86 tempSelectedVocabularies
.remove(btnCheckButton
.getData());
87 if (tempSelectedVocabularies
.isEmpty()) {
88 getButton(IDialogConstants
.OK_ID
).setEnabled(false);
96 public void widgetDefaultSelected(SelectionEvent e
) {
97 // TODO Auto-generated method stub
104 GridData gd_table
= new GridData(SWT
.CENTER
, SWT
.CENTER
, true, true, 2, 1);
105 gd_table
.heightHint
= 231;
106 gd_table
.widthHint
= 543;
113 protected void okPressed(){
115 for (TermVocabulary voc
: vocabularies
){
116 if (tempSelectedVocabularies
.contains(voc
)){
117 PreferencesUtil
.setBooleanValue(getPrefKey(voc
), false);
118 selectedVocabularies
.add(voc
);
120 PreferencesUtil
.setBooleanValue(getPrefKey(voc
), true);
121 selectedVocabularies
.remove(voc
);
127 private String
getPrefKey(TermVocabulary vocabulary
){
128 return "hide_"+NamedAreaSelectionDialog
.class.getCanonicalName()+vocabulary
.getUuid()+preferenceId
;