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.ui.dialog.selection;
|
10
|
|
11
|
import java.util.UUID;
|
12
|
|
13
|
import org.eclipse.jface.viewers.LabelProvider;
|
14
|
import org.eclipse.swt.events.SelectionListener;
|
15
|
import org.eclipse.swt.widgets.Shell;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
18
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
19
|
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
|
20
|
import eu.etaxonomy.cdm.model.agent.Person;
|
21
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
22
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
23
|
import eu.etaxonomy.taxeditor.newWizard.NewPersonWizard;
|
24
|
import eu.etaxonomy.taxeditor.newWizard.NewTeamWizard;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
|
27
|
/**
|
28
|
* FilteredAgentSelectionDialog class.
|
29
|
*
|
30
|
* @author n.hoffmann
|
31
|
* @created Sep 10, 2009
|
32
|
*/
|
33
|
public class AgentSelectionDialog<T extends AgentBase>
|
34
|
extends AbstractFilteredCdmResourceSelectionDialog<T> {
|
35
|
|
36
|
protected static final String PERSON = "New Person";
|
37
|
protected static final String TEAM = "New Team";
|
38
|
|
39
|
protected static boolean selectTeamMember;
|
40
|
|
41
|
/**
|
42
|
* select
|
43
|
*
|
44
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
45
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
46
|
* @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
|
47
|
* @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
|
48
|
*/
|
49
|
public static <S extends AgentBase> S select(Shell shell,
|
50
|
S entity, boolean selectTeamMember) {
|
51
|
AgentSelectionDialog<S> dialog = new AgentSelectionDialog<>(shell,
|
52
|
"Choose Agent", false, AgentSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
|
53
|
return getSelectionFromDialog(dialog);
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* <p>Constructor for FilteredAgentSelectionDialog.</p>
|
58
|
*
|
59
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
60
|
* @param title a {@link java.lang.String} object.
|
61
|
* @param agent a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
|
62
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
63
|
* @param multi a boolean.
|
64
|
* @param settings a {@link java.lang.String} object.
|
65
|
*/
|
66
|
protected AgentSelectionDialog(Shell shell,
|
67
|
String title, boolean multi, String settings, T agent, boolean selectTeamMember) {
|
68
|
super(shell, title, multi, settings, agent);
|
69
|
this.selectTeamMember = selectTeamMember;
|
70
|
}
|
71
|
|
72
|
public class DetailsLabelProvider extends LabelProvider {
|
73
|
@Override
|
74
|
public String getText(Object element) {
|
75
|
T agent = getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
|
76
|
if (agent instanceof INomenclaturalAuthor) {
|
77
|
return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitleCache() + "'";
|
78
|
} else {
|
79
|
return "'" + agent.getTitleCache() + "' is not a nomenclatural author.";
|
80
|
}
|
81
|
}
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
protected T getPersistentObject(UUID cdmUuid) {
|
86
|
return (T)CdmStore.getService(IAgentService.class).load(cdmUuid);
|
87
|
}
|
88
|
|
89
|
@Override
|
90
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
91
|
if(TEAM.equals(parameter)){
|
92
|
return new NewTeamWizard();
|
93
|
}
|
94
|
else if(PERSON.equals(parameter)){
|
95
|
return new NewPersonWizard();
|
96
|
}
|
97
|
else{
|
98
|
throw new IllegalArgumentException("Could not determine the desired wizard.");
|
99
|
}
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
protected String[] getNewWizardText() {
|
104
|
String[] result;
|
105
|
if (this.selectTeamMember){
|
106
|
result = new String[1];
|
107
|
result[0] = PERSON;
|
108
|
}else{
|
109
|
result = new String[2];
|
110
|
result[0] = PERSON;
|
111
|
result[1] = TEAM;
|
112
|
}
|
113
|
return result;
|
114
|
}
|
115
|
|
116
|
@Override
|
117
|
protected SelectionListener getNewWizardButtonSelectionListener() {
|
118
|
return super.getNewWizardButtonSelectionListener();
|
119
|
}
|
120
|
|
121
|
@Override
|
122
|
protected void callService(String pattern) {
|
123
|
Class<T> clazz = (Class)AgentBase.class;
|
124
|
if (selectTeamMember){
|
125
|
clazz = (Class)Person.class;
|
126
|
}
|
127
|
|
128
|
model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(clazz, limitOfInitialElements, pattern);
|
129
|
}
|
130
|
}
|