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;
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.widgets.NetCDFPreviewDialog;
@ -17,6 +16,11 @@ import com.google.gwt.core.shared.GWT;
*
*/
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}
@ -31,21 +35,20 @@ public class NetCDFBasicWidgets implements EntryPoint {
}
private void loadMainPanel() {
GWT.log("NetcdfBasicWidgetsManager");
// Example
SelectVariableEventHandler handler=new SelectVariableEventHandler() {
SelectVariableEventHandler handler = new SelectVariableEventHandler() {
@Override
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);
}

View File

@ -27,14 +27,15 @@ import com.google.gwt.view.client.ListDataProvider;
*/
public class NetCDFDataModel {
private String url;
private NetCDFData netCDFData;
private ArrayList<NetCDFDataEventHandler> handlers = new ArrayList<>();
private ListDataProvider<VariableData> variableDataProvider = new ListDataProvider<>();
private ListDataProvider<AttributeData> globalAttributeDataProvider = new ListDataProvider<>();
public NetCDFDataModel() {
public NetCDFDataModel(String url) {
this.url=url;
retrieveData();
}
@ -74,7 +75,7 @@ public class NetCDFDataModel {
public void retrieveData() {
NetCDFBasicWidgetServiceAsync.INSTANCE.getNetCDFFromPublicLink("", new AsyncCallback<NetCDFData>() {
NetCDFBasicWidgetServiceAsync.INSTANCE.getNetCDFFromPublicLink(url, new AsyncCallback<NetCDFData>() {
@Override
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 getNetCDFFromItem(String itemId) throws ServiceException;
public void closeNetCDF(NetCDFId netCDFId) 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 getNetCDFFromItem(String itemId, AsyncCallback<NetCDFData> callback);
void closeNetCDF(NetCDFId netCDFId, AsyncCallback<Void> callback);
void readDataVariable(NetCDFId netCDFId, VariableData variableData, boolean sample, int limit,

View File

@ -39,6 +39,7 @@ import com.google.gwt.user.client.ui.Widget;
*
*/
public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEvent.HasSelectVariableEventHandler {
private static final String TABPANEL_HEIGHT = "400px";
private static final String TABPANEL_WIDTH = "700px";
@ -53,25 +54,15 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
private DetailPanel detailPanel;
private SamplePanel samplePanel;
private InfoPanel infoPanel;
private String url;
// private DataGrid<VariableData> dataGrid;
//private DataGrid<VariableData> dataGrid;
public NetCDFPreviewDialog() {
public NetCDFPreviewDialog(String url) {
try {
initWindow();
initHandler();
addToolIcon();
create();
} catch (Throwable e) {
GWT.log(e.getLocalizedMessage());
e.printStackTrace();
}
}
public NetCDFPreviewDialog(String fileId) {
try {
GWT.log("FileId: " + fileId);
GWT.log("PublicLink: " + url);
this.url = url;
initWindow();
initHandler();
addToolIcon();
@ -89,8 +80,8 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
setGlassEnabled(true);
setAnimationEnabled(true);
setText(messages.dialogTitle());
//setHeight(DIALOG_HEIGHT);
//setWidth(DIALOG_WIDTH);
// setHeight(DIALOG_HEIGHT);
// setWidth(DIALOG_WIDTH);
}
private void initHandler() {
@ -107,7 +98,7 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
private void create() {
netCDFDataModel = new NetCDFDataModel();
netCDFDataModel = new NetCDFDataModel(url);
// Create a tab panel
TabLayoutPanel tabPanel = new TabLayoutPanel(2.5, Unit.EM);
tabPanel.setAnimationDuration(1000);
@ -116,46 +107,41 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
tabPanel.setHeight(TABPANEL_HEIGHT);
tabPanel.setWidth(TABPANEL_WIDTH);
//Variable TabPanel
// Variable TabPanel
variablesPanel = new VariablesPanel(netCDFDataModel);
tabPanel.add(variablesPanel, messages.variablesTab());
//Detail TabPanel
// Detail TabPanel
detailPanel = new DetailPanel(netCDFDataModel);
tabPanel.add(detailPanel, messages.detailTab());
//Sample TabPanel
// Sample TabPanel
samplePanel = new SamplePanel(netCDFDataModel);
tabPanel.add(samplePanel, messages.sampleTab());
//Info TabPanel
// Info TabPanel
infoPanel = new InfoPanel(netCDFDataModel);
tabPanel.add(infoPanel, messages.infoTab());
// Return the content
tabPanel.selectTab(0);
tabPanel.ensureDebugId("netcdfTabPanel");
tabPanel.addSelectionHandler(new SelectionHandler<Integer>()
{
public void onSelection(SelectionEvent<Integer> event)
{
tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {
public void onSelection(SelectionEvent<Integer> event) {
int tabId = event.getSelectedItem();
Widget tabWidget = tabPanel.getWidget(tabId);
if (tabWidget != null)
{
if(tabWidget instanceof VariablesPanel){
VariablesPanel variablesPanel=(VariablesPanel)tabWidget;
if (tabWidget != null) {
if (tabWidget instanceof VariablesPanel) {
VariablesPanel variablesPanel = (VariablesPanel) tabWidget;
variablesPanel.refresh();
} else {
if(tabWidget instanceof DetailPanel){
DetailPanel detailPanel=(DetailPanel)tabWidget;
if (tabWidget instanceof DetailPanel) {
DetailPanel detailPanel = (DetailPanel) tabWidget;
detailPanel.refresh();
} else {
if(tabWidget instanceof InfoPanel){
InfoPanel infoPanel=(InfoPanel)tabWidget;
if (tabWidget instanceof InfoPanel) {
InfoPanel infoPanel = (InfoPanel) tabWidget;
infoPanel.refresh();
} else {
@ -166,12 +152,10 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
}
});
// Create a table to layout the content
//VerticalPanel dialogContents = new VerticalPanel();
//dialogContents.setSpacing(4);
//dialogContents.add(tabPanel);
// VerticalPanel dialogContents = new VerticalPanel();
// dialogContents.setSpacing(4);
// dialogContents.add(tabPanel);
// Add Button
Button btnSave = new Button("Save");
@ -202,12 +186,13 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
FlowPanel buttonPack = new FlowPanel();
buttonPack.setWidth("100%");
//buttonPack.add(btnSave);
// buttonPack.add(btnSave);
buttonPack.add(btnClose);
/*HorizontalPanel hp=new HorizontalPanel();
hp.add(buttonPack);
hp.setCellHorizontalAlignment(buttonPack, HasHorizontalAlignment.ALIGN_CENTER);
/*
* HorizontalPanel hp=new HorizontalPanel(); hp.add(buttonPack);
* hp.setCellHorizontalAlignment(buttonPack,
* HasHorizontalAlignment.ALIGN_CENTER);
*/
DockPanel dockPanel = new DockPanel();
@ -215,15 +200,12 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
dockPanel.add(tabPanel, DockPanel.CENTER);
dockPanel.add(buttonPack, DockPanel.SOUTH);
dockPanel.setCellHorizontalAlignment(buttonPack,DockPanel.ALIGN_CENTER);
dockPanel.setCellHorizontalAlignment(buttonPack, DockPanel.ALIGN_CENTER);
dockPanel.setWidth("100%");
setWidget(dockPanel);
center();
}
@Override
@ -232,8 +214,8 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
center();
};
private void closeOnServer(){
if(netCDFDataModel!=null){
private void closeOnServer() {
if (netCDFDataModel != null) {
netCDFDataModel.close();
}
}
@ -246,7 +228,7 @@ public class NetCDFPreviewDialog extends DialogBox implements SelectVariableEven
}
private void btnSavePressed() {
Set<VariableData> selected=variablesPanel.seleceted();
Set<VariableData> selected = variablesPanel.seleceted();
if (selected == null || selected.isEmpty()) {
GWTMessages.alert("Attention", "Select a layer!", zIndex);
} 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
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.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
@ -52,9 +51,6 @@ import ucar.nc2.Variable;
*
*/
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);
@ -67,17 +63,6 @@ public class NetCDFResource {
* { 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 {
this.publicLink = publicLink;