Revision 1d066036
Added by Cherian Mathew about 9 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/StatusComposite.java | ||
---|---|---|
24 | 24 |
import com.vaadin.data.util.sqlcontainer.RowId; |
25 | 25 |
import com.vaadin.event.Action; |
26 | 26 |
import com.vaadin.event.FieldEvents; |
27 |
import com.vaadin.event.FieldEvents.FocusEvent; |
|
28 | 27 |
import com.vaadin.event.FieldEvents.TextChangeEvent; |
29 |
import com.vaadin.server.ThemeResource; |
|
28 |
import com.vaadin.event.LayoutEvents.LayoutClickEvent; |
|
29 |
import com.vaadin.event.LayoutEvents.LayoutClickListener; |
|
30 |
import com.vaadin.server.FontAwesome; |
|
30 | 31 |
import com.vaadin.ui.Alignment; |
31 | 32 |
import com.vaadin.ui.Button; |
32 | 33 |
import com.vaadin.ui.Button.ClickEvent; |
... | ... | |
42 | 43 |
import com.vaadin.ui.Table; |
43 | 44 |
import com.vaadin.ui.Table.ColumnHeaderMode; |
44 | 45 |
import com.vaadin.ui.TextField; |
46 |
import com.vaadin.ui.Tree.ExpandEvent; |
|
47 |
import com.vaadin.ui.Tree.ExpandListener; |
|
48 |
import com.vaadin.ui.TreeTable; |
|
45 | 49 |
import com.vaadin.ui.VerticalLayout; |
46 |
import com.vaadin.ui.themes.Reindeer; |
|
47 | 50 |
|
48 |
import eu.etaxonomy.cdm.vaadin.presenter.StatusPresenter;
|
|
51 |
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
|
|
49 | 52 |
import eu.etaxonomy.cdm.vaadin.view.IStatusComposite; |
50 | 53 |
|
51 | 54 |
/** |
... | ... | |
62 | 65 |
@AutoGenerated |
63 | 66 |
private Label inViewLabel; |
64 | 67 |
@AutoGenerated |
65 |
private Table taxaTreeTable; |
|
66 |
@AutoGenerated |
|
67 |
private HorizontalLayout addRemovehorizontalLayout; |
|
68 |
@AutoGenerated |
|
69 |
private Button removeButton; |
|
70 |
@AutoGenerated |
|
71 |
private ComboBox addComboBox; |
|
68 |
private TreeTable taxaTreeTable; |
|
72 | 69 |
@AutoGenerated |
73 | 70 |
private HorizontalLayout searchHorizontalLayout; |
74 | 71 |
@AutoGenerated |
... | ... | |
76 | 73 |
@AutoGenerated |
77 | 74 |
private TextField searchTextField; |
78 | 75 |
@AutoGenerated |
76 |
private HorizontalLayout addRemovehorizontalLayout; |
|
77 |
@AutoGenerated |
|
78 |
private Button removeButton; |
|
79 |
@AutoGenerated |
|
80 |
private ComboBox addComboBox; |
|
81 |
@AutoGenerated |
|
79 | 82 |
private VerticalLayout filterVerticalLayout; |
80 | 83 |
@AutoGenerated |
81 | 84 |
private Table filterTable; |
... | ... | |
112 | 115 |
buildMainLayout(); |
113 | 116 |
setCompositionRoot(mainLayout); |
114 | 117 |
|
118 |
searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() { |
|
119 |
|
|
120 |
@Override |
|
121 |
public void layoutClick(LayoutClickEvent event) { |
|
122 |
if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) { |
|
123 |
searchTextField.setValue(""); |
|
124 |
} |
|
125 |
} |
|
126 |
}); |
|
115 | 127 |
addUIListeners(); |
116 | 128 |
initAddComboBox(); |
117 | 129 |
initSearchTextField(); |
... | ... | |
130 | 142 |
taxaTreeTable.setEnabled(enable); |
131 | 143 |
addComboBox.setEnabled(enable); |
132 | 144 |
removeButton.setEnabled(enable); |
145 |
searchTextField.setEnabled(enable); |
|
146 |
clearSearchButton.setEnabled(enable); |
|
133 | 147 |
} |
134 | 148 |
|
135 | 149 |
private void initTaxaTable(int classificationId) { |
136 | 150 |
|
151 |
taxaTreeTable.setSelectable(true); |
|
152 |
taxaTreeTable.setImmediate(false); |
|
153 |
|
|
137 | 154 |
if(listener != null) { |
138 | 155 |
List<String> columnIds = new ArrayList<String>(); |
139 |
columnIds.add(StatusPresenter.NAME_ID);
|
|
140 |
taxaTreeTable.setColumnExpandRatio(StatusPresenter.NAME_ID, 1);
|
|
141 |
columnIds.add(StatusPresenter.PB_ID);
|
|
142 |
taxaTreeTable.setColumnWidth(StatusPresenter.PB_ID, -1);
|
|
156 |
columnIds.add(LeafNodeTaxonContainer.NAME_ID);
|
|
157 |
taxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
|
|
158 |
columnIds.add(LeafNodeTaxonContainer.PB_ID);
|
|
159 |
taxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
|
|
143 | 160 |
|
144 | 161 |
ValueChangeListener pbListener = new ValueChangeListener() { |
145 | 162 |
@Override |
... | ... | |
149 | 166 |
} |
150 | 167 |
|
151 | 168 |
}; |
152 |
taxaTreeTable.addGeneratedColumn(StatusPresenter.PB_ID, new BooleanCheckBoxGenerator(pbListener));
|
|
169 |
taxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new BooleanCheckBoxGenerator(pbListener));
|
|
153 | 170 |
try { |
154 | 171 |
taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId), columnIds); |
155 | 172 |
} catch (SQLException e) { |
156 | 173 |
//TODO : throw up warning dialog |
157 | 174 |
e.printStackTrace(); |
158 | 175 |
} |
176 |
|
|
177 |
taxaTreeTable.addExpandListener(new ExpandListener() { |
|
178 |
|
|
179 |
@Override |
|
180 |
public void nodeExpand(ExpandEvent event) { |
|
181 |
//listener.addChildren(event.getItemId()); |
|
182 |
} |
|
183 |
|
|
184 |
}); |
|
185 |
|
|
186 |
taxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() { |
|
187 |
|
|
188 |
@Override |
|
189 |
public String getStyle(Table source, Object itemId, Object propertyId) { |
|
190 |
Property hasSynProperty = source.getItem(itemId).getItemProperty(LeafNodeTaxonContainer.HAS_SYN_ID); |
|
191 |
if(hasSynProperty == null) { |
|
192 |
// this is a synonym |
|
193 |
return "synonym"; |
|
194 |
} |
|
195 |
return null; |
|
196 |
} |
|
197 |
}); |
|
198 |
|
|
199 |
// NOTE : Not really sure why we need to refresh the container here. |
|
200 |
// in the case of 'Table' this is not required |
|
201 |
listener.refresh(); |
|
159 | 202 |
updateInViewLabel(); |
160 | 203 |
} |
161 | 204 |
|
... | ... | |
222 | 265 |
|
223 | 266 |
filterTable.setContainerDataSource(container); |
224 | 267 |
filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN); |
225 |
filterTable.addStyleName(Reindeer.TABLE_BORDERLESS); |
|
226 |
|
|
227 | 268 |
|
228 | 269 |
|
229 | 270 |
ValueChangeListener selectedListener = new ValueChangeListener() { |
230 | 271 |
|
272 |
private static final long serialVersionUID = -5551250788805117454L; |
|
231 | 273 |
|
232 | 274 |
@Override |
233 | 275 |
public void valueChange(ValueChangeEvent event) { |
... | ... | |
256 | 298 |
}; |
257 | 299 |
filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new BooleanCheckBoxGenerator(selectedListener)); |
258 | 300 |
|
259 |
// filterTable.setCellStyleGenerator(new Table.CellStyleGenerator() { |
|
260 |
// |
|
261 |
// private static final long serialVersionUID = -3363906932807556720L; |
|
262 |
// |
|
263 |
// @Override |
|
264 |
// public String getStyle(Table source, Object itemId, Object propertyId) { |
|
265 |
// return "removable"; |
|
266 |
// } |
|
267 |
// }); |
|
268 | 301 |
} |
269 | 302 |
|
270 | 303 |
private void updateInViewLabel() { |
271 |
inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentSize()) + " / " + String.valueOf(listener.getSize()) + " taxa");
|
|
304 |
inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
|
|
272 | 305 |
} |
273 | 306 |
|
274 | 307 |
private void initSearchTextField() { |
... | ... | |
287 | 320 |
} |
288 | 321 |
|
289 | 322 |
private void initClearSearchButton() { |
290 |
ThemeResource resource = new ThemeResource("icons/32/cancel.png"); |
|
291 |
clearSearchButton.setIcon(resource);
|
|
323 |
//ThemeResource resource = new ThemeResource("icons/32/cancel.png");
|
|
324 |
clearSearchButton.setIcon(FontAwesome.REFRESH);
|
|
292 | 325 |
clearSearchButton.setCaption(""); |
293 | 326 |
} |
294 | 327 |
|
... | ... | |
319 | 352 |
}); |
320 | 353 |
} |
321 | 354 |
|
322 |
// private void addFilterComboBoxListener() { |
|
323 |
// filterComboBox.addValueChangeListener(new Property.ValueChangeListener() { |
|
324 |
// |
|
325 |
// private static final long serialVersionUID = 1314542578509878256L; |
|
326 |
// |
|
327 |
// @Override |
|
328 |
// public void valueChange(ValueChangeEvent event) { |
|
329 |
// if (filterComboBox.getValue() != null) { |
|
330 |
// String selected = (String)filterComboBox.getValue(); |
|
331 |
// if(!selected.equals(SELECT_FILTER)) { |
|
332 |
// filterTable.addItem(new Object[]{selected}, filterTable.getItemIds().size() + 1); |
|
333 |
// filterComboBox.setValue(SELECT_FILTER); |
|
334 |
// } |
|
335 |
// } |
|
336 |
// } |
|
337 |
// }); |
|
338 |
// } |
|
339 | 355 |
|
340 | 356 |
private void addAddComboBoxListener() { |
341 | 357 |
addComboBox.addValueChangeListener(new Property.ValueChangeListener() { |
... | ... | |
363 | 379 |
@Override |
364 | 380 |
public void textChange(TextChangeEvent event) { |
365 | 381 |
listener.setNameFilter(event.getText()); |
382 |
updateInViewLabel(); |
|
366 | 383 |
} |
367 | 384 |
|
368 | 385 |
}); |
369 |
searchTextField.addFocusListener(new FieldEvents.FocusListener(){ |
|
370 | 386 |
|
371 |
@Override |
|
372 |
public void focus(FocusEvent event) { |
|
373 |
searchTextField.setValue(""); |
|
374 |
} |
|
375 |
|
|
376 |
}); |
|
377 | 387 |
} |
378 | 388 |
|
379 | 389 |
private void addClearSearchButtonListener() { |
... | ... | |
383 | 393 |
public void buttonClick(ClickEvent event) { |
384 | 394 |
listener.removeNameFilter(); |
385 | 395 |
searchTextField.setValue(FILTER_TAXA_INPUT); |
396 |
updateInViewLabel(); |
|
386 | 397 |
} |
387 | 398 |
|
388 | 399 |
}); |
389 | 400 |
} |
390 |
// private void addFilterTableListener() { |
|
391 |
// filterTable.addItemClickListener(new ItemClickEvent.ItemClickListener() { |
|
392 |
// |
|
393 |
// private static final long serialVersionUID = -4722168300711497739L; |
|
394 |
// |
|
395 |
// @Override |
|
396 |
// public void itemClick(ItemClickEvent event) { |
|
397 |
// filterTable.removeItem(event.getItemId()); |
|
398 |
// }} |
|
399 |
// ); |
|
400 |
// } |
|
401 |
|
|
401 | 402 |
|
402 | 403 |
|
403 | 404 |
/* (non-Javadoc) |
... | ... | |
422 | 423 |
*/ |
423 | 424 |
@Override |
424 | 425 |
public Component generateCell(Table source, Object itemId, Object columnId) { |
425 |
Property prop = source.getItem(itemId).getItemProperty(columnId); |
|
426 |
CheckBox cb = new CheckBox(null, prop); |
|
427 |
cb.addValueChangeListener(listener); |
|
428 |
cb.setData(itemId); |
|
429 |
return cb; |
|
426 |
if(source.getItem(itemId) != null) { |
|
427 |
Property prop = source.getItem(itemId).getItemProperty(columnId); |
|
428 |
if(prop == null) { |
|
429 |
return null; |
|
430 |
} |
|
431 |
CheckBox cb = new CheckBox(null, prop); |
|
432 |
cb.addValueChangeListener(listener); |
|
433 |
cb.setData(itemId); |
|
434 |
return cb; |
|
435 |
} else { |
|
436 |
return null; |
|
437 |
} |
|
438 |
|
|
430 | 439 |
} |
431 | 440 |
} |
432 | 441 |
|
... | ... | |
458 | 467 |
mainLayout.addComponent(filterVerticalLayout, 0, 1); |
459 | 468 |
mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20)); |
460 | 469 |
|
461 |
// searchHorizontalLayout |
|
462 |
searchHorizontalLayout = buildSearchHorizontalLayout(); |
|
463 |
mainLayout.addComponent(searchHorizontalLayout, 0, 3); |
|
464 |
mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48)); |
|
465 |
|
|
466 | 470 |
// addRemovehorizontalLayout |
467 | 471 |
addRemovehorizontalLayout = buildAddRemovehorizontalLayout(); |
468 | 472 |
mainLayout.addComponent(addRemovehorizontalLayout, 0, 2); |
469 | 473 |
mainLayout.setComponentAlignment(addRemovehorizontalLayout, new Alignment(48)); |
470 | 474 |
|
475 |
// searchHorizontalLayout |
|
476 |
searchHorizontalLayout = buildSearchHorizontalLayout(); |
|
477 |
mainLayout.addComponent(searchHorizontalLayout, 0, 3); |
|
478 |
mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48)); |
|
479 |
|
|
471 | 480 |
// taxaTreeTable |
472 |
taxaTreeTable = new Table(); |
|
481 |
taxaTreeTable = new TreeTable();
|
|
473 | 482 |
taxaTreeTable.setImmediate(false); |
474 | 483 |
taxaTreeTable.setWidth("100.0%"); |
475 | 484 |
taxaTreeTable.setHeight("534px"); |
... | ... | |
515 | 524 |
return filterVerticalLayout; |
516 | 525 |
} |
517 | 526 |
|
527 |
@AutoGenerated |
|
528 |
private HorizontalLayout buildAddRemovehorizontalLayout() { |
|
529 |
// common part: create layout |
|
530 |
addRemovehorizontalLayout = new HorizontalLayout(); |
|
531 |
addRemovehorizontalLayout.setImmediate(false); |
|
532 |
addRemovehorizontalLayout.setWidth("100.0%"); |
|
533 |
addRemovehorizontalLayout.setHeight("-1px"); |
|
534 |
addRemovehorizontalLayout.setMargin(false); |
|
535 |
addRemovehorizontalLayout.setSpacing(true); |
|
536 |
|
|
537 |
// addComboBox |
|
538 |
addComboBox = new ComboBox(); |
|
539 |
addComboBox.setImmediate(false); |
|
540 |
addComboBox.setWidth("100.0%"); |
|
541 |
addComboBox.setHeight("-1px"); |
|
542 |
addRemovehorizontalLayout.addComponent(addComboBox); |
|
543 |
addRemovehorizontalLayout.setExpandRatio(addComboBox, 3.0f); |
|
544 |
|
|
545 |
// removeButton |
|
546 |
removeButton = new Button(); |
|
547 |
removeButton.setCaption("Remove"); |
|
548 |
removeButton.setImmediate(true); |
|
549 |
removeButton.setWidth("100.0%"); |
|
550 |
removeButton.setHeight("-1px"); |
|
551 |
addRemovehorizontalLayout.addComponent(removeButton); |
|
552 |
addRemovehorizontalLayout.setExpandRatio(removeButton, 2.0f); |
|
553 |
|
|
554 |
return addRemovehorizontalLayout; |
|
555 |
} |
|
556 |
|
|
518 | 557 |
@AutoGenerated |
519 | 558 |
private HorizontalLayout buildSearchHorizontalLayout() { |
520 | 559 |
// common part: create layout |
... | ... | |
547 | 586 |
return searchHorizontalLayout; |
548 | 587 |
} |
549 | 588 |
|
550 |
@AutoGenerated |
|
551 |
private HorizontalLayout buildAddRemovehorizontalLayout() { |
|
552 |
// common part: create layout |
|
553 |
addRemovehorizontalLayout = new HorizontalLayout(); |
|
554 |
addRemovehorizontalLayout.setImmediate(false); |
|
555 |
addRemovehorizontalLayout.setWidth("100.0%"); |
|
556 |
addRemovehorizontalLayout.setHeight("-1px"); |
|
557 |
addRemovehorizontalLayout.setMargin(false); |
|
558 |
addRemovehorizontalLayout.setSpacing(true); |
|
559 |
|
|
560 |
// addComboBox |
|
561 |
addComboBox = new ComboBox(); |
|
562 |
addComboBox.setImmediate(false); |
|
563 |
addComboBox.setWidth("100.0%"); |
|
564 |
addComboBox.setHeight("-1px"); |
|
565 |
addRemovehorizontalLayout.addComponent(addComboBox); |
|
566 |
addRemovehorizontalLayout.setExpandRatio(addComboBox, 3.0f); |
|
567 |
|
|
568 |
// removeButton |
|
569 |
removeButton = new Button(); |
|
570 |
removeButton.setCaption("Remove"); |
|
571 |
removeButton.setImmediate(true); |
|
572 |
removeButton.setWidth("100.0%"); |
|
573 |
removeButton.setHeight("-1px"); |
|
574 |
addRemovehorizontalLayout.addComponent(removeButton); |
|
575 |
addRemovehorizontalLayout.setExpandRatio(removeButton, 2.0f); |
|
576 |
|
|
577 |
return addRemovehorizontalLayout; |
|
578 |
} |
|
579 |
|
|
580 | 589 |
} |
Also available in: Unified diff
StatusComposite, IStatusComposite : added font awesome refresh icon, updated checkbox generator
CdmSQLContainer : added methods to disable change ebents and possiblity to add items
LeafNodeTaxonContainer : corrected and split queris for taxon and synonyms
StatusPresenter : moving filter / query logic to container
StatusEditorUI : using new edit theme
CdmQueryFactory : new factory for sql queries
StatusPresenterTest, StatusPresenterTest : added tests for loading synonyms