Project

General

Profile

Download (2.78 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.navigation.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.taxon.Classification;
29
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
30
import eu.etaxonomy.taxeditor.wizard.ClassificationWizard;
31

    
32
/**
33
 * <p>EditHandler class.</p>
34
 *
35
 * @author n.hoffmann
36
 * @created May 12, 2010
37
 * @version 1.0
38
 */
39
public class EditHandler extends AbstractHandler implements IHandler{
40

    
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
43
	 */
44
	/** {@inheritDoc} */
45
	public Object execute(ExecutionEvent event) throws ExecutionException {
46
	
47
		ISelection selection = HandlerUtil.getCurrentSelection(event);//navigator.getSelection();
48
		
49
		if(selection instanceof StructuredSelection){
50
			final StructuredSelection structuredSelection = (StructuredSelection) selection;
51
			
52
			if(structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof Classification){
53
				ClassificationWizard classificationWizard = new ClassificationWizard((Classification) structuredSelection.getFirstElement());
54
				
55
				WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
56
				dialog.open();
57
				
58
			}
59
			else{
60

    
61
				Job job = new Job("Opening editor") {
62
					
63
					@Override
64
					protected IStatus run(IProgressMonitor monitor) {
65
						for(final Object selectedObject : structuredSelection.toArray()){
66
							
67
							if(selectedObject instanceof CdmBase){
68
								// let the openEditor() method handle everything from now on
69
								Display.getDefault().asyncExec(new Runnable(){
70

    
71
									public void run() {
72
										NavigationUtil.openEditor((CdmBase) selectedObject);
73
									}
74
									
75
								});
76
							}else{
77
								throw new IllegalArgumentException("selectedObject is not of type CdmBase");
78
							}
79
						}
80
						return Status.OK_STATUS;
81
					}
82
				};
83
				
84
				job.schedule();
85
			}
86
		}
87
		
88
		return null;
89
	}
90
}
(2-2/7)