add new layer by wms request

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gis-viewer-app@101732 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-11-27 16:40:58 +00:00
parent 51bc0404e7
commit 1cf76320c1
8 changed files with 331 additions and 26 deletions

View File

@ -6,6 +6,9 @@
<dependent-module archiveName="gis-viewer-3.6.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gisViewer/gisViewer">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="geoserverinterface-1.10.4-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoserverinterface/geoserverinterface">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="gis-viewer-app"/>
</wb-module>

View File

@ -10,10 +10,16 @@ import org.gcube.portlets.user.gisviewer.client.DataPanelOpenListener;
import org.gcube.portlets.user.gisviewer.client.GisViewerPanel;
import org.gcube.portlets.user.gisviewer.client.GisViewerParameters;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.fx.Resizable;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
@ -22,7 +28,7 @@ import com.google.gwt.user.client.ui.RootPanel;
* @Oct 8, 2014
*
*/
public class ApplicationController {
public class ApplicationController implements WmsDialogHandler{
/**
*
@ -32,6 +38,10 @@ public class ApplicationController {
private ContentPanel gisViewerContentPanel;
private LayoutContainer mainPanel;
private GisViewerParameters gisViewerParameters;
private BaloonPanel baloonWMS;
private LayoutContainer lcWMS = new LayoutContainer();
private WmsRequestConverter wmsRequestConverter;
private final ApplicationController INSTANCE = this;
/**
*
*/
@ -43,6 +53,7 @@ public class ApplicationController {
gisViewerPanel = new GisViewerPanel(gisViewerParameters);
initGisViewerContentPanel();
gisViewerContentPanel.add(gisViewerPanel);
wmsRequestConverter = new WmsRequestConverter(gisViewerPanel);
mainPanel.add(gisViewerContentPanel);
}
@ -106,7 +117,7 @@ public class ApplicationController {
/**
* @param rootPanel
*/
public void go(RootPanel rootPanel) {
public void go(final RootPanel rootPanel) {
rootPanel.add(mainPanel);
String wmsRequest = Window.Location.getParameter(ConstantGisViewerApp.GET_WMS_PARAMETER);
@ -121,17 +132,59 @@ public class ApplicationController {
// wmsRequest = wmsRequest.replaceAll(replacement, wmsRequest);
// }
WmsRequestConverter convert = new WmsRequestConverter(gisViewerPanel);
try {
convert.parseRequest(wmsRequest);
convert.addRequestToGisViewer();
wmsRequestConverter.parseRequest(wmsRequest,null);
wmsRequestConverter.addRequestToGisViewer();
} catch (Exception e) {
ConstantGisViewerApp.logger.log(Level.INFO, "An error occurred on adding wmsrequest :"+wmsRequest);
e.printStackTrace();
}
}
rootPanel.add(lcWMS);
lcWMS.setId("WMS");
Command cmd = new Command() {
@Override
public void execute() {
WmsDialog win = new WmsDialog(INSTANCE);
win.show();
}
};
baloonWMS = new BaloonPanel("+WMS", false, cmd);
lcWMS.addListener(Events.Render, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
Timer tm = new Timer() {
@Override
public void run() {
String zi = rootPanel.getElement().getStyle().getZIndex();
GWT.log("zindex "+zi);
int zIndex = 50;
try{
zIndex += Integer.parseInt(zi);
}catch(NumberFormatException e){
}
baloonWMS.getElement().getStyle().setZIndex(zIndex);
}
};
tm.schedule(1000);
}
});
}
/**
*
* @param wmsRequest
@ -151,4 +204,25 @@ public class ApplicationController {
return gisViewerPanel;
}
/**
*
*/
public void moveWMSBalloon() {
baloonWMS.showRelativeTo(lcWMS);
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.gisviewerapp.client.WmsDialogHandler#addWmsLayer(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void addWmsLayer(String displayName, String url) {
try {
wmsRequestConverter.parseRequest(url, displayName);
wmsRequestConverter.addRequestToGisViewer();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,52 @@
/**
*
*/
package org.gcube.portlets.user.gisviewerapp.client;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.PopupPanel;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Mar 21, 2014
*
*/
public class BaloonPanel extends PopupPanel{
private boolean shouldHide = false;
private Command command;
/**
*
* @param baloonText
* @param shouldHide
* @param cmd on Click
*/
public BaloonPanel(String baloonText, boolean shouldHide, Command cmd) {
super(shouldHide);
this.shouldHide = shouldHide;
this.command = cmd;
setAutoHideEnabled(shouldHide);
setStyleName("baloonPanel");
// some sample widget will be content of the balloon
HTML text = new HTML(baloonText);
text.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
command.execute();
}
});
setWidget(text);
}
@Override
public void show() {
super.show();
}
}

View File

@ -59,5 +59,6 @@ public class GisViewerApp implements EntryPoint {
appController.getMainPanel().setHeight(rootHeight);
appController.getMainPanel().setWidth(rootWidth);
appController.moveWMSBalloon();
}
}

