Project

General

Profile

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

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

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

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

    
25
    private final String name;
26
    private PolytomousKey key;
27

    
28

    
29
    protected PolytomousKeyEditorInput(ConversationHolder conversation,
30
            UUID polytomousKeyUuid) {
31
        super(conversation);
32
        List<String> propertyPath = new ArrayList<>();
33
        propertyPath.add("root");
34
        propertyPath.add("root.*");
35
        this.key = CdmStore.getService(IPolytomousKeyService.class).load(polytomousKeyUuid, propertyPath);
36
        this.name = key.getTitleCache();
37
    }
38

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

    
45

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

    
55

    
56
    @Override
57
    public PolytomousKey getKey() {
58
        return key;
59
    }
60

    
61
    /* (non-Javadoc)
62
     * @see java.lang.Object#equals(java.lang.Object)
63
     */
64
    @Override
65
    public boolean equals(Object object) {
66
        if (object instanceof PolytomousKeyEditorInput
67
                && getKey() != null
68
                && getKey().equals(((PolytomousKeyEditorInput) object).getKey())
69
                ){
70
            return true;
71
        }
72
        return super.equals(object);
73
    }
74

    
75
    /* (non-Javadoc)
76
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
77
     */
78
    @Override
79
    public  List<PolytomousKey> getRootEntities() {
80
        return Arrays.asList(key);
81
    }
82

    
83
    /* (non-Javadoc)
84
     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
85
     */
86
    @Override
87
    public void merge() {
88
       key = CdmStore.getService(IPolytomousKeyService.class).merge(key,true).getMergedEntity();
89

    
90
    }
91

    
92
    @Override
93
    public Map<Object, List<String>> getPropertyPathsMap() {
94
        Map<Object,List<String>> propertyPathsMap = new HashMap<Object,List<String>>();
95

    
96
        List<String> polytomousKeyNodePropertyPaths = Arrays.asList(new String[] {
97
                "statement" //$NON-NLS-1$
98
        });
99
         propertyPathsMap.put("children", polytomousKeyNodePropertyPaths); //$NON-NLS-1$
100
         return propertyPathsMap;
101
    }
102

    
103
}
(2-2/11)