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