Project

General

Profile

Download (9.03 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.model.taxon.Classification;
26
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
27
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
28
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

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

    
39
    /**
40
     * The selected classification
41
     */
42
    private TaxonNode taxonNode = null;
43

    
44
    private final List<TaxonBase> taxa = new ArrayList<TaxonBase>();
45

    
46
    private Classification classification = null;
47

    
48
    private final ConversationHolder conversation;
49

    
50

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

    
66
    /**
67
     * @param taxonNode2
68
     */
69
    private void getChildTaxa(TaxonNode taxonNode2) {
70
       taxonNode2.removeNullValueFromChildren();
71
       if (taxonNode2.hasChildNodes()){
72
           for (TaxonNode node: taxonNode2.getChildNodes()){
73
               taxa.add(node.getTaxon());
74
               getChildTaxa(node);
75
           }
76
       }
77

    
78

    
79
    }
80

    
81
    /**
82
     * Creates an editor input for the {@link ChecklistView} with the currently selected classification.
83
     * @param classificationUuid
84
     */
85
    public ChecklistEditorInput(Classification classification) {
86
        super(true);
87
        this.conversation = CdmStore.createConversation();
88
        this.classification = CdmStore.getCurrentApplicationConfiguration().getClassificationService().load(classification.getUuid());
89

    
90
    }
91

    
92

    
93

    
94
    /* (non-Javadoc)
95
     * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
96
     */
97
    @Override
98
    public Object getAdapter(Class adapter) {
99
        // TODO Auto-generated method stub
100
        return null;
101
    }
102

    
103
    /* (non-Javadoc)
104
     * @see org.eclipse.ui.IEditorInput#exists()
105
     */
106
    @Override
107
    public boolean exists() {
108
        return false;
109
    }
110

    
111
    /* (non-Javadoc)
112
     * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
113
     */
114
    @Override
115
    public ImageDescriptor getImageDescriptor() {
116
        // TODO Auto-generated method stub
117
        return null;
118
    }
119

    
120
    /* (non-Javadoc)
121
     * @see org.eclipse.ui.IEditorInput#getName()
122
     */
123
    @Override
124
    public String getName() {
125
        if(taxonNode != null){
126
            return taxonNode.getTaxon().getName().getTitleCache();
127
        }else{
128
            return classification.getTitleCache();
129
        }
130
    }
131

    
132
    /* (non-Javadoc)
133
     * @see org.eclipse.ui.IEditorInput#getPersistable()
134
     */
135
    @Override
136
    public IPersistableElement getPersistable() {
137
        return null;
138
    }
139

    
140
    /* (non-Javadoc)
141
     * @see org.eclipse.ui.IEditorInput#getToolTipText()
142
     */
143
    @Override
144
    public String getToolTipText() {
145
        return classification.getTitleCache();
146
    }
147

    
148
    /**
149
     * @return the taxonNode
150
     */
151
    public TaxonNode getTaxonNode() {
152
        return taxonNode;
153
    }
154

    
155
    /**
156
     * @return classification
157
     */
158
    public Classification getClassification(){
159
    	return classification;
160
    }
161

    
162
//    /**
163
//     * @return the conversationHolder
164
//     */
165
//    public ConversationHolder getConversationHolder() {
166
//        return conversationHolder;
167
//    }
168

    
169

    
170

    
171
    /* (non-Javadoc)
172
     * @see java.lang.Object#hashCode()
173
     */
174
    @Override
175
    public int hashCode() {
176
        final int prime = 31;
177
        int result = 1;
178
        result = prime * result + ((classification == null) ? 0 : classification.hashCode());
179
        result = prime * result + ((taxonNode == null) ? 0 : taxonNode.hashCode());
180
        return result;
181
    }
182

    
183
    /* (non-Javadoc)
184
     * @see java.lang.Object#equals(java.lang.Object)
185
     */
186
    @Override
187
    public boolean equals(Object obj) {
188
        if (this == obj) {
189
            return true;
190
        }
191
        if (obj == null) {
192
            return false;
193
        }
194
        if (getClass() != obj.getClass()) {
195
            return false;
196
        }
197
        ChecklistEditorInput other = (ChecklistEditorInput) obj;
198
        if (classification == null) {
199
            if (other.classification != null) {
200
                return false;
201
            }
202
        } else if (!classification.equals(other.classification)) {
203
            return false;
204
        }
205
        if (taxonNode == null) {
206
            if (other.taxonNode != null) {
207
                return false;
208
            }
209
        } else if (!taxonNode.equals(other.taxonNode)) {
210
            return false;
211
        }
212
        return true;
213
    }
214

    
215
    /* (non-Javadoc)
216
     * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
217
     */
218
    @Override
219
    public void saveState(IMemento memento) {
220
        UUID uuid = classification.getUuid();
221
    }
222

    
223
    @Override
224
    public void merge() {
225
        for (TaxonBase taxon:taxa){
226
            CdmStore.getService(ITaxonService.class).merge(taxon, true);
227
        }
228

    
229
    //    CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
230
    }
231

    
232
    /* (non-Javadoc)
233
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
234
     */
235
    @Override
236
    public List<TaxonNode> getRootEntities() {
237
        return Arrays.asList(taxonNode);
238
    }
239

    
240
    /**
241
     * @return the conversation
242
     */
243
    public ConversationHolder getConversation() {
244
        return conversation;
245
    }
246
    
247
    private List<String> getTaxonNodePropertyPaths() {
248
        List<String> taxonNodePropertyPaths = new ArrayList<String>();
249
        for(String propertyPath : getTaxonBasePropertyPaths()) {
250
            taxonNodePropertyPaths.add("taxon." + propertyPath); //$NON-NLS-1$
251
        }
252
        return taxonNodePropertyPaths;
253
    }
254

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

    
290
        return taxonBasePropertyPaths;
291
    }
292
    
293
//    @Override
294
//    public void dispose(){
295
//    	conversation.unbind();
296
//    	conversation.close();
297
//    	getCdmEntitySession().dispose();
298
//    	super.dispose();
299
//    }
300

    
301
}
(4-4/5)