Project

General

Profile

Download (3.12 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.model.MessagingUtils;
18
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
19
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20

    
21
public class OpenChecklistEditorHandler extends AbstractHandler {
22

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

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