diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index f84671a..14ac512 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -22,9 +22,6 @@ uses - - uses - diff --git a/src/main/java/org/gcube/portlets/user/td/client/Constants.java b/src/main/java/org/gcube/portlets/user/td/client/Constants.java new file mode 100644 index 0000000..2c59c64 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/client/Constants.java @@ -0,0 +1,24 @@ +/** + * + */ +package org.gcube.portlets.user.td.client; + + +/** + */ +public class Constants { + + public static String VERSION = "1.0.0"; + public static boolean TEST_MODE = false; + public final static String DEFAULT_USER = + (!TEST_MODE) ? "test.user" : + "giancarlo.panichi"; + + + public static final String DEFAULT_SCOPE = "/gcube/devsec/devVRE";//"/gcube/devsec"; + + public static final String TD_DATASOURCE_FACTORY_ID = "TDDataSourceFactory"; + + public static final String APPLICATION_ID = "org.gcube.portlets.user.td.server.portlet.TabularDataPortlet"; + +} diff --git a/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java b/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java index e5fe060..08b8db4 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java +++ b/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java @@ -3,28 +3,24 @@ */ package org.gcube.portlets.user.td.client; +import org.gcube.portlets.user.sdmximportwizardtd.client.SDMXImportWizardTD; +import org.gcube.portlets.user.sdmximportwizardtd.client.general.WizardListener; import org.gcube.portlets.user.td.ciw.client.CSVImporterWidget; +import org.gcube.portlets.user.td.client.event.CloseTabularResourceEvent; +import org.gcube.portlets.user.td.client.event.CloseTabularResourceType; import org.gcube.portlets.user.td.client.event.ImportTableEvent; import org.gcube.portlets.user.td.client.event.ImportTableType; import org.gcube.portlets.user.td.client.event.OpenTabularResourceEvent; import org.gcube.portlets.user.td.client.event.OpenTabularResourceType; import org.gcube.portlets.user.td.importer.client.TabularDataImporterListener; import org.gcube.portlets.user.td.open.client.TDOpen; -import org.gcube.portlets.user.sdmximportwizardtd.client.SDMXImportWizardTD; -import org.gcube.portlets.user.sdmximportwizardtd.client.general.WizardListener; - +import org.gcube.portlets.user.tdw.client.TabularData; +import org.gcube.portlets.user.tdw.shared.model.TableDefinition; +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.event.logical.shared.CloseEvent; -import com.google.gwt.event.logical.shared.CloseHandler; -import com.google.gwt.event.logical.shared.HasCloseHandlers; -import com.google.gwt.event.logical.shared.HasOpenHandlers; -import com.google.gwt.event.logical.shared.OpenEvent; -import com.google.gwt.event.logical.shared.OpenHandler; -import com.google.gwt.event.shared.GwtEvent; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.web.bindery.event.shared.EventBus; import com.google.web.bindery.event.shared.SimpleEventBus; import com.sencha.gxt.widget.core.client.info.Info; @@ -36,7 +32,25 @@ public class TabularDataController { //implements HasCloseHandlers, HasOpenHandlers { protected SimpleEventBus eventBus; - + protected TabularData tabularData; + + /** + * Tabular Data Id + */ + protected TableId tableOpening; + + /** + * Table Open + */ + protected boolean tableOpen=false; + + /** + * Table Id + */ + protected String tableId; + + + public TabularDataController() { eventBus = new SimpleEventBus(); bindToEvents(); @@ -48,7 +62,13 @@ public class TabularDataController { public EventBus getEventBus() { return eventBus; } - + + + public void setTabularData(TabularData tabularData){ + this.tabularData=tabularData; + } + + protected void bindToEvents() { eventBus.addHandler(ImportTableEvent.TYPE, new ImportTableEvent.ImportTableHandler() { @@ -66,11 +86,20 @@ public class TabularDataController { doOpenTabularResource(event.getOpenType()); } }); + eventBus.addHandler(CloseTabularResourceEvent.TYPE, + new CloseTabularResourceEvent.CloseTabularResourceHandler() { + + @Override + public void onCloseTabularResource(CloseTabularResourceEvent event) { + doCloseTabularResource(event.getCloseType()); + } + }); + } public void doImportTable(ImportTableType importType) { Log.trace("doImportTable importType: " + importType); - Info.display("ImportTableEvent", "importType: " + importType); + Info.display("Import Tabular Resource", "type: " + importType); try { switch (importType) { case SDMX: @@ -86,13 +115,13 @@ public class TabularDataController { break; } } catch (Exception e) { - Log.error("doImportTable Error : " + e.getLocalizedMessage()+ " \n "+e.getCause()); + Log.error("doImportTable Error : " + e.getLocalizedMessage()+ " \n "+e.getMessage()); } } public void doOpenTabularResource(OpenTabularResourceType openType) { Log.trace("doOpenTabularResource openType: " + openType); - Info.display("OpenTabularResourceEvent", "openType: " + openType); + Info.display("Open Tabular Resource", "open: " + openType); try { switch (openType) { case TABLE: @@ -102,7 +131,24 @@ public class TabularDataController { break; } } catch (Exception e) { - Log.error("doOpenTable Error : " + e.getLocalizedMessage()+ " \n "+e.getCause()); + Log.error("doOpenTable Error : " + e.getLocalizedMessage()+ " \n "+e.getMessage()); + } + } + + + public void doCloseTabularResource(CloseTabularResourceType closeType) { + Log.trace("doCloseTabularResource closeType: " + closeType); + Info.display("Close Tabular Resource", "close: " + closeType); + try { + switch (closeType) { + case TABLE: + closeTabularResources(); + break; + default: + break; + } + } catch (Exception e) { + Log.error("doOpenTable Error : " + e.getLocalizedMessage()+ " \n "+e.getMessage()); } } @@ -118,7 +164,7 @@ public class TabularDataController { @Override public void completed() { - //TableId importWizard.getTable(index); + //importWizard.getTable(); } @@ -164,21 +210,27 @@ public class TabularDataController { } + /** + * + */ + protected void closeTabularResources(){ + if(tableOpen) tabularData.closeTable(); + } + + /** + * + */ protected void openTabularResources() { + Log.info("Open Tabular Resources"); + GWT.runAsync(new RunAsyncCallback() { @Override public void onSuccess() { TDOpen tdOpen= new TDOpen("Tabular Resources Open"); - - tdOpen.addListener(new org.gcube.portlets.user.td.open.client.general.WizardListener(){ - - @Override - public void completed() { - // TODO Auto-generated method stub - - } + + tdOpen.addListener(new org.gcube.portlets.user.td.open.client.general.OpenListener(){ @Override public void aborted() { @@ -192,9 +244,18 @@ public class TabularDataController { // TODO Auto-generated method stub } - + + @Override + public void completed(String tablekey) { + + tableOpening=new TableId(Constants.TD_DATASOURCE_FACTORY_ID,tablekey); + tabularData.openTable(tableOpening); + tableOpen=true; + tableId=tablekey; + + } }); - + Log.info("TDOpen add Listener"); tdOpen.show(); } diff --git a/src/main/java/org/gcube/portlets/user/td/client/TabularDataPortlet.java b/src/main/java/org/gcube/portlets/user/td/client/TabularDataPortlet.java index 0ec8b24..0f0c5b8 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/TabularDataPortlet.java +++ b/src/main/java/org/gcube/portlets/user/td/client/TabularDataPortlet.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.td.client; + import org.gcube.portlets.user.td.client.ribbon.TabularDataRibbon; import org.gcube.portlets.user.td.client.rpc.TabularDataService; import org.gcube.portlets.user.td.client.rpc.TabularDataServiceAsync; @@ -8,6 +9,7 @@ import org.gcube.portlets.user.tdw.client.TabularData; import org.gcube.portlets.user.tdw.client.TabularDataGridPanel; import org.gcube.portlets.user.tdw.client.event.FailureEvent; import org.gcube.portlets.user.tdw.client.event.FailureEventHandler; +import org.gcube.portlets.user.tdw.shared.model.DataRow; import org.gcube.portlets.user.tdw.shared.model.TableId; import com.allen_sauer.gwt.log.client.Log; @@ -15,15 +17,18 @@ import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.user.client.ui.ResizeLayoutPanel; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.core.client.util.Margins; +import com.sencha.gxt.widget.core.client.Dialog; import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer; import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer.BorderLayoutData; import com.sencha.gxt.widget.core.client.container.MarginData; import com.sencha.gxt.widget.core.client.container.SimpleContainer; import com.sencha.gxt.widget.core.client.container.Viewport; +import com.sencha.gxt.widget.core.client.grid.Grid; import com.sencha.gxt.widget.core.client.info.Info; /** @@ -46,9 +51,12 @@ public class TabularDataPortlet implements EntryPoint { /** * Create a remote service proxy to talk to the server-side Greeting service. */ + @SuppressWarnings("unused") private final TabularDataServiceAsync greetingService = GWT.create(TabularDataService.class); - + //Private TabularData + private static TabularData tabularData; + /** * {@inheritDoc} */ @@ -74,8 +82,22 @@ public class TabularDataPortlet implements EntryPoint { TabularDataController controller = new TabularDataController(); EventBus eventBus = controller.getEventBus(); + tabularData = new TabularData(Constants.TD_DATASOURCE_FACTORY_ID); + tabularData.addFailureHandler(new FailureEventHandler() { + + @Override + public void onFailure(FailureEvent event) { + Info.display("Error: "+event.getMessage(), event.getCaught().getMessage()); + + } + }); + controller.setTabularData(tabularData); + + + //Layout final BorderLayoutContainer mainPanelLayout = new BorderLayoutContainer(); mainPanelLayout.setBorders(true); + //Ribbon Menu @@ -90,24 +112,17 @@ public class TabularDataPortlet implements EntryPoint { mainPanelLayout.setNorthWidget(toolBarPanel, toolBarData); - //Grid - final TabularData tabularData = new TabularData("TDDataSourceFactory"); - tabularData.addFailureHandler(new FailureEventHandler() { - - @Override - public void onFailure(FailureEvent event) { - Info.display("Error: "+event.getMessage(), event.getCaught().getMessage()); - - } - }); - - final TabularDataGridPanel grid = tabularData.getGridPanel(); + //Grid + final TabularDataGridPanel gridPanel = tabularData.getGridPanel(); MarginData gridData = new MarginData(); + - mainPanelLayout.setCenterWidget(grid, gridData); - - TableId tableopening=new TableId("TDDataSourceFactory","1"); + /*TableId tableopening=new TableId(Constants.TD_DATASOURCE_FACTORY_ID,"1"); tabularData.openTable(tableopening); + gridPanel.setHeaderVisible(false);*/ + + mainPanelLayout.setCenterWidget(gridPanel, gridData); + //Main SimpleContainer mainPanel = new SimpleContainer(); mainPanel.add(mainPanelLayout); @@ -131,4 +146,6 @@ public class TabularDataPortlet implements EntryPoint { root.add(viewport); } } + + } diff --git a/src/main/java/org/gcube/portlets/user/td/client/event/CloseTabularResourceEvent.java b/src/main/java/org/gcube/portlets/user/td/client/event/CloseTabularResourceEvent.java new file mode 100644 index 0000000..6c95543 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/client/event/CloseTabularResourceEvent.java @@ -0,0 +1,42 @@ +package org.gcube.portlets.user.td.client.event; + +import com.google.gwt.event.shared.GwtEvent; +import com.google.gwt.event.shared.EventHandler; + +import com.google.gwt.event.shared.HasHandlers; + +public class CloseTabularResourceEvent extends GwtEvent { + + public static Type TYPE = new Type(); + private CloseTabularResourceType closeType; + + public interface CloseTabularResourceHandler extends EventHandler { + void onCloseTabularResource(CloseTabularResourceEvent event); + } + + public CloseTabularResourceEvent(CloseTabularResourceType closeType) { + this.closeType = closeType; + } + + public CloseTabularResourceType getCloseType() { + return closeType; + } + + @Override + protected void dispatch(CloseTabularResourceHandler handler) { + handler.onCloseTabularResource(this); + } + + @Override + public Type getAssociatedType() { + return TYPE; + } + + public static Type getType() { + return TYPE; + } + + public static void fire(HasHandlers source, CloseTabularResourceType closeType) { + source.fireEvent(new CloseTabularResourceEvent(closeType)); + } +} diff --git a/src/main/java/org/gcube/portlets/user/td/client/event/CloseTabularResourceType.java b/src/main/java/org/gcube/portlets/user/td/client/event/CloseTabularResourceType.java new file mode 100644 index 0000000..8bd362b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/client/event/CloseTabularResourceType.java @@ -0,0 +1,12 @@ +/** + * + */ +package org.gcube.portlets.user.td.client.event; + +/** + * @author "Federico De Faveri defaveri@isti.cnr.it" + * + */ +public enum CloseTabularResourceType { + TABLE; +} diff --git a/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBar.java b/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBar.java index b7f95f7..c6fb8e4 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBar.java +++ b/src/main/java/org/gcube/portlets/user/td/client/ribbon/FileToolBar.java @@ -3,6 +3,8 @@ */ package org.gcube.portlets.user.td.client.ribbon; +import org.gcube.portlets.user.td.client.event.CloseTabularResourceEvent; +import org.gcube.portlets.user.td.client.event.CloseTabularResourceType; import org.gcube.portlets.user.td.client.event.ImportTableEvent; import org.gcube.portlets.user.td.client.event.ImportTableType; import org.gcube.portlets.user.td.client.event.OpenTabularResourceEvent; @@ -36,7 +38,7 @@ public class FileToolBar { protected ToolBar toolBar; protected TextButton openButton; - protected TextButton saveButton; + //protected TextButton saveButton; protected TextButton closeButton; protected TextButton propertiesButton; @@ -91,6 +93,7 @@ public class FileToolBar { dataLayout.setWidget(0, 0, openButton); dataLayout.getFlexCellFormatter().setRowSpan(0, 0, 2); + /* saveButton = new TextButton("Save", TabularDataResources.INSTANCE.save32()); saveButton.setScale(ButtonScale.LARGE); saveButton.setIconAlign(IconAlign.TOP); @@ -107,7 +110,7 @@ public class FileToolBar { dataLayout.setWidget(0, 1, saveButton); dataLayout.getFlexCellFormatter().setRowSpan(0, 1, 2); - + */ closeButton = new TextButton("Close", TabularDataResources.INSTANCE.close()); closeButton.setToolTip("Close table"); @@ -116,7 +119,7 @@ public class FileToolBar { @Override public void onSelect(SelectEvent event) { - //eventBus.fireEvent(new ImportTableEvent(ImportTableType.CSV)); + eventBus.fireEvent(new CloseTabularResourceEvent(CloseTabularResourceType.TABLE)); } }); diff --git a/src/main/java/org/gcube/portlets/user/td/server/TabularDataServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/server/TabularDataServiceImpl.java index bcf9c24..1c6b4f1 100644 --- a/src/main/java/org/gcube/portlets/user/td/server/TabularDataServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/server/TabularDataServiceImpl.java @@ -31,7 +31,7 @@ public class TabularDataServiceImpl extends RemoteServiceServlet implements Tabu public void init() throws ServletException { super.init(); - System.out.println("initializing the TabularDataImporterManager"); + System.out.println("initializing the TabularDataImportManager"); TabularDataImporterManager importerManager = new TabularDataImporterManager(); //importerManager.scanAvailableImporters(); importerManager.add(new CSVTDImporter()); @@ -43,6 +43,7 @@ public class TabularDataServiceImpl extends RemoteServiceServlet implements Tabu ScopeProvider.instance.set("/gcube/devsec"); + System.out.println("initializing TDDataSourceFactory"); DataSourceFactoryRegistry.getInstance().add(new TDDataSourceFactory()); }