Project

General

Profile

Revision 1b9d7954

ID1b9d79547daa36bbe5c4ec048e4cf6e838555cf8
Parent 6689ac7b
Child e6af66a6

Added by Alexander Oppermann almost 6 years ago

Implementing UserContainer

View differences:

.gitattributes
4 4
src/main/java/eu/etaxonomy/cdm/vaadin/AppWidgetSet.gwt.xml -text
5 5
src/main/java/eu/etaxonomy/cdm/vaadin/CdmAppInitializer.java.bkp -text
6 6
src/main/java/eu/etaxonomy/cdm/vaadin/container/CdmSQLContainer.java -text
7
src/main/java/eu/etaxonomy/cdm/vaadin/model/User.java -text
8
src/main/java/eu/etaxonomy/cdm/vaadin/model/Users.java -text
7 9
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/AuthenticationPresenter.java -text
8 10
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionSelectionPresenter.java -text
9 11
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java -text
src/main/java/eu/etaxonomy/cdm/vaadin/model/User.java
1
package eu.etaxonomy.cdm.vaadin.model;
2

  
3
import java.io.Serializable;
4
import java.util.ArrayList;
5
import java.util.Collection;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9

  
10
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
11
import eu.etaxonomy.cdm.model.description.Distribution;
12

  
13
public class User implements Serializable {
14

  
15
	/**
16
	 * 
17
	 */
18
	private static final long serialVersionUID = 1L;
19
	private String name;
20
	private Map<String, String> prop;
21

  
22
	public User(String name) {
23
		this.name = name;
24
		prop = new HashMap<String, String>();
25
	}
26

  
27
	public void addProp(String column, String value) {
28
		prop.put(column, value);
29
	}
30

  
31
	public Collection<String> getPropertyId() {
32
		List<String> propertyId = new ArrayList<String>();
33
		for (Map.Entry<String, String> entry : prop.entrySet()) {
34
			propertyId.add(entry.getKey());
35
		}
36
		return propertyId;
37
	}
38

  
39
	public Collection<String> getItemId() {
40
		List<String> getItemId = new ArrayList<String>();
41
		for (Map.Entry<String, String> entry : prop.entrySet()) {
42
			getItemId.add(entry.getValue());
43
		}
44
		return getItemId;
45
	}
46
}
src/main/java/eu/etaxonomy/cdm/vaadin/model/Users.java
1
package eu.etaxonomy.cdm.vaadin.model;
2

  
3
import java.util.ArrayList;
4
import java.util.Collection;
5
import java.util.List;
6

  
7
import com.vaadin.data.Container;
8
import com.vaadin.data.Item;
9
import com.vaadin.data.Property;
10

  
11
public class Users implements Container {
12
	/**
13
	 * 
14
	 */
15
	private static final long serialVersionUID = 1L;
16
	private List<User> users;
17

  
18
	public Users() {
19

  
20
		User user1 = new User("first user");
21
		user1.addProp("p1", "val_b_1");
22
		user1.addProp("p2", "val_b_2");
23

  
24
		User user2 = new User("second_user");
25
		user2.addProp("p1", "val_a_1");
26
		user2.addProp("p2", "val_a_2");
27

  
28
		users = new ArrayList<User>();
29
		users.add(user1);
30
		users.add(user2);
31
	}
32

  
33
	@Override
34
	public Item getItem(Object itemId) {
35
		String tool = "string";
36
		String bar = "foo"; 
37
		return null;
38
	}
39

  
40
	@Override
41
	public Collection<?> getContainerPropertyIds() {
42
		// TODO Auto-generated method stub
43
		for(User user:users){
44
			return user.getPropertyId();
45
		}
46
		return null;
47
	}
48

  
49
	@Override
50
	public Collection<?> getItemIds() {
51
		for(User user:users){
52
			return user.getItemId();
53
		}
54
		return null;
55
	}
56

  
57
	@Override
58
	public Property getContainerProperty(Object itemId, Object propertyId) {
59
		// TODO Auto-generated method stub
60
		return null;
61
	}
62

  
63
	@Override
64
	public Class<?> getType(Object propertyId) {
65
		// TODO Auto-generated method stub
66
		return String.class;
67
	}
68

  
69
	@Override
70
	public int size() {
71
		// TODO Auto-generated method stub
72
		return users.size();
73
	}
74

  
75
	@Override
76
	public boolean containsId(Object itemId) {
77
		// TODO Auto-generated method stub
78
		return false;
79
	}
80

  
81
	@Override
82
	public Item addItem(Object itemId) throws UnsupportedOperationException {
83
		// TODO Auto-generated method stub
84
		return null;
85
	}
86

  
87
	@Override
88
	public Object addItem() throws UnsupportedOperationException {
89
		// TODO Auto-generated method stub
90
		return null;
91
	}
92

  
93
	@Override
94
	public boolean removeItem(Object itemId)
95
			throws UnsupportedOperationException {
96
		// TODO Auto-generated method stub
97
		return false;
98
	}
99

  
100
	@Override
101
	public boolean addContainerProperty(Object propertyId, Class<?> type,
102
			Object defaultValue) throws UnsupportedOperationException {
103
		// TODO Auto-generated method stub
104
		return false;
105
	}
106

  
107
	@Override
108
	public boolean removeContainerProperty(Object propertyId)
109
			throws UnsupportedOperationException {
110
		// TODO Auto-generated method stub
111
		return false;
112
	}
113

  
114
	@Override
115
	public boolean removeAllItems() throws UnsupportedOperationException {
116
		// TODO Auto-generated method stub
117
		return false;
118
	}
119
}
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
11 11
import com.vaadin.server.VaadinSession;
12 12
import com.vaadin.ui.ComboBox;
13 13

  
14
import eu.etaxonomy.cdm.api.service.IClassificationService;
14 15
import eu.etaxonomy.cdm.api.service.IDescriptionService;
16
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
15 17
import eu.etaxonomy.cdm.api.service.ITermService;
16 18
import eu.etaxonomy.cdm.api.service.IVocabularyService;
17 19
import eu.etaxonomy.cdm.model.common.CdmBase;
......
21 23
import eu.etaxonomy.cdm.model.description.Distribution;
22 24
import eu.etaxonomy.cdm.model.description.Feature;
23 25
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
26
import eu.etaxonomy.cdm.model.taxon.Classification;
24 27
import eu.etaxonomy.cdm.model.taxon.Taxon;
28
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
29
import eu.etaxonomy.cdm.vaadin.model.DbTableDTO;
30
import eu.etaxonomy.cdm.vaadin.model.DbTableDTOS;
31
import eu.etaxonomy.cdm.vaadin.model.DistributionDTO;
32
import eu.etaxonomy.cdm.vaadin.model.LazyLoadedContainer;
25 33
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
26 34
import eu.etaxonomy.cdm.vaadin.view.dbstatus.DistributionTableView;
27 35
import eu.etaxonomy.cdm.vaadin.view.dbstatus.IDistributionTableComponent;
......
29 37

  
30 38
public class DistributionTablePresenter implements IDistributionTableComponent.DistributionTableComponentListener{
31 39

  
40
	private final IClassificationService classificationService;
32 41
	private final IVocabularyService vocabularyService;
33 42
	private final IDescriptionService descriptionService;
43
	private final ITaxonNodeService taxonNodeService;
34 44
	private final ITermService termService;
35 45
	private final DistributionTableView view;
36 46

  
37 47
	public DistributionTablePresenter(DistributionTableView dtv){
38 48
	    this.view = dtv;
39 49
	    view.addListener(this);
40

  
50
	    view.dataBinding();
51
	    classificationService = (IClassificationService)CdmSpringContextHelper.newInstance().getBean("classificationServiceImpl");
52
	    taxonNodeService = (ITaxonNodeService)CdmSpringContextHelper.newInstance().getBean("taxonNodeServiceImpl");
41 53
		vocabularyService = (IVocabularyService)CdmSpringContextHelper.newInstance().getBean("vocabularyServiceImpl");
42 54
		descriptionService = (IDescriptionService)CdmSpringContextHelper.newInstance().getBean("descriptionServiceImpl");
43 55
		termService = (ITermService)CdmSpringContextHelper.newInstance().getBean("termServiceImpl");
44 56
	}
45 57

  
46 58

  
47
	@Override
59
	
48 60
	public ComboBox updateDistributionField(DescriptionElementBase deb,
49 61
			Distribution db,
50 62
			BeanItemContainer<PresenceAbsenceTerm> termContainer, ComboBox box,
......
66 78
	public HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon) {
67 79
		Set<Feature> setFeature = new HashSet<Feature>(Arrays.asList(Feature.DISTRIBUTION()));
68 80
		List<DescriptionElementBase> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
81
		HashMap<DescriptionElementBase, Distribution> map = null;
69 82
		for(DescriptionElementBase deb : listTaxonDescription){
70 83
			if(deb instanceof Distribution){
71 84
				Distribution db = (Distribution)deb;
72 85
				String titleCache = dt.getTitleCache();
73 86
				if(db.getArea().getTitleCache().equalsIgnoreCase(titleCache)){
74
					HashMap<DescriptionElementBase, Distribution> map = new HashMap<DescriptionElementBase, Distribution>();
87
					map = new HashMap<DescriptionElementBase, Distribution>();
75 88
					map.put(deb, db);
76
					return map;
77 89
				}
78 90
			}
79 91
		}
80
		return null;
92
		return map;
81 93
	}
82 94

  
95
	
96
	@Override
97
	public List<Distribution> getDistribution(Taxon taxon) {
98
		Set<Feature> setFeature = new HashSet<Feature>(Arrays.asList(Feature.DISTRIBUTION()));
99
		List<Distribution> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
100
		return listTaxonDescription;
101
		
102
	}
103
	
104
	
105
	public List<TaxonNode> getAllNodes(int start, int end){
106
		Classification classification = loadClassification();
107
		List<TaxonNode> nodesForClassification = taxonNodeService.listAllNodesForClassification(classification, start, end);
108
		return nodesForClassification;
109
	}
110

  
111

  
112

  
113
	private Classification loadClassification() {
114
		VaadinSession session = VaadinSession.getCurrent();
115
		UUID classificationUUID = (UUID) session.getAttribute("classificationUUID");
116
		Classification classification = classificationService.load(classificationUUID);
117
		return classification;
118
	}
119
	
120
	@Override
121
	public int getSizeOfClassification(){
122
		Classification classification = loadClassification();
123
		return taxonNodeService.countAllNodesForClassification(classification);
124
	}
125
	
126
	@Override
127
	public DbTableDTOS getDataList(int start, int end){
128
		List<TaxonNode> nodes = getAllNodes(start, end);
129
		DbTableDTOS items = new DbTableDTOS();
130
		for(TaxonNode tn: nodes){
131
			Taxon taxon = tn.getTaxon();
132
			DbTableDTO dbTableDTO = new DbTableDTO(taxon);
133

  
134
			Set<DefinedTermBase> terms = getChosenTerms();
135
			List<Distribution> distribution = getDistribution(taxon);
136
			for(DefinedTermBase dt: terms){
137
				for(Distribution db : distribution){
138
					if(dt.getTitleCache().equalsIgnoreCase(db.getArea().getTitleCache())){
139
//						DistributionDTO distributionDTO = new DistributionDTO(db.getStatus().getTitleCache());
140
//						dbTableDTO.setdDTO(distributionDTO);
141
					}
142
					
143
				}
144
			}	
145
			items.add(dbTableDTO);
146
		}
147
		return items;
148
	}
149
	
150
	void nestedContainer(){
151
		BeanItemContainer<DbTableDTO> container = new BeanItemContainer<DbTableDTO>(DbTableDTO.class);
152
		
153
	}
154
	
83 155
	@Override
84 156
	public List<PresenceAbsenceTerm> getPresenceAbsenceTerms() {
85 157
		//TODO Better to use TermType instead of class to get the list
......
101 173
    });
