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