View File

@ -0,0 +1,128 @@
package org.gcube.portlets.user.gisviewerapp.client;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.google.gwt.event.dom.client.KeyCodes;
/**
* @author ceras
*
*/
public class WmsDialog extends Dialog {
private static final String WMS_DIALOG_HEADING = "Add WMS Layer";
private TextField<String> displayName = new TextField<String>();
private TextField<String> url = new TextField<String>();
private WmsDialogHandler handler;
private FormData formData;
private FormPanel form;
/**
*
*/
public WmsDialog(WmsDialogHandler handler) {
super();
this.handler = handler;
this.setHeading(WMS_DIALOG_HEADING);
this.setButtons(Dialog.OK);
//dialog.setBodyStyleName("pad-text");
// this.setAutoWidth(true);
this.setModal(true);
this.setWidth(400);
this.setScrollMode(Scroll.AUTO);
this.setClosable(true);
this.setHideOnButtonClick(true);
this.addListener(Events.Close, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
hide();
}
});
Button okButton = (Button)(this.getButtonBar().getItemByItemId("ok"));
okButton.removeAllListeners();
okButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
submit();
}
});
// this.addListener(Events.clos, new Listener<BaseEvent>() {
// public void handleEvent(BaseEvent be) {
// hide();
// }
// });
KeyListener keyListener = new KeyListener(){
@Override
public void componentKeyDown(ComponentEvent event) {
super.componentKeyDown(event);
if (event.getKeyCode() == KeyCodes.KEY_ENTER)
submit();
}
};
VerticalPanel vp = new VerticalPanel();
// init title field
displayName = new TextField<String>();
displayName.setWidth(300);
displayName.setAllowBlank(true);
displayName.setFieldLabel("TITLE");
displayName.setEmptyText("Enter layer display name (optional)...");
displayName.addKeyListener(keyListener);
// init title field
url = new TextField<String>();
url.setWidth(300);
url.setAllowBlank(false);
url.setFieldLabel("Layer WMS URL");
url.setEmptyText("Enter layer WMS URL...");
url.addKeyListener(keyListener);
createForm();
}
/**
*
*/
private void createForm() {
formData = new FormData("-20");
form = new FormPanel();
// form.setHeading(WMS_DIALOG_HEADING);
form.setFrame(true);
form.setHeaderVisible(false);
form.add(displayName, formData);
form.add(url, formData);
displayName.setAllowBlank(true);
url.setAllowBlank(false);
this.add(form);
}
private void submit() {
String name = this.displayName.getValue();
String url = this.url.getValue();
if (url==null)
MessageBox.alert("Error", "Insert a valid WMS URL", null);
else {
handler.addWmsLayer(name, url);
this.hide();
}
}
}

View File

@ -0,0 +1,18 @@
package org.gcube.portlets.user.gisviewerapp.client;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Nov 27, 2014
*
*/
public interface WmsDialogHandler {
/**
* @param displayTitle
* @param url
*/
void addWmsLayer(String displayTitle, String url);
}

View File

