2014-10-10 18:54:43 +02:00
|
|
|
package org.gcube.portlets.user.td.mapwidget.client;
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-13 11:58:16 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.map.MapCreationSession;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
2014-10-15 18:45:33 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
|
2014-10-13 11:58:16 +02:00
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
|
2014-10-10 18:54:43 +02:00
|
|
|
import org.gcube.portlets.user.td.wizardwidget.client.WizardWindow;
|
2014-10-13 11:58:16 +02:00
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2014-10-10 18:54:43 +02:00
|
|
|
import com.google.web.bindery.event.shared.EventBus;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author giancarlo
|
|
|
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class MapWidgetTD extends WizardWindow {
|
|
|
|
|
2014-10-13 11:58:16 +02:00
|
|
|
protected MapCreationSession mapCreationSession;
|
2014-10-10 18:54:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param title
|
|
|
|
* @param eventBus
|
|
|
|
*/
|
2014-10-15 18:45:33 +02:00
|
|
|
public MapWidgetTD(TRId trId, UserInfo userInfo, String title, EventBus eventBus) {
|
2014-10-10 18:54:43 +02:00
|
|
|
super(title,eventBus);
|
|
|
|
|
2014-10-13 11:58:16 +02:00
|
|
|
mapCreationSession= new MapCreationSession();
|
|
|
|
mapCreationSession.setTrId(trId);
|
2014-10-15 18:45:33 +02:00
|
|
|
mapCreationSession.setUsername(userInfo.getUsername());
|
2014-10-13 11:58:16 +02:00
|
|
|
retrieveColumns();
|
|
|
|
}
|
2014-10-10 18:54:43 +02:00
|
|
|
|
|
|
|
|
2014-10-13 11:58:16 +02:00
|
|
|
private void startMapCreation() {
|
|
|
|
MapWidgetConfigCard mapWidgetConfigCard=new MapWidgetConfigCard(mapCreationSession);
|
|
|
|
addCard(mapWidgetConfigCard);
|
|
|
|
mapWidgetConfigCard.setup();
|
|
|
|
show();
|
2014-10-10 18:54:43 +02:00
|
|
|
}
|
2014-10-13 11:58:16 +02:00
|
|
|
|
2014-10-10 18:54:43 +02:00
|
|
|
|
2014-10-13 11:58:16 +02:00
|
|
|
|
2014-10-10 18:54:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-13 11:58:16 +02:00
|
|
|
protected void retrieveColumns(){
|
|
|
|
TDGWTServiceAsync.INSTANCE
|
|
|
|
.getColumns(new AsyncCallback<ArrayList<ColumnData>>() {
|
|
|
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
|
|
eventBus
|
|
|
|
.fireEvent(
|
|
|
|
new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
if (caught instanceof TDGWTIsLockedException) {
|
|
|
|
Log.error(caught.getLocalizedMessage());
|
|
|
|
showErrorAndHide("Error Locked",
|
|
|
|
caught.getLocalizedMessage(), caught);
|
|
|
|
} else {
|
|
|
|
Log.error("No load columns: "
|
|
|
|
+ caught.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onSuccess(ArrayList<ColumnData> result) {
|
|
|
|
Log.trace("loaded " + result.size() + " columns");
|
|
|
|
ArrayList<ColumnData> geometryColumnsList=new ArrayList<ColumnData>();
|
|
|
|
boolean existsGeometryColumn=false;
|
|
|
|
int countGeometryColumns=0;
|
|
|
|
for(ColumnData column:result){
|
|
|
|
if(column.getDataTypeName().compareTo(ColumnDataType.Geometry.toString())==0){
|
|
|
|
existsGeometryColumn=true;
|
|
|
|
countGeometryColumns++;
|
|
|
|
geometryColumnsList.add(column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mapCreationSession.setColumns(result);
|
|
|
|
mapCreationSession.setGeometryColumns(geometryColumnsList);
|
|
|
|
mapCreationSession.setExistsGeometryColumn(existsGeometryColumn);
|
|
|
|
mapCreationSession.setCountGeometryColumns(countGeometryColumns);
|
|
|
|
|
|
|
|
if(!existsGeometryColumn){
|
|
|
|
Log.info("Attention, no Geometry Column present!");
|
2014-10-14 10:11:55 +02:00
|
|
|
showErrorAndHide("Attention",
|
|
|
|
"No Geometry Column Present!",new Throwable("No Geometry Column Present!"));
|
2014-10-13 11:58:16 +02:00
|
|
|
close(false);
|
|
|
|
} else {
|
|
|
|
if(countGeometryColumns==1){
|
|
|
|
mapCreationSession.setGeometry(geometryColumnsList.get(0));
|
|
|
|
}
|
|
|
|
startMapCreation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2014-10-10 18:54:43 +02:00
|
|
|
}
|