CdmTransientEntityCacher, EntityCacherDebugResult : moved debug methods to debug...
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / key / polytomous / PolytomousKeyEditorInput.java
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.session.ICdmEntitySession;
15 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
16 import eu.etaxonomy.taxeditor.store.CdmStore;
17
18 /**
19 * @author n.hoffmann
20 *
21 */
22 public class PolytomousKeyEditorInput extends AbstractIdentificationEditorInput<PolytomousKey> implements ICdmEntitySessionEnabled {
23
24 private final PolytomousKey key;
25 private final ICdmEntitySession cdmEntitySession;
26
27 protected PolytomousKeyEditorInput(ConversationHolder conversation,
28 PolytomousKey key) {
29 super(conversation);
30 cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
31
32 this.key = key;
33 }
34
35
36
37 public static PolytomousKeyEditorInput NewInstance(UUID polytomousKeyUuid) throws Exception{
38 try{
39 ConversationHolder conversation = CdmStore.createConversation();
40
41 return NewInstance(polytomousKeyUuid, conversation);
42 }catch(Exception e){
43 throw e;
44 }
45 }
46
47 public static PolytomousKeyEditorInput NewInstance(UUID polytomousKeyUuid, ConversationHolder conversation) throws Exception{
48 PolytomousKey polytomousKey = CdmStore.getService(IPolytomousKeyService.class).load(polytomousKeyUuid, null);
49
50 return new PolytomousKeyEditorInput(conversation, polytomousKey);
51 }
52
53 /* (non-Javadoc)
54 * @see org.eclipse.ui.IEditorInput#getName()
55 */
56 @Override
57 public String getName() {
58 return key.getTitleCache();
59 }
60
61 @Override
62 public PolytomousKey getKey() {
63 return key;
64 }
65
66 /* (non-Javadoc)
67 * @see java.lang.Object#equals(java.lang.Object)
68 */
69 @Override
70 public boolean equals(Object object) {
71 if (object instanceof PolytomousKeyEditorInput
72 && getKey() != null
73 && getKey().equals(((PolytomousKeyEditorInput) object).getKey())
74 ){
75 return true;
76 }
77 return super.equals(object);
78 }
79
80 public void dispose() {
81 cdmEntitySession.dispose();
82 }
83
84
85
86 /* (non-Javadoc)
87 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
88 */
89 @Override
90 public ICdmEntitySession getCdmEntitySession() {
91 return cdmEntitySession;
92 }
93
94
95
96 /* (non-Javadoc)
97 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
98 */
99 @Override
100 public List<PolytomousKey> getRootEntities() {
101 return Arrays.asList(key);
102 }
103 }