Project

General

Profile

Download (3.03 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.taxeditor.editor.key.polytomous;
5

    
6
import java.util.Arrays;
7
import java.util.HashMap;
8
import java.util.List;
9
import java.util.Map;
10
import java.util.UUID;
11

    
12
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
13
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
14
import eu.etaxonomy.cdm.model.description.PolytomousKey;
15
import eu.etaxonomy.taxeditor.editor.key.AbstractIdentificationEditorInput;
16
import eu.etaxonomy.taxeditor.store.CdmStore;
17

    
18
/**
19
 * @author n.hoffmann
20
 *
21
 */
22
public class PolytomousKeyEditorInput extends AbstractIdentificationEditorInput<PolytomousKey> {
23

    
24
    private final String name;
25
    private final UUID keyUuid;
26
    private PolytomousKey key;
27

    
28

    
29
    protected PolytomousKeyEditorInput(ConversationHolder conversation,
30
            UUID polytomousKeyUuid) {
31
        super(conversation);
32
        this.keyUuid = polytomousKeyUuid;
33
        this.key = CdmStore.getService(IPolytomousKeyService.class).load(polytomousKeyUuid, null);
34
        this.name = key.getTitleCache();
35
    }
36

    
37
//    public PolytomousKeyEditorInput(UUID polytomousKeyUuid, String name) {
38
//        super(CdmStore.createConversation());
39
//        this.keyUuid = polytomousKeyUuid;
40
//        this.name = name;
41
//    }
42

    
43

    
44
    public static PolytomousKeyEditorInput NewInstance(UUID polytomousKeyUuid) throws Exception{
45
        try{
46
            ConversationHolder conversation = CdmStore.createConversation();
47
            return new PolytomousKeyEditorInput(conversation, polytomousKeyUuid);
48
        }catch(Exception e){
49
            throw e;
50
        }
51
    }
52

    
53

    
54
    /* (non-Javadoc)
55
     * @see org.eclipse.ui.IEditorInput#getName()
56
     */
57
    @Override
58
    public String getName() {
59
        return name;
60
    }
61

    
62
    @Override
63
    public PolytomousKey getKey() {
64
        return key;
65
    }
66

    
67
    /* (non-Javadoc)
68
     * @see java.lang.Object#equals(java.lang.Object)
69
     */
70
    @Override
71
    public boolean equals(Object object) {
72
        if (object instanceof PolytomousKeyEditorInput
73
                && getKey() != null
74
                && getKey().equals(((PolytomousKeyEditorInput) object).getKey())
75
                ){
76
            return true;
77
        }
78
        return super.equals(object);
79
    }
80

    
81
    /* (non-Javadoc)
82
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
83
     */
84
    @Override
85
    public  List<PolytomousKey> getRootEntities() {
86
        return Arrays.asList(key);
87
    }
88

    
89
    /* (non-Javadoc)
90
     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
91
     */
92
    @Override
93
    public void merge() {
94
       key = CdmStore.getService(IPolytomousKeyService.class).merge(key,true).getMergedEntity();
95
      
96
    }
97

    
98
    @Override
99
    public Map<Object, List<String>> getPropertyPathsMap() {
100
        Map<Object,List<String>> propertyPathsMap = new HashMap<Object,List<String>>();
101

    
102
        List<String> polytomousKeyNodePropertyPaths = Arrays.asList(new String[] {
103
                "statement"
104
        });
105
         propertyPathsMap.put("children", polytomousKeyNodePropertyPaths);
106
         return propertyPathsMap;
107
    }
108

    
109
}
(2-2/11)