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.bulkeditor.e4.handler;
|
10
|
|
11
|
import javax.inject.Named;
|
12
|
|
13
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
14
|
import org.eclipse.e4.core.di.annotations.Execute;
|
15
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
16
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
17
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
18
|
import org.eclipse.jface.dialogs.MessageDialog;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
21
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
22
|
import eu.etaxonomy.cdm.model.agent.Person;
|
23
|
import eu.etaxonomy.cdm.model.agent.Team;
|
24
|
import eu.etaxonomy.cdm.strategy.merge.MergeException;
|
25
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.AnnotatedTableItem;
|
26
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
|
27
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
|
30
|
/**
|
31
|
* @author k.luther
|
32
|
* @date 12.05.2015
|
33
|
*
|
34
|
*/
|
35
|
public class ConvertTeam2PersonHandlerE4 {
|
36
|
|
37
|
@Execute
|
38
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)AnnotatedTableItem item,
|
39
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
|
40
|
|
41
|
BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
|
42
|
|
43
|
if (editor.isDirty()){
|
44
|
boolean proceed = MessageDialog.openQuestion(null,
|
45
|
"Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
|
46
|
if (proceed) {
|
47
|
editor.save();
|
48
|
} else {
|
49
|
return;
|
50
|
}
|
51
|
}
|
52
|
|
53
|
Person person = null;
|
54
|
UpdateResult result = null;
|
55
|
|
56
|
try {
|
57
|
result = CdmStore.getService(IAgentService.class).convertTeam2Person(item.getElement().getUuid());
|
58
|
} catch (IllegalArgumentException e) {
|
59
|
MessagingUtils.informationDialog("Can not convert Team to Person", e.getMessage());
|
60
|
} catch (MergeException e) {
|
61
|
MessagingUtils.informationDialog("Can not convert Team to Person", e.getMessage());
|
62
|
}
|
63
|
if (result != null && result.isOk()){
|
64
|
person = (Person)result.getCdmEntity();
|
65
|
}
|
66
|
if (person != null){
|
67
|
editor.refresh();
|
68
|
}
|
69
|
}
|
70
|
|
71
|
@CanExecute
|
72
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)AnnotatedTableItem selection,
|
73
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
74
|
MHandledMenuItem menuItem){
|
75
|
boolean canExecute = false;
|
76
|
canExecute = ((BulkEditorE4)activePart.getObject()).getEditorInput().isConvertingEnabled() && selection.getElement() instanceof Team;
|
77
|
menuItem.setVisible(canExecute);
|
78
|
return canExecute;
|
79
|
}
|
80
|
|
81
|
}
|