1
|
/**
|
2
|
* Copyright (C) 2015 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.navigation.key.polytomous.e4.handler;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
|
13
|
import javax.inject.Named;
|
14
|
|
15
|
import org.eclipse.core.runtime.IProgressMonitor;
|
16
|
import org.eclipse.core.runtime.IStatus;
|
17
|
import org.eclipse.core.runtime.Status;
|
18
|
import org.eclipse.core.runtime.jobs.Job;
|
19
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
20
|
import org.eclipse.e4.core.di.annotations.Execute;
|
21
|
import org.eclipse.e4.ui.model.application.MApplication;
|
22
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
23
|
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
|
24
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
25
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
26
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
27
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
28
|
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
|
29
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
30
|
import org.eclipse.swt.widgets.Display;
|
31
|
|
32
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
33
|
import eu.etaxonomy.taxeditor.editor.AppModelId;
|
34
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
|
35
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.e4.PolytomousKeyListEditorE4;
|
36
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
37
|
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewLabels;
|
38
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
39
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
40
|
|
41
|
/**
|
42
|
* @author cmathew
|
43
|
* @date 29 Jun 2015
|
44
|
*
|
45
|
*/
|
46
|
public class RemotingEditPolytomousKeyNodesHandlerE4 {
|
47
|
|
48
|
public static final String OPENING_POLYTOMOUS_KEYS = Messages.EditPolytomousKeyNodesHandler_OPEN_KEYS;
|
49
|
|
50
|
@Execute
|
51
|
public void execute(EModelService modelService, EPartService partService, MApplication application,
|
52
|
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection structuredSelection) {
|
53
|
|
54
|
Job job = new Job(OPENING_POLYTOMOUS_KEYS){
|
55
|
|
56
|
@Override
|
57
|
protected IStatus run(IProgressMonitor monitor) {
|
58
|
monitor.beginTask(OPENING_POLYTOMOUS_KEYS, structuredSelection.size());
|
59
|
|
60
|
for(final Object selectedObject : structuredSelection.toArray()){
|
61
|
if(selectedObject instanceof PolytomousKey){
|
62
|
|
63
|
Display.getDefault().asyncExec(new Runnable(){
|
64
|
|
65
|
@Override
|
66
|
public void run() {
|
67
|
try {
|
68
|
PolytomousKey key = (PolytomousKey) selectedObject;
|
69
|
PolytomousKeyEditorInput input = PolytomousKeyEditorInput.NewInstance(key.getUuid());
|
70
|
|
71
|
//check if editor already open
|
72
|
Collection<MPart> parts = partService.getParts();
|
73
|
MPart part = null;
|
74
|
//check if part is already opened
|
75
|
for (MPart mPart : parts) {
|
76
|
if(mPart.getObject() instanceof PolytomousKeyListEditorE4
|
77
|
&& ((PolytomousKeyListEditorE4) mPart.getObject()).getViewerInputKey().equals(input.getKey())){
|
78
|
part = mPart;
|
79
|
break;
|
80
|
}
|
81
|
}
|
82
|
if(part==null){
|
83
|
part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_KEY_POLYTOMOUS_E4_POLYTOMOUSKEYLISTEDITORE4);
|
84
|
MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
|
85
|
if(editorAreaPartStack!=null){
|
86
|
editorAreaPartStack.getChildren().add(part);
|
87
|
}
|
88
|
part = partService.showPart(part, PartState.ACTIVATE);
|
89
|
PolytomousKeyListEditorE4 editor = (PolytomousKeyListEditorE4) part.getObject();
|
90
|
editor.init(input);
|
91
|
}
|
92
|
part = partService.showPart(part, PartState.ACTIVATE);
|
93
|
} catch(Exception ex) {
|
94
|
MessagingUtils.warningDialog(PolytomousKeyViewLabels.ERROR_OPENING_KEY_EDITOR_MESSAGE,
|
95
|
RemotingEditPolytomousKeyNodesHandlerE4.this,
|
96
|
ex.getLocalizedMessage());
|
97
|
ex.printStackTrace();
|
98
|
}
|
99
|
}
|
100
|
|
101
|
});
|
102
|
monitor.worked(1);
|
103
|
}
|
104
|
}
|
105
|
monitor.done();
|
106
|
return Status.OK_STATUS;
|
107
|
}
|
108
|
|
109
|
};
|
110
|
|
111
|
job.setPriority(Job.SHORT);
|
112
|
job.schedule();
|
113
|
|
114
|
}
|
115
|
|
116
|
@CanExecute
|
117
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
118
|
MHandledMenuItem menuItem){
|
119
|
boolean canExecute = !selection.isEmpty();
|
120
|
Object[] array = selection.toArray();
|
121
|
for (Object object : array) {
|
122
|
canExecute &= object instanceof PolytomousKey;
|
123
|
}
|
124
|
menuItem.setVisible(canExecute);
|
125
|
return canExecute;
|
126
|
}
|
127
|
|
128
|
}
|