1
|
package eu.etaxonomy.taxeditor.handler.defaultHandler;
|
2
|
|
3
|
import java.util.UUID;
|
4
|
|
5
|
import org.eclipse.core.commands.AbstractHandler;
|
6
|
import org.eclipse.core.commands.ExecutionEvent;
|
7
|
import org.eclipse.core.commands.ExecutionException;
|
8
|
import org.eclipse.core.commands.ParameterType;
|
9
|
import org.eclipse.core.commands.common.NotDefinedException;
|
10
|
import org.eclipse.jface.viewers.ISelection;
|
11
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
12
|
import org.eclipse.ui.handlers.HandlerUtil;
|
13
|
|
14
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
15
|
|
16
|
public abstract class DefaultOpenHandlerBase <T> extends AbstractHandler {
|
17
|
|
18
|
@Override
|
19
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
20
|
String commandId = event.getCommand().getId();
|
21
|
String uuidParameterId = commandId+".uuid";
|
22
|
//check if uuid parameter is set
|
23
|
if(event.getParameter(uuidParameterId)!=null){
|
24
|
Object object = event.getObjectParameterForExecution(uuidParameterId);
|
25
|
ParameterType parameterType;
|
26
|
try {
|
27
|
parameterType = event.getCommand().getParameterType(uuidParameterId);
|
28
|
if(parameterType.isCompatible(object)){
|
29
|
T entity = getEntity((UUID) object);
|
30
|
open(event, entity);
|
31
|
}
|
32
|
} catch (NotDefinedException e) {
|
33
|
MessagingUtils.error(DefaultOpenHandlerBase.class, "Error while opening entity!", e);
|
34
|
}
|
35
|
}
|
36
|
//if not try current selection
|
37
|
else{
|
38
|
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
39
|
if(selection instanceof IStructuredSelection){
|
40
|
open(event, (T) ((IStructuredSelection) selection).getFirstElement());
|
41
|
}
|
42
|
}
|
43
|
return null;
|
44
|
}
|
45
|
|
46
|
|
47
|
protected abstract T getEntity(UUID uuid);
|
48
|
|
49
|
protected abstract void open(ExecutionEvent event, T entity);
|
50
|
|
51
|
}
|