Project

General

Profile

Download (4.91 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.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
	protected static final String PERSON = "Person";
45
	/**
46
	 *
47
	 */
48
	protected static final String TEAM = "Team";
49
	
50
	protected static boolean selectTeamMember;
51

    
52
	/**
53
	 * <p>select</p>
54
	 *
55
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
56
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
57
	 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
58
	 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
59
	 */
60
	public static AgentBase select(Shell shell, ConversationHolder conversation, AgentBase entity, boolean selectTeamMember) {
61
		AgentSelectionDialog dialog = new AgentSelectionDialog(shell, conversation,
62
				"Choose Agent", false, AgentSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
63
		return getSelectionFromDialog(dialog);
64
	}
65

    
66
	/**
67
	 * <p>Constructor for FilteredAgentSelectionDialog.</p>
68
	 *
69
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
70
	 * @param title a {@link java.lang.String} object.
71
	 * @param agent a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
72
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
73
	 * @param multi a boolean.
74
	 * @param settings a {@link java.lang.String} object.
75
	 */
76
	protected AgentSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, String settings, AgentBase agent, boolean selectTeamMember) {
77
		super(shell, conversation, title, multi, settings, agent);
78
		this.selectTeamMember = selectTeamMember;
79
	}
80

    
81

    
82
	/**
83
	 * @author p.ciardelli
84
	 * @created 18.09.2009
85
	 * @version 1.0
86
	 */
87
	public class DetailsLabelProvider extends LabelProvider {
88
		/* (non-Javadoc)
89
		 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
90
		 */
91
		@Override
92
        public String getText(Object element) {
93
			AgentBase agent = getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
94
			if (agent instanceof INomenclaturalAuthor) {
95
				return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitle() + "'";
96
			} else {
97
				return "'" + agent.getTitleCache() + "' is not a nomenclatural author.";
98
			}
99
		}
100
	}
101

    
102
	/* (non-Javadoc)
103
	 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObect(java.util.UUID)
104
	 */
105
	/** {@inheritDoc} */
106
	@Override
107
	protected AgentBase getPersistentObject(UUID cdmUuid) {
108
		return CdmStore.getService(IAgentService.class).load(cdmUuid);
109
	}
110

    
111
	/** {@inheritDoc} */
112
	@Override
113
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
114
		if(TEAM.equals(parameter)){
115
			return new NewTeamWizard();
116
		}
117
		else if(PERSON.equals(parameter)){
118
			return new NewPersonWizard();
119
		}
120
		else{
121
			throw new IllegalArgumentException("Could not determine the desired wizard.");
122
		}
123
	}
124

    
125
	/** {@inheritDoc} */
126
	@Override
127
	protected String getNewWizardLinkText() {
128
		if (this.selectTeamMember){
129
			return String.format("Create a new <a>%1s</a>", PERSON);
130
		}
131
		return String.format("Create a new <a>%1s</a> or <a>%2s</a>", TEAM, PERSON);
132
	}
133

    
134
	/* (non-Javadoc)
135
	 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkSelectionListener()
136
	 */
137
	@Override
138
	protected SelectionListener getNewWizardLinkSelectionListener() {
139
		return super.getNewWizardLinkSelectionListener();
140
	}
141

    
142
	/** {@inheritDoc} */
143
	@Override
144
	protected void initModel() {
145
	    Control control = getPatternControl();
146
        String pattern = null;
147
        if (control != null){
148
            pattern = ((Text)control).getText();
149
        }
150

    
151

    
152
		model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
153
	}
154

    
155

    
156
}
(3-3/33)