1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.dialog.selection;
|
12
|
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.eclipse.jface.viewers.LabelProvider;
|
16
|
import org.eclipse.swt.events.SelectionListener;
|
17
|
import org.eclipse.swt.widgets.Shell;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
20
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
21
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
22
|
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
|
23
|
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
|
24
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
25
|
import eu.etaxonomy.taxeditor.newWizard.NewPersonWizard;
|
26
|
import eu.etaxonomy.taxeditor.newWizard.NewTeamWizard;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
|
29
|
/**
|
30
|
* <p>FilteredAgentSelectionDialog class.</p>
|
31
|
*
|
32
|
* @author n.hoffmann
|
33
|
* @created Sep 10, 2009
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class AgentSelectionDialog extends
|
37
|
AbstractFilteredCdmResourceSelectionDialog<AgentBase> {
|
38
|
|
39
|
/**
|
40
|
*
|
41
|
*/
|
42
|
private static final String PERSON = "Person";
|
43
|
/**
|
44
|
*
|
45
|
*/
|
46
|
private static final String TEAM = "Team";
|
47
|
|
48
|
/**
|
49
|
* <p>select</p>
|
50
|
*
|
51
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
52
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
53
|
* @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
|
54
|
* @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
|
55
|
*/
|
56
|
public static AgentBase select(Shell shell, ConversationHolder conversation, AgentBase entity) {
|
57
|
AgentSelectionDialog dialog = new AgentSelectionDialog(shell, conversation,
|
58
|
"Choose Agent", false, AgentSelectionDialog.class.getCanonicalName(), entity);
|
59
|
return getSelectionFromDialog(dialog);
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* <p>Constructor for FilteredAgentSelectionDialog.</p>
|
64
|
*
|
65
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
66
|
* @param title a {@link java.lang.String} object.
|
67
|
* @param agent a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
|
68
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
69
|
* @param multi a boolean.
|
70
|
* @param settings a {@link java.lang.String} object.
|
71
|
*/
|
72
|
protected AgentSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, String settings, AgentBase agent) {
|
73
|
super(shell, conversation, title, multi, settings, agent);
|
74
|
}
|
75
|
|
76
|
|
77
|
/**
|
78
|
* @author p.ciardelli
|
79
|
* @created 18.09.2009
|
80
|
* @version 1.0
|
81
|
*/
|
82
|
public class DetailsLabelProvider extends LabelProvider {
|
83
|
/* (non-Javadoc)
|
84
|
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
|
85
|
*/
|
86
|
@Override
|
87
|
public String getText(Object element) {
|
88
|
AgentBase agent = getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
|
89
|
if (agent instanceof INomenclaturalAuthor) {
|
90
|
return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitle() + "'";
|
91
|
} else {
|
92
|
return "'" + agent.getTitleCache() + "' is not a nomenclatural author.";
|
93
|
}
|
94
|
}
|
95
|
}
|
96
|
|
97
|
/* (non-Javadoc)
|
98
|
* @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObect(java.util.UUID)
|
99
|
*/
|
100
|
/** {@inheritDoc} */
|
101
|
@Override
|
102
|
protected AgentBase getPersistentObject(UUID cdmUuid) {
|
103
|
return CdmStore.getService(IAgentService.class).load(cdmUuid);
|
104
|
}
|
105
|
|
106
|
/** {@inheritDoc} */
|
107
|
@Override
|
108
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
109
|
if(TEAM.equals(parameter)){
|
110
|
return new NewTeamWizard();
|
111
|
}
|
112
|
else if(PERSON.equals(parameter)){
|
113
|
return new NewPersonWizard();
|
114
|
}
|
115
|
else{
|
116
|
throw new IllegalArgumentException("Could not determine the desired wizard.");
|
117
|
}
|
118
|
}
|
119
|
|
120
|
/** {@inheritDoc} */
|
121
|
@Override
|
122
|
protected String getNewWizardLinkText() {
|
123
|
return String.format("Create a new <a>%1s</a> or <a>%2s</a>", TEAM, PERSON);
|
124
|
}
|
125
|
|
126
|
/* (non-Javadoc)
|
127
|
* @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkSelectionListener()
|
128
|
*/
|
129
|
@Override
|
130
|
protected SelectionListener getNewWizardLinkSelectionListener() {
|
131
|
return super.getNewWizardLinkSelectionListener();
|
132
|
}
|
133
|
|
134
|
/** {@inheritDoc} */
|
135
|
@Override
|
136
|
protected void initModel() {
|
137
|
model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache();
|
138
|
}
|
139
|
|
140
|
|
141
|
}
|