Project

General

Profile

« Previous | Next » 

Revision 785fc5d7

Added by Patrick Plitzner over 7 years ago

ref #5458 Add abbreviated labels to distribution table

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionSelectionPresenter.java
32 32
		view.dataBinding();
33 33
	}
34 34

  
35
	public void buttonClick(TaxonNode taxonNode, TermVocabulary<DefinedTermBase> term, Set<NamedArea> selectedAreas) {
35
	public void buttonClick(TaxonNode taxonNode, TermVocabulary<NamedArea> term, Set<NamedArea> selectedAreas) {
36 36
		DistributionTableView dtv = new DistributionTableView();
37 37
		new DistributionTablePresenter(dtv);
38 38
		UI.getCurrent().getNavigator().addView("table", dtv);
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
9 9
import java.util.HashSet;
10 10
import java.util.List;
11 11
import java.util.Set;
12
import java.util.SortedSet;
13 12
import java.util.UUID;
14 13

  
15 14
import com.vaadin.server.VaadinSession;
......
20 19
import eu.etaxonomy.cdm.api.service.ITaxonService;
21 20
import eu.etaxonomy.cdm.api.service.ITermService;
22 21
import eu.etaxonomy.cdm.api.service.IVocabularyService;
23
import eu.etaxonomy.cdm.common.CdmUtils;
24 22
import eu.etaxonomy.cdm.model.common.CdmBase;
25 23
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
26 24
import eu.etaxonomy.cdm.model.common.Language;
......
42 40

  
43 41
public class DistributionTablePresenter {
44 42

  
45
	private final IClassificationService classificationService;
43
    private final IClassificationService classificationService;
46 44
	private final IVocabularyService vocabularyService;
47 45
	private final IDescriptionService descriptionService;
48 46
	private final ITaxonNodeService taxonNodeService;
......
119 117
	}
120 118

  
121 119
	public List<String> getAbbreviatedTermList() {
122
		SortedSet<DefinedTermBase> terms = getTermSet();
120
		Set<NamedArea> terms = getTermSet();
123 121
		List<String> list = new ArrayList<String>();
124 122
		for(DefinedTermBase dtb: terms){
125 123
		    for(Representation r : dtb.getRepresentations()){
......
129 127
		return list;
130 128
	}
131 129

  
132
    public List<String> getNamedAreas(){
133
    	String selectedAreas = (String) VaadinSession.getCurrent().getAttribute("selectedAreas");
134
    	if(CdmUtils.isBlank(selectedAreas)){
135
    	    SortedSet<DefinedTermBase> terms = getTermSet();
136
            List<String> list = new ArrayList<String>();
137
            for(DefinedTermBase dtb: terms){
138
               list.add(dtb.getTitleCache());
139
            }
140
    	    return list;
141
    	}
142
    	return Arrays.asList(selectedAreas.split(","));
130
	public Set<NamedArea> getNamedAreas(){
131
	    Set<NamedArea> namedAreas = (Set<NamedArea>) VaadinSession.getCurrent().getAttribute("selectedAreas");
132
	    if(namedAreas.isEmpty()){
133
	        return getTermSet();
134
	    }
135
        return namedAreas;
136
	}
137

  
138
    public List<String> getNamedAreasLabels(boolean abbreviated){
139
        Set<NamedArea> selectedAreas = getNamedAreas();
140
    	List<String> namedAreaTitles = new ArrayList<>();
141
    	for (NamedArea namedArea : selectedAreas) {
142
    	    if(abbreviated){
143
    	        namedAreaTitles.add(namedArea.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel());
144
    	    }
145
    	    else{
146
    	        namedAreaTitles.add(namedArea.getRepresentation(Language.DEFAULT()).getLabel());
147
    	    }
148
        }
149
    	return namedAreaTitles;
143 150
    }
144 151

  
145
	private SortedSet<DefinedTermBase> getTermSet(){
152
	private Set<NamedArea> getTermSet(){
146 153
	    VaadinSession session = VaadinSession.getCurrent();
147 154
	    UUID termUUID = (UUID) session.getAttribute("selectedTerm");
148
	    TermVocabulary<DefinedTermBase> term = vocabularyService.load(termUUID);
149
	    term = CdmBase.deproxy(term, TermVocabulary.class);
150
	    return term.getTermsOrderedByLabels(Language.DEFAULT());
155
	    TermVocabulary<NamedArea> vocabulary = vocabularyService.load(termUUID);
156
	    vocabulary = CdmBase.deproxy(vocabulary, TermVocabulary.class);
157
	    return vocabulary.getTermsOrderedByLabels(Language.DEFAULT());
151 158
	}
152 159

  
153 160
	public HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon) {
......
209 216
		for (TaxonNode taxonNode : getAllNodes()) {
210 217
			nodeIds.add(taxonNode.getId());
211 218
		}
212
		List<String> namesAreaUuids = getNamedAreas();
213
		CdmSQLContainer container = new CdmSQLContainer(CdmQueryFactory.generateTaxonDistributionQuery(nodeIds, namesAreaUuids));
219
		Set<NamedArea> namesAreas = getNamedAreas();
220
		CdmSQLContainer container = new CdmSQLContainer(CdmQueryFactory.generateTaxonDistributionQuery(nodeIds, namesAreas, true));
214 221
		return container;
215 222
	}
216 223

  
src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmQueryFactory.java
10 10
package eu.etaxonomy.cdm.vaadin.util;
11 11

  
12 12
import java.sql.SQLException;
13
import java.util.Collection;
13 14
import java.util.Iterator;
14 15
import java.util.List;
15 16
import java.util.regex.Matcher;
......
20 21
import com.vaadin.data.util.sqlcontainer.query.FreeformQuery;
21 22
import com.vaadin.data.util.sqlcontainer.query.QueryDelegate;
22 23

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

  
25 28
/**
......
59 62
        return generateQueryDelegate(SELECT_QUERY, COUNT_QUERY, CONTAINS_QUERY);
60 63
    }
61 64

  
62
    public static QueryDelegate generateTaxonDistributionQuery(List<Integer> taxonNodeIds, List<String> namedAreas) throws SQLException {
65
    public static QueryDelegate generateTaxonDistributionQuery(List<Integer> taxonNodeIds, Collection<NamedArea> namedAreas, boolean abbreviatedLabels) throws SQLException {
63 66

  
64 67
    	String idString = "";
65 68
    	Iterator<Integer> nodeIterator = taxonNodeIds.iterator();
......
93 96
        		"tb.titleCache AS "+TAXON_COLUMN+", " +
94 97
        		"rank.titleCache AS "+RANK_COLUMN+", ";
95 98

  
96
        for(String namedArea : namedAreas){
97
            SELECT_QUERY += "MAX( IF(area.titleCache = '"+ namedArea +"', statusTerm.titleCache, NULL) ) as '"+ namedArea +"'," ;
99
        for(NamedArea namedArea : namedAreas){
100
            String label;
101
            if(abbreviatedLabels){
102
                label = namedArea.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel();
103
            }
104
            else{
105
                label = namedArea.getTitleCache();
106
            }
107
            SELECT_QUERY += "MAX( IF(area.titleCache = '"+ label +"', statusTerm.titleCache, NULL) ) as '"+ label +"'," ;
98 108
        }
99 109
        SELECT_QUERY = StringUtils.stripEnd(SELECT_QUERY, ",")+" ";
100 110
        SELECT_QUERY= SELECT_QUERY + FROM_QUERY + GROUP_BY + ORDER_BY;
src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
2 2

  
3 3
import java.util.Set;
4 4

  
5
import org.apache.commons.lang.StringUtils;
6

  
7 5
import com.vaadin.server.VaadinSession;
8 6
import com.vaadin.ui.Notification;
9 7
import com.vaadin.ui.UI;
10 8

  
11
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
12 9
import eu.etaxonomy.cdm.model.common.TermVocabulary;
13 10
import eu.etaxonomy.cdm.model.location.NamedArea;
14 11
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
15 12

  
16 13
public class DistributionEditorUtil {
17 14

  
18
	public static void openDistributionView(TaxonNode taxonNode, TermVocabulary<DefinedTermBase> term, Set<NamedArea> selectedAreas) {
15
    public static final String SEPARATOR = ";;";
16

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

  
36 35
	    //navigate to table view
37 36
	    UI.getCurrent().getNavigator().navigateTo("table");
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSelectionView.java
71 71
		if(taxonNode==null){
72 72
			taxonNode = (TaxonNode) classificationBox.getValue();
73 73
		}
74
		TermVocabulary<DefinedTermBase> term = (TermVocabulary<DefinedTermBase>)distributionAreaBox.getValue();
74
		TermVocabulary<NamedArea> term = (TermVocabulary<NamedArea>)distributionAreaBox.getValue();
75 75
		Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
76 76
		distListener.buttonClick(taxonNode, term, selectedAreas);
77 77
	}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
106 106
		table.setSortEnabled(true);
107 107

  
108 108
		columnList = new ArrayList<String>(Arrays.asList(new String[]{CdmQueryFactory.TAXON_COLUMN,CdmQueryFactory.RANK_COLUMN}));
109
		List<String> termList = listener.getNamedAreas();
110
		columnList.addAll(termList);
111
		Object[] visibleColumns = columnList.toArray();
112
		table.setVisibleColumns(visibleColumns);
109
		List<String> namedAreas = listener.getNamedAreasLabels(true);
110
		columnList.addAll(namedAreas);
111
		table.setVisibleColumns(columnList.toArray());
113 112

  
114 113
		headerList = new ArrayList<String>(Arrays.asList(new String[]{CdmQueryFactory.TAXON_COLUMN,"Rang"}));
115
		headerList.addAll(listener.getAbbreviatedTermList());
114
		headerList.addAll(listener.getNamedAreasLabels(true));
115
		String[] string = new String[headerList.size()];
116
		table.setColumnHeaders(headerList.toArray(string));
116 117

  
118
//		table.setColumnExpandRatio(propertyId, expandRatio);
117 119
		table.setColumnCollapsingAllowed(true);
118 120
		table.setSelectable(true);
119 121
		table.setPageLength(20);
......
125 127
		//add generated columns for NamedAreas
126 128
		Collection<?> containerPropertyIds = table.getContainerPropertyIds();
127 129
		for (Object object : containerPropertyIds) {
128
			if(termList.contains(object)){
130
			if(namedAreas.contains(object)){
129 131
				table.removeGeneratedColumn(object);
130 132
				table.addGeneratedColumn(object, new AreaColumnGenerator());
131 133
			}
......
204 206
            final String area = columnId.toString();
205 207
            box.setImmediate(true);
206 208
            box.setBuffered(true);
209
            box.setSizeFull();
207 210
            box.setValue(TermCacher.getInstance().getPresenceAbsenceTerm((String)value));
208 211
            box.addValueChangeListener(new ValueChangeListener() {
209 212
                private static final long serialVersionUID = 6221534597911674067L;
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
27 27
import com.vaadin.ui.VerticalLayout;
28 28
import com.vaadin.ui.Window;
29 29

  
30
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
31 30
import eu.etaxonomy.cdm.model.common.TermVocabulary;
32 31
import eu.etaxonomy.cdm.model.location.NamedArea;
33 32
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
......
52 51
    private Button cancelButton;
53 52
    private final SettingsPresenter presenter;
54 53
	private Window window;
55
    
54

  
56 55
    /**
57 56
     * The constructor should first build the main layout, set the
58 57
     * composition root and then do any custom initialization.
......
86 85
        distAreaBox.setContainerDataSource(distributionContainer);
87 86
        distAreaBox.setValue(chosenArea);
88 87
        distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
89
        
88

  
90 89
        okButton.addClickListener(new ClickListener() {
91
			
90

  
92 91
			@Override
93 92
			public void buttonClick(ClickEvent event) {
94 93
				TaxonNode taxonNode;
95
				TermVocabulary<DefinedTermBase> term = null;
94
				TermVocabulary<NamedArea> term = null;
96 95
				taxonNode = (TaxonNode) taxonTree.getValue();
97 96
				if(taxonNode==null){
98 97
					taxonNode = (TaxonNode) classificationBox.getValue();
99 98
				}
100
				term = (TermVocabulary<DefinedTermBase>) distAreaBox.getValue();
99
				term = (TermVocabulary<NamedArea>) distAreaBox.getValue();
101 100
				DistributionEditorUtil.openDistributionView(taxonNode, term, new HashSet<NamedArea>());
102 101
				window.close();
103 102
			}
104 103
		});
105 104
        cancelButton.addClickListener(new ClickListener() {
106
			
105

  
107 106
			@Override
108 107
			public void buttonClick(ClickEvent event) {
109 108
				window.close();
......
128 127
        mainLayout.setSizeFull();
129 128
        mainLayout.setMargin(true);
130 129
        mainLayout.setSpacing(true);
131
        
130

  
132 131
        HorizontalLayout topContainer = new HorizontalLayout();
133 132
        topContainer.setImmediate(false);
134 133
        topContainer.setSizeFull();
......
136 135

  
137 136
        VerticalLayout verticalLayout = new VerticalLayout();
138 137
        verticalLayout.setImmediate(false);
139
        
138

  
140 139
        //classification and term
141 140
        classificationBox = new ComboBox("Classification");
142 141
        classificationBox.setImmediate(true);
......
145 144
        distAreaBox = new ComboBox("Distribution Area:");
146 145
        distAreaBox.setImmediate(false);
147 146
        distAreaBox.setWidth("100%");
148
        
147

  
149 148
        //distribution status
150 149
        distStatusSelect = new TwinColSelect("Distribution Status:");
151 150
        distStatusSelect.setImmediate(false);
......
154 153
        //taxonomy
155 154
        taxonTree = new Tree("Taxonomy");
156 155
        taxonTree.setImmediate(false);
157
        
156

  
158 157
        verticalLayout.addComponent(classificationBox);
159 158
        verticalLayout.addComponent(distAreaBox);
160 159
        verticalLayout.addComponent(distStatusSelect);
161 160
        verticalLayout.setExpandRatio(distStatusSelect, 1);
162 161
        verticalLayout.setSizeFull();
163
        
162

  
164 163
        topContainer.addComponent(verticalLayout);
165 164
        topContainer.addComponent(taxonTree);
166 165
        topContainer.setExpandRatio(taxonTree, 1);

Also available in: Unified diff