Project

General

Profile

Revision 5f031b4f

ID5f031b4f0cbbc4f06a7604b258f72338abf291bf
Parent 785fc5d7
Child 558d5bd1

Added by Patrick Plitzner about 5 years ago

ref #5458 Error handling for abbreviated labels

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java
2 2

  
3 3
import java.util.List;
4 4

  
5
import com.vaadin.data.util.BeanContainer;
5
import com.vaadin.data.util.BeanItemContainer;
6 6

  
7
import eu.etaxonomy.cdm.model.common.Language;
8 7
import eu.etaxonomy.cdm.model.common.TermType;
9 8
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
10 9
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
11 10
import eu.etaxonomy.cdm.vaadin.util.TermCacher;
12 11

  
13
public class PresenceAbsenceTermContainer extends BeanContainer<String, PresenceAbsenceTerm> {
12
public class PresenceAbsenceTermContainer extends BeanItemContainer<PresenceAbsenceTerm> {
14 13

  
15 14
	private static final long serialVersionUID = -7891310979870159325L;
16 15

  
......
19 18
	private PresenceAbsenceTermContainer()
20 19
			throws IllegalArgumentException {
21 20
		super(PresenceAbsenceTerm.class);
22
		setBeanIdResolver(new BeanIdResolver<String, PresenceAbsenceTerm>() {
23

  
24
            private static final long serialVersionUID = -6008191522128487319L;
25

  
26
            @Override
27
            public String getIdForBean(PresenceAbsenceTerm bean) {
28
                return bean.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel();
29
            }
30
        });
31 21
		List<PresenceAbsenceTerm> terms = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
32 22
		TermCacher termCacher = TermCacher.getInstance();
33 23
		for (PresenceAbsenceTerm presenceAbsenceTerm : terms) {
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
63 63
	    Set<DefinedTermBase> chosenTerms = getChosenTerms();
64 64
	    NamedArea namedArea = null;
65 65
	    for(DefinedTermBase term:chosenTerms){
66
	        if(term.getTitleCache().equalsIgnoreCase(distributionAreaString)){
66
	        if(term.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel().equalsIgnoreCase(distributionAreaString)){
67 67
	            namedArea = (NamedArea) term;
68 68
	            break;
69 69
	        }
70
	        if(term.getTitleCache().equalsIgnoreCase(distributionAreaString)){
71
	        	namedArea = (NamedArea) term;
72
	        	break;
73
	        }
70 74
	    }
71 75
	    List<Distribution> distributions = getDistributions(taxon);
72 76
	    Distribution distribution = null;
73 77
	    for(Distribution dist : distributions){
74
	        if(dist.getArea().equals(namedArea)){
78
	        if(dist.getArea()!=null && dist.getArea().equals(namedArea)){
75 79
	            distribution = dist;
76 80
	            break;
77 81
	        }
......
139 143
        Set<NamedArea> selectedAreas = getNamedAreas();
140 144
    	List<String> namedAreaTitles = new ArrayList<>();
141 145
    	for (NamedArea namedArea : selectedAreas) {
142
    	    if(abbreviated){
143
    	        namedAreaTitles.add(namedArea.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel());
146
    		String title = null;
147
    	    Representation representation = namedArea.getRepresentation(Language.DEFAULT());
148
    	    if(representation!=null){
149
    	    	if(abbreviated){
150
    	    		title = representation.getAbbreviatedLabel();
151
    	    	}
152
    	    	else{
153
    	    		title = representation.getLabel();
154
    	    	}
144 155
    	    }
145
    	    else{
146
    	        namedAreaTitles.add(namedArea.getRepresentation(Language.DEFAULT()).getLabel());
156
    	    if(title==null){
157
    	    	title = namedArea.getTitleCache();
147 158
    	    }
159
    	    namedAreaTitles.add(title);
148 160
        }
149 161
    	return namedAreaTitles;
150 162
    }
src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmQueryFactory.java
22 22
import com.vaadin.data.util.sqlcontainer.query.QueryDelegate;
23 23

  
24 24
import eu.etaxonomy.cdm.model.common.Language;
25
import eu.etaxonomy.cdm.model.common.Representation;
25 26
import eu.etaxonomy.cdm.model.location.NamedArea;
26 27
import eu.etaxonomy.cdm.vaadin.statement.CdmStatementDelegate;
27 28

  
......
97 98
        		"rank.titleCache AS "+RANK_COLUMN+", ";
98 99

  
99 100
        for(NamedArea namedArea : namedAreas){
100
            String label;
101
            if(abbreviatedLabels){
102
                label = namedArea.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel();
101
            String label = null;
102
            Representation representation = namedArea.getRepresentation(Language.DEFAULT());
103
            if(representation!=null){
104
            	if(abbreviatedLabels){
105
            		label = representation.getAbbreviatedLabel();
106
            	}
107
            	else{
108
            		label = representation.getLabel();
109
            	}
103 110
            }
104
            else{
105
                label = namedArea.getTitleCache();
111
            if(label==null){
112
            	label = namedArea.getTitleCache();
106 113
            }
107
            SELECT_QUERY += "MAX( IF(area.titleCache = '"+ label +"', statusTerm.titleCache, NULL) ) as '"+ label +"'," ;
114
            SELECT_QUERY += "MAX( IF(area.titleCache = '"+ namedArea.getTitleCache() +"', statusTerm.titleCache, NULL) ) as '"+ label +"'," ;
108 115
        }
109 116
        SELECT_QUERY = StringUtils.stripEnd(SELECT_QUERY, ",")+" ";
110 117
        SELECT_QUERY= SELECT_QUERY + FROM_QUERY + GROUP_BY + ORDER_BY;
src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
14 14

  
15 15
    public static final String SEPARATOR = ";;";
16 16

  
17
    public static final String SESSION_ABBREVIATED_LABELS = "abbreviatedLabels";
18

  
17 19
    public static void openDistributionView(TaxonNode taxonNode, TermVocabulary<NamedArea> term, Set<NamedArea> selectedAreas) {
18 20
		if(taxonNode==null){
19 21
			Notification.show("Please choose a classification and/or taxon", Notification.Type.HUMANIZED_MESSAGE);
......
25 27
		}
26 28
	    VaadinSession.getCurrent().setAttribute("taxonNodeUUID", taxonNode.getUuid());
27 29
	    VaadinSession.getCurrent().setAttribute("selectedTerm", term.getUuid());
28
//	    String selectedAreaUuids = "";
29
//	    for (NamedArea namedArea : selectedAreas) {
30
//			selectedAreaUuids += namedArea.getTitleCache()+SEPARATOR;
31
//		}
32
//	    selectedAreaUuids = StringUtils.stripEnd(selectedAreaUuids, SEPARATOR);
33 30
	    VaadinSession.getCurrent().setAttribute("selectedAreas", selectedAreas);
34 31

  
35 32
	    //navigate to table view
36 33
	    UI.getCurrent().getNavigator().navigateTo("table");
37 34
	}
38 35

  
36

  
39 37
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
29 29

  
30 30
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
31 31
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
32
import eu.etaxonomy.cdm.model.common.Language;
33
import eu.etaxonomy.cdm.model.common.Representation;
32 34
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
35
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
33 36
import eu.etaxonomy.cdm.model.taxon.Taxon;
34 37
import eu.etaxonomy.cdm.vaadin.component.DetailWindow;
35 38
import eu.etaxonomy.cdm.vaadin.component.HorizontalToolbar;
......
37 40
import eu.etaxonomy.cdm.vaadin.container.PresenceAbsenceTermContainer;
38 41
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionTablePresenter;
39 42
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
43
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
40 44
import eu.etaxonomy.cdm.vaadin.util.TermCacher;
41 45

  
42 46
public class DistributionTableView extends CustomComponent implements View{
......
207 211
            box.setImmediate(true);
208 212
            box.setBuffered(true);
209 213
            box.setSizeFull();
210
            box.setValue(TermCacher.getInstance().getPresenceAbsenceTerm((String)value));
214
            PresenceAbsenceTerm presenceAbsenceTerm = TermCacher.getInstance().getPresenceAbsenceTerm((String)value);
215
			box.setValue(presenceAbsenceTerm);
216
			if(presenceAbsenceTerm!=null){
217
				String itemCaption = null;
218
				Representation representation = presenceAbsenceTerm.getRepresentation(Language.DEFAULT());
219
				if(representation!=null){
220
					if((Boolean)VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SESSION_ABBREVIATED_LABELS)){
221
						itemCaption = representation.getAbbreviatedLabel();
222
					}
223
					else{
224
						itemCaption = representation.getLabel();
225
					}
226
				}
227
				if(itemCaption==null){
228
					itemCaption = presenceAbsenceTerm.getTitleCache();
229
				}
230
				box.setItemCaption(presenceAbsenceTerm, itemCaption);
231
			}
211 232
            box.addValueChangeListener(new ValueChangeListener() {
212 233
                private static final long serialVersionUID = 6221534597911674067L;
213 234

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)