@ -10,6 +10,8 @@ import org.gcube.portlets.user.gisviewer.client.GisViewerPanel;
import org.gcube.portlets.user.gisviewer.client.GisViewerPanel.LayerType;
import org.gcube.portlets.user.gisviewerapp.shared.WmsParameters;
import com.google.gwt.user.client.Window;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Oct 9, 2014
@ -21,7 +23,7 @@ public class WmsRequestConverter {
private LayerType layerType = LayerType.FEATURETYPE;
private String title;
private String layerName;
private String displayLayerName;
private String url;
private boolean isExternal = false;
private boolean isBase = false;
@ -37,7 +39,7 @@ public class WmsRequestConverter {
this.gisViewer = gisViewerPanel;
}
public void parseRequest(String wmsRequest) throws Exception{
public void parseRequest(String wmsRequest, String displayName) throws Exception{
this.wmsRequest = wmsRequest;
//FIND BASE URL
@ -46,16 +48,20 @@ public class WmsRequestConverter {
url = wmsRequest.substring(0, indexStart); //get only parameters
url = url.trim(); //string trim
}else{
throw new Exception("Bad server request '?' not found!");
Window.alert("Bad wms request '?' not found!");
// throw new Exception("Bad server request '?' not found!");
}
//FIND LAYERS NAME (AND TITLE)
String value = getValueOfParameter(WmsParameters.LAYERS, wmsRequest);
if(value==null || value.isEmpty()){
Window.alert("Bad wms request LAYER parameter not found!");
throw new Exception("Layer name not found!");
}else{
layerName = value;
displayLayerName = value;
title = value;
if(displayName!=null && !displayName.isEmpty())
displayLayerName = displayName;
}
//FIND STILE
@ -65,7 +71,7 @@ public class WmsRequestConverter {
}
public void addRequestToGisViewer(){
gisViewer.addLayerByWms(GisViewerPanel.LayerType.FEATURETYPE, layerName, title, url, isExternal, isBase, displayInLayerSwitcher, listStyles, wmsRequest, onTop);
gisViewer.addLayerByWms(GisViewerPanel.LayerType.FEATURETYPE, displayLayerName, title, url, isExternal, isBase, displayInLayerSwitcher, listStyles, wmsRequest, onTop);
}
private String getValueOfParameter(WmsParameters wmsParam, String url){
@ -102,7 +108,7 @@ public class WmsRequestConverter {
}
public String getLayerName() {
return layerName;
return displayLayerName;
}
public String getUrl() {
@ -142,7 +148,7 @@ public class WmsRequestConverter {
}
public void setLayerName(String layerName) {
this.layerName = layerName;
this.displayLayerName = layerName;
}
public void setUrl(String url) {
@ -183,7 +189,7 @@ public class WmsRequestConverter {
builder.append(", title=");
builder.append(title);
builder.append(", layerName=");
builder.append(layerName);
builder.append(displayLayerName);
builder.append(", url=");
builder.append(url);
builder.append(", isExternal=");

View File

@ -1,34 +1,57 @@
/** Add css rules here for your application. */
/** Example rules used by the template application (remove for your app) */
h1 {
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
}
.sendButton {
display: block;
font-size: 16pt;
display: block;
font-size: 16pt;
}
/** Most GWT widgets already have a style name defined */
.gwt-DialogBox {
width: 400px;
width: 400px;
}
.dialogVPanel {
margin: 5px;
margin: 5px;
}
.serverResponseLabelError {
color: red;
color: red;
}
/** Set ids using widget.getElement().setId("idOfElement") */
#closeButton {
margin: 15px 6px 6px;
margin: 15px 6px 6px;
}
.baloonPanel {
padding: 5px;
border: solid;
border-width: 1px;
border-color: rgb(200, 210, 240);
/* border-radius: 15px; */
-webkit-border-top-right-radius: 10px;
-webkit-border-bottom-right-radius: 10px;
-moz-border-radius-topright: 10px;
-moz-border-radius-bottomright: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
background-color: #0B3C9E;
color: #D2D2D2;
font-family: verdana, arial;
font-size: 10px;
margin-left: 1px;
opacity: 0.8;
}
.baloonPanel :HOVER {
cursor: pointer;
color: #FFF;
}