geoportal-data-viewer-app/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/TimelineRelationPanel.java

197 lines
6.6 KiB
Java
Raw Normal View History

2022-11-02 18:05:38 +01:00
package org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation;
import java.util.List;
2022-11-03 17:03:15 +01:00
import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences;
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
2022-11-02 18:05:38 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync;
2022-11-03 17:03:15 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent.EVENT_SOURCE;
2022-11-03 17:03:15 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAImages;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.ProjectUtil;
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
2022-11-02 18:05:38 +01:00
2022-11-03 17:03:15 +01:00
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
2022-11-02 18:05:38 +01:00
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
2022-11-03 17:03:15 +01:00
import com.google.gwt.dom.client.Style.TextAlign;
2022-11-08 10:45:39 +01:00
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
2022-11-03 17:03:15 +01:00
import com.google.gwt.event.shared.HandlerManager;
2022-11-02 18:05:38 +01:00
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
2022-11-08 10:45:39 +01:00
import com.google.gwt.user.client.ui.Anchor;
2022-11-02 18:05:38 +01:00
import com.google.gwt.user.client.ui.Composite;
2022-11-03 17:03:15 +01:00
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image;
2022-11-02 18:05:38 +01:00
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
public class TimelineRelationPanel extends Composite {
@UiField
ScrollPanel timelineContainer;
2022-11-03 17:03:15 +01:00
@UiField
2022-11-08 10:45:39 +01:00
HTMLPanel timelineHeader;
2022-11-08 10:45:39 +01:00
@UiField
Anchor timelinePopupCloser;
2022-11-04 17:16:37 +01:00
private LoaderIcon loaderData = new LoaderIcon("Loading data... please wait",
new Image(GNAImages.ICONS.spinnerClock()));
2022-11-03 17:03:15 +01:00
private TimelineRelationPanel instance = this;
private String selectedTimelineProjectID;
2022-11-03 17:03:15 +01:00
private ProjectDV theProjectDV;
private HandlerManager applicationBus;
2022-11-02 18:05:38 +01:00
private static TimelineRelationPanelUiBinder uiBinder = GWT.create(TimelineRelationPanelUiBinder.class);
interface TimelineRelationPanelUiBinder extends UiBinder<Widget, TimelineRelationPanel> {
}
2022-11-03 17:03:15 +01:00
public TimelineRelationPanel(HandlerManager applicationBus, ProjectDV theProjectDV) {
2022-11-02 18:05:38 +01:00
initWidget(uiBinder.createAndBindUi(this));
2022-11-03 17:03:15 +01:00
this.theProjectDV = theProjectDV;
this.applicationBus = applicationBus;
2022-11-04 17:16:37 +01:00
String html = ProjectUtil.toHMLCode(theProjectDV.getTheDocument());
HTML title = new HTML("Relationships of the Project" + " <br>" + html);
2022-11-08 10:45:39 +01:00
timelineHeader.add(title);
timelineContainer.getElement().setId("timeline-content");
timelineHeader.getElement().setId("timeline-header");
2022-11-04 17:16:37 +01:00
2022-11-03 17:03:15 +01:00
loaderData.getElement().getStyle().setTextAlign(TextAlign.CENTER);
2022-11-02 18:05:38 +01:00
timelineContainer.getElement().setId("visualization");
2022-11-04 17:16:37 +01:00
timelineContainer.add(loaderData);
2022-11-08 10:45:39 +01:00
timelinePopupCloser.addClickHandler(new ClickHandler() {
2022-11-08 10:45:39 +01:00
@Override
public void onClick(ClickEvent event) {
if (timelineContainer.isVisible())
2022-11-08 14:50:48 +01:00
setTimelineContainerVisible(false);
2022-11-08 10:45:39 +01:00
else
2022-11-08 14:50:48 +01:00
setTimelineContainerVisible(true);
2022-11-08 10:45:39 +01:00
}
});
2022-11-04 17:16:37 +01:00
2022-11-02 18:05:38 +01:00
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
2022-11-03 17:03:15 +01:00
GeoportalDataViewerServiceAsync.Util.getInstance().getRelationshipsForTimeline(
theProjectDV.getProfileID(), theProjectDV.getId(), new AsyncCallback<List<String>>() {
2022-11-02 18:05:38 +01:00
@Override
public void onSuccess(List<String> result) {
2022-11-04 17:16:37 +01:00
timelineContainer.remove(loaderData);
2022-11-02 18:05:38 +01:00
JSONArray toJsonArr = new JSONArray();
for (int i = 0; i < result.size(); i++) {
toJsonArr.set(i, JSONParser.parseStrict(result.get(i)));
}
2022-11-03 17:03:15 +01:00
instanceTimeline(timelineContainer.getElement().getId(), toJsonArr, instance);
2022-11-04 17:16:37 +01:00
2022-11-02 18:05:38 +01:00
}
@Override
public void onFailure(Throwable caught) {
2022-11-04 17:16:37 +01:00
timelineContainer.remove(loaderData);
2022-11-03 17:03:15 +01:00
Alert alert = new Alert(caught.getMessage());
alert.setType(AlertType.ERROR);
alert.setClose(false);
2022-11-08 10:45:39 +01:00
timelineHeader.add(alert);
2022-11-02 18:05:38 +01:00
}
});
};
});
}
2022-11-08 14:50:48 +01:00
public void setTimelineContainerVisible(boolean bool) {
timelineContainer.setVisible(bool);
}
2023-01-12 11:00:09 +01:00
/*
* Called when a project (box) is clicked into Timeline
*/
private void setSelectedProject(String theComposedProjectID) {
this.selectedTimelineProjectID = theComposedProjectID;
//selectedTimelineProjectID is the couple ProfileID,ProjectID
GWT.log("selectedTimelineProjectID: " + selectedTimelineProjectID);
if (selectedTimelineProjectID == null || selectedTimelineProjectID.isEmpty())
2022-11-07 17:58:06 +01:00
return;
2022-11-04 17:16:37 +01:00
String[] references = this.selectedTimelineProjectID.split(",");
2022-11-03 17:03:15 +01:00
final String thePofileID = references[0];
final String theProjectID = references[1];
GeoportalItemReferences gir = new GeoportalItemReferences(theProjectID, thePofileID);
ShowDetailsEvent showDetailsEvent = new ShowDetailsEvent(gir, null, false, false,
EVENT_SOURCE.LOCATE_FROM_TIMELINE);
2022-12-21 11:00:12 +01:00
showDetailsEvent.setEventFromTimeline(true);
GWT.log("fireEvent: " + showDetailsEvent);
2022-11-04 17:16:37 +01:00
applicationBus.fireEvent(showDetailsEvent);
2022-11-03 17:03:15 +01:00
}
public String getSelectedProjectID() {
return selectedTimelineProjectID;
2022-11-03 17:03:15 +01:00
}
public static native String instanceTimeline(String idDivContainer, JSONArray jsonItems,
TimelineRelationPanel instance) /*-{
console.log('showing timeline');
//console.log('showTimeline_instanceTimeline for json items: '+jsonItems);
2022-11-02 18:05:38 +01:00
//console.log("showTimeline_template: " + $wnd.templateHandlebars);
2022-11-02 18:05:38 +01:00
// DOM element where the Timeline will be attached
var container = $doc.getElementById(idDivContainer);
//console.log("showTimeline_container: " + container);
2022-11-02 18:05:38 +01:00
var myArray = $wnd.JSON.parse(jsonItems);
//console.log("showTimeline_jsonItems: " + myArray);
2022-11-02 18:05:38 +01:00
var container = $doc.getElementById(idDivContainer);
// Create a DataSet (allows two way data-binding)
var items = new $wnd.vis.DataSet(myArray);
// Create a Timeline
var timeline = new $wnd.vis.Timeline(container, items,
$wnd.optionsTimeline);
2022-11-04 17:16:37 +01:00
timeline
.on(
'select',
function(properties, items) {
//console.log('selected: ' + $wnd.JSON.stringify(properties));
console.log('selected items: ' + properties.items);
instance.@org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation.TimelineRelationPanel::setSelectedProject(Ljava/lang/String;)(properties.items+'')
});
//timeline.redraw();
2022-11-03 17:03:15 +01:00
2022-11-02 18:05:38 +01:00
}-*/;
}