530711ca41b8660c53149aaae8493f180a99d1b3
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / util / DistributionEditorUtil.java
1 package eu.etaxonomy.cdm.vaadin.util;
2
3 import java.sql.SQLException;
4 import java.util.List;
5 import java.util.UUID;
6
7 import com.vaadin.server.VaadinSession;
8 import com.vaadin.ui.Notification;
9 import com.vaadin.ui.Notification.Type;
10
11 import eu.etaxonomy.cdm.model.common.TermVocabulary;
12 import eu.etaxonomy.cdm.model.location.NamedArea;
13 import eu.etaxonomy.cdm.model.taxon.Classification;
14 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
15 import eu.etaxonomy.cdm.vaadin.view.distributionStatus.IDistributionTableView;
16
17 /**
18 * A utility class for the distribution status editor.
19 *
20 */
21 public class DistributionEditorUtil {
22
23 public static final String VIEW_TABLE = "table";
24
25 public static final String SATTR_SELECTED_AREAS = "selectedAreas";
26
27 public static final String SATTR_SELECTED_AREA_VOCABULARY_UUID = "selectedVocabularyUuid";
28
29 public static final String SATTR_TAXON_NODES_UUID = "taxonNodesUUID";
30
31 public static final String SATTR_CLASSIFICATION = "classificationUUID";
32
33 public static final String SATTR_ABBREVIATED_LABELS = "abbreviatedLabels";
34
35 public static final String SATTR_DISTRIBUTION_STATUS = "distributionStatus";
36
37 public static final String SEPARATOR = ";;";
38
39 public static final boolean INCLUDE_UNPUBLISHED = true;
40
41 /**
42 * Updates the vaadin session attributes related to the chosen
43 * {@link TaxonNode}s, {@link NamedArea}s and {@link Classification}
44 * and refreshes the given {@code distributionStatusTableView}.
45 * @param distributionTableView The view to refresh after updating the session variables.
46 * @param taxonNodes The taxa to be shown in the {@code distributionTableView}.
47 * @param areaVoc The {@link TermVocabulary} of {@link NamedArea}s to be used.
48 * @param selectedAreas The {@link NamedArea}s to be availbale in the {@code distributionTableView}.
49 * @param classificationUuid The {@link UUID} of the {@link Classification} the {@code taxonNodes} belong to.
50 */
51 public static void updateDistributionView(IDistributionTableView distributionTableView, List<UUID> taxonNodes, TermVocabulary<NamedArea> areaVoc,
52 List<NamedArea> selectedAreas, UUID classificationUuid) {
53 VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, taxonNodes);
54 VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREA_VOCABULARY_UUID, areaVoc.getUuid());
55 VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, selectedAreas);
56 VaadinSession.getCurrent().setAttribute(SATTR_CLASSIFICATION, classificationUuid);
57 distributionTableView.update();
58 }
59
60 /**
61 * Clears the session attributes related to the chosen
62 * {@link TaxonNode}s, {@link TermVocabulary} of {@link NamedArea}s,
63 * {@link NamedArea}s and {@link Classification}.
64 */
65 public static void clearSessionAttributes(){
66 VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, null);
67 VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREA_VOCABULARY_UUID, null);
68 VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, null);
69 VaadinSession.getCurrent().setAttribute(SATTR_CLASSIFICATION, null);
70 }
71
72 /**
73 * Returns {@code true} if abbreviated labels should be used.
74 * @return {@code true} if abbreviated labels should be used.
75 */
76 public static boolean isAbbreviatedLabels(){
77 Object isAbbreviated = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS);
78 return (isAbbreviated==null || (boolean) isAbbreviated);
79 }
80
81 /**
82 * Shows an {@link SQLException} to the user.
83 * @param e The exception to show.
84 */
85 public static void showSqlError(SQLException e) {
86 Notification.show("Error while accessing data base.","Cause: "+e.getMessage(), Type.ERROR_MESSAGE);
87 e.printStackTrace();
88 }
89
90 public static final String SATTR_CONVERSATION = "conversation";
91
92
93 }