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.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.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.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; public class ProjectViewer extends Composite { private static ProjectViewerUiBinder uiBinder = GWT.create(ProjectViewerUiBinder.class); interface ProjectViewerUiBinder extends UiBinder { } @UiField HTMLPanel headerPanel; @UiField HTMLPanel pageViewDetails; @UiField HTMLPanel centroidPanel; @UiField Button shareButton; @UiField Button expandButton; @UiField Button relationshipsButton; private ProjectView theProjectView; private CustomFlexTable customTable = new CustomFlexTable(); private GeoportalItemReferences geoportalItemReferences; private String myLogin; private boolean viewImageButtonVisible = true; private boolean openImageButtonVisible = true; private ProjectViewer() { initWidget(uiBinder.createAndBindUi(this)); pageViewDetails.getElement().setId("page-view-details"); } public ProjectViewer(GeoportalItemReferences geoportalItemRefs, ProjectView projectView) { this(geoportalItemRefs, projectView, true, true); } public ProjectViewer(GeoportalItemReferences geoportalItemRefs, final ProjectView projectView, boolean viewImageButtonVisible, boolean openImageButtonVisible) { this(); GWT.log("Rendering " + projectView.getTheProjectDV().getId()); this.theProjectView = projectView; this.geoportalItemReferences = geoportalItemRefs; this.viewImageButtonVisible = viewImageButtonVisible; this.openImageButtonVisible = openImageButtonVisible; final String theTitle = projectView.getTheProjectDV().getProfileName() != null ? projectView.getTheProjectDV().getProfileName() : projectView.getTheProjectDV().getId(); headerPanel.add(new HTML("Project: " + 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(geoportalItemReferences, theProjectView, false, openImageButtonVisible); cv.setExpandViewButtonVisible(false); int width = Window.getClientWidth() * 75 / 100; int height = Window.getClientHeight() * 70 / 100; ModalWindow mw = new ModalWindow(theTitle, 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); GeoportalDataViewerServiceAsync.Util.getInstance().getMyLogin(new AsyncCallback() { @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); } } } 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.getCentroidLat() != null && theProjectView.getCentroidLong() != null) { Coordinate coord = new Coordinate(theProjectView.getCentroidLong(), theProjectView.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); centroidPanel.add(mapView); } else if (theProjectView != null) { GeoportalDataViewerConstants .printJs("I cannot add centroid as maker one or both coordinates are null. Lat: " + theProjectView.getCentroidLong() + ", Long:" + theProjectView.getCentroidLat()); } } public ProjectView getProjectView() { return theProjectView; } protected void setExpandViewButtonVisible(boolean bool) { expandButton.setVisible(bool); } }