2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import org
.apache
.commons
.lang
.StringUtils
;
16 import org
.eclipse
.swt
.widgets
.Shell
;
18 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
19 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
20 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
21 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
24 import eu
.etaxonomy
.taxeditor
.preference
.CdmPreferenceCache
;
25 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
33 public class CommonNameNamedAreaSelectionDialog
extends NamedAreaSelectionDialog
{
41 * @param preselectedVocabularyUuids
43 protected CommonNameNamedAreaSelectionDialog(Shell shell
, String title
, boolean multi
, NamedArea namedArea
,
44 Object preferenceId
) {
45 super(shell
, title
, multi
, namedArea
, preferenceId
, createVocabularyUuidList());
50 private static UUID
[] createVocabularyUuidList() {
51 String preselectedVocString
= PreferencesUtil
.getStringValue(PreferencePredicate
.CommonNameAreaVocabularies
.getKey());
52 if (StringUtils
.isBlank(preselectedVocString
)){
55 String
[] preselectedVocArray
= preselectedVocString
.split(";");
56 UUID
[] uuidList
= new UUID
[preselectedVocArray
.length
];
58 for (String uuidString
: preselectedVocArray
){
59 uuidList
[i
]= UUID
.fromString(uuidString
);
65 protected void init() {
66 vocabularies
= getAvailableVocabularies();
70 protected List
<TermVocabulary
> getAvailableVocabularies(){
71 List
<TermVocabulary
> vocabularies
= new ArrayList();
73 UUID
[] preselectedVocabularyUuids
= createVocabularyUuidList();
74 CdmPreferenceCache cache
= CdmPreferenceCache
.instance();
75 CdmPreference pref
= cache
.get(PreferencePredicate
.CommonNameAreaVocabularies
.getKey());
76 if ((pref
!= null && !pref
.isAllowOverride()) && preselectedVocabularyUuids
!=null) {
77 for(int i
=0;i
<preselectedVocabularyUuids
.length
;i
++){
78 TermVocabulary preselectedVocabulary
= CdmStore
.getService(IVocabularyService
.class).find(preselectedVocabularyUuids
[i
]);
79 vocabularies
.add(preselectedVocabulary
);
82 vocabularies
= CdmStore
.getService(IVocabularyService
.class).listByTermType(TermType
.NamedArea
, true, null, null, null, null);
89 * Creates a filtered selection dialog to select a named area.
92 * The shell for displaying this widget
94 * A namedArea that should be selected when the dialog opens
95 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
96 * @param preferenceId a class which is used for generating the preference key so that every
97 * dialogs can be grouped to have their own preferences depending on this id
98 * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies
99 * @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
101 public static NamedArea
select(Shell shell
, //ConversationHolder conversation,
102 NamedArea namedArea
, String preferenceId
) {
103 CommonNameNamedAreaSelectionDialog dialog
= new CommonNameNamedAreaSelectionDialog(shell
, //conversation,
104 "Choose an area", false, namedArea
, preferenceId
);
105 return getSelectionFromDialog(dialog
);