LibrAlign dependency version updated.
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / AgentSelectionDialog.java
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
10 package eu.etaxonomy.taxeditor.ui.dialog.selection;
11
12 import java.util.UUID;
13
14 import org.eclipse.jface.viewers.LabelProvider;
15 import org.eclipse.swt.events.SelectionListener;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.swt.widgets.Text;
19
20 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
21 import eu.etaxonomy.cdm.api.service.IAgentService;
22 import eu.etaxonomy.cdm.model.agent.AgentBase;
23 import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
24 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
25 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
26 import eu.etaxonomy.taxeditor.newWizard.NewPersonWizard;
27 import eu.etaxonomy.taxeditor.newWizard.NewTeamWizard;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 /**
31 * <p>FilteredAgentSelectionDialog class.</p>
32 *
33 * @author n.hoffmann
34 * @created Sep 10, 2009
35 * @version 1.0
36 */
37 public class AgentSelectionDialog extends
38 AbstractFilteredCdmResourceSelectionDialog<AgentBase> {
39
40 /**
41 *
42 */
43 protected static final String PERSON = "Person";
44 /**
45 *
46 */
47 protected static final String TEAM = "Team";
48
49 protected static boolean selectTeamMember;
50
51 /**
52 * <p>select</p>
53 *
54 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
55 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
56 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
57 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
58 */
59 public static AgentBase select(Shell shell, ConversationHolder conversation, AgentBase entity, boolean selectTeamMember) {
60 AgentSelectionDialog dialog = new AgentSelectionDialog(shell, conversation,
61 "Choose Agent", false, AgentSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
62 return getSelectionFromDialog(dialog);
63 }
64
65 /**
66 * <p>Constructor for FilteredAgentSelectionDialog.</p>
67 *
68 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
69 * @param title a {@link java.lang.String} object.
70 * @param agent a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
71 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
72 * @param multi a boolean.
73 * @param settings a {@link java.lang.String} object.
74 */
75 protected AgentSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, String settings, AgentBase agent, boolean selectTeamMember) {
76 super(shell, conversation, title, multi, settings, agent);
77 this.selectTeamMember = selectTeamMember;
78 }
79
80
81 /**
82 * @author p.ciardelli
83 * @created 18.09.2009
84 * @version 1.0
85 */
86 public class DetailsLabelProvider extends LabelProvider {
87 /* (non-Javadoc)
88 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
89 */
90 @Override
91 public String getText(Object element) {
92 AgentBase agent = getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
93 if (agent instanceof INomenclaturalAuthor) {
94 return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitle() + "'";
95 } else {
96 return "'" + agent.getTitleCache() + "' is not a nomenclatural author.";
97 }
98 }
99 }
100
101 /* (non-Javadoc)
102 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObect(java.util.UUID)
103 */
104 /** {@inheritDoc} */
105 @Override
106 protected AgentBase getPersistentObject(UUID cdmUuid) {
107 return CdmStore.getService(IAgentService.class).load(cdmUuid);
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
113 if(TEAM.equals(parameter)){
114 return new NewTeamWizard();
115 }
116 else if(PERSON.equals(parameter)){
117 return new NewPersonWizard();
118 }
119 else{
120 throw new IllegalArgumentException("Could not determine the desired wizard.");
121 }
122 }
123
124 /** {@inheritDoc} */
125 @Override
126 protected String getNewWizardLinkText() {
127 if (this.selectTeamMember){
128 return String.format("Create a new <a>%1s</a>", PERSON);
129 }
130 return String.format("Create a new <a>%1s</a> or <a>%2s</a>", TEAM, PERSON);
131 }
132
133 /* (non-Javadoc)
134 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkSelectionListener()
135 */
136 @Override
137 protected SelectionListener getNewWizardLinkSelectionListener() {
138 return super.getNewWizardLinkSelectionListener();
139 }
140
141 /** {@inheritDoc} */
142 @Override
143 protected void initModel() {
144 Control control = getPatternControl();
145 String pattern = null;
146 if (control != null){
147 pattern = ((Text)control).getText();
148 }
149
150
151 model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
152 }
153
154
155 }