ingo@1400: package de.intevation.flys.client.client.ui.map; ingo@1400: christian@3347: import com.google.gwt.core.client.GWT; christian@4965: aheinecke@5818: import com.smartgwt.client.widgets.HTMLPane; christian@3347: import com.smartgwt.client.widgets.Label; christian@3347: import com.smartgwt.client.widgets.Window; christian@3347: import com.smartgwt.client.widgets.layout.VLayout; aheinecke@5813: import com.smartgwt.client.widgets.viewer.DetailViewer; aheinecke@5813: import com.smartgwt.client.widgets.viewer.DetailViewerField; aheinecke@5813: import com.smartgwt.client.widgets.viewer.DetailViewerRecord; christian@3347: christian@3347: import de.intevation.flys.client.client.FLYSConstants; christian@3347: import de.intevation.flys.client.shared.model.FeatureInfo; aheinecke@5818: import de.intevation.flys.client.shared.model.FeatureInfoResponse; christian@3347: aheinecke@5813: import java.util.ArrayList; ingo@1402: import java.util.List; ingo@1402: import java.util.Map; ingo@1402: import java.util.Set; aheinecke@5813: import java.util.MissingResourceException; ingo@1402: ingo@1400: import org.gwtopenmaps.openlayers.client.feature.VectorFeature; ingo@1400: import org.gwtopenmaps.openlayers.client.util.Attributes; ingo@1400: import org.gwtopenmaps.openlayers.client.util.JSObject; ingo@1400: ingo@1400: ingo@1400: public class GetFeatureInfoWindow extends Window { ingo@1400: ingo@1400: protected FLYSConstants MSG = GWT.create(FLYSConstants.class); ingo@1400: ingo@1402: protected List features; ingo@1400: aheinecke@5813: protected String title; aheinecke@5813: aheinecke@5818: protected String featureInfoHTML; aheinecke@5818: ingo@1400: ingo@1402: public static final int ROW_HEIGHT = 25; ingo@1402: ingo@1402: aheinecke@5813: public GetFeatureInfoWindow(List features, String title) { ingo@1400: super(); ingo@1402: this.features = features; aheinecke@5813: this.title = title; ingo@1402: ingo@1400: initLayout(); ingo@1400: } ingo@1400: aheinecke@5818: public GetFeatureInfoWindow(String featureInfoHTML, String title) { aheinecke@5818: super(); aheinecke@5818: features = null; aheinecke@5818: this.title = title; aheinecke@5818: this.featureInfoHTML = featureInfoHTML; aheinecke@5818: aheinecke@5818: initLayoutHTML(); aheinecke@5818: } aheinecke@5818: aheinecke@5818: protected void initLayoutHTML() { aheinecke@5818: HTMLPane pane = new HTMLPane(); aheinecke@5818: pane.setContents(featureInfoHTML); aheinecke@5818: addItem(pane); aheinecke@5818: setWidth(500); aheinecke@5818: setHeight(300); aheinecke@5818: aheinecke@5821: setTitle(MSG.getFeatureInfoWindowTitle() + " " + title); aheinecke@5821: aheinecke@5818: setIsModal(false); aheinecke@5818: // setShowModalMask(true); aheinecke@5818: aheinecke@5818: centerInPage(); aheinecke@5818: } ingo@1400: ingo@1400: protected void initLayout() { ingo@1400: VLayout root = new VLayout(); ingo@1400: ingo@1402: for (FeatureInfo feature: features) { aheinecke@5813: // Currently this should alway be only one aheinecke@5813: root.addMember(createFeatureViewer(feature)); aheinecke@5813: setTitle(MSG.getFeatureInfoWindowTitle() + " " + title); ingo@1400: } ingo@1400: ingo@1400: addItem(root); ingo@1400: christian@3521: setWidth(500); aheinecke@5813: setHeight(300); ingo@1400: aheinecke@5813: setIsModal(false); aheinecke@5813: // setShowModalMask(true); ingo@2470: ingo@1400: centerInPage(); ingo@1400: } ingo@1400: ingo@1400: aheinecke@5813: protected DetailViewer createFeatureViewer(FeatureInfo feature) { aheinecke@5813: DetailViewer detailViewer = new DetailViewer(); aheinecke@5813: detailViewer.setWidth(487); ingo@1402: ingo@1402: Map attrs = feature.getAttrs(); ingo@1402: Set> entries = attrs.entrySet(); aheinecke@5813: List fields = new ArrayList(); aheinecke@5813: DetailViewerRecord dr = new DetailViewerRecord(); aheinecke@5813: aheinecke@5813: DetailViewerField path_field = null; // Make sure path is always the last element ingo@1402: christian@3347: for (Map.Entry entry: entries) { aheinecke@5813: String localized; aheinecke@5813: try { aheinecke@5813: localized = MSG.getString(entry.getKey()); aheinecke@5813: } catch (MissingResourceException mre) { aheinecke@5813: localized = entry.getKey(); aheinecke@5813: // We filter unwanted information by localization aheinecke@5813: // Uncomment to filter out unlocalized elements aheinecke@5813: // continue; aheinecke@5813: } aheinecke@5813: if (entry.getKey().equals("PATH")) { aheinecke@5813: path_field = new DetailViewerField(entry.getKey(), localized); aheinecke@5813: } else { aheinecke@5813: fields.add(new DetailViewerField(entry.getKey(), localized)); aheinecke@5813: } aheinecke@5813: dr.setAttribute(entry.getKey(), entry.getValue()); aheinecke@5813: } aheinecke@5813: if (path_field != null) aheinecke@5813: fields.add(path_field); ingo@1402: aheinecke@5813: DetailViewerField[] fieldArray = new DetailViewerField[fields.size()]; aheinecke@5813: detailViewer.setFields(fields.toArray(fieldArray)); aheinecke@5813: detailViewer.setData(new DetailViewerRecord[]{dr}); aheinecke@5813: detailViewer.setCanSelectText(true); ingo@1400: aheinecke@5813: return detailViewer; ingo@1400: } ingo@1400: ingo@1400: ingo@1400: protected String[][] extractProperties(VectorFeature feature) { ingo@1400: Attributes tmp = feature.getAttributes(); ingo@1400: JSObject jsobj = tmp.getJSObject(); ingo@1400: ingo@1400: String tmpNames = jsobj.getPropertyNames(); ingo@1400: String[] allNames = tmpNames.split(","); ingo@1400: ingo@1400: String[][] attr = new String[allNames.length][]; ingo@1400: ingo@1400: for (int i = 0, n = attr.length; i < n; i++) { ingo@1400: attr[i] = new String[] { ingo@1400: allNames[i], ingo@1400: jsobj.getPropertyAsString(allNames[i]) }; ingo@1400: } ingo@1400: ingo@1400: return attr; ingo@1400: } ingo@1400: } ingo@1400: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :