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.section.agent;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.Comparator;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.swt.graphics.Color;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
18
|
import eu.etaxonomy.cdm.model.agent.Person;
|
19
|
import eu.etaxonomy.cdm.model.agent.Team;
|
20
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.PersonSelectionDialog;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.CacheRelevance;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.CacheRelevanceHelper;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.ICacheRelevantFormElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
|
28
|
|
29
|
/**
|
30
|
* TeamMemberSection class.
|
31
|
*
|
32
|
* @author n.hoffmann
|
33
|
* @created Apr 30, 2010
|
34
|
*/
|
35
|
public class TeamMemberSection
|
36
|
extends AbstractEntityCollectionSection<Team, Person>
|
37
|
implements ICacheRelevantFormElement {
|
38
|
|
39
|
private boolean isNomenclaturalTeam = false;
|
40
|
|
41
|
private CacheRelevanceHelper cacheRelevanceHelper = new CacheRelevanceHelper();
|
42
|
|
43
|
/**
|
44
|
* <p>Constructor for TeamMemberSection.</p>
|
45
|
*
|
46
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
47
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
48
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
49
|
* @param style a int.
|
50
|
*/
|
51
|
public TeamMemberSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style, boolean isNomenclatural) {
|
52
|
super(cdmFormFactory, conversation, parentElement, null, style);
|
53
|
isNomenclaturalTeam = isNomenclatural;
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public String getTitleString() {
|
58
|
return "Team Members";
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public void addElement(Person element) {
|
63
|
getEntity().addTeamMember(element);
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public Person createNewElement() {
|
68
|
Person selection = PersonSelectionDialog.select(getShell(), null);
|
69
|
return selection;
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public String getEmptyString() {
|
74
|
return "No persons yet.";
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
protected String getTooltipString() {
|
79
|
return "Add a member to this team";
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public void removeElement(Person element) {
|
84
|
getEntity().removeTeamMember(element);
|
85
|
}
|
86
|
|
87
|
|
88
|
|
89
|
@Override
|
90
|
public Comparator<Person> getComparator() {
|
91
|
return (p1, p2) -> {
|
92
|
if (p1 == p2){
|
93
|
return 0;
|
94
|
}else if(p1==null){
|
95
|
return -1;
|
96
|
}else if(p2==null){
|
97
|
return 1;
|
98
|
}
|
99
|
|
100
|
List<Person> teamMembers = getEntity().getTeamMembers();
|
101
|
int indexOfP1 = teamMembers.indexOf(p1);
|
102
|
int indexOfP2 = teamMembers.indexOf(p2);
|
103
|
if(indexOfP1==-1){
|
104
|
return 1;
|
105
|
}
|
106
|
if(indexOfP2==-1){
|
107
|
return -1;
|
108
|
}
|
109
|
return indexOfP1 - indexOfP2;
|
110
|
};
|
111
|
}
|
112
|
|
113
|
public boolean isNomenclaturalTeam() {
|
114
|
return isNomenclaturalTeam;
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public Person addExisting() {
|
119
|
return null;
|
120
|
}
|
121
|
|
122
|
@Override
|
123
|
public boolean allowAddExisting() {
|
124
|
return true;
|
125
|
}
|
126
|
|
127
|
@Override
|
128
|
public void updateCacheRelevance() {
|
129
|
Color color = cacheRelevance().getColor();
|
130
|
setBackground(color);
|
131
|
}
|
132
|
|
133
|
@Override
|
134
|
public void addDependsOnCache(ToggleableTextElement toggleElement) {
|
135
|
cacheRelevanceHelper.addDependsOnCache(toggleElement);
|
136
|
}
|
137
|
|
138
|
@Override
|
139
|
public CacheRelevance cacheRelevance() {
|
140
|
return cacheRelevanceHelper.cacheRelevance();
|
141
|
}
|
142
|
|
143
|
@Override
|
144
|
public Collection<Person> getCollection(Team entity) {
|
145
|
return entity.getTeamMembers();
|
146
|
|
147
|
}
|
148
|
// @Override
|
149
|
// protected Control createToolbar() {
|
150
|
// ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
151
|
//
|
152
|
// Action addAction = new Action("add", IAction.AS_PUSH_BUTTON){
|
153
|
//
|
154
|
// @Override
|
155
|
// public void run() {
|
156
|
//
|
157
|
// if(! getSection().isExpanded()) {
|
158
|
// getSection().setExpanded(true);
|
159
|
// }
|
160
|
// addElement(createNewElement());
|
161
|
// internalUpdateSection(true);
|
162
|
// }
|
163
|
// };
|
164
|
// addAction.setImageDescriptor(new ImageDescriptor() {
|
165
|
//
|
166
|
// @Override
|
167
|
// public ImageData getImageData() {
|
168
|
// return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
|
169
|
// }
|
170
|
// });
|
171
|
// addAction.setToolTipText(getTooltipString());
|
172
|
//
|
173
|
// toolBarManager.add(addAction);
|
174
|
//
|
175
|
// return toolBarManager.createControl(this);
|
176
|
// }
|
177
|
|
178
|
|
179
|
|
180
|
}
|