2022-10-11 15:00:39 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2022-10-14 17:19:40 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV;
|
2022-10-14 15:31:32 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.FilesetDV;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV;
|
2022-10-11 15:00:39 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.gallery.ImagesSectionGallery;
|
2022-10-14 17:19:40 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.layers.LayersSectionViewer;
|
2022-10-11 16:10:46 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.CustomFlexTable;
|
2022-10-11 15:00:39 +02:00
|
|
|
|
2022-11-18 11:06:47 +01:00
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
2022-10-11 15:00:39 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.PageHeader;
|
2022-11-18 11:06:47 +01:00
|
|
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
2022-10-11 15:00:39 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2023-01-19 11:35:50 +01:00
|
|
|
import com.google.gwt.core.client.Scheduler;
|
|
|
|
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
2022-10-11 15:00:39 +02:00
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
public class SectionViewer extends Composite {
|
|
|
|
|
|
|
|
private static SectionViewerUiBinder uiBinder = GWT.create(SectionViewerUiBinder.class);
|
|
|
|
|
|
|
|
interface SectionViewerUiBinder extends UiBinder<Widget, SectionViewer> {
|
|
|
|
}
|
|
|
|
|
|
|
|
private SectionView sectionView;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
HTMLPanel sectionPanelContainer;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
PageHeader sectionTitle;
|
|
|
|
|
2022-11-18 11:06:47 +01:00
|
|
|
public SectionViewer(SectionView sectionView, String topTargetId) {
|
2022-10-11 15:00:39 +02:00
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
this.sectionView = sectionView;
|
2023-01-19 11:35:50 +01:00
|
|
|
|
2022-10-11 15:00:39 +02:00
|
|
|
List<SubDocumentView> subDocuments = sectionView.getListSubDocuments();
|
|
|
|
|
|
|
|
sectionTitle.setTitle(sectionView.getSectionTitle());
|
|
|
|
sectionTitle.setText(sectionView.getSectionTitle());
|
2023-01-19 11:35:50 +01:00
|
|
|
|
|
|
|
if (subDocuments == null)
|
|
|
|
return;
|
|
|
|
|
2022-11-18 11:06:47 +01:00
|
|
|
Button goToTop = new Button("");
|
|
|
|
goToTop.setType(ButtonType.LINK);
|
|
|
|
goToTop.setIcon(IconType.DOUBLE_ANGLE_UP);
|
2023-01-19 11:35:50 +01:00
|
|
|
goToTop.setHref("#" + topTargetId);
|
2022-11-18 11:06:47 +01:00
|
|
|
goToTop.setTitle("Go to top");
|
|
|
|
goToTop.getElement().setClassName("go-top-right");
|
2023-01-19 11:35:50 +01:00
|
|
|
|
2022-11-18 11:06:47 +01:00
|
|
|
sectionTitle.add(goToTop);
|
2022-10-11 15:00:39 +02:00
|
|
|
|
|
|
|
boolean displayAsGallery = false;
|
|
|
|
|
2023-01-19 11:35:50 +01:00
|
|
|
try {
|
|
|
|
for (SubDocumentView subDocumentView : subDocuments) {
|
|
|
|
if (subDocumentView.getListImages() != null && subDocumentView.getListImages().size() > 0) {
|
|
|
|
GWT.log("Section with images: " + subDocumentView.getListImages());
|
|
|
|
displayAsGallery = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-10-14 15:31:32 +02:00
|
|
|
}
|
|
|
|
|
2023-01-19 11:35:50 +01:00
|
|
|
boolean displayAsMapOfLayers = false;
|
2022-10-14 17:19:40 +02:00
|
|
|
for (SubDocumentView subDocumentView : subDocuments) {
|
2023-01-19 11:35:50 +01:00
|
|
|
if (subDocumentView.getListLayers() != null && subDocumentView.getListLayers().size() > 0) {
|
|
|
|
GWT.log("Section with layers: " + subDocumentView.getListImages());
|
|
|
|
displayAsMapOfLayers = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Displaying the whole section as a Gallery
|
|
|
|
if (displayAsGallery) {
|
|
|
|
GWT.log("displayAsGallery the: " + sectionView);
|
|
|
|
ImagesSectionGallery sectionGallery = new ImagesSectionGallery(sectionView);
|
|
|
|
sectionPanelContainer.add(sectionGallery.getGalleryPanel());
|
|
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute() {
|
|
|
|
sectionGallery.fillGallery();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// Displaying the whole section as a Map of Layers
|
|
|
|
} else if (displayAsMapOfLayers) {
|
|
|
|
GWT.log("displayAsMapOfLayers the: " + sectionView);
|
|
|
|
for (SubDocumentView subDocumentView : subDocuments) {
|
2022-10-17 16:52:22 +02:00
|
|
|
// String table = GeoportalDataViewerConstants.jsonToTableHTML(subDocumentView.getMetadataAsJSON());
|
|
|
|
// sectionPanelContainer.add(new HTML(table));
|
2022-10-14 17:19:40 +02:00
|
|
|
|
2023-01-19 11:35:50 +01:00
|
|
|
List<GCubeSDIViewerLayerDV> layers = subDocumentView.getListLayers();
|
|
|
|
if (layers != null) {
|
|
|
|
for (GCubeSDIViewerLayerDV gCubeLayer : layers) {
|
|
|
|
LayersSectionViewer layerSectionViewer = new LayersSectionViewer(gCubeLayer,
|
|
|
|
subDocumentView);
|
|
|
|
sectionPanelContainer.add(layerSectionViewer);
|
|
|
|
// showLinkToDownloadWsContent(fileset.getName(), fileset.getListPayload());
|
|
|
|
}
|
2022-10-14 17:19:40 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-14 15:31:32 +02:00
|
|
|
|
2023-01-19 11:35:50 +01:00
|
|
|
} else {
|
|
|
|
GWT.log("displaying default the: " + sectionView);
|
|
|
|
for (SubDocumentView subDocumentView : subDocuments) {
|
|
|
|
String table = GeoportalDataViewerConstants.jsonToTableHTML(subDocumentView.getMetadataAsJSON());
|
|
|
|
sectionPanelContainer.add(new HTML(table));
|
|
|
|
|
|
|
|
List<FilesetDV> files = subDocumentView.getListFiles();
|
|
|
|
if (files != null) {
|
|
|
|
for (FilesetDV fileset : files) {
|
2023-04-13 11:46:17 +02:00
|
|
|
showLinkToDownloadWsContent(fileset.getGcubeProfileFieldName(), fileset.getListPayload());
|
2023-01-19 11:35:50 +01:00
|
|
|
}
|
2022-10-11 16:10:46 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-11 15:00:39 +02:00
|
|
|
}
|
2023-01-19 11:35:50 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
GWT.log("Error on rendering the section: "+e.getMessage());
|
2022-10-11 15:00:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-10-14 15:31:32 +02:00
|
|
|
|
2022-10-11 16:10:46 +02:00
|
|
|
private void showLinkToDownloadWsContent(String title, List<PayloadDV> listPayloads) {
|
|
|
|
|
|
|
|
if (listPayloads != null) {
|
|
|
|
CustomFlexTable customTable = new CustomFlexTable();
|
|
|
|
int i = 0;
|
|
|
|
String fieldLabel = title;
|
|
|
|
for (PayloadDV payload : listPayloads) {
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
fieldLabel = "";
|
|
|
|
}
|
2022-10-14 15:31:32 +02:00
|
|
|
|
2022-10-11 16:10:46 +02:00
|
|
|
String downloadLabel = "download";
|
2022-10-14 15:31:32 +02:00
|
|
|
if (payload.getName() != null) {
|
2022-10-11 16:10:46 +02:00
|
|
|
downloadLabel = payload.getName();
|
|
|
|
}
|
|
|
|
|
2022-10-14 15:31:32 +02:00
|
|
|
customTable.addNextKeyWidget(fieldLabel,
|
|
|
|
new HTML("<a href=\"" + payload.getLink() + "\">" + downloadLabel + "</a>"));
|
2022-10-11 16:10:46 +02:00
|
|
|
}
|
2022-10-14 15:31:32 +02:00
|
|
|
|
2022-10-11 16:10:46 +02:00
|
|
|
sectionPanelContainer.add(customTable);
|
|
|
|
}
|
|
|
|
}
|
2022-10-11 15:00:39 +02:00
|
|
|
|
|
|
|
}
|