Project

General

Profile

Download (3.73 KB) Statistics
| Branch: | Tag: | Revision:
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
    /**
40
     * Updates the vaadin session attributes related to the chosen 
41
     * {@link TaxonNode}s, {@link NamedArea}s and {@link Classification}
42
     * and refreshes the given {@code distributionStatusTableView}.
43
     * @param distributionTableView The view to refresh after updating the session variables.
44
     * @param taxonNodes The taxa to be shown in the {@code distributionTableView}.
45
     * @param areaVoc The {@link TermVocabulary} of {@link NamedArea}s to be used.
46
     * @param selectedAreas The {@link NamedArea}s to be availbale in the {@code distributionTableView}.
47
     * @param classificationUuid The {@link UUID} of the {@link Classification} the {@code taxonNodes} belong to.
48
     */
49
    public static void updateDistributionView(IDistributionTableView distributionTableView, List<UUID> taxonNodes, TermVocabulary<NamedArea> areaVoc,
50
            List<NamedArea> selectedAreas, UUID classificationUuid) {
51
	    VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, taxonNodes);
52
	    VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREA_VOCABULARY_UUID, areaVoc.getUuid());
53
	    VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, selectedAreas);
54
	    VaadinSession.getCurrent().setAttribute(SATTR_CLASSIFICATION, classificationUuid);
55
	    distributionTableView.update();
56
	}
57

    
58
    /**
59
     * Clears the session attributes related to the chosen 
60
     * {@link TaxonNode}s, {@link TermVocabulary} of {@link NamedArea}s,
61
     * {@link NamedArea}s and {@link Classification}.
62
     */
63
    public static void clearSessionAttributes(){
64
    	VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, null);
65
    	VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREA_VOCABULARY_UUID, null);
66
    	VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, null);
67
    	VaadinSession.getCurrent().setAttribute(SATTR_CLASSIFICATION, null);
68
    }
69

    
70
    /**
71
     * Returns {@code true} if abbreviated labels should be used.
72
     * @return {@code true} if abbreviated labels should be used.
73
     */
74
    public static boolean isAbbreviatedLabels(){
75
    	Object isAbbreviated = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS);
76
		return (isAbbreviated==null || (boolean) isAbbreviated);
77
    }
78

    
79
    /**
80
     * Shows an {@link SQLException} to the user.
81
     * @param e The exception to show.
82
     */
83
	public static void showSqlError(SQLException e) {
84
		Notification.show("Error while accessing data base.","Cause: "+e.getMessage(), Type.ERROR_MESSAGE);
85
		e.printStackTrace();
86
	}
87

    
88
	public static final String SATTR_CONVERSATION = "conversation";
89

    
90

    
91
}
(9-9/15)