package org.gcube.portlets.user.geoportaldataviewer.client.ui.products.concessioni; import java.util.ArrayList; 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; 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; import org.gcube.portlets.user.geoportaldataviewer.client.ui.ModalWindow; import org.gcube.portlets.user.geoportaldataviewer.client.ui.dialogs.DialogShareableLink; import org.gcube.portlets.user.geoportaldataviewer.client.ui.gallery.ImagesGallery; 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; import com.google.gwt.user.client.Window; 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; public class ConcessioneView extends Composite { private static ConcessioneViewUiBinder uiBinder = GWT.create(ConcessioneViewUiBinder.class); interface ConcessioneViewUiBinder extends UiBinder { } @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 Button viewButton; private ConcessioneDV concessioneDV; private Thumbnails thumbNails = new Thumbnails(); private CustomFlexTable customTable = new CustomFlexTable(); private GeoNaItemRef geonaItemRef; private String myLogin; private boolean viewImageButtonVisible = true; private boolean openImageButtonVisible = true; private ConcessioneView() { initWidget(uiBinder.createAndBindUi(this)); pageViewDetails.getElement().setId("page-view-details"); } public ConcessioneView(GeoNaItemRef item, ConcessioneDV concDV) { this(item, concDV, true, true); } public ConcessioneView(GeoNaItemRef item, ConcessioneDV concDV, boolean viewImageButtonVisible, boolean openImageButtonVisible) { this(); GWT.log("Rendering "+concDV.getNome()); this.concessioneDV = concDV; this.geonaItemRef = item; this.viewImageButtonVisible = viewImageButtonVisible; this.openImageButtonVisible = openImageButtonVisible; titolo.setText(concessioneDV.getNome()); introduzione.setText(concessioneDV.getIntroduzione()); if (concessioneDV.getDataInizioProgetto() != null) { customTable.addNextKeyValue("Data Inizio Progetto", concessioneDV.getDataInizioProgetto()); } 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); } 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); } if (concessioneDV.getTitolariCopyright() != null) { customTable.addNextKeyValues("Titolare Copyright", concessioneDV.getTitolariCopyright(),GeoportalDataViewerConstants.NEW_LINE_BR); } 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); } }); viewButton.setType(ButtonType.LINK); viewButton.setIcon(IconType.EXPAND); viewButton.setTitle("View Details in New Dialog"); viewButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { ConcessioneView cv = new ConcessioneView(geonaItemRef, concessioneDV, false, openImageButtonVisible); cv.setViewDetailsButtonVisible(false); int width = Window.getClientWidth()*75/100; int height = Window.getClientHeight()*70/100; ModalWindow mw = new ModalWindow(concessioneDV.getNome(), width, height); mw.add(cv); mw.setCaller(ConcessioneView.this); //mw.setWidth(900); mw.show(); } }); concessioniPanel.add(customTable); GeoportalDataViewerServiceAsync.Util.getInstance().getMyLogin(new AsyncCallback() { @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 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() { AbstractRelazioneScavoDV abstractRS = concessioneDV.getAbstractRelazioneScavo(); if(abstractRS==null) return; if(abstractRS.getPolicy()==null || abstractRS.getPolicy().equalsIgnoreCase("OPEN")) { relazioneScavoPanel.setVisible(true); relazioneScavoPanel.add(new RelazioneScavoView(abstractRS, concessioneDV.getRelazioneScavo(), false)); }else { //I need to be authenticated to show the fields according to POLICY if(myLogin!=null) { relazioneScavoPanel.setVisible(true); relazioneScavoPanel.add(new RelazioneScavoView(abstractRS, concessioneDV.getRelazioneScavo(), true)); } } } 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); 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()); } } private void addUploadedImages() { GWT.log("Managing immagini: "+concessioneDV.getImmaginiRappresentative()); List immagini = concessioneDV.getImmaginiRappresentative(); if (immagini != null && immagini.size() > 0) { imagesPanel.setVisible(true); List immaginiToShow = new ArrayList(); //SHOWING ONLY OPEN IMAGES OR IF THE USER IS LOGGED for (UploadedImageDV uploadedImageDV : immagini) { if(uploadedImageDV.getPolicy()==null || uploadedImageDV.getPolicy().equalsIgnoreCase("OPEN")) { immaginiToShow.add(uploadedImageDV); }else { if(myLogin!=null) { immaginiToShow.add(uploadedImageDV); } } } if(immaginiToShow.size()>0) { ImagesGallery gallery = new ImagesGallery(immaginiToShow); imagesPanel.add(gallery.getGalleryPanel()); gallery.fillGallery(); } } } public ConcessioneDV getConcessioneDV() { return concessioneDV; } protected void setViewDetailsButtonVisible(boolean bool) { viewButton.setVisible(bool); } }