ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / wizard / AvailableDistributionWizard.java
1 /**
2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.preference.wizard;
10
11 import java.util.ArrayList;
12 import java.util.Arrays;
13 import java.util.UUID;
14
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;
19
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;
28
29 /**
30 * @author alex
31 * @date 21.07.2014
32 *
33 */
34 public class AvailableDistributionWizard extends Wizard implements IConversationEnabled {
35
36 private ConversationHolder conversation;
37 private final AvailableDistributionPage aPage;
38
39 public AvailableDistributionWizard() {
40 setWindowTitle("Distribution Selection Wizard");
41 // TODO if preferenceStore has elements checked load elements in wizard
42 aPage = new AvailableDistributionPage("AvailableDistributionPage");
43 }
44
45 /*
46 * (non-Javadoc)
47 *
48 * @see org.eclipse.jface.wizard.Wizard#performFinish()
49 */
50 @Override
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());
65
66 }else if(o instanceof OrderedTermVocabulary){
67 OrderedTermVocabulary otb = (OrderedTermVocabulary) o;
68 listUIIDGrayed.add(otb.getUuid());
69 }
70 }
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());
78 }
79
80 }
81
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);
87 return true;
88 } else {
89 return false;
90 }
91 }
92
93 @Override
94 public void addPages() {
95 addPage(aPage);
96 }
97
98 private boolean checkNoneChecked() {
99
100 if (aPage.getViewer().getCheckedElements().length == 0) {
101 aPage.setMessage("Please check at least one item", aPage.WARNING);
102 return true;
103 } else {
104 aPage.setMessage(null);
105 return false;
106 }
107 }
108
109 @Override
110 public ConversationHolder getConversationHolder() {
111 if (conversation == null) {
112 conversation = CdmStore.createConversation();
113 }
114 return conversation;
115 }
116
117 /*
118 * (non-Javadoc)
119 *
120 * @see
121 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
122 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
123 */
124 @Override
125 public void update(CdmDataChangeMap changeEvents) {
126 // TODO Auto-generated method stub
127
128 }
129 }