Project

General

Profile

Download (2.55 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.List;
8
import java.util.UUID;
9

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

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

    
22
    private final String name;
23
    private final UUID keyUuid;
24
    private PolytomousKey key;
25

    
26

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

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

    
41

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

    
51

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

    
60
    @Override
61
    public PolytomousKey getKey() {
62
        return key;
63
    }
64

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

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

    
87
    /* (non-Javadoc)
88
     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
89
     */
90
    @Override
91
    public void merge() {
92
        CdmStore.getService(IPolytomousKeyService.class).merge(key);
93
    }
94

    
95
}
(3-3/9)