Project

General

Profile

Revision 4f7ccb87

ID4f7ccb8756f21eed80db5ead22051239b2af89d4
Parent e37d3114
Child f9837f2a

Added by Patrick Plitzner about 5 years ago

ref #5458 Implement multi select for NamedArea selection

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/container/NamedAreaContainer.java
1
package eu.etaxonomy.cdm.vaadin.container;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5
import java.util.Set;
6

  
7
import com.vaadin.data.util.BeanItemContainer;
8

  
9
import eu.etaxonomy.cdm.model.common.TermVocabulary;
10
import eu.etaxonomy.cdm.model.location.NamedArea;
11

  
12
public class NamedAreaContainer extends BeanItemContainer<NamedArea> {
13

  
14
    private static final long serialVersionUID = 9150424479597481361L;
15

  
16
	public static final Map<String, NamedArea> titleToNamedAreaMap = new HashMap<>();
17

  
18
	public NamedAreaContainer(TermVocabulary<NamedArea> vocabulary)
19
	        throws IllegalArgumentException {
20
	    super(NamedArea.class);
21
	    Set<NamedArea> namedAreas = vocabulary.getTerms();
22
	    for (NamedArea namedArea: namedAreas) {
23
	        titleToNamedAreaMap.put(namedArea.getTitleCache(), namedArea);
24
	        addBean(namedArea);
25
	    }
26
	}
27

  
28
}
src/main/java/eu/etaxonomy/cdm/vaadin/model/LazyLoadedContainer.java
9 9
import eu.etaxonomy.cdm.model.common.CdmBase;
10 10
import eu.etaxonomy.cdm.model.taxon.Taxon;
11 11
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
12
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionTablePresenter;
12 13
import eu.etaxonomy.cdm.vaadin.view.dbstatus.IDistributionTableComponent;
13 14

  
14 15
public class LazyLoadedContainer extends BeanContainer implements Serializable, IDistributionTableComponent {
......
18 19

  
19 20
	DistributionTableComponentListener listener;
20 21

  
21
	
22

  
22 23
	public LazyLoadedContainer(Class type) throws IllegalArgumentException {
23 24
		super(type);
24 25
	}
25
//	
26
//
26 27
//	public LazyLoadedContainer(Class type, IClassificationService classificationService, ITaxonNodeService taxonNodeService, IDescriptionService descriptionService) throws IllegalArgumentException {
27 28
//		super(type);
28 29
//		this.classificationService = classificationService;
29 30
//		this.taxonNodeService = taxonNodeService;
30 31
//		this.descriptionService = descriptionService;
31
//		
32
//
32 33
//	}
33
	
34

  
34 35
	@Override
35 36
	public int size(){
36 37
		return listener.getSizeOfTaxonNode();
37 38
	}
38
	
39

  
39 40
	@Override
40 41
	public BeanItem getItem(Object itemId){
41 42
		TaxonNode taxonNode = ((TaxonNode) itemId);
42 43
		CdmBase.deproxy(taxonNode, TaxonNode.class);
43
		Taxon taxon = (Taxon)taxonNode.getTaxon();
44
		Taxon taxon = taxonNode.getTaxon();
44 45
		CdmBase.deproxy(taxon, Taxon.class);
45 46
		CdmTaxonTableCollection cttc = new CdmTaxonTableCollection(taxon);
46 47
		return new BeanItem(cttc);
47 48
	}
48
	
49

  
49 50
	@Override
50 51
	public List getItemIds(){
51 52
		List<TaxonNode> listAllNodesForClassification = listener.getAllNodes();
......
55 56

  
56 57

  
57 58
	@Override
58
	public void addListener(DistributionTableComponentListener listener) {
59
	public void addListener(DistributionTablePresenter listener) {
59 60
		this.listener = listener;
60 61
	}
61 62

  
62
	
63

  
63 64

  
64 65
}
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
20 20
import eu.etaxonomy.cdm.api.service.ITaxonService;
21 21
import eu.etaxonomy.cdm.api.service.ITermService;
22 22
import eu.etaxonomy.cdm.api.service.IVocabularyService;
23
import eu.etaxonomy.cdm.common.CdmUtils;
23 24
import eu.etaxonomy.cdm.model.common.CdmBase;
24 25
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
25 26
import eu.etaxonomy.cdm.model.common.Language;
......
147 148
//      Collections.sort(list);
148 149
        return list;
149 150
    }
150
    
151
    private List<String> getNamedAreas(){
151

  
152
    public List<String> getNamedAreas(){
152 153
    	String selectedAreas = (String) VaadinSession.getCurrent().getAttribute("selectedAreas");
154
    	if(CdmUtils.isBlank(selectedAreas)){
155
    	    return getTermList();
156
    	}
153 157
    	return Arrays.asList(selectedAreas.split(","));
154 158
    }
155 159

  
......
227 231
		for (TaxonNode taxonNode : getAllNodes()) {
228 232
			nodeIds.add(taxonNode.getId());
229 233
		}
230
		List<String> termList = getTermList();
231 234
		List<String> namesAreaUuids = getNamedAreas();
232
		CdmSQLContainer container = new CdmSQLContainer(CdmQueryFactory.generateTaxonDistributionQuery(termList, nodeIds, namesAreaUuids));
235
		CdmSQLContainer container = new CdmSQLContainer(CdmQueryFactory.generateTaxonDistributionQuery(nodeIds, namesAreaUuids));
233 236
		return container;
234 237
	}
235 238

  
src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmQueryFactory.java
59 59
        return generateQueryDelegate(SELECT_QUERY, COUNT_QUERY, CONTAINS_QUERY);
60 60
    }