102 174

  
103 175

  
176
	@Override
177
	public LazyLoadedContainer getTableContainer() {
178
		// TODO Auto-generated method stub
179
		return null;
180
	}
181

  
182

  
104 183

  
105 184
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
1 1
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
2 2

  
3 3
import com.vaadin.annotations.AutoGenerated;
4
import com.vaadin.data.Container;
5
import com.vaadin.data.util.BeanItemContainer;
6
import com.vaadin.data.util.IndexedContainer;
4 7
import com.vaadin.navigator.View;
5 8
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
6 9
import com.vaadin.ui.AbsoluteLayout;
7 10
import com.vaadin.ui.Button.ClickEvent;
8 11
import com.vaadin.ui.Button.ClickListener;
12
import com.vaadin.ui.Component;
9 13
import com.vaadin.ui.CustomComponent;
14
import com.vaadin.ui.Field;
10 15
import com.vaadin.ui.Table;
16
import com.vaadin.ui.TableFieldFactory;
17

  
18
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19
import eu.etaxonomy.cdm.vaadin.model.DistributionDTO;
20
import eu.etaxonomy.cdm.vaadin.model.Users;
21
import eu.etaxonomy.cdm.vaadin.model.taxonDTO;
11 22

  
12 23
public class DistributionTableView extends CustomComponent implements IDistributionTableComponent, View, ClickListener{
13 24

  
......
21 32
	private AbsoluteLayout mainLayout;
22 33
	@AutoGenerated
23 34
	private Table table_1;
35
	
36
	private DistributionTableComponentListener listener;
37
	
24 38
	/**
25 39
	 * The constructor should first build the main layout, set the
26 40
	 * composition root and then do any custom initialization.
......
31 45
	public DistributionTableView() {
32 46
		buildMainLayout();
33 47
		setCompositionRoot(mainLayout);
34

  
35
		// TODO add user code here
48
		
49
		
36 50
	}
37 51

  
52
	
53
	public void dataBinding(){
54
//		LazyLoadedContainer container = new LazyLoadedContainer(DbTableDTO.class);
55
		BeanItemContainer<taxonDTO> taxonContainer = new BeanItemContainer<taxonDTO>(taxonDTO.class);
56
		taxonContainer.addNestedContainerProperty("distribution.name");
57
		taxonContainer.addNestedContainerProperty("distribution.status");
58
		BeanItemContainer<DistributionDTO> distContainer = new BeanItemContainer<DistributionDTO>(DistributionDTO.class);
59
		for(int i = 0; i<100; i++){
60
			distContainer.addBean(new DistributionDTO("Area"+i, "Status"+i));
61
		}
62
		for(int i = 0; i<100; i++){
63
			taxonContainer.addBean(new taxonDTO("taxon"+i, new DistributionDTO("Area"+i, "Status"+i)));
64
		}
65

  
66
		Users user = new Users();
67
		
68
		table_1.setContainerDataSource(user);
69
		
70
//		container.addNestedContainerProperty("dDTO.status");
71
	}
72
	
38 73
	@Override
39 74
	public void addListener(DistributionTableComponentListener listener) {
40
	    //TODO implement this method
75
	   this.listener = listener;
41 76
	}
42 77

  
43 78
	@AutoGenerated
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/IDistributionTableComponent.java
12 12
import eu.etaxonomy.cdm.model.description.Distribution;
13 13
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
14 14
import eu.etaxonomy.cdm.model.taxon.Taxon;
15
import eu.etaxonomy.cdm.vaadin.model.DbTableDTOS;
16
import eu.etaxonomy.cdm.vaadin.model.LazyLoadedContainer;
15 17

  
16 18
public interface IDistributionTableComponent {
17 19

  
......
23 25
		ComboBox updateDistributionField(DescriptionElementBase deb, Distribution db, BeanItemContainer<PresenceAbsenceTerm> termContainer, ComboBox box, Taxon taxon);
24 26

  
25 27
		HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon);
28
		
29
		LazyLoadedContainer getTableContainer();
30
		
31
		int getSizeOfClassification();
32
		
33
		DbTableDTOS getDataList(int start, int end);
34

  
35
		List<Distribution> getDistribution(Taxon taxon);
26 36

  
27 37
	}
28 38
	public void addListener(DistributionTableComponentListener listener);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)