geoportal-data-viewer-app/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java

215 lines
5.0 KiB
Java
Raw Normal View History

2020-10-23 18:18:06 +02:00
package org.gcube.portlets.user.geoportaldataviewer.client.ui;
2020-11-05 14:05:14 +01:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
2020-10-27 16:04:34 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM;
2020-11-05 14:05:14 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.products.ConcessioneView;
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV;
2020-10-26 17:40:38 +01:00
import com.github.gwtbootstrap.client.ui.Button;
2020-11-02 17:04:31 +01:00
import com.github.gwtbootstrap.client.ui.NavLink;
2020-10-23 18:18:06 +02:00
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.TabPanel;
2020-10-28 11:19:12 +01:00
import com.github.gwtbootstrap.client.ui.constants.IconType;
2020-10-23 18:18:06 +02:00
import com.google.gwt.core.client.GWT;
2020-11-05 14:05:14 +01:00
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
2020-10-26 17:40:38 +01:00
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
2020-10-23 18:18:06 +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.Widget;
public class GeonaDataViewMainPanel extends Composite {
private static GeonaDataViewMainPanelUiBinder uiBinder = GWT.create(GeonaDataViewMainPanelUiBinder.class);
interface GeonaDataViewMainPanelUiBinder extends UiBinder<Widget, GeonaDataViewMainPanel> {
}
@UiField
2020-10-27 10:19:32 +01:00
Tab mapTabPanel;
2020-10-28 11:19:12 +01:00
2020-10-26 17:40:38 +01:00
@UiField
2020-11-02 17:04:31 +01:00
NavLink dataPointSelection;
2020-10-28 11:19:12 +01:00
2020-10-26 17:40:38 +01:00
@UiField
2020-11-02 17:04:31 +01:00
NavLink dataBoxSelection;
2020-10-28 11:19:12 +01:00
@UiField
2020-11-02 17:04:31 +01:00
Button removeQuery;
@UiField
TabPanel mainTabPanel;
2020-11-05 14:05:14 +01:00
private List<Tab> listTabs = new ArrayList<Tab>();
2020-10-28 11:19:12 +01:00
2020-10-27 10:19:32 +01:00
private MapPanel mapPanel;
2020-10-26 17:40:38 +01:00
2020-10-27 16:04:34 +01:00
private OpenLayerOSM map;
2020-10-28 11:19:12 +01:00
private HandlerManager eventBus;
2020-11-05 14:05:14 +01:00
private Map<Long, Tab> mapProducts = new HashMap<Long, Tab>();
public GeonaDataViewMainPanel(HandlerManager eventBus) {
2020-10-23 18:18:06 +02:00
initWidget(uiBinder.createAndBindUi(this));
this.eventBus = eventBus;
2020-10-27 10:19:32 +01:00
mapPanel = new MapPanel("600px");
mapTabPanel.add(mapPanel);
2020-10-26 17:40:38 +01:00
bindHandlers();
2020-10-28 11:19:12 +01:00
dataPointSelection.setIcon(IconType.SCREENSHOT);
dataBoxSelection.setIcon(IconType.BOOKMARK);
2020-11-02 17:04:31 +01:00
removeQuery.setIcon(IconType.REMOVE);
2020-10-23 18:18:06 +02:00
}
2020-10-28 11:19:12 +01:00
2020-10-27 10:19:32 +01:00
public void setMapHeight(int height) {
2020-10-28 11:19:12 +01:00
mapPanel.setHeight(height + "px");
2020-10-26 11:01:07 +01:00
}
2020-10-23 18:18:06 +02:00
2020-10-27 10:19:32 +01:00
public MapPanel getMapPanel() {
return mapPanel;
2020-10-23 18:18:06 +02:00
}
2020-10-28 11:19:12 +01:00
2020-10-27 16:04:34 +01:00
public void setMap(OpenLayerOSM map) {
2020-10-26 17:40:38 +01:00
this.map = map;
}
2020-10-28 11:19:12 +01:00
public void bindHandlers() {
2020-10-26 17:40:38 +01:00
dataPointSelection.addClickHandler(new ClickHandler() {
2020-10-28 11:19:12 +01:00
2020-10-26 17:40:38 +01:00
@Override
public void onClick(ClickEvent event) {
2020-10-28 11:19:12 +01:00
map.removeQueryInteractions();
GWT.log("dataPointSelection.isActive() " + dataPointSelection.isActive());
if (!dataPointSelection.isActive()) {
map.addPointVectorSource();
}
2020-11-02 17:04:31 +01:00
removeQuery.setVisible(true);
//dataBoxSelection.setActive(false);
2020-10-28 11:19:12 +01:00
//dataBoxSelection.getElement().removeClassName("active");
2020-10-26 17:40:38 +01:00
}
});
2020-10-28 11:19:12 +01:00
2020-10-26 17:40:38 +01:00
dataBoxSelection.addClickHandler(new ClickHandler() {
2020-10-28 11:19:12 +01:00
2020-10-26 17:40:38 +01:00
@Override
public void onClick(ClickEvent event) {
2020-10-28 11:19:12 +01:00
map.removeQueryInteractions();
2020-10-30 17:32:05 +01:00
GWT.log("dataBoxSelection.isActive() " + dataBoxSelection.isActive());
2020-10-28 11:19:12 +01:00
if (!dataBoxSelection.isActive()) {
map.addExtentInteraction();
}
2020-11-02 17:04:31 +01:00
removeQuery.setVisible(true);
//dataPointSelection.setActive(false);
2020-10-28 11:19:12 +01:00
//dataPointSelection.getElement().removeClassName("active");
2020-10-26 17:40:38 +01:00
}
});
2020-11-02 17:04:31 +01:00
removeQuery.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
map.removeQueryInteractions();
removeQuery.setVisible(false);
}
});
2020-10-28 11:19:12 +01:00
2020-10-26 17:40:38 +01:00
}
2020-11-05 14:05:14 +01:00
public void renderProductIntoTab(Tab tab, ConcessioneDV cdv) {
tab.clear();
tab.setHeading(cdv.getNome());
2020-11-04 17:49:22 +01:00
tab.add(new ConcessioneView(cdv));
2020-11-05 14:05:14 +01:00
mapProducts.put(cdv.getId(), tab);
selectTabForProductId(cdv.getId());
}
public boolean selectTabForProductId(long productId) {
Tab product = mapProducts.get(productId);
if(product!=null) {
selectTab(product);
//found
return true;
}
//not found
return false;
}
/**
* Adds the as tab.
*
* @param tabTitle the tab title
* @param tabDescr the tab descr
* @param spinner the spinner
* @param w the w
* @return the tab
*/
public Tab addAsTab(String tabTitle, boolean spinner, Widget w){
// field_create_analytics_request.setActive(false);
Tab tab = new Tab();
mainTabPanel.add(tab);
2020-11-05 14:05:14 +01:00
if(spinner) {
LoaderIcon loader = new LoaderIcon("Loading...");
tab.add(loader);
}
tab.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
}
});
//tab.setActive(true);
tab.setHeading(tabTitle);
listTabs.add(tab);
if(w!=null)
tab.add(w);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
selectTab(tab);
}
});
return tab;
// tab.setActive(true);
}
private void selectTab(Tab theTab) {
int i = 1;
for (Tab tab : listTabs) {
GWT.log("Selecting "+tab);
tab.setActive(false);
if(tab.equals(theTab)) {
GWT.log("Tab selected "+tab);
mainTabPanel.selectTab(i);
}
i++;
}
}
2020-10-23 18:18:06 +02:00
}