482 lines
11 KiB
Java
482 lines
11 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.td.client;
|
|
|
|
import org.gcube.portlets.user.td.csvexportwidget.client.CSVExportWizardTD;
|
|
import org.gcube.portlets.user.td.csvimportwidget.client.CSVImportWizardTD;
|
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
|
import org.gcube.portlets.user.td.openwidget.client.TDOpen;
|
|
import org.gcube.portlets.user.td.sdmxexportwidget.client.SDMXExportWizardTD;
|
|
import org.gcube.portlets.user.td.sdmximportwidget.client.SDMXImportWizardTD;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.RibbonEvent;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.UIStateEvent;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.RibbonType;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.UIStateType;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
|
import org.gcube.portlets.user.td.wizardwidget.client.WizardListener;
|
|
import org.gcube.portlets.user.tdw.client.TabularData;
|
|
import org.gcube.portlets.user.tdw.shared.model.TableId;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.core.client.RunAsyncCallback;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.web.bindery.event.shared.EventBus;
|
|
import com.google.web.bindery.event.shared.SimpleEventBus;
|
|
import com.sencha.gxt.widget.core.client.ContentPanel;
|
|
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
|
|
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer.BorderLayoutData;
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent;
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
|
|
import com.sencha.gxt.widget.core.client.info.Info;
|
|
|
|
/**
|
|
*
|
|
* @author "Giancarlo Panichi" <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class TabularDataController {
|
|
// implements HasCloseHandlers<Long>, HasOpenHandlers<Long> {
|
|
|
|
protected SimpleEventBus eventBus;
|
|
protected TabularData tabularData;
|
|
protected UIStateType uiState = UIStateType.START;
|
|
|
|
protected ContentPanel toolBoxPanel;
|
|
protected BorderLayoutData eastData;
|
|
|
|
/**
|
|
* Tabular Resource Id
|
|
*/
|
|
protected TRId trId;
|
|
|
|
/**
|
|
* Grid TableId
|
|
*/
|
|
protected TableId tableOpening;
|
|
|
|
public TabularDataController() {
|
|
eventBus = new SimpleEventBus();
|
|
bindToEvents();
|
|
}
|
|
|
|
/**
|
|
* @return the eventBus
|
|
*/
|
|
public EventBus getEventBus() {
|
|
return eventBus;
|
|
}
|
|
|
|
public void setTabularData(TabularData tabularData) {
|
|
this.tabularData = tabularData;
|
|
}
|
|
|
|
public ContentPanel getToolBoxPanel() {
|
|
return toolBoxPanel;
|
|
}
|
|
|
|
public void setToolBoxPanel(ContentPanel toolBoxPanel) {
|
|
this.toolBoxPanel = toolBoxPanel;
|
|
}
|
|
|
|
|
|
|
|
public BorderLayoutData getEastData() {
|
|
return eastData;
|
|
}
|
|
|
|
public void setEastData(BorderLayoutData eastData) {
|
|
this.eastData = eastData;
|
|
}
|
|
|
|
protected void bindToEvents() {
|
|
eventBus.addHandler(RibbonEvent.TYPE,
|
|
new RibbonEvent.RibbonEventHandler() {
|
|
|
|
@Override
|
|
public void onRibbon(RibbonEvent event) {
|
|
doRibbonCommand(event);
|
|
|
|
}
|
|
});
|
|
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.START));
|
|
|
|
}
|
|
|
|
protected void alertMessage(String reason, String details) {
|
|
AlertMessageBox d = new AlertMessageBox(reason, details);
|
|
d.addHideHandler(new HideHandler() {
|
|
|
|
@Override
|
|
public void onHide(HideEvent event) {
|
|
//
|
|
}
|
|
|
|
});
|
|
d.show();
|
|
}
|
|
|
|
protected void resumeUIState() {
|
|
if (uiState == UIStateType.TR_OPEN) {
|
|
UIStateEvent uiStateEvent=new UIStateEvent(UIStateType.TR_OPEN);
|
|
uiStateEvent.setTrId(trId);
|
|
eventBus.fireEvent(uiStateEvent);
|
|
} else {
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.TR_CLOSE));
|
|
}
|
|
}
|
|
|
|
protected void openTable(TRId tabularResourceId) {
|
|
Log.debug("openTabe: "+tabularResourceId);
|
|
trId = tabularResourceId;
|
|
tableOpening = new TableId(Constants.TD_DATASOURCE_FACTORY_ID,
|
|
trId.getTableId());
|
|
tabularData.openTable(tableOpening);
|
|
uiState = UIStateType.TR_OPEN;
|
|
UIStateEvent uiStateEvent=new UIStateEvent(UIStateType.TR_OPEN);
|
|
uiStateEvent.setTrId(tabularResourceId);
|
|
eventBus.fireEvent(uiStateEvent);
|
|
}
|
|
|
|
/*
|
|
protected void updateUIProperties(){
|
|
if (uiToolBox == UIToolBox.OPENED) {
|
|
trProperties.update();
|
|
}
|
|
}
|
|
*/
|
|
|
|
protected void closeTabularResource() {
|
|
if (uiState == UIStateType.TR_OPEN) {
|
|
tabularData.closeTable();
|
|
uiState = UIStateType.TR_CLOSE;
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.TR_CLOSE));
|
|
|
|
}
|
|
}
|
|
|
|
protected void deleteTabularResource() {
|
|
Log.debug("Remove TR:"+trId);
|
|
TDGWTServiceAsync.INSTANCE.removeTabularResource(trId,
|
|
new AsyncCallback<Void>() {
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
alertMessage("Error", "Error on remove TabResource: "
|
|
+ caught.getLocalizedMessage());
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(Void result) {
|
|
closeTabularResource();
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
protected void openWizard() {
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.WIZARD_OPEN));
|
|
}
|
|
|
|
public void doRibbonCommand(RibbonEvent event) {
|
|
RibbonType type = event.getRibbonType();
|
|
Log.trace("doRibbonEvent ribbonType: " + type);
|
|
try {
|
|
switch (type) {
|
|
case OPEN:
|
|
openTabularResource();
|
|
break;
|
|
case CLOSE:
|
|
closeTabularResource();
|
|
break;
|
|
case DELETE:
|
|
deleteTabularResource();
|
|
break;
|
|
case PROPERTIES:
|
|
break;
|
|
case IMPORTSDMX:
|
|
openSDMXImportWizard();
|
|
break;
|
|
case IMPORTCSV:
|
|
openCSVImportWizard();
|
|
break;
|
|
case IMPORTJSON:
|
|
break;
|
|
case EXPORTSDMX:
|
|
openSDMXExportWizard();
|
|
break;
|
|
case EXPORTCSV:
|
|
openCSVExportWizard();
|
|
break;
|
|
case EXPORTJSON:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} catch (Exception e) {
|
|
Log.error("doRibbonCommand Error : " + e.getLocalizedMessage()
|
|
+ " \n " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
/*
|
|
protected void openToolBox() {
|
|
if (uiState == UIStateType.TR_OPEN) {
|
|
if (uiToolBox == UIToolBox.OPENED) {
|
|
toolBoxPanel.collapse();
|
|
toolBoxPanel.disable();
|
|
|
|
uiToolBox = UIToolBox.CLOSED;
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.TOOLBOX_CLOSE));
|
|
toolBox.remove(trProperties);
|
|
Info.display("Properties", "Closed");
|
|
} else {
|
|
eventBus.fireEvent(new UIStateEvent(UIStateType.TOOLBOX_OPEN));
|
|
toolBoxPanel.enable();
|
|
toolBoxPanel.expand();
|
|
uiToolBox = UIToolBox.OPENED;
|
|
|
|
}
|
|
} else {
|
|
Info.display("Properties", "No table open");
|
|
}
|
|
};*/
|
|
|
|
protected void openSDMXImportWizard() {
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
@Override
|
|
public void onSuccess() {
|
|
openWizard();
|
|
SDMXImportWizardTD importWizard = new SDMXImportWizardTD(
|
|
"SDMX Import");
|
|
importWizard.addListener(new WizardListener() {
|
|
|
|
@Override
|
|
public void completed(TRId tabularResourceId) {
|
|
openTable(tabularResourceId);
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void failed(Throwable throwable, String reason,
|
|
String details) {
|
|
alertMessage(reason, details);
|
|
resumeUIState();
|
|
}
|
|
|
|
});
|
|
|
|
importWizard.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
protected void openCSVExportWizard() {
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
openWizard();
|
|
CSVExportWizardTD exportWizard = new CSVExportWizardTD(
|
|
"CSV Export");
|
|
|
|
exportWizard.addListener(new WizardListener() {
|
|
@Override
|
|
public void failed(Throwable throwable, String reason,
|
|
String details) {
|
|
alertMessage(reason, details);
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void completed(TRId id) {
|
|
resumeUIState();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
resumeUIState();
|
|
}
|
|
});
|
|
|
|
exportWizard.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
protected void openSDMXExportWizard() {
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
openWizard();
|
|
SDMXExportWizardTD exportWizard = new SDMXExportWizardTD(
|
|
"SDMX Export");
|
|
|
|
exportWizard.addListener(new WizardListener() {
|
|
@Override
|
|
public void failed(Throwable throwable, String reason,
|
|
String details) {
|
|
alertMessage(reason, details);
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void completed(TRId id) {
|
|
resumeUIState();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
resumeUIState();
|
|
}
|
|
});
|
|
|
|
exportWizard.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
protected void openTabularResource() {
|
|
Log.info("Open Tabular Resources");
|
|
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
openWizard();
|
|
TDOpen tdOpen = new TDOpen("Open Tabular Resource");
|
|
|
|
tdOpen.addListener(new WizardListener() {
|
|
|
|
@Override
|
|
public void aborted() {
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void failed(Throwable throwable, String reason,
|
|
String details) {
|
|
alertMessage(reason, details);
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void completed(TRId tabularResourceId) {
|
|
openTable(tabularResourceId);
|
|
|
|
}
|
|
|
|
});
|
|
Log.info("TDOpen add Listener");
|
|
tdOpen.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
protected void openCSVImportWizard() {
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
openWizard();
|
|
CSVImportWizardTD importWizard = new CSVImportWizardTD(
|
|
"CSV Import");
|
|
|
|
importWizard.addListener(new WizardListener() {
|
|
|
|
@Override
|
|
public void failed(Throwable throwable, String reason,
|
|
String details) {
|
|
alertMessage(reason, details);
|
|
resumeUIState();
|
|
}
|
|
|
|
@Override
|
|
public void completed(TRId id) {
|
|
openTable(id);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void aborted() {
|
|
resumeUIState();
|
|
}
|
|
});
|
|
|
|
importWizard.show();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable reason) {
|
|
asyncCodeLoadingFailed(reason);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
protected void asyncCodeLoadingFailed(Throwable reason) {
|
|
Log.error("Async code loading failed", reason);
|
|
Info.display("Async code loading failed",
|
|
"Please retry to lunch the operation");
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*
|
|
* @Override public HandlerRegistration addCloseHandler(CloseHandler<Long>
|
|
* handler) { //return eventBus.addHandler(CloseEvent.getType(),
|
|
* handler); }
|
|
*
|
|
* /** {@inheritDoc}
|
|
* @Override public HandlerRegistration addOpenHandler(OpenHandler<Long>
|
|
* handler) { //return eventBus.addHandler(OpenEvent.getType(),
|
|
* handler); }
|
|
*/
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*
|
|
* @Override public void fireEvent(GwtEvent<?> event) {
|
|
* eventBus.fireEvent(event); }
|
|
*/
|
|
|
|
}
|