Project

General

Profile

Download (9.41 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.jface.resource.ImageDescriptor;
17
import org.eclipse.ui.IEditorInput;
18
import org.eclipse.ui.IMemento;
19
import org.eclipse.ui.IPersistable;
20
import org.eclipse.ui.IPersistableElement;
21

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

    
33
/**
34
 *
35
 * @author a.oppermann
36
 * @date 25.04.2014
37
 *
38
 */
39
public class ChecklistEditorInput extends CdmEntitySessionInput implements IEditorInput, IPersistable {
40

    
41
    /**
42
     * The selected classification
43
     */
44
    private TaxonNode taxonNode = null;
45

    
46
    private List<Taxon> taxa = new ArrayList<Taxon>();
47

    
48
    private Classification classification = null;
49

    
50
    private final ConversationHolder conversation;
51

    
52

    
53
    /**
54
     * Creates an editor input for the {@link ChecklistView} with the currently selected TaxonNode
55
     * and its childNodes.
56
     * @param taxonNode
57
     */
58
    public ChecklistEditorInput(TaxonNode taxonNode){
59
        super(false);
60
        this.conversation = CdmStore.createConversation();
61
        initSession();
62
        this.taxonNode =CdmStore.getService(ITaxonNodeService.class).load(taxonNode.getUuid(), getTaxonNodePropertyPaths());
63
        getChildTaxa(taxonNode);
64
        classification = taxonNode.getClassification();
65

    
66
    }
67

    
68

    
69
    /**
70
     * @param taxonNode2
71
     */
72
    private void getChildTaxa(TaxonNode taxonNode2) {
73
       taxonNode2.removeNullValueFromChildren();
74
       if (taxonNode2.hasChildNodes()){
75
           for (TaxonNode node: taxonNode2.getChildNodes()){
76
        	   node = CdmStore.getService(ITaxonNodeService.class).load(node.getUuid(), getTaxonNodePropertyPaths());
77
               taxa.add(HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class));
78
               getChildTaxa(node);
79
           }
80
       }
81

    
82

    
83
    }
84

    
85
    /**
86
     * Creates an editor input for the {@link ChecklistView} with the currently selected classification.
87
     * @param classificationUuid
88
     */
89
    public ChecklistEditorInput(Classification classification) {
90
        super(true);
91
        this.conversation = CdmStore.createConversation();
92
        initSession();
93
        this.classification = CdmStore.getCurrentApplicationConfiguration().getClassificationService().load(classification.getUuid());
94
        getChildTaxa(classification.getRootNode());
95

    
96
    }
97

    
98

    
99

    
100
    /* (non-Javadoc)
101
     * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
102
     */
103
    @Override
104
    public Object getAdapter(Class adapter) {
105
        // TODO Auto-generated method stub
106
        return null;
107
    }
108

    
109
    /* (non-Javadoc)
110
     * @see org.eclipse.ui.IEditorInput#exists()
111
     */
112
    @Override
113
    public boolean exists() {
114
        return false;
115
    }
116

    
117
    /* (non-Javadoc)
118
     * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
119
     */
120
    @Override
121
    public ImageDescriptor getImageDescriptor() {
122
        // TODO Auto-generated method stub
123
        return null;
124
    }
125

    
126
    public List<Taxon> getTaxa() {
127
		return taxa;
128
	}
129

    
130
    /* (non-Javadoc)
131
     * @see org.eclipse.ui.IEditorInput#getName()
132
     */
133
    @Override
134
    public String getName() {
135
        if(taxonNode != null && taxonNode.getTaxon()!=null){
136
            return taxonNode.getTaxon().getName().getTitleCache();
137
        }else{
138
            return classification.getTitleCache();
139
        }
140
    }
141

    
142
    /* (non-Javadoc)
143
     * @see org.eclipse.ui.IEditorInput#getPersistable()
144
     */
145
    @Override
146
    public IPersistableElement getPersistable() {
147
        return null;
148
    }
149

    
150
    /* (non-Javadoc)
151
     * @see org.eclipse.ui.IEditorInput#getToolTipText()
152
     */
153
    @Override
154
    public String getToolTipText() {
155
        return classification.getTitleCache();
156
    }
157

    
158
    /**
159
     * @return the taxonNode
160
     */
161
    public TaxonNode getTaxonNode() {
162
        return taxonNode;
163
    }
164

    
165
    /**
166
     * @return classification
167
     */
168
    public Classification getClassification(){
169
    	return classification;
170
    }
171

    
172
//    /**
173
//     * @return the conversationHolder
174
//     */
175
//    public ConversationHolder getConversationHolder() {
176
//        return conversationHolder;
177
//    }
178

    
179

    
180

    
181
    /* (non-Javadoc)
182
     * @see java.lang.Object#hashCode()
183
     */
184
    @Override
185
    public int hashCode() {
186
        final int prime = 31;
187
        int result = 1;
188
        result = prime * result + ((classification == null) ? 0 : classification.hashCode());
189
        result = prime * result + ((taxonNode == null) ? 0 : taxonNode.hashCode());
190
        return result;
191
    }
192

    
193
    /* (non-Javadoc)
194
     * @see java.lang.Object#equals(java.lang.Object)
195
     */
196
    @Override
197
    public boolean equals(Object obj) {
198
        if (this == obj) {
199
            return true;
200
        }
201
        if (obj == null) {
202
            return false;
203
        }
204
        if (getClass() != obj.getClass()) {
205
            return false;
206
        }
207
        ChecklistEditorInput other = (ChecklistEditorInput) obj;
208
        if (classification == null) {
209
            if (other.classification != null) {
210
                return false;
211
            }
212
        } else if (!classification.equals(other.classification)) {
213
            return false;
214
        }
215
        if (taxonNode == null) {
216
            if (other.taxonNode != null) {
217
                return false;
218
            }
219
        } else if (!taxonNode.equals(other.taxonNode)) {
220
            return false;
221
        }
222
        return true;
223
    }
224

    
225
    /* (non-Javadoc)
226
     * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
227
     */
228
    @Override
229
    public void saveState(IMemento memento) {
230
        UUID uuid = classification.getUuid();
231
    }
232

    
233
    @Override
234
    public void merge() {
235
        for (TaxonBase taxon:this.taxa){
236
            CdmStore.getService(ITaxonService.class).merge(taxon, true);
237
        }
238

    
239

    
240
    }
241

    
242
    /* (non-Javadoc)
243
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
244
     */
245
    @Override
246
    public List<TaxonNode> getRootEntities() {
247
        return Arrays.asList(taxonNode);
248
    }
249

    
250
    /**
251
     * @return the conversation
252
     */
253
    public ConversationHolder getConversation() {
254
        return conversation;
255
    }
256

    
257
    private List<String> getTaxonNodePropertyPaths() {
258
        List<String> taxonNodePropertyPaths = new ArrayList<String>();
259
        for(String propertyPath : getTaxonBasePropertyPaths()) {
260
            taxonNodePropertyPaths.add("taxon." + propertyPath); //$NON-NLS-1$
261
        }
262
        return taxonNodePropertyPaths;
263
    }
264

    
265
    private List<String> getTaxonBasePropertyPaths() {
266
        List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
267
                "sec", //$NON-NLS-1$
268
                "createdBy", //$NON-NLS-1$
269
                "updatedBy", //$NON-NLS-1$
270
                "annotations", //$NON-NLS-1$
271
                "markers", //$NON-NLS-1$
272
                "credits", //$NON-NLS-1$
273
                "extensions", //$NON-NLS-1$
274
                "rights", //$NON-NLS-1$
275
                "sources", //$NON-NLS-1$
276
                "descriptions", //$NON-NLS-1$
277
                "relationsToThisTaxon", //$NON-NLS-1$
278
                "relationsFromThisTaxon", //$NON-NLS-1$
279
                "taxonNodes", //$NON-NLS-1$
280
                "descriptions.descriptionElements.feature", //$NON-NLS-1$
281
                "descriptions.descriptionElements.area", //$NON-NLS-1$
282
                "descriptions.descriptionElements.status", //$NON-NLS-1$
283
                "descriptions.markers", //$NON-NLS-1$
284
                "name.descriptions", //$NON-NLS-1$
285
                "name.typeDesignations", //$NON-NLS-1$
286
                "name.status", //$NON-NLS-1$
287
                "name.nomenclaturalReference.inReference", //$NON-NLS-1$
288
                "name.taxonBases.taxonNodes", //$NON-NLS-1$
289
                "name.relationsFromThisName", //$NON-NLS-1$
290
                "name.relationsToThisName", //$NON-NLS-1$
291
                "name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.synonym.name.status", //$NON-NLS-1$
292
                "name.homotypicalGroup.typifiedNames.relationsToThisName.fromName", //$NON-NLS-1$
293
                "synonymRelations.synonym.name.status.type", //$NON-NLS-1$
294
                "synonymRelations.synonym.name.relationsToThisName.fromName", //$NON-NLS-1$
295
                "synonymRelations.synonym.name.nomenclaturalReference.inReference.authorship", //$NON-NLS-1$
296
                "synonymRelations.synonym.name.nomenclaturalReference.authorship", //$NON-NLS-1$
297
                "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations" //$NON-NLS-1$
298
        });
299

    
300
        return taxonBasePropertyPaths;
301
    }
302

    
303

    
304
	public void setTaxa(List<Taxon> taxonList) {
305
		this.taxa = taxonList;
306

    
307
	}
308

    
309
//    @Override
310
//    public void dispose(){
311
//    	conversation.unbind();
312
//    	conversation.close();
313
//    	getCdmEntitySession().dispose();
314
//    	super.dispose();
315
//    }
316

    
317
}
(4-4/5)