1
|
package eu.etaxonomy.taxeditor.editor.handler;
|
2
|
|
3
|
import java.util.UUID;
|
4
|
|
5
|
import org.eclipse.core.commands.ExecutionEvent;
|
6
|
import org.eclipse.ui.PartInitException;
|
7
|
|
8
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
9
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
10
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
11
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
12
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
13
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
14
|
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
|
15
|
import eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenHandlerBase;
|
16
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
17
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
18
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
19
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
20
|
|
21
|
public class OpenChecklistEditorHandler extends DefaultOpenHandlerBase<ITaxonTreeNode> {
|
22
|
|
23
|
@Override
|
24
|
protected ITaxonTreeNode getEntity(UUID uuid) {
|
25
|
ITaxonTreeNode taxonTreeNode = CdmStore.getService(ITaxonNodeService.class).load(uuid);
|
26
|
if(taxonTreeNode==null){
|
27
|
taxonTreeNode = CdmStore.getService(IClassificationService.class).load(uuid);
|
28
|
}
|
29
|
return taxonTreeNode;
|
30
|
}
|
31
|
|
32
|
@Override
|
33
|
protected void open(ExecutionEvent event, ITaxonTreeNode entity) {
|
34
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE)) {
|
35
|
if (entity instanceof Classification) {
|
36
|
ChecklistEditorInput input = new ChecklistEditorInput(((Classification) entity));
|
37
|
try {
|
38
|
EditorUtil.open(input);
|
39
|
} catch (PartInitException e) {
|
40
|
MessagingUtils.error(OpenChecklistEditorHandler.class, "Could not open ChecklistView", e);
|
41
|
} catch (NullPointerException npe) {
|
42
|
MessagingUtils.messageDialog("Failed to open Editor", OpenChecklistEditorHandler.class,
|
43
|
"Could not open ChecklistView. The hierarchy is corrupted!", npe);
|
44
|
}
|
45
|
} else if (entity instanceof TaxonNode) {
|
46
|
ChecklistEditorInput input = new ChecklistEditorInput((TaxonNode) entity);
|
47
|
try {
|
48
|
EditorUtil.open(input);
|
49
|
} catch (PartInitException e) {
|
50
|
MessagingUtils.error(OpenChecklistEditorHandler.class, "Could not open ChecklistView", e);
|
51
|
} catch (NullPointerException npe) {
|
52
|
MessagingUtils.messageDialog("Failed to open Editor", OpenChecklistEditorHandler.class,
|
53
|
"Could not open ChecklistView. The hierarchy is corrupted!", npe);
|
54
|
}
|
55
|
}
|
56
|
}
|
57
|
}
|
58
|
}
|