Project

General

Profile

Download (5.1 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

    
10
package eu.etaxonomy.taxeditor.ui.dialog.selection;
11

    
12
import java.util.UUID;
13

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

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

    
37
	/**
38
	 *
39
	 */
40
	protected static final String PERSON = "New Person";
41
	/**
42
	 *
43
	 */
44
	protected static final String TEAM = "New Team";
45

    
46
	protected static boolean selectTeamMember;
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,
57
	        AgentBase entity, boolean selectTeamMember) {
58
		AgentSelectionDialog dialog = new AgentSelectionDialog(shell, //conversation,
59
				"Choose Agent", false, AgentSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
60
		return getSelectionFromDialog(dialog);
61
	}
62

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

    
80

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

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

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

    
124
	/** {@inheritDoc} */
125
	@Override
126
	protected String[] getNewWizardText() {
127
	    String[] result;
128
		if (this.selectTeamMember){
129
		    result = new String[1];
130
		    result[0] = PERSON;
131

    
132
		}else{
133
		    result = new String[2];
134
            result[0] = PERSON;
135
            result[1] = TEAM;
136
		}
137
		return result;
138
	}
139

    
140
	/* (non-Javadoc)
141
	 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkSelectionListener()
142
	 */
143
	@Override
144
	protected SelectionListener getNewWizardButtonSelectionListener() {
145
		return super.getNewWizardButtonSelectionListener();
146
	}
147

    
148
//	/** {@inheritDoc} */
149
//	@Override
150
//	protected void search() {
151
//	    Control control = getSearchField();
152
//        String pattern = null;
153
//        if (control != null){
154
//            pattern = ((Text)control).getText();
155
//        }
156
//
157
//	}
158

    
159
    /* (non-Javadoc)
160
     * @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String)
161
     */
162
    @Override
163
    void callService(String pattern) {
164
        model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
165
    }
166

    
167

    
168
}
(4-4/44)