Merged refactoring from development branch.
[taxeditor.git] / taxeditor-navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / EditHandler.java
1 package eu.etaxonomy.taxeditor.navigation.navigator.handler;
2 // $Id$
3 /**
4 * Copyright (C) 2007 EDIT
5 * European Distributed Institute of Taxonomy
6 * http://www.e-taxonomy.eu
7 *
8 * The contents of this file are subject to the Mozilla Public License Version 1.1
9 * See LICENSE.TXT at the top of this package for the full license terms.
10 */
11
12
13 import org.eclipse.core.commands.AbstractHandler;
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.core.commands.IHandler;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.Status;
20 import org.eclipse.core.runtime.jobs.Job;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.StructuredSelection;
23 import org.eclipse.jface.wizard.WizardDialog;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.ui.handlers.HandlerUtil;
26
27 import eu.etaxonomy.cdm.model.common.CdmBase;
28 import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
29 import eu.etaxonomy.cdm.model.taxon.Classification;
30 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
31 import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
32
33 /**
34 * <p>EditHandler class.</p>
35 *
36 * @author n.hoffmann
37 * @created May 12, 2010
38 * @version 1.0
39 */
40 public class EditHandler extends AbstractHandler implements IHandler{
41
42 /* (non-Javadoc)
43 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
44 */
45 /** {@inheritDoc} */
46 public Object execute(ExecutionEvent event) throws ExecutionException {
47
48 ISelection selection = HandlerUtil.getCurrentSelection(event);//navigator.getSelection();
49
50 if(selection instanceof StructuredSelection){
51 final StructuredSelection structuredSelection = (StructuredSelection) selection;
52
53 if(structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof Classification){
54 Classification classification = (Classification) structuredSelection.getFirstElement();
55
56 NewClassificationWizard classificationWizard = new NewClassificationWizard();
57 classificationWizard.init(null, new StructuredSelection(classification));
58 WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
59 dialog.open();
60
61 }
62 else{
63
64 Job job = new Job("Opening editor") {
65
66 @Override
67 protected IStatus run(IProgressMonitor monitor) {
68 for(final Object selectedObject : structuredSelection.toArray()){
69
70 Display.getDefault().asyncExec(new Runnable(){
71
72 public void run() {
73 NavigationUtil.openEditor(selectedObject);
74 }
75
76 });
77 }
78 return Status.OK_STATUS;
79 }
80 };
81
82 job.schedule();
83 }
84 }
85
86 return null;
87 }
88 }