Merge branch 'develop' into feature/cdm-4.7
[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.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 final UUID keyUuid;
27 private PolytomousKey key;
28
29
30 protected PolytomousKeyEditorInput(ConversationHolder conversation,
31 UUID polytomousKeyUuid) {
32 super(conversation);
33 this.keyUuid = polytomousKeyUuid;
34 List<String> propertyPath = new ArrayList<>();
35 propertyPath.add("root");
36 propertyPath.add("root.*");
37 this.key = CdmStore.getService(IPolytomousKeyService.class).load(polytomousKeyUuid, propertyPath);
38 this.name = key.getTitleCache();
39 }
40
41 // public PolytomousKeyEditorInput(UUID polytomousKeyUuid, String name) {
42 // super(CdmStore.createConversation());
43 // this.keyUuid = polytomousKeyUuid;
44 // this.name = name;
45 // }
46
47
48 public static PolytomousKeyEditorInput NewInstance(UUID polytomousKeyUuid) throws Exception{
49 try{
50 ConversationHolder conversation = CdmStore.createConversation();
51 return new PolytomousKeyEditorInput(conversation, polytomousKeyUuid);
52 }catch(Exception e){
53 throw e;
54 }
55 }
56
57
58 /* (non-Javadoc)
59 * @see org.eclipse.ui.IEditorInput#getName()
60 */
61 @Override
62 public String getName() {
63 return name;
64 }
65
66 @Override
67 public PolytomousKey getKey() {
68 return key;
69 }
70
71 /* (non-Javadoc)
72 * @see java.lang.Object#equals(java.lang.Object)
73 */
74 @Override
75 public boolean equals(Object object) {
76 if (object instanceof PolytomousKeyEditorInput
77 && getKey() != null
78 && getKey().equals(((PolytomousKeyEditorInput) object).getKey())
79 ){
80 return true;
81 }
82 return super.equals(object);
83 }
84
85 /* (non-Javadoc)
86 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
87 */
88 @Override
89 public List<PolytomousKey> getRootEntities() {
90 return Arrays.asList(key);
91 }
92
93 /* (non-Javadoc)
94 * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
95 */
96 @Override
97 public void merge() {
98 key = CdmStore.getService(IPolytomousKeyService.class).merge(key,true).getMergedEntity();
99
100 }
101
102 @Override
103 public Map<Object, List<String>> getPropertyPathsMap() {
104 Map<Object,List<String>> propertyPathsMap = new HashMap<Object,List<String>>();
105
106 List<String> polytomousKeyNodePropertyPaths = Arrays.asList(new String[] {
107 "statement" //$NON-NLS-1$
108 });
109 propertyPathsMap.put("children", polytomousKeyNodePropertyPaths); //$NON-NLS-1$
110 return propertyPathsMap;
111 }
112
113 }