Project

General

Profile

Download (4.21 KB) Statistics
| Branch: | Tag: | Revision:
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
package eu.etaxonomy.taxeditor.ui.dialog.selection;
10

    
11
import java.util.UUID;
12

    
13
import org.eclipse.jface.viewers.LabelProvider;
14
import org.eclipse.swt.events.SelectionListener;
15
import org.eclipse.swt.widgets.Shell;
16

    
17
import eu.etaxonomy.cdm.api.service.IAgentService;
18
import eu.etaxonomy.cdm.model.agent.AgentBase;
19
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
20
import eu.etaxonomy.cdm.model.agent.Person;
21
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
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
 * FilteredAgentSelectionDialog class.
29
 *
30
 * @author n.hoffmann
31
 * @created Sep 10, 2009
32
 */
33
public class AgentSelectionDialog<T extends AgentBase>
34
        extends AbstractFilteredCdmResourceSelectionDialog<T> {
35

    
36
	protected static final String PERSON = "New Person";
37
	protected static final String TEAM = "New Team";
38

    
39
	protected static boolean selectTeamMember;
40

    
41
	/**
42
	 * select
43
	 *
44
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
45
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
46
	 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
47
	 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
48
	 */
49
	public static <S extends AgentBase> S select(Shell shell,
50
	        S entity, boolean selectTeamMember) {
51
		AgentSelectionDialog<S> dialog = new AgentSelectionDialog<>(shell,
52
				"Choose Agent", false, AgentSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
53
		return getSelectionFromDialog(dialog);
54
	}
55

    
56
	/**
57
	 * <p>Constructor for FilteredAgentSelectionDialog.</p>
58
	 *
59
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
60
	 * @param title a {@link java.lang.String} object.
61
	 * @param agent a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
62
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
63
	 * @param multi a boolean.
64
	 * @param settings a {@link java.lang.String} object.
65
	 */
66
	protected AgentSelectionDialog(Shell shell,
67
	        String title, boolean multi, String settings, T agent, boolean selectTeamMember) {
68
		super(shell, title, multi, settings, agent);
69
		this.selectTeamMember = selectTeamMember;
70
	}
71

    
72
	public class DetailsLabelProvider extends LabelProvider {
73
		@Override
74
        public String getText(Object element) {
75
		    T agent = getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
76
			if (agent instanceof INomenclaturalAuthor) {
77
				return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitleCache() + "'";
78
			} else {
79
				return "'" + agent.getTitleCache() + "' is not a nomenclatural author.";
80
			}
81
		}
82
	}
83

    
84

    
85

    
86
	@Override
87
	protected T getPersistentObject(UUID cdmUuid) {
88
		return (T)CdmStore.getService(IAgentService.class).load(cdmUuid);
89
	}
90

    
91
	@Override
92
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
93
		if(TEAM.equals(parameter)){
94
			return new NewTeamWizard();
95
		}
96
		else if(PERSON.equals(parameter)){
97
			return new NewPersonWizard();
98
		}
99
		else{
100
			throw new IllegalArgumentException("Could not determine the desired wizard.");
101
		}
102
	}
103

    
104
	@Override
105
	protected String[] getNewWizardText() {
106
	    String[] result;
107
		if (this.selectTeamMember){
108
		    result = new String[1];
109
		    result[0] = PERSON;
110
		}else{
111
		    result = new String[2];
112
            result[0] = PERSON;
113
            result[1] = TEAM;
114
		}
115
		return result;
116
	}
117

    
118
	@Override
119
	protected SelectionListener getNewWizardButtonSelectionListener() {
120
		return super.getNewWizardButtonSelectionListener();
121
	}
122

    
123
    @Override
124
    protected void callService(String pattern) {
125
        Class<T> clazz = (Class)AgentBase.class;
126
        if (selectTeamMember){
127
            clazz = (Class)Person.class;
128
        }
129

    
130
        model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(clazz, limitOfInitialElements, pattern);
131
    }
132

    
133

    
134
}
(4-4/46)