1 package eu
.etaxonomy
.cdm
.vaadin
.util
;
3 import java
.sql
.SQLException
;
7 import com
.vaadin
.server
.VaadinSession
;
8 import com
.vaadin
.ui
.Notification
;
9 import com
.vaadin
.ui
.Notification
.Type
;
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
;
18 * A utility class for the distribution status editor.
21 public class DistributionEditorUtil
{
23 public static final String VIEW_TABLE
= "table";
25 public static final String SATTR_SELECTED_AREAS
= "selectedAreas";
27 public static final String SATTR_SELECTED_AREA_VOCABULARY_UUID
= "selectedVocabularyUuid";
29 public static final String SATTR_TAXON_NODES_UUID
= "taxonNodesUUID";
31 public static final String SATTR_CLASSIFICATION
= "classificationUUID";
33 public static final String SATTR_ABBREVIATED_LABELS
= "abbreviatedLabels";
35 public static final String SATTR_DISTRIBUTION_STATUS
= "distributionStatus";
37 public static final String SEPARATOR
= ";;";
39 public static final boolean INCLUDE_UNPUBLISHED
= true;
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.
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();
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}.
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);
73 * Returns {@code true} if abbreviated labels should be used.
74 * @return {@code true} if abbreviated labels should be used.
76 public static boolean isAbbreviatedLabels(){
77 Object isAbbreviated
= VaadinSession
.getCurrent().getAttribute(DistributionEditorUtil
.SATTR_ABBREVIATED_LABELS
);
78 return (isAbbreviated
==null || (boolean) isAbbreviated
);
82 * Shows an {@link SQLException} to the user.
83 * @param e The exception to show.
85 public static void showSqlError(SQLException e
) {
86 Notification
.show("Error while accessing data base.","Cause: "+e
.getMessage(), Type
.ERROR_MESSAGE
);
90 public static final String SATTR_CONVERSATION
= "conversation";