geoportal-data-viewer-app/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/products/concessioni/ConcessioneView.java

357 lines
12 KiB
Java
Raw Normal View History

2020-11-19 15:19:27 +01:00
package org.gcube.portlets.user.geoportaldataviewer.client.ui.products.concessioni;
2021-07-21 12:13:24 +02:00
import java.util.ArrayList;
2020-11-19 15:19:27 +01:00
import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelazioneScavoDV;
import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils;
2020-11-20 18:10:43 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.ModalWindow;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.dialogs.DialogShareableLink;
2021-07-19 18:04:14 +02:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.gallery.ImagesGallery;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.MapView;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.CustomFlexTable;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.PageHeader;
import com.github.gwtbootstrap.client.ui.Paragraph;
import com.github.gwtbootstrap.client.ui.Thumbnails;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.github.gwtbootstrap.client.ui.constants.IconType;
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.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
2021-01-15 15:12:03 +01:00
import com.google.gwt.user.client.Window;
2020-11-19 15:19:27 +01:00
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
import ol.Coordinate;
import ol.OLFactory;
2020-11-19 15:19:27 +01:00
public class ConcessioneView extends Composite {
private static ConcessioneViewUiBinder uiBinder = GWT.create(ConcessioneViewUiBinder.class);
interface ConcessioneViewUiBinder extends UiBinder<Widget, ConcessioneView> {
}
@UiField
PageHeader titolo;
@UiField
Paragraph introduzione;
@UiField
HTMLPanel concessioniPanel;
@UiField
HTMLPanel relazioneScavoPanel;
@UiField
HTMLPanel imagesPanel;
@UiField
HTMLPanel pageViewDetails;
@UiField
HTMLPanel mapViewPanel;
@UiField
HTMLPanel posizionamentoAreaIndaginePanel;
@UiField
HTMLPanel piantaFineScavoPanel;
// @UiField
// HTMLPanel sharePanel;
@UiField
Button shareButton;
@UiField
2020-11-20 18:10:43 +01:00
Button viewButton;
2020-11-19 15:19:27 +01:00
private ConcessioneDV concessioneDV;
private Thumbnails thumbNails = new Thumbnails();
private CustomFlexTable customTable = new CustomFlexTable();
private GeoNaItemRef geonaItemRef;
private String myLogin;
2020-11-20 18:10:43 +01:00
private boolean viewImageButtonVisible = true;
private boolean openImageButtonVisible = true;
2020-11-19 15:19:27 +01:00
private ConcessioneView() {
initWidget(uiBinder.createAndBindUi(this));
pageViewDetails.getElement().setId("page-view-details");
}
2020-11-20 18:10:43 +01:00
2020-11-19 15:19:27 +01:00
public ConcessioneView(GeoNaItemRef item, ConcessioneDV concDV) {
2020-11-20 18:10:43 +01:00
this(item, concDV, true, true);
}
public ConcessioneView(GeoNaItemRef item, ConcessioneDV concDV, boolean viewImageButtonVisible, boolean openImageButtonVisible) {
2020-11-19 15:19:27 +01:00
this();
GWT.log("Rendering "+concDV.getNome());
2020-11-19 15:19:27 +01:00
this.concessioneDV = concDV;
this.geonaItemRef = item;
2020-11-20 18:10:43 +01:00
this.viewImageButtonVisible = viewImageButtonVisible;
this.openImageButtonVisible = openImageButtonVisible;
2020-11-19 15:19:27 +01:00
titolo.setText(concessioneDV.getNome());
introduzione.setText(concessioneDV.getIntroduzione());
if (concessioneDV.getDataInizioProgetto() != null) {
customTable.addNextKeyValue("Data Inizio Progetto", concessioneDV.getDataInizioProgetto());
2020-11-19 15:19:27 +01:00
}
if (concessioneDV.getDataFineProgetto() != null) {
customTable.addNextKeyValue("Data Fine Progetto", concessioneDV.getDataFineProgetto());
}
if (concessioneDV.getParoleChiaveLibere() != null) {
customTable.addNextKeyValues("Parole chiave Libere", concessioneDV.getParoleChiaveLibere(), GeoportalDataViewerConstants.NEW_LINE_BR);
2020-11-19 15:19:27 +01:00
}
if (concessioneDV.getParoleChiaveICCD() != null) {
customTable.addNextKeyValues("Parole chiave Cronologia", concessioneDV.getParoleChiaveICCD(), GeoportalDataViewerConstants.NEW_LINE_BR);
}
if (concessioneDV.getAuthors() != null) {
customTable.addNextKeyValues("Autori", concessioneDV.getAuthors(), GeoportalDataViewerConstants.NEW_LINE_BR);
}
if (concessioneDV.getContributore() != null) {
customTable.addNextKeyValue("Contributore", concessioneDV.getContributore());
}
if (concessioneDV.getEditore() != null) {
customTable.addNextKeyValue("Editore", concessioneDV.getEditore());
}
if (concessioneDV.getResponsabile() != null) {
customTable.addNextKeyValue("Responsabile", concessioneDV.getResponsabile());
}
if (concessioneDV.getRisorseCorrelate() != null) {
customTable.addNextKeyValues("Risorse Correlate", concessioneDV.getRisorseCorrelate(), GeoportalDataViewerConstants.NEW_LINE_BR);
}
if (concessioneDV.getTitolari() != null) {
customTable.addNextKeyValues("Titolari dei dati", concessioneDV.getTitolari(), GeoportalDataViewerConstants.NEW_LINE_BR);
}
if (concessioneDV.getSoggetto() != null) {
customTable.addNextKeyValues("Soggetti", concessioneDV.getSoggetto(), GeoportalDataViewerConstants.NEW_LINE_BR);
}
if (concessioneDV.getEditore() != null) {
customTable.addNextKeyValue("Editore", concessioneDV.getEditore());
}
if (concessioneDV.getFontiFinanziamento() != null) {
customTable.addNextKeyValues("Fonti di Finanziamento", concessioneDV.getFontiFinanziamento(), GeoportalDataViewerConstants.NEW_LINE_BR);
}
if (concessioneDV.getLicenzaID() != null) {
customTable.addNextKeyValue("ID Licenza", concessioneDV.getLicenzaID());
}
if (concessioneDV.getTitolariLicenza() != null) {
customTable.addNextKeyValues("Titolare Licenza", concessioneDV.getTitolariLicenza(), GeoportalDataViewerConstants.NEW_LINE_BR);
2020-11-19 15:19:27 +01:00
}
if (concessioneDV.getTitolariCopyright() != null) {
customTable.addNextKeyValues("Titolare Copyright", concessioneDV.getTitolariCopyright(),GeoportalDataViewerConstants.NEW_LINE_BR);
2020-11-19 15:19:27 +01:00
}
shareButton.setType(ButtonType.LINK);
shareButton.setIcon(IconType.SHARE);
shareButton.setTitle("Get a link to share with...");
shareButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
DialogShareableLink dg = new DialogShareableLink(geonaItemRef, null);
}
});
2020-11-20 18:10:43 +01:00
viewButton.setType(ButtonType.LINK);
viewButton.setIcon(IconType.EXPAND);
viewButton.setTitle("View Details in New Dialog");
2020-11-19 15:19:27 +01:00
2020-11-20 18:10:43 +01:00
viewButton.addClickHandler(new ClickHandler() {
2020-11-19 15:19:27 +01:00
@Override
public void onClick(ClickEvent event) {
2020-11-20 18:10:43 +01:00
ConcessioneView cv = new ConcessioneView(geonaItemRef, concessioneDV, false, openImageButtonVisible);
cv.setViewDetailsButtonVisible(false);
2021-01-15 15:12:03 +01:00
int width = Window.getClientWidth()*75/100;
int height = Window.getClientHeight()*70/100;
ModalWindow mw = new ModalWindow(concessioneDV.getNome(), width, height);
2020-11-20 18:10:43 +01:00
mw.add(cv);
mw.setCaller(ConcessioneView.this);
//mw.setWidth(900);
2020-11-20 18:10:43 +01:00
mw.show();
2020-11-19 15:19:27 +01:00
}
});
concessioniPanel.add(customTable);
GeoportalDataViewerServiceAsync.Util.getInstance().getMyLogin(new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
myLogin = result;
addCentroidMap();
addRelazioneDiScavo();
addPosizionamentoAreaIndagine();
addPiantaFineScavo();
}
@Override
public void onFailure(Throwable caught) {
}
});
addUploadedImages();
}
private void addPosizionamentoAreaIndagine() {
LayerConcessioneDV layer = concessioneDV.getPosizionamentoScavo();
if(layer==null)
return;
if(layer.getPolicy()==null || layer.getPolicy().equalsIgnoreCase("OPEN")) {
posizionamentoAreaIndaginePanel.setVisible(true);
posizionamentoAreaIndaginePanel.add(new LayerConcessioneView(layer));
}else {
//I need to be authenticated to show the fields according to POLICY
if(myLogin!=null) {
posizionamentoAreaIndaginePanel.setVisible(true);
posizionamentoAreaIndaginePanel.add(new LayerConcessioneView(layer));
}
}
}
private void addPiantaFineScavo() {
List<LayerConcessioneDV> listLayersDV = concessioneDV.getPianteFineScavo();
if(listLayersDV==null)
return;
for (LayerConcessioneDV layer : listLayersDV) {
if(layer.getPolicy()==null || layer.getPolicy().equalsIgnoreCase("OPEN")) {
piantaFineScavoPanel.setVisible(true);
piantaFineScavoPanel.add(new LayerConcessioneView(layer));
}else {
//I need to be authenticated to show the fields according to POLICY
if(myLogin!=null) {
piantaFineScavoPanel.setVisible(true);
piantaFineScavoPanel.add(new LayerConcessioneView(layer));
}
}
}
}
private void addRelazioneDiScavo() {
2021-01-15 15:12:03 +01:00
AbstractRelazioneScavoDV abstractRS = concessioneDV.getAbstractRelazioneScavo();
2020-11-19 15:19:27 +01:00
2021-01-15 15:12:03 +01:00
if(abstractRS==null)
2020-11-19 15:19:27 +01:00
return;
2021-01-15 15:12:03 +01:00
if(abstractRS.getPolicy()==null || abstractRS.getPolicy().equalsIgnoreCase("OPEN")) {
2020-11-19 15:19:27 +01:00
relazioneScavoPanel.setVisible(true);
2021-01-15 15:12:03 +01:00
relazioneScavoPanel.add(new RelazioneScavoView(abstractRS, concessioneDV.getRelazioneScavo(), false));
2020-11-19 15:19:27 +01:00
}else {
//I need to be authenticated to show the fields according to POLICY
if(myLogin!=null) {
relazioneScavoPanel.setVisible(true);
2021-01-15 15:12:03 +01:00
relazioneScavoPanel.add(new RelazioneScavoView(abstractRS, concessioneDV.getRelazioneScavo(), true));
2020-11-19 15:19:27 +01:00
}
}
}
private void addCentroidMap() {
Coordinate centerCoordinate = OLFactory.createCoordinate(GeoportalDataViewerConstants.ITALY_CENTER_LONG, GeoportalDataViewerConstants.ITALY_CENTER_LAT);
Coordinate transformedCenterCoordinate = MapUtils.transformCoordiante(centerCoordinate, GeoportalDataViewerConstants.EPSG_4326, GeoportalDataViewerConstants.EPSG_3857);
2021-01-15 15:12:03 +01:00
MapView mapView = new MapView(transformedCenterCoordinate, GeoportalDataViewerConstants.LIGHT_MAP_ITALY_FIT_ZOOM_ON, "70%", "300px");
if(concessioneDV!=null && concessioneDV.getCentroidLat()!=null && concessioneDV.getCentroidLong()!=null) {
Coordinate coord = new Coordinate(concessioneDV.getCentroidLong(), concessioneDV.getCentroidLat());
Coordinate transfCoord = MapUtils.transformCoordiante(coord, GeoportalDataViewerConstants.EPSG_4326, GeoportalDataViewerConstants.EPSG_3857);
//Coordinate invertedCoordinate = MapUtils.reverseCoordinate(coord);
boolean authenticatedUser = myLogin!=null?true:false;
mapView.addMarker(transfCoord, authenticatedUser);
mapViewPanel.add(mapView);
}else if(concessioneDV!=null){
GeoportalDataViewerConstants.printJs("I cannot add centroid as maker one or both coordinates are null. Lat: "+concessioneDV.getCentroidLong() +", Long:"+concessioneDV.getCentroidLat());
}
2020-11-19 15:19:27 +01:00
}
private void addUploadedImages() {
2021-07-21 12:13:24 +02:00
GWT.log("Managing immagini: "+concessioneDV.getImmaginiRappresentative());
2020-11-19 15:19:27 +01:00
List<UploadedImageDV> immagini = concessioneDV.getImmaginiRappresentative();
if (immagini != null && immagini.size() > 0) {
imagesPanel.setVisible(true);
2021-07-19 18:04:14 +02:00
2021-07-21 12:13:24 +02:00
List<UploadedImageDV> immaginiToShow = new ArrayList<UploadedImageDV>();
//SHOWING ONLY OPEN IMAGES OR IF THE USER IS LOGGED
2020-11-19 15:19:27 +01:00
for (UploadedImageDV uploadedImageDV : immagini) {
if(uploadedImageDV.getPolicy()==null || uploadedImageDV.getPolicy().equalsIgnoreCase("OPEN")) {
2021-07-21 12:13:24 +02:00
immaginiToShow.add(uploadedImageDV);
}else {
if(myLogin!=null) {
2021-07-21 12:13:24 +02:00
immaginiToShow.add(uploadedImageDV);
}
}
}
2021-07-21 12:13:24 +02:00
if(immaginiToShow.size()>0) {
ImagesGallery gallery = new ImagesGallery(immaginiToShow);
imagesPanel.add(gallery.getGalleryPanel());
gallery.fillGallery();
}
2020-11-19 15:19:27 +01:00
}
}
public ConcessioneDV getConcessioneDV() {
return concessioneDV;
}
2020-11-20 18:10:43 +01:00
protected void setViewDetailsButtonVisible(boolean bool) {
viewButton.setVisible(bool);
}
2020-11-19 15:19:27 +01:00
}