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
.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
;
38 public class FilterDialog
extends Dialog
{
40 List
<TermVocabulary
> vocabularies
= new ArrayList
<TermVocabulary
>();
42 List
<TermVocabulary
> selectedVocabularies
= new ArrayList
<TermVocabulary
>();
43 List
<TermVocabulary
> tempSelectedVocabularies
= new ArrayList
<TermVocabulary
>();
44 boolean performOk
= true;
51 protected FilterDialog(Shell parentShell
, Object preferenceId
, List
<TermVocabulary
> selectedVocabularies
) {
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
);
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);
73 btnCheckButton
.setSelection(false);
76 btnCheckButton
.addSelectionListener(new SelectionListener(){
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);
88 if (tempSelectedVocabularies
.contains(btnCheckButton
.getData())){
89 tempSelectedVocabularies
.remove(btnCheckButton
.getData());
90 if (tempSelectedVocabularies
.isEmpty()) {
91 getButton(IDialogConstants
.OK_ID
).setEnabled(false);
99 public void widgetDefaultSelected(SelectionEvent e
) {
100 // TODO Auto-generated method stub
107 GridData gd_table
= new GridData(SWT
.CENTER
, SWT
.CENTER
, true, true, 2, 1);
108 gd_table
.heightHint
= 231;
109 gd_table
.widthHint
= 543;
116 protected void okPressed(){
118 for (TermVocabulary voc
: vocabularies
){
119 if (tempSelectedVocabularies
.contains(voc
)){
120 PreferencesUtil
.getPreferenceStore().setValue(getPrefKey(voc
), false);
121 selectedVocabularies
.add(voc
);
123 PreferencesUtil
.getPreferenceStore().setValue(getPrefKey(voc
), true);
124 selectedVocabularies
.remove(voc
);
130 private String
getPrefKey(TermVocabulary vocabulary
){
131 return "hide_"+NamedAreaSelectionDialog
.class.getCanonicalName()+vocabulary
.getUuid()+preferenceId
;