Revision 880f5390
Added by Andreas Müller almost 3 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/defaultHandler/DefaultOpenTaxonEditorForTaxonBaseHandler.java | ||
---|---|---|
14 | 14 |
import org.eclipse.swt.widgets.Shell; |
15 | 15 |
|
16 | 16 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
17 |
import eu.etaxonomy.cdm.persistence.dto.ReferencingObjectDto; |
|
18 | 17 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
19 | 18 |
import eu.etaxonomy.taxeditor.editor.AppModelId; |
20 | 19 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
21 | 20 |
import eu.etaxonomy.taxeditor.handler.defaultHandler.e4.DefaultOpenHandlerBaseE4; |
22 | 21 |
|
23 | 22 |
public class DefaultOpenTaxonEditorForTaxonBaseHandler |
24 |
extends DefaultOpenHandlerBaseE4<Object> {
|
|
23 |
extends DefaultOpenHandlerBaseE4<TaxonBase, UuidAndTitleCache<TaxonBase>> {
|
|
25 | 24 |
|
26 | 25 |
@Override |
27 |
protected void open(Object entity, Shell shell, EPartService partService) throws Exception { |
|
28 |
if (entity instanceof TaxonBase){ |
|
29 |
EditorUtil.openTaxonBaseE4(((TaxonBase<?>)entity).getUuid(), modelService, partService, application); |
|
30 |
}else if (entity instanceof UuidAndTitleCache){ |
|
31 |
UUID uuid = getTaxonUuid((UuidAndTitleCache<?>)entity); |
|
32 |
EditorUtil.openTaxonBaseE4(uuid, modelService, partService, application); |
|
33 |
}else{ |
|
34 |
throw new Exception("Only objects of type taxonbase can be handled."); |
|
35 |
} |
|
36 |
} |
|
37 |
|
|
38 |
private UUID getTaxonUuid(UuidAndTitleCache<?> dto) { |
|
39 |
dto = getTarget(dto); |
|
40 |
if (TaxonBase.class.isAssignableFrom(dto.getType())){ |
|
41 |
return dto.getUuid(); |
|
42 |
// }else if (SecundumSource.class.isAssignableFrom(dto.getType())) { |
|
43 |
// //TODO use entity directly from RefObjectDto (but currently not available here) |
|
44 |
// SecundumSource source = CdmStore.getCommonService().find(SecundumSource.class, dto.getUuid()); |
|
45 |
// return source.getSourcedTaxon().getUuid(); |
|
46 |
}else { |
|
47 |
return dto.getUuid(); //to avoid NPE at this point |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
private UuidAndTitleCache<?> getTarget(UuidAndTitleCache<?> entity) { |
|
52 |
if (entity instanceof ReferencingObjectDto){ |
|
53 |
ReferencingObjectDto dto = (ReferencingObjectDto)entity; |
|
54 |
entity = dto.getOpenInTarget() != null ? dto.getOpenInTarget() : entity; |
|
55 |
} |
|
56 |
return entity; |
|
26 |
protected void open(UuidAndTitleCache<TaxonBase> entity, Shell shell, EPartService partService) throws Exception { |
|
27 |
UUID uuid = entity.getUuid(); |
|
28 |
EditorUtil.openTaxonBaseE4(uuid, modelService, partService, application); |
|
57 | 29 |
} |
58 | 30 |
|
59 | 31 |
@Override |
60 |
protected boolean canExecute(Object entity) {
|
|
61 |
if (entity instanceof TaxonBase){
|
|
32 |
protected boolean canExecute(UuidAndTitleCache<TaxonBase> entity) {
|
|
33 |
if (TaxonBase.class.isAssignableFrom(entity.getType())) {
|
|
62 | 34 |
return true; |
63 |
} else if (entity instanceof UuidAndTitleCache){ |
|
64 |
UuidAndTitleCache<?> dto = getTarget((UuidAndTitleCache<?>)entity); |
|
65 |
if (TaxonBase.class.isAssignableFrom(dto.getType())) { |
|
66 |
return true; |
|
67 |
} |
|
68 | 35 |
} |
69 | 36 |
return false; |
70 | 37 |
} |
Also available in: Unified diff
ref #9541 refactor Open..Handlers to all use UuidAndTitleCache as input and some more changes and bugfixes