2 * Copyright (C) 2014 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
.Arrays
;
13 import java
.util
.UUID
;
15 import org
.apache
.commons
.collections
.CollectionUtils
;
16 import org
.apache
.commons
.lang
.StringUtils
;
17 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
18 import org
.eclipse
.jface
.wizard
.Wizard
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
21 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
22 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
24 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
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 AvailableDistributionWizard
extends Wizard
implements IConversationEnabled
{
36 private ConversationHolder conversation
;
37 private final AvailableDistributionPage aPage
;
39 public AvailableDistributionWizard() {
40 setWindowTitle("Distribution Selection Wizard");
41 // TODO if preferenceStore has elements checked load elements in wizard
42 aPage
= new AvailableDistributionPage("AvailableDistributionPage");
48 * @see org.eclipse.jface.wizard.Wizard#performFinish()
51 public boolean performFinish() {
52 // TODO: get Selection and save in EditorPreferences
53 if (!checkNoneChecked()) {
54 Object
[] checkedElements
= aPage
.getViewer().getCheckedElements();
55 Object
[] grayedElements
= aPage
.getViewer().getGrayedElements();
56 ArrayList checkedList
= new ArrayList(Arrays
.asList(checkedElements
));
57 ArrayList grayedList
= new ArrayList(Arrays
.asList(grayedElements
));
58 checkedList
= (ArrayList
) CollectionUtils
.subtract(checkedList
, grayedList
);
59 ArrayList
<UUID
> listUIIDChecked
= new ArrayList
<UUID
>();
60 ArrayList
<UUID
> listUIIDGrayed
= new ArrayList
<UUID
>();
61 for (Object o
: checkedList
) {
62 if (o
instanceof NamedArea
) {
63 NamedArea na
= (NamedArea
) o
;
64 listUIIDChecked
.add(na
.getUuid());
66 }else if(o
instanceof OrderedTermVocabulary
){
67 OrderedTermVocabulary otb
= (OrderedTermVocabulary
) o
;
68 listUIIDGrayed
.add(otb
.getUuid());
71 for (Object o
: grayedList
) {
72 if(o
instanceof DefinedTermBase
){
73 DefinedTermBase dt
= (DefinedTermBase
) o
;
74 listUIIDGrayed
.add(dt
.getUuid());
75 }else if(o
instanceof OrderedTermVocabulary
){
76 OrderedTermVocabulary otb
= (OrderedTermVocabulary
) o
;
77 listUIIDGrayed
.add(otb
.getUuid());
82 String saveCheckedElements
= StringUtils
.join(listUIIDChecked
, ",");
83 String saveGrayedElements
= StringUtils
.join(listUIIDGrayed
, ",");
84 IPreferenceStore preferenceStore
= PreferencesUtil
.getPreferenceStore();
85 preferenceStore
.setValue(PreferencesUtil
.DISTRIBUTION_AREA_OCCURENCE_STATUS
, saveCheckedElements
);
86 preferenceStore
.setValue(PreferencesUtil
.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED
, saveGrayedElements
);
94 public void addPages() {
98 private boolean checkNoneChecked() {
100 if (aPage
.getViewer().getCheckedElements().length
== 0) {
101 aPage
.setMessage("Please check at least one item", aPage
.WARNING
);
104 aPage
.setMessage(null);
110 public ConversationHolder
getConversationHolder() {
111 if (conversation
== null) {
112 conversation
= CdmStore
.createConversation();
121 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
122 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
125 public void update(CdmDataChangeMap changeEvents
) {
126 // TODO Auto-generated method stub