Project

General

Profile

Download (2.71 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.group.authority.handler;
10

    
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.core.runtime.jobs.Job;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.swt.widgets.Display;
20

    
21
import eu.etaxonomy.cdm.model.common.Group;
22
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
23
import eu.etaxonomy.taxeditor.editor.EditorUtil;
24
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor;
25
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
26
import eu.etaxonomy.taxeditor.model.LineSelection;
27
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28

    
29

    
30
/**
31
 * Handler which opens an instance of the {@link CdmAuthorityEditor} for a particluar group.
32
 *
33
 * @author cmathew
34
 * @created Mar 28, 2013
35
 *
36
 */
37

    
38
public class EditCdmAuthoritiesHandler  extends AbstractHandler {
39

    
40
    private static final String OPENING_CDM_AUTHORITIES = Messages.EditCdmAuthoritiesHandler_OPEN_AUTHORITIES;
41

    
42
    /* (non-Javadoc)
43
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
44
	 */
45
	@Override
46
	public Object execute(ExecutionEvent event) throws ExecutionException {
47
		BulkEditor editor = (BulkEditor) EditorUtil.getActiveEditor();
48

    
49
		ISelection selection = editor.getSite().getSelectionProvider().getSelection();
50
		if(selection instanceof LineSelection){
51

    
52
			final LineSelection lineSelection = (LineSelection) selection;
53

    
54
			Job job = new Job(OPENING_CDM_AUTHORITIES){
55

    
56
				@Override
57
				protected IStatus run(IProgressMonitor monitor) {
58
					monitor.beginTask(OPENING_CDM_AUTHORITIES, lineSelection.size());
59

    
60
					for(final Object selectedObject : lineSelection.toArray()){
61
						if(selectedObject instanceof Group){
62

    
63
							Display.getDefault().asyncExec(new Runnable(){
64

    
65
								@Override
66
								public void run() {
67
									try {
68
										EditorUtil.openCdmAuthorities(((Group)selectedObject).getUuid());
69
									} catch (Exception e) {
70
										MessagingUtils.warningDialog(Messages.EditCdmAuthoritiesHandler_COULD_NOT_OPEN_AUTHORITIES, EditorUtil.class, e.getMessage());
71
									}
72
								}
73

    
74
							});
75
							monitor.worked(1);
76
						}
77
					}
78
					monitor.done();
79
					return Status.OK_STATUS;
80
				}
81

    
82
			};
83

    
84
			job.setPriority(Job.SHORT);
85
			job.schedule();
86

    
87
		}
88
		return null;
89
	}
90

    
91
}
92

    
    (1-1/1)