2020-11-19 15:19:27 +01:00
package org.gcube.portlets.user.geoportaldataviewer.client.ui.products.concessioni ;
import java.util.List ;
2020-12-02 14:39:52 +01:00
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef ;
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 ;
2020-11-20 18:10:43 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.images.ThumbnailImageView ;
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 org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV ;
2021-01-15 15:12:03 +01:00
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.AbstractRelazioneScavoDV ;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.LayerConcessioneDV ;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV ;
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 ;
2020-11-24 11:26:05 +01:00
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 ( ) ;
2020-11-24 17:24:41 +01:00
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 ) {
2020-11-24 17:24:41 +01:00
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 ) {
2020-11-24 17:24:41 +01:00
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 ( ) ) ;
}
2020-12-02 14:39:52 +01:00
if ( concessioneDV . getTitolariLicenza ( ) ! = null ) {
customTable . addNextKeyValues ( " Titolare Licenza " , concessioneDV . getTitolariLicenza ( ) , GeoportalDataViewerConstants . NEW_LINE_BR ) ;
2020-11-19 15:19:27 +01:00
}
2020-12-02 14:39:52 +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 ) ;
2020-11-24 11:26:05 +01:00
//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 ( ) {
2020-11-24 11:26:05 +01:00
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 " ) ;
2020-12-11 09:51:20 +01:00
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 ( ) {
List < UploadedImageDV > immagini = concessioneDV . getImmaginiRappresentative ( ) ;
if ( immagini ! = null & & immagini . size ( ) > 0 ) {
imagesPanel . setVisible ( true ) ;
2020-12-02 14:39:52 +01:00
boolean addedImage = false ;
imagesPanel . add ( thumbNails ) ;
2020-11-19 15:19:27 +01:00
for ( UploadedImageDV uploadedImageDV : immagini ) {
2020-12-02 14:39:52 +01:00
if ( uploadedImageDV . getPolicy ( ) = = null | | uploadedImageDV . getPolicy ( ) . equalsIgnoreCase ( " OPEN " ) ) {
thumbNails . add ( new ThumbnailImageView ( uploadedImageDV , viewImageButtonVisible , openImageButtonVisible ) ) ;
addedImage = true ;
} else {
if ( myLogin ! = null ) {
thumbNails . add ( new ThumbnailImageView ( uploadedImageDV , viewImageButtonVisible , openImageButtonVisible ) ) ;
addedImage = true ;
}
}
}
if ( ! addedImage ) {
imagesPanel . remove ( thumbNails ) ;
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
}