Project

General

Profile

Download (5.33 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.core.runtime.CoreException;
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.service.IAgentService;
22
import eu.etaxonomy.cdm.model.agent.AgentBase;
23
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
24
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
25
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
26
import eu.etaxonomy.taxeditor.newWizard.NewPersonWizard;
27
import eu.etaxonomy.taxeditor.newWizard.NewTeamWizard;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * <p>FilteredAgentSelectionDialog class.</p>
32
 *
33
 * @author n.hoffmann
34
 * @created Sep 10, 2009
35
 * @version 1.0
36
 */
37
public class AgentSelectionDialog extends
38
		AbstractFilteredCdmResourceSelectionDialog<AgentBase> {
39

    
40
	/**
41
	 *
42
	 */
43
	protected static final String PERSON = "new Person";
44
	/**
45
	 *
46
	 */
47
	protected static final String TEAM = "new Team";
48

    
49
	protected static boolean selectTeamMember;
50

    
51
	/**
52
	 * <p>select</p>
53
	 *
54
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
55
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
56
	 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
57
	 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
58
	 */
59
	public static AgentBase select(Shell shell, //ConversationHolder conversation,
60
	        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,
77
	        String title, boolean multi, String settings, AgentBase agent, boolean selectTeamMember) {
78
		super(shell, //conversation,
79
		        title, multi, settings, agent);
80
		this.selectTeamMember = selectTeamMember;
81
	}
82

    
83

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

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

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

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

    
135
		}else{
136
		    result = new String[2];
137
            result[0] = PERSON;
138
            result[1] = TEAM;
139
		}
140
		return result;
141
	}
142

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

    
151
	/** {@inheritDoc} */
152
	@Override
153
	protected void search() {
154
	    Control control = getSearchField();
155
        String pattern = null;
156
        if (control != null){
157
            pattern = ((Text)control).getText();
158
        }
159
        if (pattern == null || pattern.equals("?")){
160
            model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(null, null);
161
        }else{
162
            model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
163
        }
164
        try {
165
            fillContentProvider(null);
166
        } catch (CoreException e) {
167
            // TODO Auto-generated catch block
168
            e.printStackTrace();
169
        }
170
	}
171

    
172

    
173
}
(4-4/39)