Project

General

Profile

Download (4.29 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.persistence.dto.UuidAndTitleCache;
21
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
22
import eu.etaxonomy.taxeditor.newWizard.NewPersonWizard;
23
import eu.etaxonomy.taxeditor.newWizard.NewTeamWizard;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26
/**
27
 * FilteredAgentSelectionDialog class.
28
 *
29
 * @author n.hoffmann
30
 * @created Sep 10, 2009
31
 */
32
public class AgentSelectionDialog<T extends AgentBase>
33
        extends AbstractFilteredCdmResourceSelectionDialog<T> {
34

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

    
38
	protected static boolean selectTeamMember;
39

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

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

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

    
83
	@Override
84
	protected T getPersistentObject(UUID cdmUuid) {
85
		return (T)CdmStore.getService(IAgentService.class).load(cdmUuid);
86
	}
87

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

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

    
115
	@Override
116
	protected SelectionListener getNewWizardButtonSelectionListener() {
117
		return super.getNewWizardButtonSelectionListener();
118
	}
119

    
120
//	@Override
121
//	protected void search() {
122
//	    Control control = getSearchField();
123
//        String pattern = null;
124
//        if (control != null){
125
//            pattern = ((Text)control).getText();
126
//        }
127
//	}
128

    
129
    @Override
130
    protected void callService(String pattern) {
131
        Class<T> clazz = (Class)AgentBase.class;
132
        model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(clazz, limitOfInitialElements, pattern);
133
    }
134
}
(4-4/45)