in progress cross-filtering
parent
16d9feffe0
commit
a208b37791
@ -1,4 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-viewer-app/target/geoportal-data-viewer-app-3.4.0-SNAPSHOT
|
||||
lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-viewer-app/target/geoportal-data-viewer-app-3.5.0-SNAPSHOT
|
||||
warSrcDir=src/main/webapp
|
||||
warSrcDirIsOutput=false
|
||||
|
@ -0,0 +1,320 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.client.ui.crossfiltering;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.CrossFilteringLayerDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.CheckBox;
|
||||
import com.github.gwtbootstrap.client.ui.ControlGroup;
|
||||
import com.github.gwtbootstrap.client.ui.ControlLabel;
|
||||
import com.github.gwtbootstrap.client.ui.Controls;
|
||||
import com.github.gwtbootstrap.client.ui.Fieldset;
|
||||
import com.github.gwtbootstrap.client.ui.ListBox;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ChangeEvent;
|
||||
import com.google.gwt.event.dom.client.ChangeHandler;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.http.client.Request;
|
||||
import com.google.gwt.http.client.RequestBuilder;
|
||||
import com.google.gwt.http.client.RequestCallback;
|
||||
import com.google.gwt.http.client.RequestException;
|
||||
import com.google.gwt.http.client.Response;
|
||||
import com.google.gwt.json.client.JSONParser;
|
||||
import com.google.gwt.json.client.JSONString;
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
import ol.Feature;
|
||||
|
||||
/**
|
||||
* The Class CrossFilteringLayerPanel.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* May 15, 2023
|
||||
*/
|
||||
public class CrossFilteringLayerPanel extends Composite {
|
||||
|
||||
public static String COLORSCALERANGE = "COLORSCALERANGE";
|
||||
|
||||
//@UiField
|
||||
//WellForm panelContainer;
|
||||
|
||||
@UiField
|
||||
Fieldset fieldSet;
|
||||
|
||||
private CheckBox checkbox;
|
||||
|
||||
private GeoInformationForWMSRequest geoInformation;
|
||||
|
||||
private static CrossFilteringLayerPanelUiBinder uiBinder = GWT.create(CrossFilteringLayerPanelUiBinder.class);
|
||||
|
||||
private HandlerManager applicationBus;
|
||||
|
||||
private LayerItem layerItem;
|
||||
|
||||
private LinkedHashMap<Integer, HashMap<String, SelectableItem>> mapInnestedFeatures = new LinkedHashMap<Integer, HashMap<String, SelectableItem>>();
|
||||
|
||||
private LinkedHashMap<Integer, List<? extends LayerIDV>> mapInnestedFiltering = new LinkedHashMap<Integer, List<? extends LayerIDV>>();
|
||||
|
||||
private LinkedHashMap<Integer, List<ListBox>> mapInnestedListBoxes = new LinkedHashMap<Integer, List<ListBox>>();
|
||||
|
||||
private GroupedLayersDV<? extends LayerIDV> groupedLayersDV;
|
||||
|
||||
/**
|
||||
* The Interface LayerCollectionPanelUiBinder.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jan 16, 2023
|
||||
*/
|
||||
interface CrossFilteringLayerPanelUiBinder extends UiBinder<Widget, CrossFilteringLayerPanel> {
|
||||
}
|
||||
|
||||
public class SelectableItem {
|
||||
String key;
|
||||
String parentKey;
|
||||
String itemField;
|
||||
|
||||
String provenance; // layerName
|
||||
|
||||
SelectableItem() {
|
||||
|
||||
}
|
||||
|
||||
public SelectableItem(String key, String parentKey, String itemField, String provenance) {
|
||||
super();
|
||||
this.key = key;
|
||||
this.parentKey = parentKey;
|
||||
this.itemField = itemField;
|
||||
this.provenance = provenance;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getParentKey() {
|
||||
return parentKey;
|
||||
}
|
||||
|
||||
public String getItemField() {
|
||||
return itemField;
|
||||
}
|
||||
|
||||
public String getProvenance() {
|
||||
return provenance;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void setParentKey(String parentKey) {
|
||||
this.parentKey = parentKey;
|
||||
}
|
||||
|
||||
public void setItemField(String itemField) {
|
||||
this.itemField = itemField;
|
||||
}
|
||||
|
||||
public void setProvenance(String provenance) {
|
||||
this.provenance = provenance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("SelectableItem [key=");
|
||||
builder.append(key);
|
||||
builder.append(", parentKey=");
|
||||
builder.append(parentKey);
|
||||
builder.append(", itemField=");
|
||||
builder.append(itemField);
|
||||
builder.append(", provenance=");
|
||||
builder.append(provenance);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void recursivelyBuildSelectableLevels(int level, List<? extends LayerIDV> layersIDV) {
|
||||
|
||||
if (layersIDV == null)
|
||||
return;
|
||||
|
||||
mapInnestedFiltering.put(level, layersIDV);
|
||||
|
||||
for (LayerIDV layerIDV : layersIDV) {
|
||||
if (layerIDV instanceof CrossFilteringLayerDV) {
|
||||
CrossFilteringLayerDV crossFilteringLayer = (CrossFilteringLayerDV) layerIDV;
|
||||
|
||||
if (crossFilteringLayer.getRelated_to() != null) {
|
||||
recursivelyBuildSelectableLevels(++level, crossFilteringLayer.getRelated_to());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new overlay custom layer panel.
|
||||
*
|
||||
* @param listGroupedLayers the layer item
|
||||
* @param applicationBus the application bus
|
||||
*/
|
||||
public CrossFilteringLayerPanel(GroupedLayersDV<? extends LayerIDV> groupedLayersDV,
|
||||
HandlerManager applicationBus) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
this.applicationBus = applicationBus;
|
||||
this.groupedLayersDV = groupedLayersDV;
|
||||
GWT.log("Building cross-filtering for: " + groupedLayersDV);
|
||||
|
||||
int level = 0;
|
||||
// Building mapInnestedFiltering
|
||||
recursivelyBuildSelectableLevels(level, groupedLayersDV.getListCustomLayers());
|
||||
|
||||
GWT.log("cross-filtering mapInnestedFiltering: " + mapInnestedFiltering);
|
||||
|
||||
for (Integer theLevel : mapInnestedFiltering.keySet()) {
|
||||
addListBoxesLevelToPanel(theLevel, mapInnestedFiltering.get(theLevel));
|
||||
}
|
||||
|
||||
// filleSelectableLevel(level, mapInnestedFiltering.get(level),
|
||||
// mapInnestedListBoxes.get(level));
|
||||
|
||||
}
|
||||
|
||||
private void filleSelectableLevel(int level, List<? extends LayerIDV> layersIDV, List<ListBox> listBoxes) {
|
||||
|
||||
if (layersIDV == null)
|
||||
return;
|
||||
|
||||
HashMap<String, SelectableItem> mapSelectableFeatures = mapInnestedFeatures.get(level);
|
||||
|
||||
if (mapSelectableFeatures == null) {
|
||||
mapSelectableFeatures = new HashMap<String, SelectableItem>();
|
||||
HashMap<String, SelectableItem> mapFeatures = new HashMap<String, SelectableItem>();
|
||||
|
||||
for (LayerIDV layerIDV : layersIDV) {
|
||||
if (layerIDV instanceof CrossFilteringLayerDV) {
|
||||
CrossFilteringLayerDV crossFilteringLayer = (CrossFilteringLayerDV) layerIDV;
|
||||
String wfsURL = crossFilteringLayer.getWFS_URL();
|
||||
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsURL);
|
||||
|
||||
try {
|
||||
|
||||
Request response = builder.sendRequest(null, new RequestCallback() {
|
||||
public void onError(Request request, Throwable exception) {
|
||||
// Code omitted for clarity
|
||||
}
|
||||
|
||||
public void onResponseReceived(Request request, Response response) {
|
||||
JSONString json = new JSONString(response.getText());
|
||||
JSONValue parser = JSONParser.parse(response.getText());
|
||||
Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326,
|
||||
response.getText());
|
||||
for (Feature feature : features) {
|
||||
String key = feature.get(crossFilteringLayer.getTable_key_field());
|
||||
String parentKey = feature.get(crossFilteringLayer.getTable_parent_key_field());
|
||||
String itemField = feature.get(crossFilteringLayer.getTable_show_field());
|
||||
|
||||
parentKey = parentKey == null ? "" : parentKey;
|
||||
|
||||
SelectableItem selectableItem = new SelectableItem(key, parentKey, itemField,
|
||||
crossFilteringLayer.getName());
|
||||
|
||||
String mapKey = "root_" + parentKey + key;
|
||||
mapFeatures.put(mapKey, selectableItem);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (RequestException e) {
|
||||
// Code omitted for clarity
|
||||
}
|
||||
}
|
||||
}
|
||||
mapSelectableFeatures.putAll(mapFeatures);
|
||||
}
|
||||
|
||||
fillListBoxLevel(level, mapSelectableFeatures, listBoxes);
|
||||
// mapInnestedFeatures.put(level, mapSelectableFeatures);
|
||||
|
||||
}
|
||||
|
||||
private void addListBoxesLevelToPanel(int level, List<? extends LayerIDV> layersIDV) {
|
||||
|
||||
if (layersIDV == null)
|
||||
return;
|
||||
|
||||
List<ListBox> listBoxes = new ArrayList<ListBox>(layersIDV.size());
|
||||
|
||||
for (LayerIDV layerIDV : layersIDV) {
|
||||
ControlGroup cg = new ControlGroup();
|
||||
ControlLabel cl = new ControlLabel(layerIDV.getTitle());
|
||||
Controls controls = new Controls();
|
||||
ListBox listBox = new ListBox();
|
||||
listBox.addItem("Select " + layerIDV.getTitle() + " ...");
|
||||
listBoxes.add(listBox);
|
||||
|
||||
controls.add(listBox);
|
||||
cg.add(cl);
|
||||
cg.add(controls);
|
||||
|
||||
fieldSet.add(cg);
|
||||
}
|
||||
|
||||
mapInnestedListBoxes.put(level, listBoxes);
|
||||
}
|
||||
|
||||
private void fillListBoxLevel(int level, HashMap<String, SelectableItem> mapSelectableFeatures,
|
||||
List<ListBox> listBoxes) {
|
||||
|
||||
if (mapSelectableFeatures == null)
|
||||
return;
|
||||
|
||||
ListBox listBox = listBoxes.get(0); // Expected one
|
||||
|
||||
for (String key : mapSelectableFeatures.keySet()) {
|
||||
SelectableItem selItem = mapSelectableFeatures.get(key);
|
||||
listBox.addItem(selItem.getItemField(), key);
|
||||
}
|
||||
|
||||
listBox.addChangeHandler(new ChangeHandler() {
|
||||
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
loadInnerLevel(level);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadInnerLevel(int level) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
// public void resetCurrentSearch() {
|
||||
// searchField.setText("");
|
||||
// resetSearch.setVisible(false);
|
||||
// panelResults.clear();
|
||||
// latestResult = null;
|
||||
// appManagerBus.fireEvent(new SearchPerformedEvent(profileID, null, true));
|
||||
// setSearchEnabled(false);
|
||||
// }
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui"
|
||||
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
|
||||
<ui:style>
|
||||
.important {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.margin-left-10 {
|
||||
margin-left: 10px;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<g:ScrollPanel>
|
||||
<b:Form ui:field="panelForm">
|
||||
<b:Fieldset ui:field="fieldSet">
|
||||
</b:Fieldset>
|
||||
</b:Form>
|
||||
</g:ScrollPanel>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
@ -0,0 +1,55 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.client.ui.util;
|
||||
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
|
||||
|
||||
import ol.Feature;
|
||||
import ol.OLFactory;
|
||||
import ol.format.GeoJson;
|
||||
import ol.format.GeoJsonFeatureOptions;
|
||||
import ol.format.GeoJsonOptions;
|
||||
import ol.proj.Projection;
|
||||
import ol.proj.ProjectionOptions;
|
||||
|
||||
/**
|
||||
* The Class OLGeoJSONUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* May 25, 2023
|
||||
*/
|
||||
public class OLGeoJSONUtil {
|
||||
|
||||
/**
|
||||
* Builds the geo JSON.
|
||||
*
|
||||
* @param projection the projection
|
||||
* @param geoJSONString the geo JSON string
|
||||
* @return the geo json
|
||||
*/
|
||||
public static GeoJson buildGeoJSON(MAP_PROJECTION projection, String geoJSONString) {
|
||||
GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions();
|
||||
ProjectionOptions projectionOptions = new ProjectionOptions();
|
||||
projectionOptions.setCode(projection.getName());
|
||||
Projection fp = new Projection(projectionOptions);
|
||||
fo.setFeatureProjection(fp);
|
||||
fo.setDataProjection(fp);
|
||||
GeoJsonOptions geoJsonOpt = new GeoJsonOptions();
|
||||
geoJsonOpt.setDefaultDataProjection(fp);
|
||||
geoJsonOpt.setFeatureProjection(fp);
|
||||
return OLFactory.createGeoJSON(geoJsonOpt);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Read geo json features.
|
||||
*
|
||||
* @param projection the projection
|
||||
* @param geoJSONString the geo JSON string
|
||||
* @return the feature[]
|
||||
*/
|
||||
public static Feature[] readGeoJsonFeatures(MAP_PROJECTION projection, String geoJSONString) {
|
||||
GeoJson geoJson = buildGeoJSON(projection, geoJSONString);
|
||||
return geoJson.readFeatures(geoJSONString);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue