Moved all logging and dialog functionality to the new class MessagingUtils.
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / group / authority / handler / EditCdmAuthoritiesHandler.java
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.model.LineSelection;
26 import eu.etaxonomy.taxeditor.model.MessagingUtils;
27
28
29 /**
30 * Handler which opens an instance of the {@link CdmAuthorityEditor} for a particluar group.
31 *
32 * @author cmathew
33 * @created Mar 28, 2013
34 *
35 */
36
37 public class EditCdmAuthoritiesHandler extends AbstractHandler {
38
39 /* (non-Javadoc)
40 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
41 */
42 @Override
43 public Object execute(ExecutionEvent event) throws ExecutionException {
44 BulkEditor editor = (BulkEditor) EditorUtil.getActiveEditor();
45
46 ISelection selection = editor.getSite().getSelectionProvider().getSelection();
47 if(selection instanceof LineSelection){
48
49 final LineSelection lineSelection = (LineSelection) selection;
50
51 Job job = new Job("Opening Cdm Authorities"){
52
53 @Override
54 protected IStatus run(IProgressMonitor monitor) {
55 monitor.beginTask("Opening Cdm Authorities", lineSelection.size());
56
57 for(final Object selectedObject : lineSelection.toArray()){
58 if(selectedObject instanceof Group){
59
60 Display.getDefault().asyncExec(new Runnable(){
61
62 @Override
63 public void run() {
64 try {
65 EditorUtil.openCdmAuthorities(((Group)selectedObject).getUuid());
66 } catch (Exception e) {
67 MessagingUtils.warningDialog("Could not open CDM Authority Editor", EditorUtil.class, e.getMessage());
68 }
69 }
70
71 });
72 monitor.worked(1);
73 }
74 }
75 monitor.done();
76 return Status.OK_STATUS;
77 }
78
79 };
80
81 job.setPriority(Job.SHORT);
82 job.schedule();
83
84 }
85 return null;
86 }
87
88 }
89