a8627627a3dd54cfb3d9d00fb4655812ef041b75
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / component / StatusComposite.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.cdm.vaadin.component;
11
12 import java.sql.SQLException;
13 import java.util.ArrayList;
14 import java.util.Arrays;
15 import java.util.List;
16 import java.util.Set;
17 import java.util.UUID;
18
19 import org.apache.log4j.Logger;
20 import org.vaadin.peter.contextmenu.ContextMenu;
21 import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItem;
22 import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickEvent;
23 import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickListener;
24
25 import com.vaadin.annotations.AutoGenerated;
26 import com.vaadin.data.Item;
27 import com.vaadin.data.Property;
28 import com.vaadin.data.Property.ValueChangeEvent;
29 import com.vaadin.data.Property.ValueChangeListener;
30 import com.vaadin.data.util.IndexedContainer;
31 import com.vaadin.data.util.sqlcontainer.RowId;
32 import com.vaadin.event.FieldEvents;
33 import com.vaadin.event.FieldEvents.TextChangeEvent;
34 import com.vaadin.event.ItemClickEvent;
35 import com.vaadin.event.ItemClickEvent.ItemClickListener;
36 import com.vaadin.event.LayoutEvents.LayoutClickEvent;
37 import com.vaadin.event.LayoutEvents.LayoutClickListener;
38 import com.vaadin.navigator.View;
39 import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
40 import com.vaadin.server.FontAwesome;
41 import com.vaadin.ui.Alignment;
42 import com.vaadin.ui.Button;
43 import com.vaadin.ui.Button.ClickEvent;
44 import com.vaadin.ui.CheckBox;
45 import com.vaadin.ui.ComboBox;
46 import com.vaadin.ui.Component;
47 import com.vaadin.ui.CustomComponent;
48 import com.vaadin.ui.GridLayout;
49 import com.vaadin.ui.HorizontalLayout;
50 import com.vaadin.ui.Label;
51 import com.vaadin.ui.Notification;
52 import com.vaadin.ui.Notification.Type;
53 import com.vaadin.ui.Table;
54 import com.vaadin.ui.Table.ColumnHeaderMode;
55 import com.vaadin.ui.Table.TableDragMode;
56 import com.vaadin.ui.TextField;
57 import com.vaadin.ui.TreeTable;
58 import com.vaadin.ui.UI;
59 import com.vaadin.ui.VerticalLayout;
60 import com.vaadin.ui.Window;
61
62 import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
63 import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
64 import eu.etaxonomy.cdm.vaadin.presenter.NewTaxonBasePresenter;
65 import eu.etaxonomy.cdm.vaadin.presenter.StatusPresenter;
66 import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
67 import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
68 import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
69 import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
70 import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
71 import eu.etaxonomy.cdm.vaadin.view.IStatusComposite;
72
73 /**
74 * @author cmathew
75 * @date 11 Mar 2015
76 *
77 */
78 public class StatusComposite extends CustomComponent implements View, IStatusComposite, ICdmChangeListener {
79
80 /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
81
82 @AutoGenerated
83 private GridLayout mainLayout;
84 @AutoGenerated
85 private Label inViewLabel;
86 @AutoGenerated
87 private TreeTable taxaTreeTable;
88 @AutoGenerated
89 private HorizontalLayout searchHorizontalLayout;
90 @AutoGenerated
91 private Button clearSearchButton;
92 @AutoGenerated
93 private TextField searchTextField;
94 @AutoGenerated
95 private VerticalLayout filterVerticalLayout;
96 @AutoGenerated
97 private Table filterTable;
98 @AutoGenerated
99 private Label filterLabel;
100 @AutoGenerated
101 private ComboBox classificationComboBox;
102 private static final Logger logger = Logger.getLogger(StatusComposite.class);
103 private StatusComponentListener listener;
104
105 private Object currentClickedTaxonItemId;
106
107 private final boolean taxaTreeTableMultiSelectMode = true;
108
109 private static final String SELECT_FILTER = "Select filter ...";
110 private static final String SELECT_CLASSIFICATION = "Select classification ...";
111
112 private static final String ADD_TAXON_SYNONYM_INPUT = "Add ...";
113 private static final String CREATE_ACC_TAXON = "Create Accepted Taxon";
114 private static final String CREATE_SYNONYM = "Create Synonym";
115 private static final String SET_AS_DELETED = "Set as Deleted";
116 private static final String SET_AS_EXCLUDED = "Set as Excluded";
117 private static final String SET_AS_OUT_OF_SCOPE = "Set as Out Of Scope";
118
119 private static final String PROPERTY_FILTER_ID = "filter";
120 private static final String PROPERTY_SELECTED_ID = "selected";
121
122 private static final String FILTER_NOT_RESOLVED = "not resolved";
123 private static final String FILTER_UNPLACED = "unplaced";
124 private static final String FILTER_UNFINISHED = "unfinished";
125 private static final String FILTER_UNPUBLISHED = "unpublished";
126
127
128 private static final String FILTER_TAXA_INPUT = "Filter Taxa ...";
129 private static final String IN_VIEW_PREFIX = "in view : ";
130
131 private boolean isTaxaTableInitialised = false;
132 private boolean isFiltertableInitialised = false;
133
134 private String selectedTaxaTableMenuItem = null;
135
136 ContextMenu taxaTableContextMenu;
137
138 /**
139 * The constructor should first build the main layout, set the
140 * composition root and then do any custom initialization.
141 *
142 * The constructor will not be automatically regenerated by the
143 * visual editor.
144 */
145 public StatusComposite() {
146 buildMainLayout();
147 setCompositionRoot(mainLayout);
148
149 this.listener = new StatusPresenter();
150 CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this);
151 addUIListeners();
152
153 initSearchTextField();
154 initClearSearchButton();
155 setEnabledAll(false);
156
157 init();
158 }
159
160
161
162 public void setClassification(String classification) {
163 if(classification == null) {
164 return;
165 }
166 Object selectedClassificationId = listener.getClassificationId(classification);
167 if(selectedClassificationId == null) {
168 Notification.show("Classification named " + classification + " does not exist.");
169 } else {
170 classificationComboBox.setValue(selectedClassificationId);
171 classificationComboBox.setReadOnly(true);
172 }
173 }
174
175 public void init() {
176 taxaTreeTable.setSelectable(true);
177 initClassificationComboBox();
178 }
179
180 public void setEnabledAll(boolean enabled) {
181 CdmVaadinUtilities.setEnabled(mainLayout, enabled, Arrays.asList(classificationComboBox));
182 }
183
184
185 public TreeTable getTaxaTreeTable() {
186 return taxaTreeTable;
187 }
188
189 public LeafNodeTaxonContainer getTaxonContainer() {
190 return listener.getCurrentLeafNodeTaxonContainer();
191 }
192
193 public void clearTaxaTableSelections() {
194 taxaTreeTable.setValue(null);
195 }
196
197 public UUID getSelectedClassificationUuid() {
198 if(classificationComboBox.getValue() != null) {
199 return listener.getClassificationContainer().getUuid(classificationComboBox.getValue());
200 }
201 return null;
202 }
203
204 private void initTaxaTable(int classificationId) {
205 taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
206 taxaTreeTable.setImmediate(false);
207 taxaTreeTable.setDragMode(TableDragMode.ROW);
208 if(listener != null) {
209 List<String> columnIds = new ArrayList<String>();
210 columnIds.add(LeafNodeTaxonContainer.NAME_ID);
211 taxaTreeTable.setColumnExpandRatio(LeafNodeTaxonContainer.NAME_ID, 1);
212 columnIds.add(LeafNodeTaxonContainer.PB_ID);
213 taxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
214
215 if(!isTaxaTableInitialised) {
216 taxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
217 }
218
219 try {
220 taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId), columnIds);
221 } catch (SQLException e) {
222 //TODO : throw up warning dialog
223 e.printStackTrace();
224 }
225
226
227 taxaTreeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
228
229 @Override
230 public String getStyle(Table source, Object itemId, Object propertyId) {
231 if(source.getItem(itemId) == null) {
232 return null;
233 }
234 if(listener.isSynonym(itemId)) {
235 // this is a synonym, so we activate the corresponding css class
236 return "synonym";
237 } else {
238 return "taxon";
239 }
240
241 }
242 });
243
244 taxaTreeTable.setSortContainerPropertyId(LeafNodeTaxonContainer.NAME_ID);
245
246 // NOTE : Not really sure why we need to refresh the container here.
247 // in the case of 'Table' this is not required
248 listener.refresh();
249 updateInViewLabel();
250 isTaxaTableInitialised = true;
251 }
252
253 taxaTableContextMenu = new ContextMenu();
254 taxaTableContextMenu.setAsContextMenuOf(taxaTreeTable);
255 addTaxaTreeContextMenuItemListener();
256
257
258 }
259
260 private void initClassificationComboBox() {
261
262 classificationComboBox.setNewItemsAllowed(false);
263 classificationComboBox.setNullSelectionAllowed(false);
264 classificationComboBox.setImmediate(true);
265 classificationComboBox.setItemCaptionPropertyId(StatusPresenter.C_TCACHE_ID);
266 classificationComboBox.setInputPrompt(SELECT_CLASSIFICATION);
267 if(listener != null) {
268 try {
269 classificationComboBox.setContainerDataSource(listener.loadClassifications());
270 } catch (SQLException e) {
271 //TODO : throw up warning dialog
272 e.printStackTrace();
273 }
274 }
275 }
276
277
278
279 private void initFilterTable() {
280 filterTable.setNullSelectionAllowed(false);
281 final IndexedContainer container = new IndexedContainer();
282 container.addContainerProperty("filter", String.class, "");
283 container.addContainerProperty("selected", Boolean.class, "");
284
285 // Item item = container.addItem(FILTER_NOT_RESOLVED);
286 // item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_NOT_RESOLVED);
287 // item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
288 //
289 // item = container.addItem(FILTER_UNPLACED);
290 // item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPLACED);
291 // item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
292
293 Item item = container.addItem(FILTER_UNFINISHED);
294 item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNFINISHED);
295 item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
296
297 item = container.addItem(FILTER_UNPUBLISHED);
298 item.getItemProperty(PROPERTY_FILTER_ID).setValue(FILTER_UNPUBLISHED);
299 item.getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
300
301
302 filterTable.setContainerDataSource(container);
303 filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
304
305
306 ValueChangeListener selectedListener = new ValueChangeListener() {
307
308 private static final long serialVersionUID = -5551250788805117454L;
309
310 @Override
311 public void valueChange(ValueChangeEvent event) {
312 boolean value = (Boolean) event.getProperty().getValue();
313 String selectedFilter = (String)filterTable.getItem(((CheckBox)event.getProperty()).getData()).getItemProperty(PROPERTY_FILTER_ID).getValue();
314 if(selectedFilter != null) {
315 if(value) {
316 if(selectedFilter.equals(FILTER_UNPLACED)) {
317 listener.setUnplacedFilter();
318 }
319 if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
320 listener.setUnpublishedFilter();
321 }
322 } else {
323 if(selectedFilter.equals(FILTER_UNPLACED)) {
324 listener.removeUnplacedFilter();
325 }
326 if(selectedFilter.equals(FILTER_UNPUBLISHED)) {
327 listener.removeUnpublishedFilter();
328 }
329 }
330 updateInViewLabel();
331 }
332 }
333 };
334
335 if(!isFiltertableInitialised) {
336 filterTable.addGeneratedColumn(PROPERTY_SELECTED_ID, new CheckBoxGenerator(selectedListener));
337 }
338
339 isFiltertableInitialised = true;
340
341 }
342
343 private void updateInViewLabel() {
344 inViewLabel.setValue(IN_VIEW_PREFIX + String.valueOf(listener.getCurrentNoOfTaxa()) + " / " + String.valueOf(listener.getTotalNoOfTaxa()) + " taxa");
345 }
346
347 private void initSearchTextField() {
348 searchTextField.setInputPrompt(FILTER_TAXA_INPUT);
349 }
350
351
352 private void initClearSearchButton() {
353 clearSearchButton.setIcon(FontAwesome.REFRESH);
354 clearSearchButton.setCaption("");
355 }
356
357
358 private void addUIListeners() {
359
360 searchHorizontalLayout.addLayoutClickListener(new LayoutClickListener() {
361
362 @Override
363 public void layoutClick(LayoutClickEvent event) {
364 if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) {
365 searchTextField.setValue("");
366 }
367 }
368 });
369
370 addClassificationComboBoxListener();
371 addTaxaTreeTableListener();
372
373 addSearchTextFieldListener();
374 addClearSearchButtonListener();
375 }
376
377 private void addClassificationComboBoxListener() {
378
379 classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
380
381 private static final long serialVersionUID = 4196786323147791606L;
382
383 @Override
384 public void valueChange(ValueChangeEvent event) {
385 if (classificationComboBox.getValue() != null) {
386 Object selected = classificationComboBox.getValue();
387 int classificationId = (Integer)((RowId)selected).getId()[0];
388 initTaxaTable(classificationId);
389 initFilterTable();
390 setEnabledAll(true);
391 }
392 }
393 });
394 }
395
396 private void addTaxaTreeTableListener() {
397
398 taxaTreeTable.addItemClickListener(new ItemClickListener() {
399 @Override
400 public void itemClick(ItemClickEvent event) {
401 Object itemId = event.getItemId();
402 if(taxaTreeTable.isSelectable()) {
403 boolean isSynonym = listener.isSynonym(itemId);
404 if(!CdmVaadinUtilities.isSelected(taxaTreeTable, itemId) && !isSynonym) {
405 UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
406 String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
407 Object idUuidName = new IdUuidName(itemId, taxonUuid, taxonName);
408 CdmVaadinSessionUtilities.getCurrentSelectionService()
409 .fireSelectionEvent(new SelectionEvent(Arrays.asList(idUuidName, getSelectedClassificationUuid()), StatusComposite.class), true);
410 }
411 taxaTreeTable.setValue(Arrays.asList(itemId));
412 generateTaxaTreeTableContextMenu(!isSynonym);
413
414 }
415 }
416 });
417
418 //taxaTreeTable.add
419
420
421 }
422
423 private void generateTaxaTreeTableContextMenu(boolean isSynonym) {
424
425 taxaTableContextMenu.removeAllItems();
426 if(isSynonym) {
427 ContextMenuItem createSynMenuItem = taxaTableContextMenu.addItem(CREATE_SYNONYM);
428 createSynMenuItem.setData(CREATE_SYNONYM);
429 }
430 ContextMenuItem setDeletedMenuItem = taxaTableContextMenu.addItem(SET_AS_DELETED);
431 setDeletedMenuItem.setData(SET_AS_DELETED);
432
433 ContextMenuItem setExcludedMenuItem = taxaTableContextMenu.addItem(SET_AS_EXCLUDED);
434 setExcludedMenuItem.setData(SET_AS_EXCLUDED);
435
436 ContextMenuItem setOutOfScopeMenuItem = taxaTableContextMenu.addItem(SET_AS_OUT_OF_SCOPE);
437 setOutOfScopeMenuItem.setData(SET_AS_OUT_OF_SCOPE);
438
439 setOutOfScopeMenuItem.setSeparatorVisible(true);
440
441 ContextMenuItem createAccTaxonMenuItem = taxaTableContextMenu.addItem(CREATE_ACC_TAXON);
442 createAccTaxonMenuItem.setData(CREATE_ACC_TAXON);
443
444 }
445
446 private void addTaxaTreeContextMenuItemListener() {
447 if(taxaTableContextMenu != null) {
448 taxaTableContextMenu.addItemClickListener(new ContextMenuItemClickListener() {
449
450 @Override
451 public void contextMenuItemClicked(ContextMenuItemClickEvent event) {
452 Object source = event.getSource();
453 if(source instanceof ContextMenuItem) {
454 ContextMenuItem menuItem = (ContextMenuItem) source;
455 String action = (String)menuItem.getData();
456 if(CREATE_ACC_TAXON.equals(action) || CREATE_SYNONYM.equals(action)) {
457 showAddTaxonBaseWindow(action);
458 } else {
459 Notification.show(action + " to be implemented", Type.WARNING_MESSAGE);
460 }
461 }
462 }
463 });
464 }
465 }
466
467
468 private void showAddTaxonBaseWindow(String action) {
469 if (action != null) {
470 String windowTitle;
471
472 Object selectedItemId = null;
473 IdUuidName accTaxonIdUuid = null;
474 String accTaxonName = null;
475 if(action.equals(CREATE_SYNONYM)) {
476 Set<Object> selectedIds = (Set<Object>)taxaTreeTable.getValue();
477 // if zero or more than one items (taxa / synonyms) are selected
478 // throw a warning
479 if(selectedIds.size() != 1) {
480 Notification.show("Multiple or No selection", "Please select a single Taxon", Type.WARNING_MESSAGE);
481 return;
482 }
483 selectedItemId = selectedIds.iterator().next();
484 // if a synonym is selected then throw warning
485 if(listener.isSynonym(selectedItemId)) {
486 Notification.show("Synonym selected", "Please choose a Taxon", Type.WARNING_MESSAGE);
487 return;
488 }
489 windowTitle = "Add New Synonym";
490 accTaxonIdUuid = new IdUuidName(selectedItemId,
491 listener.getCurrentLeafNodeTaxonContainer().getUuid(selectedItemId),
492 (String) listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue());
493 accTaxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(selectedItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
494 } else {
495 windowTitle = "Add New Taxon";
496 }
497
498 try {
499 Window dialog = new Window(windowTitle);
500 dialog.setModal(true);
501 dialog.setClosable(false);
502 dialog.setResizable(false);
503 UI.getCurrent().addWindow(dialog);
504 Object cId = classificationComboBox.getValue();
505 UUID classificationUuid = listener.getClassificationContainer().getUuid(cId);
506 IdUuidName classificationIdUuid = new IdUuidName(classificationComboBox.getValue(),
507 classificationUuid,
508 (String) listener.getClassificationContainer().getProperty(cId, StatusPresenter.C_TCACHE_ID).getValue());
509 NewTaxonBaseComposite newTaxonComponent =
510 new NewTaxonBaseComposite(dialog,
511 new NewTaxonBasePresenter(),
512 accTaxonIdUuid,
513 accTaxonName,
514 classificationIdUuid);
515 dialog.setContent(newTaxonComponent);
516 } catch (SQLException e) {
517 // TODO Auto-generated catch block
518 e.printStackTrace();
519 }
520 }
521 }
522
523
524 private void addSearchTextFieldListener() {
525 searchTextField.addTextChangeListener(new FieldEvents.TextChangeListener() {
526
527 private static final long serialVersionUID = -7376538870420619534L;
528
529 @Override
530 public void textChange(TextChangeEvent event) {
531 listener.setNameFilter(event.getText());
532 updateInViewLabel();
533 }
534
535 });
536
537 }
538
539 private void addClearSearchButtonListener() {
540 clearSearchButton.addClickListener(new Button.ClickListener() {
541
542 @Override
543 public void buttonClick(ClickEvent event) {
544 clearDynamicFilters();
545 updateInViewLabel();
546 }
547
548 });
549 }
550
551 private void clearDynamicFilters() {
552 listener.removeDynamicFilters();
553 searchTextField.setValue(FILTER_TAXA_INPUT);
554 for(Object itemId : filterTable.getItemIds()) {
555 filterTable.getItem(itemId).getItemProperty(PROPERTY_SELECTED_ID).setValue(false);
556 }
557 }
558
559
560
561
562 /* (non-Javadoc)
563 * @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
564 */
565 @Override
566 public void setListener(StatusComponentListener listener) {
567 this.listener = listener;
568 }
569
570
571 class TaxonTableCheckBoxGenerator implements Table.ColumnGenerator {
572
573
574 /**
575 * Generates the cell containing an open image when boolean is true
576 */
577 @Override
578 public Component generateCell(Table source, final Object itemId, Object columnId) {
579 if(source.getItem(itemId) != null) {
580 Property prop = source.getItem(itemId).getItemProperty(columnId);
581 if(prop == null) {
582 return null;
583 }
584 CheckBox cb = new CheckBox(null, prop);
585 ValueChangeListener pbListener = new ValueChangeListener() {
586 @Override
587 public void valueChange(ValueChangeEvent event) {
588 boolean value = (Boolean) event.getProperty().getValue();
589 listener.updatePublished(value, itemId);
590 }
591 };
592 cb.addValueChangeListener(pbListener);
593 cb.setData(itemId);
594 return cb;
595 } else {
596 return null;
597 }
598
599 }
600 }
601
602 class CheckBoxGenerator implements Table.ColumnGenerator {
603
604 private final ValueChangeListener vcListener;
605
606 public CheckBoxGenerator(ValueChangeListener vcListener) {
607 this.vcListener = vcListener;
608 }
609
610 /**
611 * Generates the cell containing an open image when boolean is true
612 */
613 @Override
614 public Component generateCell(Table source, final Object itemId, Object columnId) {
615 if(source.getItem(itemId) != null) {
616 Property prop = source.getItem(itemId).getItemProperty(columnId);
617 if(prop == null) {
618 return null;
619 }
620 CheckBox cb = new CheckBox(null, prop);
621 cb.addValueChangeListener(vcListener);
622 cb.setData(itemId);
623 return cb;
624 } else {
625 return null;
626 }
627 }
628 }
629
630
631 /* (non-Javadoc)
632 * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
633 */
634 @Override
635 public void onCreate(CdmChangeEvent event) {
636 if(event.getSourceType().equals(NewTaxonBaseComposite.class)) {
637 Object itemId = event.getChangedObjects().get(0);
638 try {
639 taxaTreeTable.setMultiSelect(false);
640 if(listener.getCurrentLeafNodeTaxonContainer().isSynonym(itemId)) {
641 taxaTreeTable.setCollapsed(taxaTreeTable.getValue(), false);
642 listener.refresh();
643 taxaTreeTable.setValue(itemId);
644 } else {
645 clearDynamicFilters();
646 listener.setIdFilter(itemId);
647 taxaTreeTable.setValue(itemId);
648 }
649 } finally {
650 taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
651 }
652 }
653 }
654
655 /* (non-Javadoc)
656 * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
657 */
658 @Override
659 public void onUpdate(CdmChangeEvent event) {
660 // TODO Auto-generated method stub
661
662 }
663
664 /* (non-Javadoc)
665 * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
666 */
667 @Override
668 public void onDelete(CdmChangeEvent event) {
669 // TODO Auto-generated method stub
670
671 }
672
673 /* (non-Javadoc)
674 * @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
675 */
676 @Override
677 public void enter(ViewChangeEvent event) {
678 // TODO Auto-generated method stub
679
680 }
681
682 @AutoGenerated
683 private GridLayout buildMainLayout() {
684 // common part: create layout
685 mainLayout = new GridLayout();
686 mainLayout.setImmediate(false);
687 mainLayout.setWidth("340px");
688 mainLayout.setHeight("840px");
689 mainLayout.setMargin(true);
690 mainLayout.setRows(6);
691
692 // top-level component properties
693 setWidth("340px");
694 setHeight("840px");
695
696 // classificationComboBox
697 classificationComboBox = new ComboBox();
698 classificationComboBox.setImmediate(false);
699 classificationComboBox.setWidth("100.0%");
700 classificationComboBox.setHeight("-1px");
701 mainLayout.addComponent(classificationComboBox, 0, 0);
702
703 // filterVerticalLayout
704 filterVerticalLayout = buildFilterVerticalLayout();
705 mainLayout.addComponent(filterVerticalLayout, 0, 1);
706 mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
707
708 // searchHorizontalLayout
709 searchHorizontalLayout = buildSearchHorizontalLayout();
710 mainLayout.addComponent(searchHorizontalLayout, 0, 3);
711 mainLayout.setComponentAlignment(searchHorizontalLayout, new Alignment(48));
712
713 // taxaTreeTable
714 taxaTreeTable = new TreeTable();
715 taxaTreeTable.setImmediate(false);
716 taxaTreeTable.setWidth("100.0%");
717 taxaTreeTable.setHeight("614px");
718 mainLayout.addComponent(taxaTreeTable, 0, 4);
719 mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
720
721 // inViewLabel
722 inViewLabel = new Label();
723 inViewLabel.setImmediate(false);
724 inViewLabel.setWidth("100.0%");
725 inViewLabel.setHeight("-1px");
726 inViewLabel.setValue("in view : ");
727 mainLayout.addComponent(inViewLabel, 0, 5);
728
729 return mainLayout;
730 }
731
732
733
734 @AutoGenerated
735 private VerticalLayout buildFilterVerticalLayout() {
736 // common part: create layout
737 filterVerticalLayout = new VerticalLayout();
738 filterVerticalLayout.setImmediate(false);
739 filterVerticalLayout.setWidth("100.0%");
740 filterVerticalLayout.setHeight("-1px");
741 filterVerticalLayout.setMargin(false);
742
743 // filterLabel
744 filterLabel = new Label();
745 filterLabel.setImmediate(false);
746 filterLabel.setWidth("100.0%");
747 filterLabel.setHeight("-1px");
748 filterLabel.setValue("Filter by :");
749 filterVerticalLayout.addComponent(filterLabel);
750
751 // filterTable
752 filterTable = new Table();
753 filterTable.setImmediate(false);
754 filterTable.setWidth("100.0%");
755 filterTable.setHeight("74px");
756 filterVerticalLayout.addComponent(filterTable);
757 filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
758
759 return filterVerticalLayout;
760 }
761
762
763
764 @AutoGenerated
765 private HorizontalLayout buildSearchHorizontalLayout() {
766 // common part: create layout
767 searchHorizontalLayout = new HorizontalLayout();
768 searchHorizontalLayout.setImmediate(false);
769 searchHorizontalLayout.setWidth("100.0%");
770 searchHorizontalLayout.setHeight("-1px");
771 searchHorizontalLayout.setMargin(false);
772 searchHorizontalLayout.setSpacing(true);
773
774 // searchTextField
775 searchTextField = new TextField();
776 searchTextField.setImmediate(false);
777 searchTextField.setWidth("100.0%");
778 searchTextField.setHeight("-1px");
779 searchHorizontalLayout.addComponent(searchTextField);
780 searchHorizontalLayout.setExpandRatio(searchTextField, 4.0f);
781 searchHorizontalLayout.setComponentAlignment(searchTextField, new Alignment(48));
782
783 // clearSearchButton
784 clearSearchButton = new Button();
785 clearSearchButton.setCaption("Button");
786 clearSearchButton.setImmediate(true);
787 clearSearchButton.setWidth("100.0%");
788 clearSearchButton.setHeight("-1px");
789 searchHorizontalLayout.addComponent(clearSearchButton);
790 searchHorizontalLayout.setExpandRatio(clearSearchButton, 1.0f);
791 searchHorizontalLayout.setComponentAlignment(clearSearchButton, new Alignment(48));
792
793 return searchHorizontalLayout;
794 }
795
796 }