Revision c7d830cc
Added by Cherian Mathew about 9 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java | ||
---|---|---|
1 | 1 |
/** |
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
2 |
* Copyright (C) 2007 EDIT
|
|
3 |
* European Distributed Institute of Taxonomy
|
|
4 |
* http://www.e-taxonomy.eu
|
|
5 |
*
|
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms.
|
|
8 |
*/
|
|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.editor; |
11 | 11 |
|
12 |
import java.util.Arrays; |
|
12 | 13 |
import java.util.HashSet; |
14 |
import java.util.List; |
|
13 | 15 |
import java.util.Set; |
14 | 16 |
import java.util.UUID; |
15 | 17 |
|
... | ... | |
46 | 48 |
* @created 19.03.2009 |
47 | 49 |
* @version 1.0 |
48 | 50 |
*/ |
49 |
public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPersistableElement { |
|
51 |
public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorInput, IConversationEnabled, IPersistableElement {
|
|
50 | 52 |
|
51 |
private final ConversationHolder conversation;
|
|
53 |
private final ConversationHolder conversation;
|
|
52 | 54 |
|
53 |
private final TaxonNode taxonNode;
|
|
55 |
private TaxonNode taxonNode;
|
|
54 | 56 |
|
55 |
private TaxonEditorInputDataChangeBehaviour dataChangeBehavior;
|
|
57 |
private TaxonEditorInputDataChangeBehaviour dataChangeBehavior;
|
|
56 | 58 |
|
57 |
private TaxonBase initiallySelectedTaxonBase;
|
|
59 |
private TaxonBase initiallySelectedTaxonBase;
|
|
58 | 60 |
|
59 |
private TaxonEditorInput(TaxonNode taxonNode, ConversationHolder conversation){ |
|
60 |
this.conversation = conversation; |
|
61 |
this.taxonNode = taxonNode; |
|
62 |
} |
|
61 |
private final ITaxonNodeService service; |
|
62 |
|
|
63 |
private enum CdmType { |
|
64 |
TAXON_NODE, |
|
65 |
TAXON_BASE, |
|
66 |
PARENT_TAXON_NODE |
|
67 |
} |
|
63 | 68 |
|
69 |
private TaxonEditorInput(UUID uuid, CdmType type) { |
|
70 |
this.conversation = CdmStore.createConversation(); |
|
71 |
service = CdmStore.getService(ITaxonNodeService.class); |
|
72 |
switch(type) { |
|
73 |
case PARENT_TAXON_NODE: |
|
74 |
initForParentTaxonNode(uuid); |
|
75 |
break; |
|
76 |
case TAXON_BASE: |
|
77 |
initForTaxonBase(uuid); |
|
78 |
break; |
|
79 |
case TAXON_NODE: |
|
80 |
initForTaxonNode(uuid); |
|
81 |
break; |
|
82 |
} |
|
83 |
} |
|
64 | 84 |
|
85 |
private void init(TaxonNode taxonNode) { |
|
86 |
this.taxonNode = taxonNode; |
|
87 |
} |
|
65 | 88 |
|
66 |
/** |
|
67 |
* <p>NewInstance</p> |
|
68 |
* |
|
69 |
* @param taxonNodeUuid a {@link java.util.UUID} object. |
|
70 |
* @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. |
|
71 |
* @throws java.lang.Exception if any. |
|
72 |
*/ |
|
73 |
public static TaxonEditorInput NewInstance(UUID taxonNodeUuid) throws Exception{ |
|
74 |
try{ |
|
75 |
ConversationHolder conversation = CdmStore.createConversation(); |
|
76 |
return NewInstance(taxonNodeUuid, conversation); |
|
77 |
}catch(Exception e){ |
|
78 |
throw e; |
|
79 |
} |
|
80 |
} |
|
81 | 89 |
|
82 | 90 |
/** |
91 |
* <p>NewInstance</p> |
|
83 | 92 |
* |
84 |
* @param taxonNodeUuid |
|
85 |
* @param conversation
|
|
86 |
* @return
|
|
93 |
* @param taxonNodeUuid a {@link java.util.UUID} object.
|
|
94 |
* @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object.
|
|
95 |
* @throws java.lang.Exception if any.
|
|
87 | 96 |
*/ |
88 |
private static TaxonEditorInput NewInstance(UUID taxonNodeUuid, ConversationHolder conversation){
|
|
97 |
private void initForTaxonNode(UUID taxonNodeUuid) {
|
|
89 | 98 |
|
90 | 99 |
|
91 |
TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeUuid, null); |
|
100 |
TaxonNode taxonNode = getCdmEntitySession().remoteLoad(service,taxonNodeUuid, null); |
|
101 |
taxonNode = getCdmEntitySession().load(taxonNode); |
|
102 |
if(taxonNode == null){ |
|
103 |
MessagingUtils.warningDialog("Not yet implemented", TaxonEditorInput.class, "Selected element is not type TaxonBase."); |
|
104 |
} |
|
105 |
init(taxonNode); |
|
92 | 106 |
|
93 |
if(taxonNode == null){ |
|
94 |
MessagingUtils.warningDialog("Not yet implemented", TaxonEditorInput.class, "Selected element is not type TaxonBase."); |
|
95 |
return null; |
|
96 |
} |
|
107 |
} |
|
97 | 108 |
|
98 |
return new TaxonEditorInput(taxonNode, conversation); |
|
109 |
private void initForTaxonBase(UUID taxonBaseUuid) { |
|
110 |
|
|
111 |
TaxonBase taxonBase = getCdmEntitySession().remoteLoad(CdmStore.getService(ITaxonService.class),taxonBaseUuid); |
|
112 |
if (taxonBase != null){ |
|
113 |
if(taxonBase.isInstanceOf(Taxon.class)){ |
|
114 |
Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class); |
|
115 |
|
|
116 |
if (taxon.getTaxonNodes().size() == 0 && taxon.isMisapplication()){ |
|
117 |
// TODO get accepted taxon |
|
118 |
MessagingUtils.info("trying to open Mispplied Name "); |
|
119 |
|
|
120 |
Set<Taxon> acceptedTaxa = new HashSet<Taxon>(); |
|
121 |
Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon(); |
|
122 |
for(TaxonRelationship relation : relations){ |
|
123 |
if(relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){ |
|
124 |
acceptedTaxa.add(relation.getToTaxon()); |
|
125 |
} |
|
126 |
} |
|
127 |
setInputForMultipleTaxa(conversation, acceptedTaxa); |
|
128 |
|
|
129 |
}else{ |
|
130 |
setInputForMultipleNodes(conversation, taxon.getTaxonNodes()); |
|
131 |
} |
|
132 |
}else if(taxonBase instanceof Synonym){ |
|
133 |
Synonym synonym = (Synonym) taxonBase; |
|
134 |
|
|
135 |
Set<Taxon> taxa = synonym.getAcceptedTaxa(); |
|
136 |
setInputForMultipleTaxa(conversation, taxa); |
|
137 |
} |
|
138 |
} |
|
99 | 139 |
} |
100 | 140 |
|
141 |
|
|
101 | 142 |
/** |
102 |
* <p>NewInstanceFromTaxonBase</p>
|
|
143 |
* <p>NewEmptyInstance</p>
|
|
103 | 144 |
* |
104 |
* @param taxonBaseUuid a {@link java.util.UUID} object.
|
|
145 |
* @param parentNodeUuid a {@link java.util.UUID} object.
|
|
105 | 146 |
* @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. |
106 | 147 |
*/ |
107 |
public static TaxonEditorInput NewInstanceFromTaxonBase(UUID taxonBaseUuid){ |
|
108 |
ConversationHolder conversation = CdmStore.createConversation(); |
|
109 |
|
|
110 |
TaxonEditorInput input = null; |
|
111 |
|
|
112 |
TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).find(taxonBaseUuid); |
|
113 |
if (taxonBase != null){ |
|
114 |
if(taxonBase.isInstanceOf(Taxon.class)){ |
|
115 |
Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class); |
|
116 |
|
|
117 |
if (taxon.getTaxonNodes().size() == 0 && taxon.isMisapplication()){ |
|
118 |
// TODO get accepted taxon |
|
119 |
MessagingUtils.info("trying to open Mispplied Name "); |
|
120 |
|
|
121 |
Set<Taxon> acceptedTaxa = new HashSet<Taxon>(); |
|
122 |
Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon(); |
|
123 |
for(TaxonRelationship relation : relations){ |
|
124 |
if(relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){ |
|
125 |
acceptedTaxa.add(relation.getToTaxon()); |
|
126 |
} |
|
127 |
} |
|
128 |
input = getInputForMultipleTaxa(conversation, acceptedTaxa); |
|
129 |
|
|
130 |
}else{ |
|
131 |
input = getInputForMultipleNodes(conversation, taxon.getTaxonNodes()); |
|
132 |
} |
|
133 |
}else if(taxonBase instanceof Synonym){ |
|
134 |
Synonym synonym = (Synonym) taxonBase; |
|
135 |
|
|
136 |
Set<Taxon> taxa = synonym.getAcceptedTaxa(); |
|
137 |
input = getInputForMultipleTaxa(conversation, taxa); |
|
138 |
} |
|
139 |
if (input != null){ |
|
140 |
input.setInitiallySelectedTaxonBase(taxonBase); |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
|
|
145 |
return input; |
|
148 |
private void initForParentTaxonNode(UUID parentNodeUuid){ |
|
149 |
|
|
150 |
|
|
151 |
TaxonNameBase<?, ?> name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null); |
|
152 |
ITaxonTreeNode parentNode = CdmStore.getService(IClassificationService.class).getTreeNodeByUuid(parentNodeUuid); |
|
153 |
parentNode = getCdmEntitySession().load(parentNode); |
|
154 |
|
|
155 |
Taxon newTaxon = Taxon.NewInstance(name, parentNode.getReference()); |
|
156 |
TaxonNode newTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference()); |
|
157 |
|
|
158 |
// add the new taxon to the editors persistence context |
|
159 |
UUID newTaxonNodeUuid = getCdmEntitySession().remoteSave(CdmStore.getService(ITaxonNodeService.class),newTaxonNode); |
|
160 |
|
|
161 |
initForTaxonNode(newTaxonNodeUuid); |
|
146 | 162 |
} |
147 | 163 |
|
148 |
private static TaxonEditorInput getInputForMultipleNodes(ConversationHolder conversation, Set<TaxonNode> taxonNodes){ |
|
149 |
if(taxonNodes.size() == 1){
|
|
150 |
TaxonNode taxonNode = taxonNodes.iterator().next();
|
|
151 |
return NewInstance(taxonNode.getUuid(), conversation);
|
|
152 |
}else if(taxonNodes.size() > 1){
|
|
153 |
TaxonNode taxonNode = ChooseFromMultipleTaxonNodesDialog.choose(taxonNodes);
|
|
154 |
if(taxonNode != null){
|
|
155 |
return NewInstance(taxonNode.getUuid(), conversation);
|
|
156 |
}
|
|
157 |
}else if(taxonNodes.size() == 0){
|
|
158 |
// this is an undesired state
|
|
159 |
MessagingUtils.warningDialog("Incorrect state", TaxonEditorInput.class, "The accepted taxon is not part of any classification. This should not have happened.");
|
|
160 |
}
|
|
161 |
return null;
|
|
164 |
|
|
165 |
private void setInputForMultipleNodes(ConversationHolder conversation, Set<TaxonNode> taxonNodes){
|
|
166 |
if(taxonNodes.size() == 1){
|
|
167 |
TaxonNode taxonNode = taxonNodes.iterator().next();
|
|
168 |
init(taxonNode);
|
|
169 |
}else if(taxonNodes.size() > 1){
|
|
170 |
TaxonNode taxonNode = ChooseFromMultipleTaxonNodesDialog.choose(taxonNodes);
|
|
171 |
if(taxonNode != null){
|
|
172 |
init(taxonNode);
|
|
173 |
}
|
|
174 |
}else if(taxonNodes.size() == 0){
|
|
175 |
// this is an undesired state
|
|
176 |
MessagingUtils.warningDialog("Incorrect state", TaxonEditorInput.class, "The accepted taxon is not part of any classification. This should not have happened.");
|
|
177 |
}
|
|
162 | 178 |
} |
163 | 179 |
|
164 |
private static TaxonEditorInput getInputForMultipleTaxa(ConversationHolder conversation, Set<Taxon> taxa){ |
|
165 |
if(taxa.size() == 1){ |
|
166 |
Taxon taxon = taxa.iterator().next(); |
|
167 |
Set<TaxonNode> nodes = taxon.getTaxonNodes(); |
|
168 |
return getInputForMultipleNodes(conversation, nodes); |
|
169 |
}else if(taxa.size() > 1){ |
|
170 |
Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>(); |
|
171 |
for ( Taxon taxon : taxa ){ |
|
172 |
taxonNodes.addAll(taxon.getTaxonNodes()); |
|
173 |
} |
|
174 |
return getInputForMultipleNodes(conversation, taxonNodes); |
|
175 |
}else if(taxa.size() == 0){ |
|
176 |
// this is an undesired state |
|
177 |
MessagingUtils.warningDialog("Incorrect state", TaxonEditorInput.class, "Trying to open accepted taxon for a synonym or misapplication but" + |
|
178 |
" no accepted taxa are present. This should not have happened."); |
|
179 |
} |
|
180 |
return null; |
|
180 |
private void setInputForMultipleTaxa(ConversationHolder conversation, Set<Taxon> taxa){ |
|
181 |
if(taxa.size() == 1){ |
|
182 |
Taxon taxon = taxa.iterator().next(); |
|
183 |
Set<TaxonNode> nodes = taxon.getTaxonNodes(); |
|
184 |
setInputForMultipleNodes(conversation, nodes); |
|
185 |
}else if(taxa.size() > 1){ |
|
186 |
Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>(); |
|
187 |
for ( Taxon taxon : taxa ){ |
|
188 |
taxonNodes.addAll(taxon.getTaxonNodes()); |
|
189 |
} |
|
190 |
setInputForMultipleNodes(conversation, taxonNodes); |
|
191 |
}else if(taxa.size() == 0){ |
|
192 |
// this is an undesired state |
|
193 |
MessagingUtils.warningDialog("Incorrect state", TaxonEditorInput.class, "Trying to open accepted taxon for a synonym or misapplication but" + |
|
194 |
" no accepted taxa are present. This should not have happened."); |
|
195 |
} |
|
181 | 196 |
} |
182 | 197 |
|
183 | 198 |
/** |
184 |
* <p>NewEmptyInstance</p>
|
|
199 |
* <p>NewInstance</p> |
|
185 | 200 |
* |
186 |
* @param parentNodeUuid a {@link java.util.UUID} object.
|
|
201 |
* @param taxonNodeUuid a {@link java.util.UUID} object.
|
|
187 | 202 |
* @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. |
203 |
* @throws java.lang.Exception if any. |
|
188 | 204 |
*/ |
189 |
public static TaxonEditorInput NewEmptyInstance(UUID parentNodeUuid){
|
|
190 |
ConversationHolder conversation = CdmStore.createConversation();
|
|
205 |
public static TaxonEditorInput NewInstance(UUID taxonNodeUuid) throws Exception {
|
|
206 |
return new TaxonEditorInput(taxonNodeUuid, CdmType.TAXON_NODE);
|
|
191 | 207 |
|
192 |
TaxonNameBase<?, ?> name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null); |
|
193 |
ITaxonTreeNode parentNode = CdmStore.getService(IClassificationService.class).getTreeNodeByUuid(parentNodeUuid); |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* <p>NewInstanceFromTaxonBase</p> |
|
212 |
* |
|
213 |
* @param taxonBaseUuid a {@link java.util.UUID} object. |
|
214 |
* @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. |
|
215 |
*/ |
|
216 |
public static TaxonEditorInput NewInstanceFromTaxonBase(UUID taxonBaseUuid){ |
|
217 |
return new TaxonEditorInput(taxonBaseUuid, CdmType.TAXON_BASE); |
|
218 |
} |
|
194 | 219 |
|
195 |
Taxon newTaxon = Taxon.NewInstance(name, parentNode.getReference()); |
|
196 |
TaxonNode newTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference()); |
|
197 | 220 |
|
198 |
// add the new taxon to the editors persistence context |
|
199 |
UUID newTaxonNodeUuid = CdmStore.getService(ITaxonNodeService.class).save(newTaxonNode); |
|
200 | 221 |
|
201 |
return new TaxonEditorInput(newTaxonNode, conversation); |
|
222 |
|
|
223 |
/** |
|
224 |
* <p>NewEmptyInstance</p> |
|
225 |
* |
|
226 |
* @param parentNodeUuid a {@link java.util.UUID} object. |
|
227 |
* @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. |
|
228 |
*/ |
|
229 |
public static TaxonEditorInput NewEmptyInstance(UUID parentNodeUuid){ |
|
230 |
return new TaxonEditorInput(parentNodeUuid, CdmType.PARENT_TAXON_NODE); |
|
202 | 231 |
} |
203 | 232 |
|
204 |
/* (non-Javadoc)
|
|
205 |
* @see org.eclipse.ui.IEditorInput#exists()
|
|
206 |
*/
|
|
207 |
/**
|
|
208 |
* <p>exists</p>
|
|
209 |
*
|
|
210 |
* @return a boolean.
|
|
211 |
*/
|
|
212 |
@Override
|
|
233 |
/* (non-Javadoc)
|
|
234 |
* @see org.eclipse.ui.IEditorInput#exists()
|
|
235 |
*/
|
|
236 |
/**
|
|
237 |
* <p>exists</p>
|
|
238 |
*
|
|
239 |
* @return a boolean.
|
|
240 |
*/
|
|
241 |
@Override
|
|
213 | 242 |
public boolean exists() { |
214 |
return taxonNode != null;
|
|
215 |
}
|
|
216 |
|
|
217 |
/* (non-Javadoc)
|
|
218 |
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
|
|
219 |
*/
|
|
220 |
/**
|
|
221 |
* <p>getImageDescriptor</p>
|
|
222 |
*
|
|
223 |
* @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
|
|
224 |
*/
|
|
225 |
@Override
|
|
243 |
return taxonNode != null;
|
|
244 |
}
|
|
245 |
|
|
246 |
/* (non-Javadoc)
|
|
247 |
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
|
|
248 |
*/
|
|
249 |
/**
|
|
250 |
* <p>getImageDescriptor</p>
|
|
251 |
*
|
|
252 |
* @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
|
|
253 |
*/
|
|
254 |
@Override
|
|
226 | 255 |
public ImageDescriptor getImageDescriptor() { |
227 |
return null;
|
|
228 |
}
|
|
229 |
|
|
230 |
/* (non-Javadoc)
|
|
231 |
* @see org.eclipse.ui.IEditorInput#getName()
|
|
232 |
*/
|
|
233 |
/**
|
|
234 |
* <p>getName</p>
|
|
235 |
*
|
|
236 |
* @return a {@link java.lang.String} object.
|
|
237 |
*/
|
|
238 |
@Override
|
|
256 |
return null;
|
|
257 |
}
|
|
258 |
|
|
259 |
/* (non-Javadoc)
|
|
260 |
* @see org.eclipse.ui.IEditorInput#getName()
|
|
261 |
*/
|
|
262 |
/**
|
|
263 |
* <p>getName</p>
|
|
264 |
*
|
|
265 |
* @return a {@link java.lang.String} object.
|
|
266 |
*/
|
|
267 |
@Override
|
|
239 | 268 |
public String getName() { |
240 |
if(getTaxon() == null){
|
|
241 |
return null;
|
|
242 |
}
|
|
243 |
TaxonNameBase<?, ?> name = getTaxon().getName();
|
|
244 |
if (name == null || name.getTitleCache() == null) {
|
|
245 |
return "New taxon";
|
|
246 |
} else {
|
|
247 |
return name.getTitleCache();
|
|
248 |
}
|
|
249 |
}
|
|
250 |
|
|
251 |
/* (non-Javadoc)
|
|
252 |
* @see org.eclipse.ui.IEditorInput#getPersistable()
|
|
253 |
*/
|
|
254 |
/**
|
|
255 |
* <p>getPersistable</p>
|
|
256 |
*
|
|
257 |
* @return a {@link org.eclipse.ui.IPersistableElement} object.
|
|
258 |
*/
|
|
259 |
@Override
|
|
269 |
if(getTaxon() == null){
|
|
270 |
return null;
|
|
271 |
}
|
|
272 |
TaxonNameBase<?, ?> name = getTaxon().getName();
|
|
273 |
if (name == null || name.getTitleCache() == null) {
|
|
274 |
return "New taxon";
|
|
275 |
} else {
|
|
276 |
return name.getTitleCache();
|
|
277 |
}
|
|
278 |
}
|
|
279 |
|
|
280 |
/* (non-Javadoc)
|
|
281 |
* @see org.eclipse.ui.IEditorInput#getPersistable()
|
|
282 |
*/
|
|
283 |
/**
|
|
284 |
* <p>getPersistable</p>
|
|
285 |
*
|
|
286 |
* @return a {@link org.eclipse.ui.IPersistableElement} object.
|
|
287 |
*/
|
|
288 |
@Override
|
|
260 | 289 |
public IPersistableElement getPersistable() { |
261 |
// if(CdmStore.isActive()){ |
|
262 |
// TaxonNode test = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid()); |
|
263 |
// boolean isPersistable = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid()) != null; |
|
264 |
// if (isPersistable) { |
|
265 |
// return this; |
|
266 |
// } |
|
267 |
// } |
|
268 |
return null;
|
|
269 |
}
|
|
270 |
|
|
271 |
/* (non-Javadoc)
|
|
272 |
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
|
273 |
*/
|
|
274 |
/**
|
|
275 |
* <p>getToolTipText</p>
|
|
276 |
*
|
|
277 |
* @return a {@link java.lang.String} object.
|
|
278 |
*/
|
|
279 |
@Override
|
|
290 |
// if(CdmStore.isActive()){
|
|
291 |
// TaxonNode test = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid());
|
|
292 |
// boolean isPersistable = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid()) != null;
|
|
293 |
// if (isPersistable) {
|
|
294 |
// return this;
|
|
295 |
// }
|
|
296 |
// }
|
|
297 |
return null;
|
|
298 |
}
|
|
299 |
|
|
300 |
/* (non-Javadoc)
|
|
301 |
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
|
302 |
*/
|
|
303 |
/**
|
|
304 |
* <p>getToolTipText</p>
|
|
305 |
*
|
|
306 |
* @return a {@link java.lang.String} object.
|
|
307 |
*/
|
|
308 |
@Override
|
|
280 | 309 |
public String getToolTipText() { |
281 |
return getName();
|
|
282 |
}
|
|
283 |
|
|
284 |
/* (non-Javadoc)
|
|
285 |
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
|
286 |
*/
|
|
287 |
/** {@inheritDoc} */
|
|
288 |
@Override
|
|
310 |
return getName();
|
|
311 |
}
|
|
312 |
|
|
313 |
/* (non-Javadoc)
|
|
314 |
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
|
315 |
*/
|
|
316 |
/** {@inheritDoc} */
|
|
317 |
@Override
|
|
289 | 318 |
public Object getAdapter(Class adapter) { |
290 | 319 |
|
291 |
if (adapter == Taxon.class) {
|
|
292 |
return taxonNode.getTaxon();
|
|
293 |
}
|
|
320 |
if (adapter == Taxon.class) {
|
|
321 |
return getTaxon();
|
|
322 |
}
|
|
294 | 323 |
|
295 |
if (adapter == TaxonNode.class) {
|
|
296 |
return taxonNode;
|
|
297 |
}
|
|
324 |
if (adapter == TaxonNode.class) {
|
|
325 |
return taxonNode;
|
|
326 |
}
|
|
298 | 327 |
|
299 |
return null;
|
|
300 |
}
|
|
328 |
return null;
|
|
329 |
}
|
|
301 | 330 |
|
302 |
/**
|
|
303 |
* {@inheritDoc}
|
|
304 |
*
|
|
305 |
* Overrides equals to ensure that a taxon can only be edited by
|
|
306 |
* one editor at a time.
|
|
307 |
*/
|
|
308 |
@Override
|
|
331 |
/**
|
|
332 |
* {@inheritDoc}
|
|
333 |
*
|
|
334 |
* Overrides equals to ensure that a taxon can only be edited by
|
|
335 |
* one editor at a time.
|
|
336 |
*/
|
|
337 |
@Override
|
|
309 | 338 |
public boolean equals(Object obj) { |
310 |
if (TaxonEditorInput.class.equals(obj.getClass()) |
|
311 |
&& getTaxon() != null |
|
312 |
&& getTaxon().equals(((TaxonEditorInput) obj).getTaxon())){ |
|
313 |
if(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase() != null){ |
|
314 |
setInitiallySelectedTaxonBase(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase()); |
|
315 |
} |
|
316 |
return true; |
|
317 |
} |
|
318 |
return false; |
|
319 |
} |
|
320 |
|
|
321 |
/** |
|
322 |
* <p>getTaxon</p> |
|
323 |
* |
|
324 |
* @return the taxon |
|
325 |
*/ |
|
326 |
public Taxon getTaxon(){ |
|
327 |
return taxonNode.getTaxon(); |
|
328 |
} |
|
329 |
|
|
330 |
/** |
|
331 |
* <p>Getter for the field <code>taxonNode</code>.</p> |
|
332 |
* |
|
333 |
* @return the taxonNode |
|
334 |
*/ |
|
335 |
public TaxonNode getTaxonNode() { |
|
336 |
return taxonNode; |
|
337 |
} |
|
338 |
|
|
339 |
/* |
|
340 |
* (non-Javadoc) |
|
341 |
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder() |
|
342 |
*/ |
|
343 |
/** |
|
344 |
* <p>getConversationHolder</p> |
|
345 |
* |
|
346 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
347 |
*/ |
|
348 |
@Override |
|
339 |
if (TaxonEditorInput.class.equals(obj.getClass()) |
|
340 |
&& getTaxon() != null |
|
341 |
&& getTaxon().equals(((TaxonEditorInput) obj).getTaxon())){ |
|
342 |
if(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase() != null){ |
|
343 |
setInitiallySelectedTaxonBase(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase()); |
|
344 |
} |
|
345 |
return true; |
|
346 |
} |
|
347 |
return false; |
|
348 |
} |
|
349 |
|
|
350 |
/** |
|
351 |
* <p>getTaxon</p> |
|
352 |
* |
|
353 |
* @return the taxon |
|
354 |
*/ |
|
355 |
public Taxon getTaxon(){ |
|
356 |
Taxon taxon = CdmBase.deproxy(taxonNode.getTaxon(), Taxon.class); |
|
357 |
return taxon; |
|
358 |
} |
|
359 |
|
|
360 |
/** |
|
361 |
* <p>Getter for the field <code>taxonNode</code>.</p> |
|
362 |
* |
|
363 |
* @return the taxonNode |
|
364 |
*/ |
|
365 |
public TaxonNode getTaxonNode() { |
|
366 |
return taxonNode; |
|
367 |
} |
|
368 |
|
|
369 |
/* |
|
370 |
* (non-Javadoc) |
|
371 |
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder() |
|
372 |
*/ |
|
373 |
/** |
|
374 |
* <p>getConversationHolder</p> |
|
375 |
* |
|
376 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
377 |
*/ |
|
378 |
@Override |
|
349 | 379 |
public ConversationHolder getConversationHolder() { |
350 |
return conversation;
|
|
351 |
}
|
|
352 |
|
|
353 |
/*
|
|
354 |
* (non-Javadoc)
|
|
355 |
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
|
|
356 |
*/
|
|
357 |
/** {@inheritDoc} */
|
|
358 |
@Override
|
|
380 |
return conversation;
|
|
381 |
}
|
|
382 |
|
|
383 |
/*
|
|
384 |
* (non-Javadoc)
|
|
385 |
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
|
|
386 |
*/
|
|
387 |
/** {@inheritDoc} */
|
|
388 |
@Override
|
|
359 | 389 |
public void update(CdmDataChangeMap events) { |
360 |
if(dataChangeBehavior == null){
|
|
361 |
dataChangeBehavior = new TaxonEditorInputDataChangeBehaviour(this);
|
|
362 |
}
|
|
363 |
|
|
364 |
DataChangeBridge.handleDataChange(events, dataChangeBehavior);
|
|
365 |
}
|
|
366 |
|
|
367 |
/* (non-Javadoc)
|
|
368 |
* @see org.eclipse.ui.IPersistableElement#getFactoryId()
|
|
369 |
*/
|
|
370 |
/**
|
|
371 |
* <p>getFactoryId</p>
|
|
372 |
*
|
|
373 |
* @return a {@link java.lang.String} object.
|
|
374 |
*/
|
|
375 |
@Override
|
|
390 |
if(dataChangeBehavior == null){
|
|
391 |
dataChangeBehavior = new TaxonEditorInputDataChangeBehaviour(this);
|
|
392 |
}
|
|
393 |
|
|
394 |
DataChangeBridge.handleDataChange(events, dataChangeBehavior);
|
|
395 |
}
|
|
396 |
|
|
397 |
/* (non-Javadoc)
|
|
398 |
* @see org.eclipse.ui.IPersistableElement#getFactoryId()
|
|
399 |
*/
|
|
400 |
/**
|
|
401 |
* <p>getFactoryId</p>
|
|
402 |
*
|
|
403 |
* @return a {@link java.lang.String} object.
|
|
404 |
*/
|
|
405 |
@Override
|
|
376 | 406 |
public String getFactoryId() { |
377 |
return TaxonEditorInputFactory.getFactoryId();
|
|
378 |
}
|
|
379 |
|
|
380 |
/* (non-Javadoc)
|
|
381 |
* @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
|
|
382 |
*/
|
|
383 |
/** {@inheritDoc} */
|
|
384 |
@Override
|
|
407 |
return TaxonEditorInputFactory.getFactoryId();
|
|
408 |
}
|
|
409 |
|
|
410 |
/* (non-Javadoc)
|
|
411 |
* @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
|
|
412 |
*/
|
|
413 |
/** {@inheritDoc} */
|
|
414 |
@Override
|
|
385 | 415 |
public void saveState(IMemento memento) { |
386 |
TaxonEditorInputFactory.saveState(memento, this);
|
|
387 |
}
|
|
416 |
TaxonEditorInputFactory.saveState(memento, this);
|
|
417 |
}
|
|
388 | 418 |
|
389 | 419 |
|
390 | 420 |
/** |
... | ... | |
393 | 423 |
* @param taxonBase a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object. |
394 | 424 |
*/ |
395 | 425 |
public void setInitiallySelectedTaxonBase(TaxonBase taxonBase) { |
396 |
this.initiallySelectedTaxonBase = taxonBase; |
|
397 |
} |
|
398 |
|
|
399 |
/** |
|
400 |
* <p>Getter for the field <code>initiallySelectedTaxonBase</code>.</p> |
|
401 |
* |
|
402 |
* @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object. |
|
403 |
*/ |
|
404 |
public TaxonBase getInitiallySelectedTaxonBase() { |
|
405 |
return initiallySelectedTaxonBase; |
|
406 |
} |
|
407 |
|
|
408 |
@Override |
|
409 |
public String toString() { |
|
410 |
return String.format("%s[%s]", this.getClass().getSimpleName(), getTaxon()); |
|
411 |
} |
|
426 |
this.initiallySelectedTaxonBase = taxonBase; |
|
427 |
} |
|
428 |
|
|
429 |
/** |
|
430 |
* <p>Getter for the field <code>initiallySelectedTaxonBase</code>.</p> |
|
431 |
* |
|
432 |
* @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object. |
|
433 |
*/ |
|
434 |
public TaxonBase getInitiallySelectedTaxonBase() { |
|
435 |
return initiallySelectedTaxonBase; |
|
436 |
} |
|
437 |
|
|
438 |
@Override |
|
439 |
public String toString() { |
|
440 |
return String.format("%s[%s]", this.getClass().getSimpleName(), getTaxon()); |
|
441 |
} |
|
442 |
|
|
443 |
/* (non-Javadoc) |
|
444 |
* @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#getService() |
|
445 |
*/ |
|
446 |
@Override |
|
447 |
public ITaxonNodeService getService() { |
|
448 |
return service; |
|
449 |
} |
|
450 |
|
|
451 |
|
|
452 |
/* (non-Javadoc) |
|
453 |
* @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#getRootEntities() |
|
454 |
*/ |
|
455 |
@Override |
|
456 |
public List<TaxonNode> getRootEntities() { |
|
457 |
return Arrays.asList(taxonNode); |
|
458 |
} |
|
412 | 459 |
} |
Also available in: Unified diff
CdmModelCacher : added recursive search in super classes
CdmTransientEntityCacher : corrected caching
EntityCacherDebugResult : new debug result object
CdmEntitySession, ICdmEntitySession, MockCdmEntitySession : added debug method
CdmEntitySessionInput : new super class for editor input objects
TaxonEditorInput : refactored and made sub class of CdmEntitySessionInput
DeleteNodeOperation : using new uuid service methods
TaxonNameEditor : removed unnecessary service call to retrieve taxon
TaxonLinkHelper : removed unnecessary second call to initialise input
AbstractCdmViewPart : now implements ISessionEnabled