255f8022724734be2741a2e058926a8fda703cfe
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / NomenclaturalAuthorSelectionDialog.java
1 // $Id$
2 /**
3 * Copyright (C) 2016 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 package eu.etaxonomy.taxeditor.ui.dialog.selection;
11
12
13
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Shell;
16 import org.eclipse.swt.widgets.Text;
17
18 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19 import eu.etaxonomy.cdm.api.service.IAgentService;
20 import eu.etaxonomy.cdm.model.agent.AgentBase;
21 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
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 * @author k.luther
29 * @date 25.05.2016
30 *
31 */
32 public class NomenclaturalAuthorSelectionDialog extends AgentSelectionDialog {
33
34
35 /**
36 * @param shell
37 * @param conversation
38 * @param title
39 * @param multi
40 * @param settings
41 * @param agent
42 */
43 protected NomenclaturalAuthorSelectionDialog(Shell shell, ConversationHolder conversation, String title,
44 boolean multi, String settings, AgentBase agent) {
45 super(shell, conversation, title, multi, settings, agent);
46 // TODO Auto-generated constructor stub
47 }
48
49 @Override
50 protected void initModel() {
51 Control control = getPatternControl();
52 String pattern = null;
53 if (control != null){
54 pattern = ((Text)control).getText();
55 }
56
57 model = CdmStore.getService(IAgentService.class).getUuidAndAbbrevTitleCache(limitOfInitialElements, pattern, null);
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
63 if(TEAM.equals(parameter)){
64 return new NewTeamWizard(true);
65 }
66 else if(PERSON.equals(parameter)){
67 return new NewPersonWizard();
68 }
69 else{
70 throw new IllegalArgumentException("Could not determine the desired wizard.");
71 }
72 }
73
74
75 /**
76 * <p>select</p>
77 *
78 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
79 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
80 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
81 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
82 */
83 public static AgentBase select(Shell shell, ConversationHolder conversation, AgentBase entity) {
84 NomenclaturalAuthorSelectionDialog dialog = new NomenclaturalAuthorSelectionDialog(shell, conversation,
85 "Choose Agent", false, NomenclaturalAuthorSelectionDialog.class.getCanonicalName(), entity);
86 return getSelectionFromDialog(dialog);
87 }
88
89 /**
90 * <p>getTitle</p>
91 *
92 * @param cdmObject a T object.
93 * @return a {@link java.lang.String} object.
94 */
95 @Override
96 protected String getTitle(AgentBase cdmObject) {
97 if(cdmObject == null){
98 return "";
99 }
100
101 if (cdmObject instanceof TeamOrPersonBase) {
102 return ((TeamOrPersonBase) cdmObject).getNomenclaturalTitle();
103 } else if (cdmObject instanceof AgentBase){
104 return ((TeamOrPersonBase) cdmObject).getTitleCache();
105 }
106
107 throw new IllegalArgumentException("Generic method only" +
108 " supports cdmObject of type IIdentifiableEntity." +
109 " Please implement specific method in subclass.");
110 }
111
112 }