61 61

  
62
    public static QueryDelegate generateTaxonDistributionQuery(List<String> termList, List<Integer> taxonNodeIds, List<String> namesAreaUuids) throws SQLException {
62
    public static QueryDelegate generateTaxonDistributionQuery(List<Integer> taxonNodeIds, List<String> namedAreas) throws SQLException {
63 63

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

  
96
        for(String term : termList){
97
        		SELECT_QUERY += "MAX( IF(area.titleCache = '"+ term +"', statusTerm.titleCache, NULL) ) as '"+ term +"'," ;
96
        for(String namedArea : namedAreas){
97
            SELECT_QUERY += "MAX( IF(area.titleCache = '"+ namedArea +"', statusTerm.titleCache, NULL) ) as '"+ namedArea +"'," ;
98 98
        }
99 99
        SELECT_QUERY = StringUtils.stripEnd(SELECT_QUERY, ",")+" ";
100 100
        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

  
5 7
import com.vaadin.server.VaadinSession;
6 8
import com.vaadin.ui.Notification;
7 9
import com.vaadin.ui.UI;
......
26 28
	    VaadinSession.getCurrent().setAttribute("selectedTerm", term.getUuid());
27 29
	    String selectedAreaUuids = "";
28 30
	    for (NamedArea namedArea : selectedAreas) {
29
			selectedAreaUuids += namedArea.getUuid().toString()+",";
31
			selectedAreaUuids += namedArea.getTitleCache()+",";
30 32
		}
33
	    selectedAreaUuids = StringUtils.stripEnd(selectedAreaUuids, ",");
31 34
	    VaadinSession.getCurrent().setAttribute("selectedAreas", selectedAreaUuids);
32
	
35

  
33 36
	    //navigate to table view
34 37
	    UI.getCurrent().getNavigator().navigateTo("table");
35 38
	}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSelectionView.java
27 27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
28 28
import eu.etaxonomy.cdm.model.location.NamedArea;
29 29
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
30
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
30 31
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
31 32

  
32 33
public class DistributionSelectionView extends CustomComponent implements IDistributionSelectionComponent, View, ClickListener{
......
98 99
			}
99 100
		});
100 101
        taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
101
        
102

  
102 103
        distributionAreaBox.addValueChangeListener(new ValueChangeListener() {
103
			
104

  
104 105
			@Override
105 106
			public void valueChange(ValueChangeEvent event) {
106
				TermVocabulary<NamedArea> voc = (TermVocabulary<NamedArea>) event.getProperty().getValue();
107
				IndexedContainer indexedContainer = new IndexedContainer(voc.getTerms());
108
				namedAreaList.setContainerDataSource(indexedContainer);
107
				TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
108
				NamedAreaContainer container = new NamedAreaContainer(vocabulary);
109
				namedAreaList.setContainerDataSource(container);
109 110
			}
110 111
		});
111
        
112

  
112 113
		List<TermVocabulary<DefinedTermBase>> namedAreaList = distListener.getNamedAreaList();
113 114
		Container d = new IndexedContainer(namedAreaList);
114 115
		distributionAreaBox.setContainerDataSource(d);
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
35 35
import eu.etaxonomy.cdm.vaadin.component.HorizontalToolbar;
36 36
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
37 37
import eu.etaxonomy.cdm.vaadin.container.PresenceAbsenceTermContainer;
38
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionTablePresenter;
38 39
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
39 40

  
40 41
public class DistributionTableView extends CustomComponent implements IDistributionTableComponent, View{
......
72 73
    private HorizontalToolbar toolbar;
73 74
	private Table table;
74 75

  
75
	private DistributionTableComponentListener listener;
76
	private DistributionTablePresenter listener;
76 77

  
77 78
	private List<String> columnList;
78 79
	private ArrayList<String> headerList;
......
96 97
		mainLayout.setImmediate(false);
97 98
		mainLayout.setWidth("100%");
98 99
		mainLayout.setHeight("100%");
99
		
100

  
100 101
		setWidth("100.0%");
101 102
		setHeight("100.0%");
102 103

  
103 104
		//Horizontal Toolbar
104 105
		toolbar = new HorizontalToolbar();
105 106
		mainLayout.addComponent(toolbar, "top:0.0px;right:0.0px;");
106
		
107

  
107 108
		// table
108 109
		table = new Table();
109 110
		table.setImmediate(false);
......
114 115
	}
115 116

  
116 117
	@Override
117
	public void addListener(DistributionTableComponentListener listener) {
118
	public void addListener(DistributionTablePresenter listener) {
118 119
	   this.listener = listener;
119 120
	}
120 121

  
......
134 135
		table.setSortEnabled(true);
135 136

  
136 137
		columnList = new ArrayList<String>(Arrays.asList(new String[]{CdmQueryFactory.TAXON_COLUMN,CdmQueryFactory.RANK_COLUMN}));
137
		List<String> termList = listener.getTermList();
138
		List<String> termList = listener.getNamedAreas();
138 139
		columnList.addAll(termList);
139 140
		Object[] visibleColumns = columnList.toArray();
140 141
		table.setVisibleColumns(visibleColumns);
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/IDistributionTableComponent.java
19 19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
20 20
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
21 21
import eu.etaxonomy.cdm.vaadin.model.LazyLoadedContainer;
22
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionTablePresenter;
22 23

  
23 24
public interface IDistributionTableComponent {
24 25

  
......
70 71
        int updateDistributionField(String distributionArea, Object comboValue, Taxon taxon);
71 72

  
72 73
	}
73
	public void addListener(DistributionTableComponentListener listener);
74
	public void addListener(DistributionTablePresenter listener);
74 75
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)