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
.preference
.wizard
;
11 import java
.util
.ArrayList
;
12 import java
.util
.UUID
;
14 import org
.apache
.commons
.lang
.StringUtils
;
15 import org
.eclipse
.jface
.viewers
.CheckboxTableViewer
;
16 import org
.eclipse
.jface
.wizard
.IWizardPage
;
17 import org
.eclipse
.jface
.wizard
.Wizard
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
21 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
25 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
26 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 public class AvailableVocabularyWizard
extends Wizard
implements IConversationEnabled
{
36 private ConversationHolder conversation
;
37 private final AvailableAreaVocabulariesPage aPage
;
38 private boolean localPref
= true;
39 private CdmPreference pref
;
41 public AvailableVocabularyWizard(boolean localPref
, CdmPreference pref
, String featureTitle
) {
42 setWindowTitle("Vocabulary Selection Wizard");
43 // TODO if preferenceStore has elements checked load elements in wizard
44 this.localPref
= localPref
;
46 aPage
= new AvailableAreaVocabulariesPage("AvailableDistributionPage", localPref
, pref
, featureTitle
);
50 public void addPages() {
61 public IWizardPage
getPage(String pageName
) {
70 public int getPageCount() {
78 public IWizardPage
[] getPages() {
79 IWizardPage
[] pages
= new IWizardPage
[1];
92 public String
getWindowTitle() {
94 return "Vocabulary Selection Wizard";
107 public boolean performCancel() {
108 // TODO Auto-generated method stub
116 public boolean performFinish() {
117 Object
[] checkedElements
= ((CheckboxTableViewer
)aPage
.getViewer()).getCheckedElements();
119 ArrayList
<UUID
> listUIIDChecked
= new ArrayList
<UUID
>();
120 for (Object o
: checkedElements
) {
121 if(o
instanceof TermVocabulary
){
122 TermVocabulary otb
= (TermVocabulary
) o
;
123 listUIIDChecked
.add(otb
.getUuid());
126 String saveCheckedElements
= StringUtils
.join(listUIIDChecked
, ";");
127 String predicate
= null;
129 predicate
= pref
.getPredicate();
131 CdmPreference savePref
= CdmPreference
.NewInstance(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.getByKey(pref
.getPredicate()), saveCheckedElements
);
132 PreferencesUtil
.setPreferenceToDB(savePref
);
134 PreferencesUtil
.updateDBPreferences();
145 public void update(CdmDataChangeMap changeEvents
) {
146 // TODO Auto-generated method stub
155 public ConversationHolder
getConversationHolder() {
156 if (conversation
== null) {
157 conversation
= CdmStore
.createConversation();