Project

General

Profile

Revision 49a35b7d

ID49a35b7dbc301ef17bad173adaea3bd77d377580
Parent f9837f2a
Child e693adbd

Added by Patrick Plitzner about 5 years ago

ref #5458 Refactoring

  • removed single implemented interfaces
  • merged methods
  • removed unnecessary try&catch blocks

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/container/CdmSQLContainer.java
8 8

  
9 9
import com.vaadin.data.Property;
10 10
import com.vaadin.data.util.sqlcontainer.SQLContainer;
11
import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool;
12 11
import com.vaadin.data.util.sqlcontainer.query.QueryDelegate;
13 12

  
14 13
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
......
21 20

  
22 21
    private static final Logger logger = Logger.getLogger(CdmSQLContainer.class);
23 22

  
24
    JDBCConnectionPool pool;
25

  
26
    DatabaseMetaData databaseMetaData;
23
    private DatabaseMetaData databaseMetaData;
27 24

  
28 25
    public static final int DEFAULT_LIMIT = 5000;
29 26
    boolean checkPropertyIdCase = false;
30 27

  
31 28
    public CdmSQLContainer(QueryDelegate delegate) throws SQLException {
32 29
        super(delegate);
33
        databaseMetaData = CdmSpringContextHelper.getCurrent().getDatabaseMetaData();
30
        databaseMetaData = CdmSpringContextHelper.getDatabaseMetaData();
34 31
        setPageLength(DEFAULT_LIMIT);
35 32
    }
36 33

  
......
44 41
        return container;
45 42
    }
46 43

  
47

  
48

  
49 44
    public UUID getUuid(Object itemId) {
50 45
        return UUID.fromString((String)getProperty(itemId,CdmQueryFactory.UUID_ID).getValue());
51 46
    }
