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.Arrays;
|
16
|
import java.util.List;
|
17
|
import java.util.Map;
|
18
|
|
19
|
import org.eclipse.swt.SWT;
|
20
|
import org.eclipse.swt.widgets.Label;
|
21
|
|
22
|
import eu.etaxonomy.cdm.common.UriUtils;
|
23
|
import eu.etaxonomy.cdm.model.common.Language;
|
24
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
|
25
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
26
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
27
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
28
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
29
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
30
|
import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.BrowserElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
33
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
34
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
35
|
|
36
|
/**
|
37
|
* <p>FeatureDistributionDetailElement class.</p>
|
38
|
*
|
39
|
* @author n.hoffmann
|
40
|
* @created Sep 23, 2010
|
41
|
* @version 1.0
|
42
|
*/
|
43
|
public class FeatureDistributionDetailElement extends AbstractCdmDetailElement<FeatureNodeContainer> {
|
44
|
|
45
|
private BrowserElement image;
|
46
|
|
47
|
/**
|
48
|
* <p>Constructor for FeatureDistributionDetailElement.</p>
|
49
|
*
|
50
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
51
|
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
52
|
*/
|
53
|
public FeatureDistributionDetailElement(CdmFormFactory formFactory,
|
54
|
ICdmFormElement formElement) {
|
55
|
super(formFactory, formElement);
|
56
|
}
|
57
|
|
58
|
|
59
|
/* (non-Javadoc)
|
60
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
|
61
|
*/
|
62
|
/** {@inheritDoc} */
|
63
|
@Override
|
64
|
protected void createControls(ICdmFormElement formElement, FeatureNodeContainer entity,
|
65
|
int style) {
|
66
|
String serviceUriString = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.EDIT_MAP_SERVICE_ACCES_POINT);
|
67
|
String message = null;
|
68
|
try {
|
69
|
URI serviceUri = new URI(serviceUriString);
|
70
|
if(UriUtils.isServiceAvailable(serviceUri)){
|
71
|
image = formFactory.createBrowserElement(formElement, null, style);
|
72
|
String mapUriString = getMapUriString(getEntity());
|
73
|
image.setImageUriString(mapUriString);
|
74
|
formElement.getLayoutComposite().layout();
|
75
|
message = mapUriString;
|
76
|
return;
|
77
|
} else {
|
78
|
message = String.format("The service is not available: %s", serviceUriString);
|
79
|
}
|
80
|
} catch (URISyntaxException e) {
|
81
|
message = String.format("The URI has problems: %s", serviceUriString);
|
82
|
}
|
83
|
|
84
|
Label label = formFactory.createLabel(getLayoutComposite(), message, SWT.WRAP);
|
85
|
addControl(label);
|
86
|
label.setLayoutData(LayoutConstants.FILL(2, 1));
|
87
|
}
|
88
|
|
89
|
|
90
|
/* (non-Javadoc)
|
91
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
|
92
|
*/
|
93
|
/** {@inheritDoc} */
|
94
|
@Override
|
95
|
public void handleEvent(Object eventSource) {
|
96
|
//
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* @return
|
101
|
* @throws URISyntaxException
|
102
|
*/
|
103
|
private String getMapUriString(FeatureNodeContainer container){
|
104
|
String accessPoint = PreferencesUtil.getMapServiceAccessPoint();
|
105
|
Map<PresenceAbsenceTermBase<?>, java.awt.Color> presenceAbsenceTermColors = null;
|
106
|
// FIXME due to a bug in the rest map service we have to ensure that width will always be an even number
|
107
|
// image.calculateWidth() % 2 == 1 ? image.calculateWidth() + 1 :
|
108
|
int width = image.calculateWidth();
|
109
|
|
110
|
String bbox = "-180,-90,180,90";
|
111
|
String backLayer = null;
|
112
|
|
113
|
List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
|
114
|
|
115
|
String parameter = CdmStore.getGeoService().getDistributionServiceRequestParameterString(getTaxonDescriptions(), presenceAbsenceTermColors, width, 0, bbox, backLayer, languages);
|
116
|
|
117
|
String mapUriString = String.format("%s?%s&ms=1000", accessPoint, parameter);
|
118
|
return mapUriString;
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* @return
|
123
|
*/
|
124
|
private List<TaxonDescription> getTaxonDescriptions() {
|
125
|
return Arrays.asList(((TaxonDescription) getEntity().getDescription()).getTaxon().getDescriptions().toArray(new TaxonDescription[0]));
|
126
|
}
|
127
|
|
128
|
}
|