diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerPanel.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerPanel.java index 43e2674..9ee20c2 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerPanel.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerPanel.java @@ -309,74 +309,6 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle layersPanel.addLayerItems(layerItems, false); layersPanel.updateLayersOrder(); } - - - - /** - * - * Addeb by Francesco - * Extension of addLayerByWms, with input parameter is external layer - * @param title - * @param layerName - * @param url - * @param isExternal - * @param isBase - * @param displayInLayerSwitcher - * @param styles - the first style of list must be the default style - */ - public void addLayerByWms(LayerType layerType, String title, String layerName, String url, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, ArrayList styles) { - LayerItem l = new LayerItem(); - l.setBaseLayer(isBase); - l.setTitle(title); - l.setName(layerName); - l.setLayer(layerName); - l.setUrl(url); - l.setGeoserverUrl(url); - l.setGeoserverWmsUrl(url); - l.setExternal(isExternal); - l.setOpacity(1d); - l.setBuffer(2); - - switch (layerType) { - - //TODO IMPLEMENT THIS CASE - case RASTER: - - l.setHasLegend(false); - l.setBaseLayer(true); - l.setTrasparent(false); - l.setClickData(false); - - break; - - case FEATURETYPE: - - //CASE FEATURE TYPE - l.setBaseLayer(false); - l.setClickData(true); - l.setTrasparent(true); - - break; - - } - - if(styles!=null & styles.size()>0){ - l.setHasLegend(true); - l.setDefaultStyle(styles.get(0)); - l.setStyle(styles.get(0)); - l.setStyles(styles); - } - - - - - List layerItems = new ArrayList(); - layerItems.add(l); - - openLayersMap.addLayerItemByWms(l, displayInLayerSwitcher); - layersPanel.addLayerItems(layerItems, false); - layersPanel.updateLayersOrder(); - } private void addLayersOnMap(List layerItems, boolean toTop) { for (LayerItem layerItem : layerItems) @@ -861,5 +793,111 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle showDataPanel(); } } + + /** + * + * Addeb by Francesco + * Extension of addLayerByWms, with input parameter is external layer + * @param title + * @param layerName + * @param url + * @param isExternal + * @param isBase + * @param displayInLayerSwitcher + * @param styles - the first style of list must be the default style + * @param onTop + */ + public void addLayerByWms(LayerType layerType, String title, String layerName, String url, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, ArrayList styles, boolean onTop) { + LayerItem l = new LayerItem(); + l.setBaseLayer(isBase); + l.setTitle(title); + l.setName(layerName); + l.setLayer(layerName); + l.setUrl(url); + l.setGeoserverUrl(url); + l.setGeoserverWmsUrl(url); + l.setExternal(isExternal); + l.setOpacity(1d); + l.setBuffer(2); + + switch (layerType) { + + //TODO IMPLEMENT THIS CASE + case RASTER: + + l.setHasLegend(false); + l.setBaseLayer(true); + l.setTrasparent(false); + l.setClickData(false); + + break; + + case FEATURETYPE: + + //CASE FEATURE TYPE + l.setBaseLayer(false); + l.setClickData(true); + l.setTrasparent(true); + + break; + + } + + if(styles!=null & styles.size()>0){ + l.setHasLegend(true); + l.setDefaultStyle(styles.get(0)); + l.setStyle(styles.get(0)); + l.setStyles(styles); + } + + List layerItems = new ArrayList(); + layerItems.add(l); + + openLayersMap.addLayerItemByWms(l, displayInLayerSwitcher); + layersPanel.addLayerItems(layerItems, onTop); + layersPanel.updateLayersOrder(); + } + + + /** + * Addeb by Francesco + * + * @param layerType + * @param listLayerItem + * @param onTop + */ + public void addLayerItemsByWms(LayerType layerType, List listLayerItem, boolean onTop) { + + for (LayerItem l : listLayerItem) { + + switch (layerType) { + + //TODO IMPLEMENT THIS CASE + case RASTER: + + l.setHasLegend(false); + l.setBaseLayer(true); + l.setTrasparent(false); + l.setClickData(false); + + break; + + case FEATURETYPE: + + //CASE FEATURE TYPE + l.setBaseLayer(false); + l.setClickData(true); + l.setTrasparent(true); + + break; + + } + + openLayersMap.addLayerItemByWms(l, false); + } + + layersPanel.addLayerItems(listLayerItem, onTop); + layersPanel.updateLayersOrder(); + } } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerService.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerService.java index f5f2546..3dee319 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerService.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerService.java @@ -6,6 +6,7 @@ import java.util.List; import org.gcube.portlets.user.gisviewer.client.commons.beans.DataResult; import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItem; import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItemsResult; +import org.gcube.portlets.user.gisviewer.client.commons.beans.Property; import org.gcube.portlets.user.gisviewer.client.commons.beans.WfsTable; import com.google.gwt.user.client.rpc.RemoteService; @@ -29,6 +30,17 @@ public interface GisViewerService extends RemoteService { List getDataResult(List layerItems, String bbox); + + + /** + * Added by Francesco M. 10/09/2013 + * @param geoserverUrl + * @param layer + * @return + */ + List getListProperty(String geoserverUrl, LayerItem layer); + + // LayerItemsResult getLayersInfoByLayerConfigurations(List layerConfigurations); } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerServiceAsync.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerServiceAsync.java index 66305b7..47614c4 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerServiceAsync.java @@ -6,6 +6,7 @@ import java.util.List; import org.gcube.portlets.user.gisviewer.client.commons.beans.DataResult; import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItem; import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItemsResult; +import org.gcube.portlets.user.gisviewer.client.commons.beans.Property; import org.gcube.portlets.user.gisviewer.client.commons.beans.WfsTable; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -27,6 +28,9 @@ public interface GisViewerServiceAsync { public void getDataResult(List layerItems, String bbox, AsyncCallback> asyncCallback); + void getListProperty(String geoserverUrl, LayerItem layer, + AsyncCallback> callback); + // public void getLayersInfoByLayerConfigurations(List layerConfigurations, AsyncCallback asyncCallback); } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/commons/beans/Property.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/commons/beans/Property.java index 1a6e92d..e3fdc94 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/commons/beans/Property.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/commons/beans/Property.java @@ -70,4 +70,23 @@ public class Property implements IsSerializable, Cloneable { public void setMinOccours(int minOccours) { this.minOccours = minOccours; } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Property [name="); + builder.append(name); + builder.append(", type="); + builder.append(type); + builder.append(", nillable="); + builder.append(nillable); + builder.append(", maxOccours="); + builder.append(maxOccours); + builder.append(", minOccours="); + builder.append(minOccours); + builder.append("]"); + return builder.toString(); + } + + } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/layerspanel/LayerToolsPanel.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/layerspanel/LayerToolsPanel.java index 41c60d9..3fdcb50 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/layerspanel/LayerToolsPanel.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/layerspanel/LayerToolsPanel.java @@ -1,8 +1,11 @@ package org.gcube.portlets.user.gisviewer.client.layerspanel; +import java.util.List; + import org.gcube.portlets.user.gisviewer.client.Constants; import org.gcube.portlets.user.gisviewer.client.GisViewer; import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItem; +import org.gcube.portlets.user.gisviewer.client.commons.beans.Property; import org.gcube.portlets.user.gisviewer.client.resources.Images; import com.extjs.gxt.ui.client.event.BaseEvent; @@ -23,6 +26,7 @@ import com.extjs.gxt.ui.client.widget.menu.Menu; import com.extjs.gxt.ui.client.widget.menu.MenuItem; import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem; import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; +import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.MouseOutEvent; @@ -30,6 +34,7 @@ import com.google.gwt.event.dom.client.MouseOutHandler; import com.google.gwt.event.dom.client.MouseOverEvent; import com.google.gwt.event.dom.client.MouseOverHandler; import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.AbstractImagePrototype; import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; @@ -93,6 +98,10 @@ public class LayerToolsPanel extends VerticalPanel { private boolean cqlTipInserted=false; private boolean transectTipInserted=false; + + // TOOLBAR TRANSECT, FILTER AND EXPORT + private ToolBar toolBar1 = new ToolBar(); +// private Button btnTransect = new Button(""); @@ -101,6 +110,8 @@ public class LayerToolsPanel extends VerticalPanel { super(); this.layerItem = layerItem; this.layersPanelHandler = layersPanelHandler; + +// this.btnTransect.setVisible(false); setTransectInfo(); this.setTableWidth("100%"); @@ -130,20 +141,9 @@ public class LayerToolsPanel extends VerticalPanel { this.add(cp); } - - private void createTools() { - tools = new VerticalPanel(); - tools.setStyleAttribute("padding-left", TOOLS_PADDING); - //tools.setStyleAttribute("background-color", "#E5E5E5"); - tools.setStyleName("layersPanel2"); - tools.setHeight(LAYER_TOOLS_PANEL_HEIGHT); - - // TOOLBAR TRANSECT, FILTER AND EXPORT - ToolBar toolBar1 = new ToolBar(); - toolBar1.setStyleName("myToolbar"); // TODO define style - toolBar1.add(new SizedLabel("General", 10)); - toolBar1.add(new SeparatorToolItem()); - + + private void activeTransect(){ + if ((tableTransect!=null && fieldTransect!=null)) { // transect button Button btnTransect = new Button("", Images.iconTransect(), new SelectionListener(){ @@ -155,9 +155,44 @@ public class LayerToolsPanel extends VerticalPanel { }); btnTransect.setToolTip("Generate a Transect function"); //btnTransect.setEnabled((tableTransect!=null && fieldTransect!=null)); +// toolBar1.layout(); toolBar1.add(btnTransect); + tools.layout(true); } + + } + + private void createTools() { + tools = new VerticalPanel(); + tools.setStyleAttribute("padding-left", TOOLS_PADDING); + //tools.setStyleAttribute("background-color", "#E5E5E5"); + tools.setStyleName("layersPanel2"); + tools.setHeight(LAYER_TOOLS_PANEL_HEIGHT); + + // TOOLBAR TRANSECT, FILTER AND EXPORT + toolBar1.setStyleName("myToolbar"); // TODO define style + toolBar1.add(new SizedLabel("General", 10)); + toolBar1.add(new SeparatorToolItem()); +// this.toolBar1.add(btnTransect); + + activeTransect(); + + +// if ((tableTransect!=null && fieldTransect!=null)) { +// // transect button +// Button btnTransect = new Button("", Images.iconTransect(), new SelectionListener(){ +// @Override +// public void componentSelected(ButtonEvent ce) { +// setTransectTip(true); +// layersPanelHandler.activateTransect(layerItem, tableTransect, fieldTransect); +// } +// }); +// btnTransect.setToolTip("Generate a Transect function"); +// //btnTransect.setEnabled((tableTransect!=null && fieldTransect!=null)); +// toolBar1.add(btnTransect); +// } + // filter button Button btnFilter = new Button("", Images.iconFilter(), new SelectionListener(){ @Override @@ -466,6 +501,49 @@ public class LayerToolsPanel extends VerticalPanel { foundDefaultStyle = true; } } + + + GisViewer.service.getListProperty(layerItem.getGeoserverUrl(), layerItem, new AsyncCallback>() { + + @Override + public void onFailure(Throwable caught) { + GWT.log("error on get list property", caught); + + } + + @Override + public void onSuccess(List result) { + layerItem.setProperties(result); + + + System.out.println("property "+layerItem.getProperties()); + if(result!=null && result.size()>0){ + + boolean cointainsPropertyTransect = false; + + if (layerItem.containsProperty("maxspeciescountinacell")) { + fieldTransect = "maxspeciescountinacell"; + tableTransect = layerItem.getName(); + cointainsPropertyTransect = true; + } else if (layerItem.containsProperty("probability")) { + + System.out.println("layerItem.containsProperty "); + + fieldTransect = "probability"; + tableTransect = layerItem.getName(); + cointainsPropertyTransect = true; + } + + System.out.println("cointainsPropertyTransect "+cointainsPropertyTransect); + + if(cointainsPropertyTransect) + activeTransect(); + } + + + + } + }); //COMMENTED BY FRANCESCO M. diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/server/GisViewerServiceImpl.java b/src/main/java/org/gcube/portlets/user/gisviewer/server/GisViewerServiceImpl.java index 461c8b4..340923f 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/server/GisViewerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/server/GisViewerServiceImpl.java @@ -573,4 +573,14 @@ public abstract class GisViewerServiceImpl extends RemoteServiceServlet implemen List result = FeatureParser.getDataResults(layerItems, bbox); return result; } + + + @Override + public List getListProperty(String geoserverUrl, LayerItem layer){ + System.out.println("getListProperty"); + // set layer properties info + return FeatureTypeParser.getProperties(geoserverUrl, layer.getLayer()); + } + + } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/server/datafeature/FeatureTypeParser.java b/src/main/java/org/gcube/portlets/user/gisviewer/server/datafeature/FeatureTypeParser.java index 192b863..7e4b911 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/server/datafeature/FeatureTypeParser.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/server/datafeature/FeatureTypeParser.java @@ -16,11 +16,16 @@ import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class FeatureTypeParser { + + public static List getProperties(String geoserverURL, String layerName) { String wfsRequestURL = geoserverURL + "/wfs?service=wfs&version=1.1.0&request=DescribeFeatureType&typeName=" + layerName; + +// System.out.println("wfsRequestURL "+wfsRequestURL); + List properties = new ArrayList(); try {