Project

General

Profile

Download (4.56 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.ui.section.feature;
12

    
13
import java.net.URI;
14
import java.net.URISyntaxException;
15
import java.util.ArrayList;
16
import java.util.Arrays;
17
import java.util.Collections;
18
import java.util.HashSet;
19
import java.util.List;
20
import java.util.Map;
21
import java.util.Set;
22

    
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.widgets.Label;
25

    
26
import eu.etaxonomy.cdm.common.UriUtils;
27
import eu.etaxonomy.cdm.model.common.Language;
28
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
29
import eu.etaxonomy.cdm.model.description.Distribution;
30
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
31
import eu.etaxonomy.cdm.model.description.TaxonDescription;
32
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
33
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
34
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36
import eu.etaxonomy.taxeditor.ui.forms.BrowserElement;
37
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
38
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
39
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
40

    
41
/**
42
 * <p>FeatureDistributionDetailElement class.</p>
43
 *
44
 * @author n.hoffmann
45
 * @created Sep 23, 2010
46
 * @version 1.0
47
 */
48
public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<FeatureNodeContainer> {
49
	
50
	private BrowserElement image;
51
	
52
	/**
53
	 * <p>Constructor for FeatureDistributionDetailElement.</p>
54
	 *
55
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
56
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
57
	 */
58
	public FeatureDistributionDetailElement(CdmFormFactory formFactory,
59
			ICdmFormElement formElement) {
60
		super(formFactory, formElement);
61
	}
62

    
63

    
64
	/* (non-Javadoc)
65
	 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
66
	 */
67
	/** {@inheritDoc} */
68
	@Override
69
	protected void createControls(ICdmFormElement formElement, FeatureNodeContainer entity,
70
			int style) {
71
		String serviceUriString = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.EDIT_MAP_SERVICE_ACCES_POINT);
72
		String message = null;
73
		try {
74
			URI serviceUri = new URI(serviceUriString);
75
			if(UriUtils.isServiceAvailable(serviceUri)){
76
				image = formFactory.createBrowserElement(formElement, null, style);
77
				String mapUriString = getMapUriString(getEntity());
78
				image.setImageUriString(mapUriString);
79
				formElement.getLayoutComposite().layout();
80
				message = mapUriString; 
81
				return;
82
			} else {
83
				message = String.format("The service is not available: %s", serviceUriString);
84
			}
85
		} catch (URISyntaxException e) {
86
			message = String.format("The URI has problems: %s", serviceUriString);
87
		}
88
		
89
		Label label = formFactory.createLabel(getLayoutComposite(), message, SWT.WRAP);
90
		addControl(label);
91
		label.setLayoutData(CdmFormFactory.FILL(2, 1));
92
	}
93

    
94

    
95
	/* (non-Javadoc)
96
	 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
97
	 */
98
	/** {@inheritDoc} */
99
	@Override
100
	public void handleEvent(Object eventSource) {
101
		// 
102
	}
103

    
104
	/**
105
	 * @return
106
	 * @throws URISyntaxException 
107
	 */
108
	private String getMapUriString(FeatureNodeContainer container){
109
		String accessPoint = PreferencesUtil.getMapServiceAccessPoint();
110
		Map<PresenceAbsenceTermBase<?>, java.awt.Color> presenceAbsenceTermColors = null;
111
		// FIXME due to a bug in the rest map service we have to ensure that width will always be an even number
112
		// image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 : 
113
		int width = image.calculateWidth();
114
		
115
		String bbox = "-180,-90,180,90"; 
116
		String backLayer = null;
117

    
118
		List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
119
		
120
		String parameter = CdmStore.getGeoService().getDistributionServiceRequestParameterString(getTaxonDescriptions(), presenceAbsenceTermColors, width, 0, bbox, backLayer, languages);
121
		
122
		String mapUriString = String.format("%s?%s&ms=1000", accessPoint, parameter);
123
		return mapUriString;
124
	}
125
	
126
	/**
127
	 * @return
128
	 */
129
	private List<TaxonDescription> getTaxonDescriptions() {
130
		return Arrays.asList(((TaxonDescription) getEntity().getDescription()).getTaxon().getDescriptions().toArray(new TaxonDescription[0]));
131
	}
132

    
133
}
(1-1/2)