Project

General

Profile

Download (3.62 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.e4.handler;
10

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
16
import org.eclipse.core.runtime.jobs.Job;
17
import org.eclipse.e4.core.di.annotations.CanExecute;
18
import org.eclipse.e4.core.di.annotations.Execute;
19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
21
import org.eclipse.e4.ui.services.IServiceConstants;
22
import org.eclipse.e4.ui.workbench.modeling.EPartService;
23
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
24
import org.eclipse.swt.widgets.Display;
25

    
26
import eu.etaxonomy.cdm.model.common.CdmBase;
27
import eu.etaxonomy.cdm.model.common.Group;
28
import eu.etaxonomy.taxeditor.editor.EditorUtil;
29
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor;
30
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
31
import eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4;
32
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
33
import eu.etaxonomy.taxeditor.model.MessagingUtils;
34

    
35
/**
36
 * Handler which opens an instance of the {@link CdmAuthorityEditor} for a2
37
 * particluar group.
38
 *
39
 * @author cmathew
40
 * @created Mar 28, 2013
41
 *
42
 */
43

    
44
public class EditCdmAuthoritiesHandlerE4 {
45

    
46
    private static final String OPENING_CDM_AUTHORITIES = Messages.EditCdmAuthoritiesHandler_OPEN_AUTHORITIES;
47

    
48
    @Execute
49
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) CdmBase selection,
50
            EPartService partService) {
51
        Job job = new Job(OPENING_CDM_AUTHORITIES) {
52
            @Override
53
            protected IStatus run(IProgressMonitor monitor) {
54
                monitor.beginTask(OPENING_CDM_AUTHORITIES, 1);//selection.size());
55

    
56
                if (selection instanceof Group) {
57
                    Display.getDefault().asyncExec(new Runnable() {
58
                        @Override
59
                        public void run() {
60
                            try {
61
                                MPart part = partService.createPart("eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4");
62
                                part = partService.showPart(part, PartState.ACTIVATE);
63
                                CdmAuthorityEditorE4 editor = (CdmAuthorityEditorE4) part.getObject();
64
                                editor.init(CdmAuthorityEditorInput.NewInstance(((Group) selection).getUuid()));
65
                            } catch (Exception e) {
66
                                MessagingUtils.warningDialog(
67
                                        Messages.EditCdmAuthoritiesHandler_COULD_NOT_OPEN_AUTHORITIES,
68
                                        EditorUtil.class, e.getMessage());
69
                            }
70
                        }
71

    
72
                    });
73
                    monitor.worked(1);
74
                }
75
                monitor.done();
76
                return Status.OK_STATUS;
77
            }
78
        };
79
        job.setPriority(Job.SHORT);
80
        job.schedule();
81
    }
82

    
83
    @CanExecute
84
    public boolean execute(@Named(IServiceConstants.ACTIVE_SELECTION) CdmBase selection,
85
            MHandledMenuItem menuItem){
86
        boolean canExecute = false;
87
        canExecute = selection instanceof Group;
88
        menuItem.setVisible(canExecute);
89
        return canExecute;
90

    
91
    }
92
}
    (1-1/1)