291 lines
9.0 KiB
Java
291 lines
9.0 KiB
Java
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 org.gcube.portlets.user.geoportaldataviewer.client.ui.util.CustomFlexTable;
|
|
|
|
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.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.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<Widget, ProjectViewer> {
|
|
}
|
|
|
|
@UiField
|
|
HTMLPanel headerPanel;
|
|
|
|
@UiField
|
|
HTMLPanel pageViewDetails;
|
|
|
|
@UiField
|
|
HTMLPanel centroidPanel;
|
|
|
|
@UiField
|
|
Button shareButton;
|
|
|
|
@UiField
|
|
Button expandButton;
|
|
|
|
@UiField
|
|
Button relationshipsButton;
|
|
|
|
@UiField
|
|
Button addLayersToMap;
|
|
|
|
private ProjectView theProjectView;
|
|
|
|
private CustomFlexTable customTable = new CustomFlexTable();
|
|
|
|
private GeoportalItemReferences geoportalItemReferences;
|
|
|
|
private String myLogin;
|
|
|
|
private HandlerManager applicationBus;
|
|
|
|
/**
|
|
* Instantiates a new project viewer.
|
|
*/
|
|
private ProjectViewer() {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
pageViewDetails.getElement().setId("page-view-details");
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
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<RelationshipDV> 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<String>() {
|
|
|
|
@Override
|
|
public void onSuccess(String result) {
|
|
myLogin = result;
|
|
addCentroidMap();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
}
|
|
});
|
|
|
|
for (SectionView sectionView : projectView.getListSections()) {
|
|
|
|
if (!sectionView.isEmpty()) {
|
|
SectionViewer sectionViewer = new SectionViewer(sectionView);
|
|
pageViewDetails.add(sectionViewer);
|
|
}
|
|
|
|
if(sectionView.hasSpatialLayers()) {
|
|
setAddLayersToMapVisible(true);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
}
|