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

334 lines
11 KiB
Java

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.RelazioneScavoDV;
import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
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.ExtentMapUtil;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.Location;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.PLACE;
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;
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
Button shareButton;
@UiField
Button expandButton;
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",
GeoportalDataViewerConstants.DT_FORMAT.format(concessioneDV.getDataInizioProgetto()));
}
if (concessioneDV.getDataFineProgetto() != null) {
customTable.addNextKeyValue("Data Fine Progetto",
GeoportalDataViewerConstants.DT_FORMAT.format(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("Staff", 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);
}
});
expandButton.setType(ButtonType.LINK);
expandButton.setIcon(IconType.EXPAND);
expandButton.setTitle("Show this view in new Window");
expandButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ConcessioneView cv = new ConcessioneView(geonaItemRef, concessioneDV, false, openImageButtonVisible);
cv.setExpandViewButtonVisible(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<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;
posizionamentoAreaIndaginePanel.setVisible(true);
posizionamentoAreaIndaginePanel.add(new LayerConcessioneView(layer));
}
private void addPiantaFineScavo() {
List<LayerConcessioneDV> listLayersDV = concessioneDV.getPianteFineScavo();
if (listLayersDV == null)
return;
for (LayerConcessioneDV layerDV : listLayersDV) {
piantaFineScavoPanel.setVisible(true);
piantaFineScavoPanel.add(new LayerConcessioneView(layerDV));
}
}
private void addRelazioneDiScavo() {
AbstractRelazioneScavoDV abstractRS = concessioneDV.getAbstractRelazioneScavo();
RelazioneScavoDV relazioneScavo = concessioneDV.getRelazioneScavo();
if (abstractRS == null && relazioneScavo==null)
return;
relazioneScavoPanel.setVisible(true);
relazioneScavoPanel.add(new RelazioneScavoView(abstractRS, concessioneDV.getRelazioneScavo()));
}
private void addCentroidMap() {
Location italyLocation = ExtentMapUtil.getLocation(PLACE.ITALY);
Coordinate transformedCenterCoordinate = italyLocation.getCoordinate(MAP_PROJECTION.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, MAP_PROJECTION.EPSG_4326.getName(),
MAP_PROJECTION.EPSG_3857.getName());
// 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<UploadedImageDV> immagini = concessioneDV.getImmaginiRappresentative();
if (immagini != null && immagini.size() > 0) {
imagesPanel.setVisible(true);
List<UploadedImageDV> immaginiToShow = new ArrayList<UploadedImageDV>();
for (UploadedImageDV uploadedImageDV : immagini) {
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 setExpandViewButtonVisible(boolean bool) {
expandButton.setVisible(bool);
}
}