src/main/java/eu/etaxonomy/cdm/vaadin/model/LazyLoadedContainer.java
1
package eu.etaxonomy.cdm.vaadin.model;
2

  
3
import java.io.Serializable;
4
import java.util.List;
5

  
6
import com.vaadin.data.util.BeanContainer;
7
import com.vaadin.data.util.BeanItem;
8

  
9
import eu.etaxonomy.cdm.model.common.CdmBase;
10
import eu.etaxonomy.cdm.model.taxon.Taxon;
11
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
12
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionTablePresenter;
13
import eu.etaxonomy.cdm.vaadin.view.dbstatus.IDistributionTableComponent;
14

  
15
public class LazyLoadedContainer extends BeanContainer implements Serializable, IDistributionTableComponent {
16

  
17
	/** autogenerated **/
18
	private static final long serialVersionUID = 1L;
19

  
20
	DistributionTableComponentListener listener;
21

  
22

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

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

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

  
50
	@Override
51
	public List getItemIds(){
52
		List<TaxonNode> listAllNodesForClassification = listener.getAllNodes();
53
		return listAllNodesForClassification;
54
	}
55

  
56

  
57

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

  
63

  
64

  
65
}
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionSelectionPresenter.java
1 1
package eu.etaxonomy.cdm.vaadin.presenter.dbstatus;
2 2

  
3
import java.sql.SQLException;
4 3
import java.util.ArrayList;
5 4
import java.util.Arrays;
6 5
import java.util.List;
......
22 21
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
23 22
import eu.etaxonomy.cdm.vaadin.view.dbstatus.DistributionSelectionView;
24 23
import eu.etaxonomy.cdm.vaadin.view.dbstatus.DistributionTableView;
25
import eu.etaxonomy.cdm.vaadin.view.dbstatus.IDistributionSelectionComponent;
26 24

  
27
public class DistributionSelectionPresenter implements IDistributionSelectionComponent.DistributionSelectionComponentListener {
25
public class DistributionSelectionPresenter {
28 26

  
29 27
	private DistributionSelectionView view;
30 28

  
......
34 32
		view.dataBinding();
35 33
	}
36 34

  
37
	@Override
38
	public void buttonClick(TaxonNode taxonNode, TermVocabulary<DefinedTermBase> term, Set<NamedArea> selectedAreas) throws SQLException {
35
	public void buttonClick(TaxonNode taxonNode, TermVocabulary<DefinedTermBase> term, Set<NamedArea> selectedAreas) {
39 36
		DistributionTableView dtv = new DistributionTableView();
40 37
		new DistributionTablePresenter(dtv);
41 38
		UI.getCurrent().getNavigator().addView("table", dtv);
......
43 40
		DistributionEditorUtil.openDistributionView(taxonNode, term, selectedAreas);
44 41
	}
45 42

  
46
	@Override
47 43
	public List<TaxonNode> getTaxonNodeList() {
48 44
		List<TaxonNode> nodes = new ArrayList<TaxonNode>();
49 45

  
......
67 63
		return nodes;
68 64
	}
69 65

  
70
	@Override
71 66
	public List<TermVocabulary<DefinedTermBase>> getNamedAreaList() {
72 67

  
73 68
		IVocabularyService vocabularyService = CdmSpringContextHelper.getVocabularyService();
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
35 35
import eu.etaxonomy.cdm.model.taxon.Taxon;
36 36
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
37 37
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
38
import eu.etaxonomy.cdm.vaadin.model.LazyLoadedContainer;
39 38
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
40 39
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
41 40
import eu.etaxonomy.cdm.vaadin.view.dbstatus.DistributionTableView;
42
import eu.etaxonomy.cdm.vaadin.view.dbstatus.IDistributionTableComponent;
43 41

  
44 42

  
45
public class DistributionTablePresenter implements IDistributionTableComponent.DistributionTableComponentListener{
46

  
43
public class DistributionTablePresenter {
47 44

  
48 45
	private final IClassificationService classificationService;
49 46
	private final IVocabularyService vocabularyService;
......
53 50
	private final DistributionTableView view;
54 51
	private final ITaxonService taxonService;
55 52

  
56
	public DistributionTablePresenter(DistributionTableView dtv) throws SQLException{
53
	public DistributionTablePresenter(DistributionTableView dtv){
57 54
	    this.view = dtv;
58 55
	    view.addListener(this);
59 56
	    taxonService = CdmSpringContextHelper.getTaxonService();
......
64 61
		termService = CdmSpringContextHelper.getTermService();
65 62
	}
66 63

  
67

  
68
	@Override
69 64
    public int updateDistributionField(String distributionAreaString, Object comboValue, Taxon taxon) {
70 65
	    Set<DefinedTermBase> chosenTerms = getChosenTerms();
71 66
	    NamedArea namedArea = null;
......
115 110
	    return -1;
116 111
	}
117 112

  
118
	@Override
119 113
	public Set<DefinedTermBase> getChosenTerms() {
120 114
		VaadinSession session = VaadinSession.getCurrent();
121 115
		UUID termUUID = (UUID) session.getAttribute("selectedTerm");
......
124 118
		return term.getTerms();
125 119
	}
126 120

  
127

  
128
	@Override
129 121
	public List<String> getAbbreviatedTermList() {
130 122
		SortedSet<DefinedTermBase> terms = getTermSet();
131 123
		List<String> list = new ArrayList<String>();
......
134 126
		        list.add(r.getAbbreviatedLabel());
135 127
		    }
136 128
		}
137
//		Collections.sort(list);
138 129
		return list;
139 130
	}
140 131

  
141
    @Override
142
    public List<String> getTermList() {
143
        SortedSet<DefinedTermBase> terms = getTermSet();
144
        List<String> list = new ArrayList<String>();
145
        for(DefinedTermBase dtb: terms){
146
           list.add(dtb.getTitleCache());
147
        }
148
//      Collections.sort(list);
149
        return list;
150
    }
151

  
152 132
    public List<String> getNamedAreas(){
153 133
    	String selectedAreas = (String) VaadinSession.getCurrent().getAttribute("selectedAreas");
154 134
    	if(CdmUtils.isBlank(selectedAreas)){
155
    	    return getTermList();
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;
156 141
    	}
157 142
    	return Arrays.asList(selectedAreas.split(","));
158 143
    }
159 144

  
160

  
161 145
	private SortedSet<DefinedTermBase> getTermSet(){
162 146
	    VaadinSession session = VaadinSession.getCurrent();
163 147
	    UUID termUUID = (UUID) session.getAttribute("selectedTerm");
......
166 150
	    return term.getTermsOrderedByLabels(Language.DEFAULT());
167 151
	}
168 152

  
169
	@Override
170 153
	public HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon) {
171 154
		Set<Feature> setFeature = new HashSet<Feature>(Arrays.asList(Feature.DISTRIBUTION()));
172 155
		List<DescriptionElementBase> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
......
183 166
		}
184 167
		return map;
185 168
	}
186
	@Override
169

  
187 170
	public List<DescriptionElementBase> listDescriptionElementsForTaxon(Taxon taxon, Set<Feature> setFeature){
188 171
		List<DescriptionElementBase> listDescriptionElementsForTaxon = descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
189 172
		sort(listDescriptionElementsForTaxon);
190 173
		return listDescriptionElementsForTaxon;
191 174
	}
192 175

  
193
	@Override
194 176
	public List<Distribution> getDistributions(Taxon taxon) {
195 177
		Set<Feature> setFeature = new HashSet<Feature>(Arrays.asList(Feature.DISTRIBUTION()));
196 178
		List<Distribution> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
......
198 180

  
199 181
	}
200 182

  
201
	@Override
202 183
	public List<TaxonNode> getAllNodes(){
203 184
		TaxonNode taxonNode = getChosenTaxonNode();
204 185
		List<TaxonNode> nodes = new ArrayList<TaxonNode>();
......
210 191
	}
211 192

  
212 193

  
213
	@Override
214 194
	public TaxonNode getChosenTaxonNode() {
215 195
		VaadinSession session = VaadinSession.getCurrent();
216 196
		UUID taxonNodeUUID = (UUID) session.getAttribute("taxonNodeUUID");
......
218 198
		return classificationNode;
219 199
	}
220 200

  
221
	@Override
222 201
	public int getSizeOfTaxonNode(){
223 202
		TaxonNode taxonNode = getChosenTaxonNode();
224 203
		return taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, null, true, null).size();
225 204
	}
226 205

  
227 206

  
228
	@Override
229 207
	public CdmSQLContainer getSQLContainer() throws SQLException{
230 208
		List<Integer> nodeIds = new ArrayList<Integer>();
231 209
		for (TaxonNode taxonNode : getAllNodes()) {
......
260 238
            "taxon2.name"
261 239
    });
262 240

  
263

  
264
	@Override
265 241
	public IClassificationService getClassificationService() {
266 242
		return classificationService;
267 243
	}
268 244

  
269

  
270
	@Override
271 245
	public IVocabularyService getVocabularyService() {
272 246
		return vocabularyService;
273 247
	}
274 248

  
275

  
276
	@Override
277 249
	public IDescriptionService getDescriptionService() {
278 250
		return descriptionService;
279 251
	}
280 252

  
281

  
282
	@Override
283 253
	public ITaxonNodeService getTaxonNodeService() {
284 254
		return taxonNodeService;
285 255
	}
286 256

  
287

  
288
	@Override
289 257
	public ITermService getTermService() {
290 258
		return termService;
291 259
	}
292

  
293
	@Override
294
	public LazyLoadedContainer getTableContainer() {
295
		return null;
296
	}
297

  
298

  
299

  
300
	@Override
301 260
	public ITaxonService getTaxonService() {
302 261
		return taxonService;
303 262
	}
304 263

  
305

  
306 264
	/**Helper Methods*/
307 265

  
308 266
	private void sort(List<DescriptionElementBase> list){
......
320 278
				}
321 279
			}
