package org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project; import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; import org.gcube.application.geoportalcommon.shared.geoportal.project.RelationshipDV; import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView; 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.events.AddLayerToMapEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.TimelineProjectRelationsEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.TimelineProjectRelationsEvent.EVENT_TYPE; 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.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 com.github.gwtbootstrap.client.ui.Button; 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.dom.client.UListElement; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Random; 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.HTML; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; import ol.Coordinate; /** * The Class ProjectViewer. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Nov 9, 2022 */ public class ProjectViewer extends Composite { private static ProjectViewerUiBinder uiBinder = GWT.create(ProjectViewerUiBinder.class); /** * The Interface ProjectViewerUiBinder. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Nov 9, 2022 */ interface ProjectViewerUiBinder extends UiBinder { } @UiField HTMLPanel headerPanel; @UiField HTMLPanel pageViewDetails; @UiField HTMLPanel projectViewerMainPanel; @UiField HTMLPanel centroidPanel; @UiField HTMLPanel tableOfContentPanel; @UiField Button shareButton; @UiField Button expandButton; @UiField Button relationshipsButton; @UiField Button addLayersToMap; @UiField HTMLPanel toc_container; @UiField HTMLPanel toc_list_container; @UiField Button reduceToc; @UiField UListElement toc_list_anchors; private ProjectView theProjectView; private GeoportalItemReferences geoportalItemReferences; private String myLogin; private HandlerManager applicationBus; private String projectViewerMainPanelID; /** * Instantiates a new project viewer. */ private ProjectViewer() { initWidget(uiBinder.createAndBindUi(this)); pageViewDetails.getElement().addClassName("page-view-details"); projectViewerMainPanelID = "projectViewer-" + Random.nextInt(); projectViewerMainPanel.getElement().setId(projectViewerMainPanelID); } /** * Instantiates a new project viewer. * * @param applicationBus the application bus * @param geoportalItemRefs the geoportal item refs * @param projectView the project view */ public ProjectViewer(HandlerManager applicationBus, GeoportalItemReferences geoportalItemRefs, final ProjectView projectView) { this(); GWT.log("Rendering " + projectView.getTheProjectDV().getId()); this.theProjectView = projectView; this.geoportalItemReferences = geoportalItemRefs; this.applicationBus = applicationBus; final String theTitle = projectView.getTheProjectDV().getProfileName() != null ? projectView.getTheProjectDV().getProfileName() : "Project ID: " + projectView.getTheProjectDV().getId(); headerPanel.add(new HTML(theTitle)); 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(geoportalItemReferences, 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) { ProjectViewer cv = new ProjectViewer(applicationBus, geoportalItemReferences, theProjectView); cv.setExpandViewButtonVisible(false); cv.setRelationshipsButtonVisible(false); cv.setAddLayersToMapVisible(false); cv.setTocContentVisible(true); int width = Window.getClientWidth() * 75 / 100; int height = Window.getClientHeight() * 70 / 100; String modalTitle = ProjectUtil.toHMLCode(false, theProjectView.getTheProjectDV().getTheDocument(), theProjectView.getTheProjectDV().getId()); ModalWindow mw = new ModalWindow(modalTitle, width, height); mw.add(cv); mw.setCaller(ProjectViewer.this); // mw.setWidth(900); mw.show(); } }); relationshipsButton.setType(ButtonType.LINK); relationshipsButton.setIcon(IconType.LINK); relationshipsButton.setTitle("Show Relationships of this Project"); List relationships = projectView.getTheProjectDV().getRelationships(); if (relationships != null && relationships.size() > 0) { relationshipsButton.setVisible(true); } else { relationshipsButton.setVisible(false); } relationshipsButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { applicationBus.fireEvent( new TimelineProjectRelationsEvent(theProjectView.getTheProjectDV(), EVENT_TYPE.SHOW)); } }); addLayersToMap.setType(ButtonType.LINK); addLayersToMap.setIcon(IconType.MAP_MARKER); addLayersToMap.setTitle("Add the layer/s of the Project to principal Map"); addLayersToMap.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { applicationBus.fireEvent(new AddLayerToMapEvent(theProjectView.getTheProjectDV(), true)); } }); setAddLayersToMapVisible(false); GeoportalDataViewerServiceAsync.Util.getInstance().getMyLogin(new AsyncCallback() { @Override public void onSuccess(String result) { myLogin = result; addCentroidMap(); } @Override public void onFailure(Throwable caught) { } }); reduceToc.setType(ButtonType.LINK); reduceToc.setIcon(IconType.PLUS_SIGN_ALT); toc_list_container.setVisible(false); reduceToc.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { boolean visible = toc_list_container.isVisible(); setTocContentVisible(!visible); // if (visible) { // toc_list_container.setVisible(false); // reduceToc.setIcon(IconType.PLUS_SIGN_ALT); // } else { // toc_list_container.setVisible(true); // reduceToc.setIcon(IconType.MINUS_SIGN_ALT); // } } }); for (SectionView sectionView : projectView.getListSections()) { if (!sectionView.isEmpty()) { SectionViewer sectionViewer = new SectionViewer(sectionView, projectViewerMainPanelID); String sectionId = sectionView.getSectionTitle().replaceAll("[^A-Za-z0-9]", "-") + "_" + Random.nextInt(); String divTarget = "
"; sectionViewer.getElement().insertFirst(new HTML(divTarget).getElement()); addAnchorToSection(sectionId, sectionView.getSectionTitle()); pageViewDetails.add(sectionViewer); } if (sectionView.hasSpatialLayers()) { setAddLayersToMapVisible(true); } } if (toc_list_anchors.getChildCount() > 0) { tableOfContentPanel.setVisible(true); } } private void addAnchorToSection(String id, String text) { String htmlAnchor = "" + text + ""; toc_list_anchors.appendChild(new HTML("
  • " + htmlAnchor + "
  • ").getElement()); } protected void setTocContentVisible(boolean bool) { toc_list_container.setVisible(bool); if (bool) { reduceToc.setIcon(IconType.MINUS_SIGN_ALT); } else { reduceToc.setIcon(IconType.PLUS_SIGN_ALT); } } /** * Adds the centroid map. */ 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 (theProjectView != null && theProjectView.getTheProjectDV() != null) { GeoJSON spatialReference = theProjectView.getTheProjectDV().getSpatialReference(); Coordinate transfCoord = MapUtils.geoJSONTToBBoxCenter(spatialReference, MAP_PROJECTION.EPSG_4326.getName(), MAP_PROJECTION.EPSG_3857.getName()); if (transfCoord != null) { boolean authenticatedUser = myLogin != null ? true : false; mapView.addMarker(transfCoord, authenticatedUser); centroidPanel.add(mapView); } } else if (theProjectView != null) { GeoportalDataViewerConstants .printJs("I cannot add centroid as maker one or both coordinates are null. Lat: " + theProjectView + ", Long:" + theProjectView); } } /** * Gets the project view. * * @return the project view */ public ProjectView getProjectView() { return theProjectView; } /** * Sets the expand view button visible. * * @param bool the new expand view button visible */ protected void setExpandViewButtonVisible(boolean bool) { expandButton.setVisible(bool); } /** * Sets the adds the layers to map visible. * * @param bool the new adds the layers to map visible */ protected void setAddLayersToMapVisible(boolean bool) { addLayersToMap.setVisible(bool); } /** * Sets the relationships button visible. * * @param bool the new relationships button visible */ protected void setRelationshipsButtonVisible(boolean bool) { relationshipsButton.setVisible(bool); } }