cleanup
[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.lang3.StringUtils;
17 import org.eclipse.jface.wizard.Wizard;
18
19 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
20 import eu.etaxonomy.cdm.persistence.dto.TermDto;
21 import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
22 import eu.etaxonomy.taxeditor.l10n.Messages;
23 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
25 /**
26 * @author alex
27 * @date 21.07.2014
28 *
29 */
30 public class AvailableDistributionWizard extends Wizard {
31
32 // private ConversationHolder conversation;
33 private final AvailableDistributionPage aPage;
34
35 public AvailableDistributionWizard() {
36 setWindowTitle(Messages.AvailableDistributionWizard_WINDOW_TITLE);
37 // TODO if preferenceStore has elements checked load elements in wizard
38 aPage = new AvailableDistributionPage(Messages.AvailableDistributionWizard_PAGE_TITLE);
39 }
40
41 @Override
42 public boolean performFinish() {
43 // TODO: get Selection and save in EditorPreferences
44 if (!checkNoneChecked()) {
45 Object[] checkedElements = aPage.getViewer().getCheckedElements();
46 Object[] grayedElements = aPage.getViewer().getGrayedElements();
47 ArrayList checkedList = new ArrayList(Arrays.asList(checkedElements));
48 ArrayList grayedList = new ArrayList(Arrays.asList(grayedElements));
49 checkedList = (ArrayList) CollectionUtils.subtract(checkedList, grayedList);
50 ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
51 ArrayList<UUID> listUIIDGrayed = new ArrayList<UUID>();
52 for (Object o : checkedList) {
53 if (o instanceof TermDto) {
54 listUIIDChecked.add(((TermDto) o).getUuid());
55
56 }else if(o instanceof TermVocabularyDto){
57 TermVocabularyDto termVocDto = (TermVocabularyDto) o;
58 listUIIDGrayed.add(termVocDto.getUuid());
59 }
60 }
61 for (Object o : grayedList) {
62 if (o instanceof TermDto) {
63 listUIIDChecked.add(((TermDto) o).getUuid());
64
65 }else if(o instanceof TermVocabularyDto){
66 TermVocabularyDto termVocDto = (TermVocabularyDto) o;
67 listUIIDGrayed.add(termVocDto.getUuid());
68 }
69 }
70
71 String saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$
72
73 PreferencesUtil.setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
74 return true;
75 } else {
76 return false;
77 }
78 }
79
80 @Override
81 public void addPages() {
82 addPage(aPage);
83 }
84
85 private boolean checkNoneChecked() {
86
87 if (aPage.getViewer().getCheckedElements().length == 0) {
88 aPage.setMessage(Messages.AvailableDistributionWizard_CHECK_MESSAGE, aPage.WARNING);
89 return true;
90 } else {
91 aPage.setMessage(null);
92 return false;
93 }
94 }
95 //
96 // @Override
97 // public ConversationHolder getConversationHolder() {
98 // if (conversation == null) {
99 // conversation = CdmStore.createConversation();
100 // }
101 // return conversation;
102 // }
103 //
104 // @Override
105 // public void update(CdmDataChangeMap changeEvents) {
106 // }
107 }