Initial import.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/netcdf-basic-widgets@157537 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-10-24 16:28:12 +00:00
parent 84c012ada2
commit 477c65a150
7 changed files with 97 additions and 148 deletions

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.widgets.netcdfbasicwidgets.client; package org.gcube.portlets.widgets.netcdfbasicwidgets.client;
import org.gcube.portlets.widgets.netcdfbasicwidgets.client.event.SelectVariableEvent; import org.gcube.portlets.widgets.netcdfbasicwidgets.client.event.SelectVariableEvent;
import org.gcube.portlets.widgets.netcdfbasicwidgets.client.event.SelectVariableEvent.SelectVariableEventHandler; import org.gcube.portlets.widgets.netcdfbasicwidgets.client.event.SelectVariableEvent.SelectVariableEventHandler;
import org.gcube.portlets.widgets.netcdfbasicwidgets.client.widgets.NetCDFPreviewDialog; import org.gcube.portlets.widgets.netcdfbasicwidgets.client.widgets.NetCDFPreviewDialog;
@ -17,6 +16,11 @@ import com.google.gwt.core.shared.GWT;
* *
*/ */
public class NetCDFBasicWidgets implements EntryPoint { public class NetCDFBasicWidgets implements EntryPoint {
// private static final String example1 =
// "http://data.d4science.org/Qnc4RXlNQmhlWS83NkFFb2dIU0hQMnhVTER1VEZjbGdHbWJQNStIS0N6Yz0";
private static final String example2 = "http://data.d4science.org/L0FuZGNERGNFL1Y4bDRQdDFHSmdFUkN5V3VvZlF4L2lHbWJQNStIS0N6Yz0";
// private static final String example3 =
// "http://data.d4science.org/WXZFNjRXeE9XWGQ4bDRQdDFHSmdFWVBPd0FEK0VzdlRHbWJQNStIS0N6Yz0";
/** /**
* {@inheritDoc} * {@inheritDoc}
@ -31,23 +35,22 @@ public class NetCDFBasicWidgets implements EntryPoint {
} }
private void loadMainPanel() { private void loadMainPanel() {
GWT.log("NetcdfBasicWidgetsManager"); GWT.log("NetcdfBasicWidgetsManager");
// Example // Example
SelectVariableEventHandler handler=new SelectVariableEventHandler() { SelectVariableEventHandler handler = new SelectVariableEventHandler() {
@Override @Override
public void onResponse(SelectVariableEvent event) { public void onResponse(SelectVariableEvent event) {
GWT.log("SelectVariable Response: "+event); GWT.log("SelectVariable Response: " + event);
} }
}; };
NetCDFPreviewDialog dialog=new NetCDFPreviewDialog(); NetCDFPreviewDialog dialog = new NetCDFPreviewDialog(example2);
dialog.addSelectVariableEventHandler(handler); dialog.addSelectVariableEventHandler(handler);
} }
} }

View File

@ -26,15 +26,16 @@ import com.google.gwt.view.client.ListDataProvider;
* *
*/ */
public class NetCDFDataModel { public class NetCDFDataModel {
private String url;
private NetCDFData netCDFData; private NetCDFData netCDFData;
private ArrayList<NetCDFDataEventHandler> handlers = new ArrayList<>(); private ArrayList<NetCDFDataEventHandler> handlers = new ArrayList<>();
private ListDataProvider<VariableData> variableDataProvider = new ListDataProvider<>(); private ListDataProvider<VariableData> variableDataProvider = new ListDataProvider<>();
private ListDataProvider<AttributeData> globalAttributeDataProvider = new ListDataProvider<>(); private ListDataProvider<AttributeData> globalAttributeDataProvider = new ListDataProvider<>();
public NetCDFDataModel() { public NetCDFDataModel(String url) {
this.url=url;
retrieveData(); retrieveData();
} }
@ -74,7 +75,7 @@ public class NetCDFDataModel {
public void retrieveData() { public void retrieveData() {
NetCDFBasicWidgetServiceAsync.INSTANCE.getNetCDFFromPublicLink("", new AsyncCallback<NetCDFData>() { NetCDFBasicWidgetServiceAsync.INSTANCE.getNetCDFFromPublicLink(url, new AsyncCallback<NetCDFData>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {

View File

@ -23,8 +23,6 @@ public interface NetCDFBasicWidgetService extends RemoteService {
public NetCDFData getNetCDFFromPublicLink(String publicLink) throws ServiceException; public NetCDFData getNetCDFFromPublicLink(String publicLink) throws ServiceException;
public NetCDFData getNetCDFFromItem(String itemId) throws ServiceException;
public void closeNetCDF(NetCDFId netCDFId) throws ServiceException; public void closeNetCDF(NetCDFId netCDFId) throws ServiceException;
public NetCDFValues readDataVariable(NetCDFId netCDFId, VariableData variableData, boolean sample, int limit) throws ServiceException; public NetCDFValues readDataVariable(NetCDFId netCDFId, VariableData variableData, boolean sample, int limit) throws ServiceException;

View File

@ -24,8 +24,6 @@ public interface NetCDFBasicWidgetServiceAsync {
void getNetCDFFromPublicLink(String publicLink, AsyncCallback<NetCDFData> callback); void getNetCDFFromPublicLink(String publicLink, AsyncCallback<NetCDFData> callback);
void getNetCDFFromItem(String itemId, AsyncCallback<NetCDFData> callback);
void closeNetCDF(NetCDFId netCDFId, AsyncCallback<Void> callback); void closeNetCDF(NetCDFId netCDFId, AsyncCallback<Void> callback);
void readDataVariable(NetCDFId netCDFId, VariableData variableData, boolean sample, int limit, void readDataVariable(NetCDFId netCDFId, VariableData variableData, boolean sample, int limit,

View File

@ -39,11 +39,12 @@ import com.google.gwt.user.client.ui.Widget;
* *
*/ */
public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEvent.HasSelectVariableEventHandler { public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEvent.HasSelectVariableEventHandler {
private static final String TABPANEL_HEIGHT = "400px"; private static final String TABPANEL_HEIGHT = "400px";
private static final String TABPANEL_WIDTH = "700px"; private static final String TABPANEL_WIDTH = "700px";
private static final NetCDFPreviewMessages messages = GWT.create(NetCDFPreviewMessages.class); private static final NetCDFPreviewMessages messages = GWT.create(NetCDFPreviewMessages.class);
private HandlerRegistration resizeHandlerRegistration; private HandlerRegistration resizeHandlerRegistration;
private Node closeEventTarget = null; private Node closeEventTarget = null;
private int zIndex = -1; private int zIndex = -1;
@ -53,25 +54,15 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
private DetailPanel detailPanel; private DetailPanel detailPanel;
private SamplePanel samplePanel; private SamplePanel samplePanel;
private InfoPanel infoPanel; private InfoPanel infoPanel;
private String url;
//private DataGrid<VariableData> dataGrid;
public NetCDFPreviewDialog() { // private DataGrid<VariableData> dataGrid;
try {
initWindow();
initHandler();
addToolIcon();
create();
} catch (Throwable e) {
GWT.log(e.getLocalizedMessage());
e.printStackTrace();
}
}
public NetCDFPreviewDialog(String fileId) {
public NetCDFPreviewDialog(String url) {
try { try {
GWT.log("FileId: " + fileId); GWT.log("PublicLink: " + url);
this.url = url;
initWindow(); initWindow();
initHandler(); initHandler();
addToolIcon(); addToolIcon();
@ -89,8 +80,8 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
setGlassEnabled(true); setGlassEnabled(true);
setAnimationEnabled(true); setAnimationEnabled(true);
setText(messages.dialogTitle()); setText(messages.dialogTitle());
//setHeight(DIALOG_HEIGHT); // setHeight(DIALOG_HEIGHT);
//setWidth(DIALOG_WIDTH); // setWidth(DIALOG_WIDTH);
} }
private void initHandler() { private void initHandler() {
@ -106,73 +97,66 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
} }
private void create() { private void create() {
netCDFDataModel = new NetCDFDataModel(); netCDFDataModel = new NetCDFDataModel(url);
// Create a tab panel // Create a tab panel
TabLayoutPanel tabPanel = new TabLayoutPanel(2.5, Unit.EM); TabLayoutPanel tabPanel = new TabLayoutPanel(2.5, Unit.EM);
tabPanel.setAnimationDuration(1000); tabPanel.setAnimationDuration(1000);
tabPanel.setAnimationVertical(true); tabPanel.setAnimationVertical(true);
tabPanel.getElement().getStyle().setMarginBottom(10.0, Unit.PX); tabPanel.getElement().getStyle().setMarginBottom(10.0, Unit.PX);
tabPanel.setHeight(TABPANEL_HEIGHT); tabPanel.setHeight(TABPANEL_HEIGHT);
tabPanel.setWidth(TABPANEL_WIDTH); tabPanel.setWidth(TABPANEL_WIDTH);
//Variable TabPanel
variablesPanel = new VariablesPanel(netCDFDataModel);
tabPanel.add(variablesPanel, messages.variablesTab());
//Detail TabPanel
detailPanel = new DetailPanel(netCDFDataModel);
tabPanel.add(detailPanel, messages.detailTab());
//Sample TabPanel
samplePanel = new SamplePanel(netCDFDataModel);
tabPanel.add(samplePanel, messages.sampleTab());
//Info TabPanel
infoPanel = new InfoPanel(netCDFDataModel);
tabPanel.add(infoPanel, messages.infoTab());
// Variable TabPanel
// Return the content variablesPanel = new VariablesPanel(netCDFDataModel);
tabPanel.selectTab(0); tabPanel.add(variablesPanel, messages.variablesTab());
tabPanel.ensureDebugId("netcdfTabPanel");
tabPanel.addSelectionHandler(new SelectionHandler<Integer>() // Detail TabPanel
{ detailPanel = new DetailPanel(netCDFDataModel);
public void onSelection(SelectionEvent<Integer> event) tabPanel.add(detailPanel, messages.detailTab());
{
int tabId = event.getSelectedItem(); // Sample TabPanel
Widget tabWidget = tabPanel.getWidget(tabId); samplePanel = new SamplePanel(netCDFDataModel);
if (tabWidget != null) tabPanel.add(samplePanel, messages.sampleTab());
{
if(tabWidget instanceof VariablesPanel){ // Info TabPanel
VariablesPanel variablesPanel=(VariablesPanel)tabWidget; infoPanel = new InfoPanel(netCDFDataModel);
variablesPanel.refresh(); tabPanel.add(infoPanel, messages.infoTab());
} else {
if(tabWidget instanceof DetailPanel){ // Return the content
DetailPanel detailPanel=(DetailPanel)tabWidget; tabPanel.selectTab(0);
detailPanel.refresh(); tabPanel.ensureDebugId("netcdfTabPanel");
} else {
if(tabWidget instanceof InfoPanel){ tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {
InfoPanel infoPanel=(InfoPanel)tabWidget; public void onSelection(SelectionEvent<Integer> event) {
infoPanel.refresh(); int tabId = event.getSelectedItem();
} else { Widget tabWidget = tabPanel.getWidget(tabId);
if (tabWidget != null) {
} if (tabWidget instanceof VariablesPanel) {
} VariablesPanel variablesPanel = (VariablesPanel) tabWidget;
} variablesPanel.refresh();
} } else {
} if (tabWidget instanceof DetailPanel) {
}); DetailPanel detailPanel = (DetailPanel) tabWidget;
detailPanel.refresh();
} else {
if (tabWidget instanceof InfoPanel) {
InfoPanel infoPanel = (InfoPanel) tabWidget;
infoPanel.refresh();
} else {
}
}
}
}
}
});
// Create a table to layout the content // Create a table to layout the content
//VerticalPanel dialogContents = new VerticalPanel(); // VerticalPanel dialogContents = new VerticalPanel();
//dialogContents.setSpacing(4); // dialogContents.setSpacing(4);
//dialogContents.add(tabPanel); // dialogContents.add(tabPanel);
// Add Button // Add Button
Button btnSave = new Button("Save"); Button btnSave = new Button("Save");
btnSave.getElement().getStyle().setMarginLeft(4, Unit.PX); btnSave.getElement().getStyle().setMarginLeft(4, Unit.PX);
@ -202,28 +186,26 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
FlowPanel buttonPack = new FlowPanel(); FlowPanel buttonPack = new FlowPanel();
buttonPack.setWidth("100%"); buttonPack.setWidth("100%");
//buttonPack.add(btnSave); // buttonPack.add(btnSave);
buttonPack.add(btnClose); buttonPack.add(btnClose);
/*HorizontalPanel hp=new HorizontalPanel(); /*
hp.add(buttonPack); * HorizontalPanel hp=new HorizontalPanel(); hp.add(buttonPack);
hp.setCellHorizontalAlignment(buttonPack, HasHorizontalAlignment.ALIGN_CENTER); * hp.setCellHorizontalAlignment(buttonPack,
*/ * HasHorizontalAlignment.ALIGN_CENTER);
*/
DockPanel dockPanel = new DockPanel(); DockPanel dockPanel = new DockPanel();
dockPanel.setSpacing(4); dockPanel.setSpacing(4);
dockPanel.add(tabPanel, DockPanel.CENTER); dockPanel.add(tabPanel, DockPanel.CENTER);
dockPanel.add(buttonPack, DockPanel.SOUTH); dockPanel.add(buttonPack, DockPanel.SOUTH);
dockPanel.setCellHorizontalAlignment(buttonPack,DockPanel.ALIGN_CENTER); dockPanel.setCellHorizontalAlignment(buttonPack, DockPanel.ALIGN_CENTER);
dockPanel.setWidth("100%"); dockPanel.setWidth("100%");
setWidget(dockPanel); setWidget(dockPanel);
center(); center();
} }
@Override @Override
@ -231,13 +213,13 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
super.show(); super.show();
center(); center();
}; };
private void closeOnServer(){ private void closeOnServer() {
if(netCDFDataModel!=null){ if (netCDFDataModel != null) {
netCDFDataModel.close(); netCDFDataModel.close();
} }
} }
private void btnClosePressed() { private void btnClosePressed() {
SelectVariableEvent event = new SelectVariableEvent(SelectVariableEventType.Aborted); SelectVariableEvent event = new SelectVariableEvent(SelectVariableEventType.Aborted);
fireEvent(event); fireEvent(event);
@ -246,7 +228,7 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
} }
private void btnSavePressed() { private void btnSavePressed() {
Set<VariableData> selected=variablesPanel.seleceted(); Set<VariableData> selected = variablesPanel.seleceted();
if (selected == null || selected.isEmpty()) { if (selected == null || selected.isEmpty()) {
GWTMessages.alert("Attention", "Select a layer!", zIndex); GWTMessages.alert("Attention", "Select a layer!", zIndex);
} else { } else {

View File

@ -85,24 +85,6 @@ public class NetCDFBasicWidgetServiceImpl extends RemoteServiceServlet implement
} }
} }
@Override
public NetCDFData getNetCDFFromItem(String itemId) throws ServiceException {
try {
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
NetCDFResource netCDFResource = new NetCDFResource();
NetCDFData netCDFData = netCDFResource.exploreNetCDF();
SessionUtil.setNetCDFData(netCDFData, this.getThreadLocalRequest(), serviceCredentials);
return netCDFData;
} catch (ServiceException e) {
logger.error("Error in getCDFResourceFromItem(): " + e.getLocalizedMessage(), e);
throw e;
} catch (Exception e) {
logger.error("Error in getCDFResourceFromItem(): " + e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
@Override @Override
public NetCDFValues readDataVariable(NetCDFId netCDFId, VariableData variableData, boolean sample, int limit) public NetCDFValues readDataVariable(NetCDFId netCDFId, VariableData variableData, boolean sample, int limit)

View File

@ -5,7 +5,6 @@ import java.io.BufferedOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.file.Files; import java.nio.file.Files;
@ -52,10 +51,7 @@ import ucar.nc2.Variable;
* *
*/ */
public class NetCDFResource { public class NetCDFResource {
//private static final String example1 = "http://data.d4science.org/Qnc4RXlNQmhlWS83NkFFb2dIU0hQMnhVTER1VEZjbGdHbWJQNStIS0N6Yz0";
private static final String example2 = "http://data.d4science.org/L0FuZGNERGNFL1Y4bDRQdDFHSmdFUkN5V3VvZlF4L2lHbWJQNStIS0N6Yz0";
//private static final String example3 = "http://data.d4science.org/WXZFNjRXeE9XWGQ4bDRQdDFHSmdFWVBPd0FEK0VzdlRHbWJQNStIS0N6Yz0";
private static Logger logger = LoggerFactory.getLogger(NetCDFId.class); private static Logger logger = LoggerFactory.getLogger(NetCDFId.class);
private URL publicLink; private URL publicLink;
@ -67,17 +63,6 @@ public class NetCDFResource {
* { System.loadLibrary("gdaljni"); } * { System.loadLibrary("gdaljni"); }
*/ */
public NetCDFResource() throws ServiceException {
try {
this.publicLink = new URL(example2);
} catch (MalformedURLException e) {
logger.error(e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e);
}
retrievePublicLink();
this.netCDFId = new NetCDFId(ncFile.toAbsolutePath().toString());
}
public NetCDFResource(URL publicLink) throws ServiceException { public NetCDFResource(URL publicLink) throws ServiceException {
this.publicLink = publicLink; this.publicLink = publicLink;