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
.lang3
.StringUtils
;
17 import org
.eclipse
.jface
.wizard
.Wizard
;
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
;
30 public class AvailableDistributionWizard
extends Wizard
{
32 // private ConversationHolder conversation;
33 private final AvailableDistributionPage aPage
;
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
);
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());
56 }else if(o
instanceof TermVocabularyDto
){
57 TermVocabularyDto termVocDto
= (TermVocabularyDto
) o
;
58 listUIIDGrayed
.add(termVocDto
.getUuid());
61 for (Object o
: grayedList
) {
62 if (o
instanceof TermDto
) {
63 listUIIDChecked
.add(((TermDto
) o
).getUuid());
65 }else if(o
instanceof TermVocabularyDto
){
66 TermVocabularyDto termVocDto
= (TermVocabularyDto
) o
;
67 listUIIDGrayed
.add(termVocDto
.getUuid());
71 String saveCheckedElements
= StringUtils
.join(listUIIDChecked
, ";"); //$NON-NLS-1$
73 PreferencesUtil
.setStringValue(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey(), saveCheckedElements
);
81 public void addPages() {
85 private boolean checkNoneChecked() {
87 if (aPage
.getViewer().getCheckedElements().length
== 0) {
88 aPage
.setMessage(Messages
.AvailableDistributionWizard_CHECK_MESSAGE
, aPage
.WARNING
);
91 aPage
.setMessage(null);
97 // public ConversationHolder getConversationHolder() {
98 // if (conversation == null) {
99 // conversation = CdmStore.createConversation();
101 // return conversation;
105 // public void update(CdmDataChangeMap changeEvents) {