322 280
		});
323

  
324 281
	}
325 282
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSelectionView.java
1 1
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
2 2

  
3
import java.sql.SQLException;
4 3
import java.util.List;
5 4
import java.util.Set;
6 5

  
......
29 28
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
30 29
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
31 30
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
31
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionSelectionPresenter;
32 32

  
33
public class DistributionSelectionView extends CustomComponent implements IDistributionSelectionComponent, View, ClickListener{
33
public class DistributionSelectionView extends CustomComponent implements View, ClickListener{
34 34

  
35 35
    private VerticalLayout mainLayout;
36 36
    private Panel panel_1;
......
44 44
    private Label labelNoClassification;
45 45

  
46 46
    private static final long serialVersionUID = 1L;
47
	private DistributionSelectionComponentListener distListener;
47
	private DistributionSelectionPresenter distListener;
48 48
	/**
49 49
	 * The constructor should first build the main layout, set the
50 50
	 * composition root and then do any custom initialization.
......
61 61
	}
62 62

  
63 63

  
64
	@Override
65
	public void addListener(DistributionSelectionComponentListener listener) {
64
	public void addListener(DistributionSelectionPresenter listener) {
66 65
		distListener = listener;
67 66
	}
68 67

  
......
74 73
		}
75 74
		TermVocabulary<DefinedTermBase> term = (TermVocabulary<DefinedTermBase>)distributionAreaBox.getValue();
76 75
		Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
77
		try {
78
			distListener.buttonClick(taxonNode, term, selectedAreas);
79
		} catch (SQLException e) {
80
			e.printStackTrace();
81
		}
76
		distListener.buttonClick(taxonNode, term, selectedAreas);
82 77
	}
83 78

  
84 79
	public void dataBinding(){
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
39 39
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
40 40
import eu.etaxonomy.cdm.vaadin.util.TermCacher;
41 41

  
42
public class DistributionTableView extends CustomComponent implements IDistributionTableComponent, View{
43

  
44
    private final class AreaColumnGenerator implements ColumnGenerator {
45
		private static final long serialVersionUID = 1L;
46

  
47
		@Override
48
		public Object generateCell(Table source, Object itemId, Object columnId) {
49
		    Property<?> containerProperty = source.getContainerProperty(itemId, columnId);
50
		    Object value = null;
51
		    if(containerProperty != null){
52
		        value = containerProperty.getValue();
53
		    }
54
		    final UUID uuid = UUID.fromString(table.getItem(itemId).getItemProperty("uuid").getValue().toString());
55
		    final ComboBox box = new ComboBox("Occurrence Status: ", PresenceAbsenceTermContainer.getInstance());
56
		    final String area = columnId.toString();
57
		    box.setImmediate(true);
58
		    box.setBuffered(true);
59
		    box.setValue(TermCacher.getInstance().getPresenceAbsenceTerm((String)value));
60
		    box.addValueChangeListener(new ValueChangeListener() {
61
				private static final long serialVersionUID = 6221534597911674067L;
62

  
63
				@Override
64
		        public void valueChange(ValueChangeEvent event) {
65
		            Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class);
66
		            listener.updateDistributionField(area, box.getValue(), taxon);
67
		        }
68
		    });
69
		    return box;
70
		}
71
	}
42
public class DistributionTableView extends CustomComponent implements View{
72 43

  
73 44
	private static final long serialVersionUID = 1L;
74 45
    private HorizontalToolbar toolbar;
......
115 86
		return mainLayout;
116 87
	}
117 88

  
118
	@Override
119 89
	public void addListener(DistributionTablePresenter listener) {
120 90
	   this.listener = listener;
121 91
	}
......
219 189

  
220 190
	}
221 191

  
192
    private final class AreaColumnGenerator implements ColumnGenerator {
193
        private static final long serialVersionUID = 1L;
194

  
195
        @Override
196
        public Object generateCell(Table source, Object itemId, Object columnId) {
197
            Property<?> containerProperty = source.getContainerProperty(itemId, columnId);
198
            Object value = null;
199
            if(containerProperty != null){
200
                value = containerProperty.getValue();
201
            }
202
            final UUID uuid = UUID.fromString(table.getItem(itemId).getItemProperty("uuid").getValue().toString());
203
            final ComboBox box = new ComboBox("Occurrence Status: ", PresenceAbsenceTermContainer.getInstance());
204
            final String area = columnId.toString();
205
            box.setImmediate(true);
206
            box.setBuffered(true);
207
            box.setValue(TermCacher.getInstance().getPresenceAbsenceTerm((String)value));
208
            box.addValueChangeListener(new ValueChangeListener() {
209
                private static final long serialVersionUID = 6221534597911674067L;
210

  
211
                @Override
212
                public void valueChange(ValueChangeEvent event) {
213
                    Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class);
214
                    listener.updateDistributionField(area, box.getValue(), taxon);
215
                }
216
            });
217
            return box;
218
        }
219
    }
220

  
222 221
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/IDistributionSelectionComponent.java
1
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
2

  
3
import java.sql.SQLException;
4
import java.util.List;
5
import java.util.Set;
6

  
7
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
8
import eu.etaxonomy.cdm.model.common.TermVocabulary;
9
import eu.etaxonomy.cdm.model.location.NamedArea;
10
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
11

  
12
public interface IDistributionSelectionComponent {
13
	public interface DistributionSelectionComponentListener{
14
		void buttonClick(TaxonNode classification, TermVocabulary<DefinedTermBase> term, Set<NamedArea> selectedAreas) throws SQLException;
15
		
16
		List<TaxonNode> getTaxonNodeList();
17
		
18
		List<TermVocabulary<DefinedTermBase>> getNamedAreaList();
19
		
20
	}
21
	public void addListener(DistributionSelectionComponentListener listener);
22
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/IDistributionTableComponent.java
1
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
2

  
3
import java.sql.SQLException;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Set;
7

  
8
import eu.etaxonomy.cdm.api.service.IClassificationService;
9
import eu.etaxonomy.cdm.api.service.IDescriptionService;
10
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
11
import eu.etaxonomy.cdm.api.service.ITaxonService;
12
import eu.etaxonomy.cdm.api.service.ITermService;
13
import eu.etaxonomy.cdm.api.service.IVocabularyService;
14
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
15
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
16
import eu.etaxonomy.cdm.model.description.Distribution;
17
import eu.etaxonomy.cdm.model.description.Feature;
18
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
20
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
21
import eu.etaxonomy.cdm.vaadin.model.LazyLoadedContainer;
22
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionTablePresenter;
23

  
24
public interface IDistributionTableComponent {
25

  
26
	public interface DistributionTableComponentListener{
27
		Set<DefinedTermBase> getChosenTerms();
28

  
29
		HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon);
30

  
31
		LazyLoadedContainer getTableContainer();
32

  
33
		int getSizeOfTaxonNode();
34

  
35
		List<Distribution> getDistributions(Taxon taxon);
36

  
37
		IClassificationService getClassificationService();
38

  
39
		IVocabularyService getVocabularyService();
40

  
41
		IDescriptionService getDescriptionService();
42

  
43
		ITaxonNodeService getTaxonNodeService();
44

  
45
		ITermService getTermService();
46

  
47
		ITaxonService getTaxonService();
48

  
49
		List<DescriptionElementBase> listDescriptionElementsForTaxon(
50
				Taxon taxon, Set<Feature> setFeature);
51

  
52
		TaxonNode getChosenTaxonNode();
53

  
54
		List<TaxonNode> getAllNodes();
55

  
56
		CdmSQLContainer getSQLContainer() throws SQLException;
57

  
58
		List<String> getTermList();
59

  
60
        /**
61
         * @return
62
         */
63
        List<String> getAbbreviatedTermList();
64

  
65
        /**
66
         * @param distributionArea
67
         * @param comboValue
68
         * @param taxon
69
         * @return
70
         */
71
        int updateDistributionField(String distributionArea, Object comboValue, Taxon taxon);
72

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

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)