145b81a1a24d89238d0749ac67fbd991a7cb60ef
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / handler / OpenChecklistEditorHandler.java
1 package eu.etaxonomy.taxeditor.editor.handler;
2
3 import java.util.UUID;
4
5 import org.apache.commons.lang.StringUtils;
6 import org.eclipse.core.commands.ExecutionEvent;
7 import org.eclipse.ui.PartInitException;
8
9 import eu.etaxonomy.cdm.api.service.IClassificationService;
10 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
11 import eu.etaxonomy.cdm.model.taxon.Classification;
12 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
13 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
14 import eu.etaxonomy.taxeditor.editor.EditorUtil;
15 import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
16 import eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenHandlerBase;
17 import eu.etaxonomy.taxeditor.model.MessagingUtils;
18 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
19 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20 import eu.etaxonomy.taxeditor.store.CdmStore;
21
22 public class OpenChecklistEditorHandler extends DefaultOpenHandlerBase<ITaxonTreeNode> {
23
24 @Override
25 protected ITaxonTreeNode getEntity(UUID uuid) {
26 ITaxonTreeNode taxonTreeNode = CdmStore.getService(ITaxonNodeService.class).load(uuid);
27 if(taxonTreeNode==null){
28 taxonTreeNode = CdmStore.getService(IClassificationService.class).load(uuid);
29 }
30 return taxonTreeNode;
31 }
32
33 @Override
34 protected void open(ExecutionEvent event, ITaxonTreeNode entity) {
35 if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE)) {
36 if (StringUtils.isBlank(PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.DISTRIBUTION_AREA_OCCURENCE_STATUS) )){
37 MessagingUtils.informationDialog("No Areas to display", "Please choose the areas you want to display. "
38 + "Therefore go to the preferences, choose the Checklist Editor and choose the areas in the Distribution Selection Wizard.");
39 this.dispose();
40 return;
41 }
42 if (entity instanceof Classification) {
43 ChecklistEditorInput input = new ChecklistEditorInput(((Classification) entity));
44 try {
45 EditorUtil.open(input);
46 } catch (PartInitException e) {
47 MessagingUtils.error(OpenChecklistEditorHandler.class, "Could not open Distribution Editor", e);
48 } catch (NullPointerException npe) {
49 MessagingUtils.messageDialog("Failed to open Editor", OpenChecklistEditorHandler.class,
50 "Could not open Distribution Editor. The hierarchy is corrupted!", npe);
51 }
52 } else if (entity instanceof TaxonNode) {
53 ChecklistEditorInput input = new ChecklistEditorInput((TaxonNode) entity);
54 try {
55 EditorUtil.open(input);
56 } catch (PartInitException e) {
57 MessagingUtils.error(OpenChecklistEditorHandler.class, "Could not open Distribution Editor", e);
58 } catch (NullPointerException npe) {
59 MessagingUtils.messageDialog("Failed to open Editor", OpenChecklistEditorHandler.class,
60 "Could not open Distribution Editor. The hierarchy is corrupted!", npe);
61 }
62 }
63 }
64 }
65 }