Revision 3f6f86d5
Added by Patrick Plitzner over 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java | ||
---|---|---|
3 | 3 |
import java.sql.SQLException; |
4 | 4 |
import java.util.ArrayList; |
5 | 5 |
import java.util.Arrays; |
6 |
import java.util.Collection; |
|
7 | 6 |
import java.util.List; |
8 | 7 |
import java.util.UUID; |
9 | 8 |
|
10 | 9 |
import com.vaadin.data.Property; |
11 |
import com.vaadin.data.Property.ValueChangeEvent; |
|
12 |
import com.vaadin.data.Property.ValueChangeListener; |
|
13 |
import com.vaadin.event.ContextClickEvent; |
|
14 |
import com.vaadin.event.ContextClickEvent.ContextClickListener; |
|
15 | 10 |
import com.vaadin.event.ItemClickEvent; |
16 | 11 |
import com.vaadin.event.ItemClickEvent.ItemClickListener; |
17 | 12 |
import com.vaadin.event.ShortcutAction.KeyCode; |
... | ... | |
20 | 15 |
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; |
21 | 16 |
import com.vaadin.server.VaadinSession; |
22 | 17 |
import com.vaadin.ui.AbsoluteLayout; |
18 |
import com.vaadin.ui.Alignment; |
|
23 | 19 |
import com.vaadin.ui.Button; |
24 | 20 |
import com.vaadin.ui.Button.ClickEvent; |
25 | 21 |
import com.vaadin.ui.Button.ClickListener; |
26 |
import com.vaadin.ui.ComboBox; |
|
27 | 22 |
import com.vaadin.ui.CustomComponent; |
23 |
import com.vaadin.ui.ListSelect; |
|
28 | 24 |
import com.vaadin.ui.Notification; |
29 | 25 |
import com.vaadin.ui.Notification.Type; |
30 | 26 |
import com.vaadin.ui.Table; |
31 |
import com.vaadin.ui.Table.ColumnGenerator; |
|
27 |
import com.vaadin.ui.UI; |
|
28 |
import com.vaadin.ui.VerticalLayout; |
|
32 | 29 |
import com.vaadin.ui.Window; |
33 | 30 |
|
34 | 31 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
35 | 32 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
36 |
import eu.etaxonomy.cdm.model.common.Language; |
|
37 |
import eu.etaxonomy.cdm.model.common.Representation; |
|
38 | 33 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
39 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
|
40 | 34 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
41 | 35 |
import eu.etaxonomy.cdm.vaadin.component.DetailWindow; |
42 | 36 |
import eu.etaxonomy.cdm.vaadin.component.HorizontalToolbar; |
... | ... | |
45 | 39 |
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionTablePresenter; |
46 | 40 |
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory; |
47 | 41 |
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil; |
48 |
import eu.etaxonomy.cdm.vaadin.util.TermCacher; |
|
49 | 42 |
|
50 | 43 |
public class DistributionTableView extends CustomComponent implements View{ |
51 | 44 |
|
... | ... | |
132 | 125 |
|
133 | 126 |
table.setCacheRate(20); |
134 | 127 |
|
135 |
//add generated columns for NamedAreas |
|
136 |
Collection<?> containerPropertyIds = table.getContainerPropertyIds(); |
|
137 |
for (Object object : containerPropertyIds) { |
|
138 |
if(namedAreas.contains(object)){ |
|
139 |
table.removeGeneratedColumn(object); |
|
140 |
table.addGeneratedColumn(object, new AreaColumnGenerator()); |
|
128 |
table.addItemClickListener(new ItemClickListener() { |
|
129 |
private static final long serialVersionUID = 2743935539139014771L; |
|
130 |
@Override |
|
131 |
public void itemClick(ItemClickEvent event) { |
|
132 |
if(!(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.TAXON_COLUMN)) && !(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.RANK_COLUMN))){ |
|
133 |
Property<?> itemProperty = event.getItem().getItemProperty("uuid"); |
|
134 |
UUID uuid = UUID.fromString(itemProperty.getValue().toString()); |
|
135 |
final Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class); |
|
136 |
final String areaID = (String) event.getPropertyId(); |
|
137 |
|
|
138 |
//popup window |
|
139 |
final Window popup = new Window("Choose terms"); |
|
140 |
final ListSelect termSelect = new ListSelect(); |
|
141 |
termSelect.setContainerDataSource(PresenceAbsenceTermContainer.getInstance()); |
|
142 |
Button btnOk = new Button("OK", new ClickListener() { |
|
143 |
private static final long serialVersionUID = -3732219609337335697L; |
|
144 |
@Override |
|
145 |
public void buttonClick(ClickEvent event) { |
|
146 |
listener.updateDistributionField(areaID, termSelect.getValue(), taxon); |
|
147 |
popup.close(); |
|
148 |
} |
|
149 |
}); |
|
150 |
VerticalLayout layout = new VerticalLayout(termSelect, btnOk); |
|
151 |
layout.setComponentAlignment(btnOk, Alignment.BOTTOM_RIGHT); |
|
152 |
popup.setContent(layout); |
|
153 |
popup.setModal(true); |
|
154 |
popup.center(); |
|
155 |
UI.getCurrent().addWindow(popup); |
|
156 |
} |
|
141 | 157 |
} |
142 |
} |
|
158 |
});
|
|
143 | 159 |
} |
144 | 160 |
|
145 | 161 |
private void createEditClickListener(){ |
... | ... | |
199 | 215 |
|
200 | 216 |
} |
201 | 217 |
|
202 |
private final class AreaColumnGenerator implements ColumnGenerator { |
|
203 |
private static final long serialVersionUID = 1L; |
|
204 |
|
|
205 |
@Override |
|
206 |
public Object generateCell(Table source, Object itemId, Object columnId) { |
|
207 |
Property<?> containerProperty = source.getContainerProperty(itemId, columnId); |
|
208 |
Object value = null; |
|
209 |
if(containerProperty != null){ |
|
210 |
value = containerProperty.getValue(); |
|
211 |
} |
|
212 |
final UUID uuid = UUID.fromString(table.getItem(itemId).getItemProperty("uuid").getValue().toString()); |
|
213 |
final ComboBox box = new ComboBox("Occurrence Status: ", PresenceAbsenceTermContainer.getInstance()); |
|
214 |
final String area = columnId.toString(); |
|
215 |
box.setImmediate(true); |
|
216 |
box.setBuffered(true); |
|
217 |
box.setSizeFull(); |
|
218 |
PresenceAbsenceTerm presenceAbsenceTerm = TermCacher.getInstance().getPresenceAbsenceTerm((String)value); |
|
219 |
box.setValue(presenceAbsenceTerm); |
|
220 |
if(presenceAbsenceTerm!=null){ |
|
221 |
String itemCaption = null; |
|
222 |
Representation representation = presenceAbsenceTerm.getRepresentation(Language.DEFAULT()); |
|
223 |
if(representation!=null){ |
|
224 |
if(DistributionEditorUtil.isAbbreviatedLabels()){ |
|
225 |
itemCaption = representation.getAbbreviatedLabel(); |
|
226 |
} |
|
227 |
else{ |
|
228 |
itemCaption = representation.getLabel(); |
|
229 |
} |
|
230 |
} |
|
231 |
if(itemCaption==null){ |
|
232 |
itemCaption = presenceAbsenceTerm.getTitleCache(); |
|
233 |
} |
|
234 |
box.setItemCaption(presenceAbsenceTerm, itemCaption); |
|
235 |
} |
|
236 |
box.addValueChangeListener(new ValueChangeListener() { |
|
237 |
private static final long serialVersionUID = 6221534597911674067L; |
|
238 |
|
|
239 |
@Override |
|
240 |
public void valueChange(ValueChangeEvent event) { |
|
241 |
Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class); |
|
242 |
listener.updateDistributionField(area, box.getValue(), taxon); |
|
243 |
} |
|
244 |
}); |
|
245 |
return box; |
|
246 |
} |
|
247 |
} |
|
248 |
|
|
249 | 218 |
} |
Also available in: Unified diff
ref #5458 Replace term dropdown with popup window for performance