Project

General

Profile

Download (3.08 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.handler;
2

    
3
import org.apache.log4j.Logger;
4
import org.eclipse.core.commands.AbstractHandler;
5
import org.eclipse.core.commands.ExecutionEvent;
6
import org.eclipse.core.commands.ExecutionException;
7
import org.eclipse.jface.viewers.ISelection;
8
import org.eclipse.jface.viewers.IStructuredSelection;
9
import org.eclipse.ui.PartInitException;
10
import org.eclipse.ui.handlers.HandlerUtil;
11

    
12
import eu.etaxonomy.cdm.model.taxon.Classification;
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.model.AbstractUtility;
17
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
18
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
19

    
20
public class OpenChecklistEditorHandler extends AbstractHandler {
21

    
22
    private static final Logger logger = Logger.getLogger(OpenChecklistEditorHandler.class);
23

    
24
    /*
25
     * (non-Javadoc)
26
     *
27
     * @see
28
     * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
29
     * ExecutionEvent)
30
     */
31
    @Override
32
    public Object execute(ExecutionEvent event) throws ExecutionException {
33
        boolean isChecklistEditorActivated = PreferencesUtil.getPreferenceStore().getBoolean(
34
                IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE);
35
        if (isChecklistEditorActivated) {
36
            ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
37
            if (currentSelection instanceof IStructuredSelection) {
38
                Object selectedElement = ((IStructuredSelection) currentSelection).getFirstElement();
39
                if (selectedElement instanceof Classification) {
40
                    ChecklistEditorInput input = new ChecklistEditorInput(((Classification) selectedElement));
41
                    try {
42
                        EditorUtil.open(input);
43
                    } catch (PartInitException e) {
44
                        AbstractUtility.error(OpenChecklistEditorHandler.class, "Could not open ChecklistView", e);
45
                    } catch (NullPointerException npe) {
46
                        AbstractUtility.errorDialog("Failed to open Editor", OpenChecklistEditorHandler.class,
47
                                "Could not open ChecklistView. The hierarchy is corrupted!", npe);
48
                    }
49
                } else if (selectedElement instanceof TaxonNode) {
50
                    ChecklistEditorInput input = new ChecklistEditorInput(((TaxonNode) selectedElement));
51
                    try {
52
                        EditorUtil.open(input);
53
                    } catch (PartInitException e) {
54
                        AbstractUtility.error(OpenChecklistEditorHandler.class, "Could not open ChecklistView", e);
55
                    } catch (NullPointerException npe) {
56
                        AbstractUtility.errorDialog("Failed to open Editor", OpenChecklistEditorHandler.class,
57
                                "Could not open ChecklistView. The hierarchy is corrupted!", npe);
58
                    }
59
                }
60
            }
61
        }
62
        return null;
63
    }
64
}
(2-2/6)