Project

General

Profile

Download (5.81 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2013 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.editor.view.checklist;
10

    
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.List;
14
import java.util.UUID;
15

    
16
import org.eclipse.ui.IMemento;
17
import org.eclipse.ui.IPersistable;
18

    
19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
21
import eu.etaxonomy.cdm.api.service.ITaxonService;
22
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
23
import eu.etaxonomy.cdm.model.taxon.Classification;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * @author a.oppermann
32
 * @date 25.04.2014
33
 */
34
public class ChecklistEditorInput extends CdmEntitySessionInput<TaxonNode> implements IPersistable {
35

    
36
    /**
37
     * The selected classification
38
     */
39
    private TaxonNode taxonNode = null;
40

    
41
    private List<TaxonBase> taxa = new ArrayList<>();
42

    
43
    private Classification classification = null;
44

    
45
    private List<TaxonBase> taxaToSave = new ArrayList<>();
46

    
47

    
48
    /**
49
     * Creates an editor input for the {@link ChecklistView} with the currently selected TaxonNode
50
     * and its childNodes.
51
     * @param taxonNode
52
     */
53
    public ChecklistEditorInput(TaxonNode taxonNode){
54
        super(false);
55
        initSession();
56
        this.taxonNode =CdmStore.getService(ITaxonNodeService.class).load(taxonNode.getUuid(), getTaxonNodePropertyPaths());
57
        getChildTaxa(taxonNode);
58
        classification = taxonNode.getClassification();
59

    
60
    }
61

    
62
    private void getChildTaxa(TaxonNode taxonNode2) {
63
//       taxonNode2.removeNullValueFromChildren();
64
       if (taxonNode2.hasChildNodes()){
65
           for (TaxonNode node: taxonNode2.getChildNodes()){
66
        	   node = CdmStore.getService(ITaxonNodeService.class).load(node.getUuid(), getTaxonNodePropertyPaths());
67
               taxa.add(HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class));
68
               getChildTaxa(node);
69
           }
70
       }
71
    }
72

    
73
    /**
74
     * Creates an editor input for the {@link ChecklistView} with the currently selected classification.
75
     * @param classificationUuid
76
     */
77
    public ChecklistEditorInput(Classification classification) {
78
        super(true);
79
        initSession();
80
        this.classification = CdmStore.getCurrentApplicationConfiguration().getClassificationService().load(classification.getUuid());
81
        getChildTaxa(classification.getRootNode());
82

    
83
    }
84

    
85
    public List<TaxonBase> getTaxa() {
86
		return taxa;
87
	}
88

    
89
    public String getName() {
90
        if(taxonNode != null && taxonNode.getTaxon()!=null){
91
            return taxonNode.getTaxon().getName().getTitleCache();
92
        }else{
93
            return classification.getTitleCache();
94
        }
95
    }
96

    
97
    public TaxonNode getTaxonNode() {
98
        return taxonNode;
99
    }
100

    
101
    public Classification getClassification(){
102
    	return classification;
103
    }
104

    
105
    @Override
106
    public boolean equals(Object obj) {
107
        if (this == obj) {
108
            return true;
109
        }
110
        if (obj == null) {
111
            return false;
112
        }
113
        if (getClass() != obj.getClass()) {
114
            return false;
115
        }
116
        ChecklistEditorInput other = (ChecklistEditorInput) obj;
117
        if (classification == null) {
118
            if (other.classification != null) {
119
                return false;
120
            }
121
        } else if (!classification.equals(other.classification)) {
122
            return false;
123
        }
124
        if (taxonNode == null) {
125
            if (other.taxonNode != null) {
126
                return false;
127
            }
128
        } else if (!taxonNode.equals(other.taxonNode)) {
129
            return false;
130
        }
131
        return true;
132
    }
133

    
134
    @Override
135
    public void saveState(IMemento memento) {
136
        UUID uuid = classification.getUuid();
137
    }
138

    
139
    @Override
140
    public void merge() {
141
        if (!getCdmEntitySession().isActive()){
142
            getCdmEntitySession().bind();
143
        }
144
        CdmStore.getService(ITaxonService.class).merge(taxaToSave, true);
145
    }
146

    
147
    @Override
148
    public List<TaxonNode> getRootEntities() {
149
        return Arrays.asList(taxonNode);
150
    }
151

    
152
    public ConversationHolder getConversation() {
153
        return null;
154
    }
155

    
156
    private List<String> getTaxonNodePropertyPaths() {
157
        List<String> taxonNodePropertyPaths = new ArrayList<String>();
158
        for(String propertyPath : getTaxonBasePropertyPaths()) {
159
            taxonNodePropertyPaths.add("taxon." + propertyPath); //$NON-NLS-1$
160
        }
161
        return taxonNodePropertyPaths;
162
    }
163

    
164
    private List<String> getTaxonBasePropertyPaths() {
165
        List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
166
                "sec", //$NON-NLS-1$
167
                "rights", //$NON-NLS-1$
168
                "sources", //$NON-NLS-1$
169
                "descriptions", //$NON-NLS-1$
170
                "descriptions.descriptionElements.feature", //$NON-NLS-1$
171
                "descriptions.descriptionElements.area", //$NON-NLS-1$
172
                "descriptions.descriptionElements.status", //$NON-NLS-1$
173
                "descriptions.markers", //$NON-NLS-1$
174

    
175
        });
176

    
177
        return taxonBasePropertyPaths;
178
    }
179

    
180
	public void setTaxa(List<TaxonBase> taxonList) {
181
		this.taxa = taxonList;
182

    
183
	}
184

    
185
    /**
186
     * @param element
187
     */
188
    public void addTaxonToSave(Taxon element) {
189
        this.taxaToSave.add(element);
190

    
191
    }
192

    
193
//    @Override
194
//    public void dispose(){
195
//    	conversation.unbind();
196
//    	conversation.close();
197
//    	getCdmEntitySession().dispose();
198
//    	super.dispose();
199
//    }
200

    
201
}
(3-3/3)