Project

General

Profile

Download (4.38 KB) Statistics
| Branch: | Tag: | Revision:
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
		public String getText(Object element) {
87
			AgentBase agent = getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
88
			if (agent instanceof INomenclaturalAuthor) {
89
				return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitle() + "'"; 
90
			} else {
91
				return "'" + agent.getTitleCache() + "' is not a nomenclatural author."; 
92
			}
93
		}
94
	}
95

    
96
	/* (non-Javadoc)
97
	 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObect(java.util.UUID)
98
	 */
99
	/** {@inheritDoc} */
100
	@Override
101
	protected AgentBase getPersistentObject(UUID cdmUuid) {
102
		return CdmStore.getService(IAgentService.class).load(cdmUuid);
103
	}
104

    
105
	/** {@inheritDoc} */
106
	@Override
107
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
108
		if(TEAM.equals(parameter)){
109
			return new NewTeamWizard();
110
		}
111
		else if(PERSON.equals(parameter)){
112
			return new NewPersonWizard();
113
		}
114
		else{
115
			throw new IllegalArgumentException("Could not determine the desired wizard.");
116
		}
117
	}
118

    
119
	/** {@inheritDoc} */
120
	@Override
121
	protected String getNewWizardLinkText() {
122
		return String.format("Create a new <a>%1s</a> or <a>%2s</a>", TEAM, PERSON);
123
	}
124
	
125
	/* (non-Javadoc)
126
	 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkSelectionListener()
127
	 */
128
	@Override
129
	protected SelectionListener getNewWizardLinkSelectionListener() {
130
		return super.getNewWizardLinkSelectionListener();
131
	}
132

    
133
	/** {@inheritDoc} */
134
	@Override
135
	protected void initModel() {
136
		model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache();
137
	}
138

    
139

    
140
}
(2-2/20)