1
|
/**
|
2
|
* Copyright (C) 2017 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.handler;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Iterator;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.core.commands.ExecutionEvent;
|
16
|
import org.eclipse.core.commands.common.NotDefinedException;
|
17
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
18
|
import org.eclipse.core.runtime.IStatus;
|
19
|
import org.eclipse.core.runtime.Status;
|
20
|
import org.eclipse.jface.dialogs.MessageDialog;
|
21
|
import org.eclipse.jface.viewers.ISelection;
|
22
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
23
|
import org.eclipse.ui.IEditorInput;
|
24
|
import org.eclipse.ui.IEditorPart;
|
25
|
import org.eclipse.ui.handlers.HandlerUtil;
|
26
|
|
27
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
28
|
import eu.etaxonomy.cdm.model.agent.Person;
|
29
|
import eu.etaxonomy.taxeditor.bulkeditor.operation.ConvertPerson2TeamOperation;
|
30
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
31
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
|
32
|
|
33
|
/**
|
34
|
* @author k.luther
|
35
|
* @date 10.05.2017
|
36
|
*
|
37
|
*/
|
38
|
public class ConvertPerson2TeamRemotingHandler extends RemotingCdmHandler {
|
39
|
IEditorPart editor;
|
40
|
|
41
|
/**
|
42
|
* @param label
|
43
|
*/
|
44
|
public ConvertPerson2TeamRemotingHandler() {
|
45
|
super(Messages.ConvertPerson2TeamHandler_lable);
|
46
|
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* {@inheritDoc}
|
51
|
*/
|
52
|
@Override
|
53
|
public IStatus allowOperations(ExecutionEvent event) {
|
54
|
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
55
|
|
56
|
editor = HandlerUtil.getActiveEditor(event);
|
57
|
|
58
|
IEditorInput input = editor.getEditorInput();
|
59
|
if (editor.isDirty()){
|
60
|
boolean proceed = MessageDialog.openQuestion(null,
|
61
|
"Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
|
62
|
if (proceed) {
|
63
|
editor.doSave(null);
|
64
|
} else {
|
65
|
return Status.CANCEL_STATUS;
|
66
|
}
|
67
|
}
|
68
|
Iterator<IStructuredSelection> it = ((IStructuredSelection) selection).iterator();
|
69
|
while( it.hasNext()){
|
70
|
Object object =it.next();
|
71
|
if (!(object instanceof Person)){
|
72
|
MessageDialog.openInformation(null, "Operation not applicable.", "This operation is only applicable for persons");
|
73
|
return Status.CANCEL_STATUS;
|
74
|
}
|
75
|
}
|
76
|
return Status.OK_STATUS;
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* {@inheritDoc}
|
81
|
*/
|
82
|
@Override
|
83
|
public AbstractOperation prepareOperation(ExecutionEvent event) {
|
84
|
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveSite(event).getSelectionProvider().getSelection();
|
85
|
|
86
|
try {
|
87
|
String label = event.getCommand().getName();
|
88
|
Iterator<IStructuredSelection> it = selection.iterator();
|
89
|
ConvertPerson2TeamOperation operation;
|
90
|
List<Person> persons = new ArrayList<Person>();
|
91
|
while( it.hasNext()){
|
92
|
Object object =it.next();
|
93
|
if (object instanceof Person){
|
94
|
Person person = HibernateProxyHelper.deproxy(object, Person.class);
|
95
|
persons.add(person);
|
96
|
}
|
97
|
}
|
98
|
return new ConvertPerson2TeamOperation(label, persons, true, editor);
|
99
|
|
100
|
|
101
|
} catch (NotDefinedException e) {
|
102
|
// TODO Auto-generated catch block
|
103
|
e.printStackTrace();
|
104
|
}
|
105
|
|
106
|
|
107
|
|
108
|
return null;
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* {@inheritDoc}
|
113
|
*/
|
114
|
@Override
|
115
|
public void onComplete() {
|
116
|
// TODO Auto-generated method stub
|
117
|
|
118
|
}
|
119
|
|
120
|
|
121
|
|
122
|
}
|