() {
+
+ public void onSuccess(String taskId) {
+ openMonitorDialog(taskId);
+
+ }
+
+ public void onFailure(Throwable caught) {
+ if (caught instanceof TDGWTSessionExpiredException) {
+ getEventBus()
+ .fireEvent(
+ new SessionExpiredEvent(
+ SessionExpiredType.EXPIREDONSERVER));
+ } else {
+ if (caught instanceof TDGWTIsLockedException) {
+ Log.error(caught.getLocalizedMessage());
+ showErrorAndHide("Error Locked",
+ caught.getLocalizedMessage(), "",
+ caught);
+ } else {
+ showErrorAndHide("Error in template export SDMX",
+ "An error occured in template export SDMX.",
+ caught.getLocalizedMessage(), caught);
+ }
+ }
+ }
+ });
+ }
+
+ @Override
+ public void setup() {
+ getWizardWindow().setEnableBackButton(false);
+ setBackButtonVisible(false);
+ getWizardWindow().setEnableNextButton(false);
+ getWizardWindow().setNextButtonToFinish();
+ exportSDMX();
+ }
+
+ //
+ protected void openMonitorDialog(String taskId) {
+ MonitorDialog monitorDialog = new MonitorDialog(taskId, getEventBus());
+ monitorDialog.addProgressDialogListener(this);
+ monitorDialog.show();
+ }
+
+ @Override
+ public void operationComplete(OperationResult operationResult) {
+ newTrId = operationResult.getTrId();
+ SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
+ safeHtmlBuilder
+ .appendHtmlConstant("Operation Completed
");
+ resultField.setHTML(safeHtmlBuilder.toSafeHtml());
+ resultField.setVisible(true);
+ Command sayComplete = new Command() {
+ public void execute() {
+ try {
+ getWizardWindow().close(false);
+ Log.info("fire Complete: " + newTrId);
+
+ getWizardWindow().fireCompleted(newTrId);
+
+ } catch (Exception e) {
+ Log.error("fire Complete :" + e.getLocalizedMessage());
+ }
+ }
+ };
+
+ getWizardWindow().setNextButtonCommand(sayComplete);
+
+ setNextButtonVisible(true);
+ getWizardWindow().setEnableNextButton(true);
+ forceLayout();
+
+ }
+
+ @Override
+ public void operationFailed(Throwable caught, String reason, String details) {
+ SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
+ safeHtmlBuilder
+ .appendHtmlConstant("Operation Failed
");
+ resultField.setHTML(safeHtmlBuilder.toSafeHtml());
+ resultField.setVisible(true);
+ if (caught instanceof TDGWTSessionExpiredException) {
+ getEventBus()
+ .fireEvent(
+ new SessionExpiredEvent(
+ SessionExpiredType.EXPIREDONSERVER));
+ } else {
+ showErrorAndHide("Error in SDMX Export", reason, details, caught);
+ }
+ forceLayout();
+ }
+
+ @Override
+ public void operationStopped(OperationResult operationResult, String reason, String details) {
+ newTrId = operationResult.getTrId();
+ SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
+ safeHtmlBuilder
+ .appendHtmlConstant("Problems in the Operation
");
+ resultField.setHTML(safeHtmlBuilder.toSafeHtml());
+ resultField.setVisible(true);
+
+ Command sayComplete = new Command() {
+ public void execute() {
+ try {
+ getWizardWindow().close(false);
+ Log.info("fire Complete: tabular resource "
+ + newTrId.getId());
+ Log.info("fire Complete: tableId " + newTrId.getTableId());
+
+ getWizardWindow().fireCompleted(newTrId);
+
+ } catch (Exception e) {
+ Log.error("fire Complete :" + e.getLocalizedMessage());
+ }
+ }
+ };
+
+ getWizardWindow().setNextButtonCommand(sayComplete);
+
+ setNextButtonVisible(true);
+ getWizardWindow().setEnableNextButton(true);
+ forceLayout();
+ }
+
+ @Override
+ public void operationAborted() {
+ SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
+ safeHtmlBuilder
+ .appendHtmlConstant("Operation Aborted
");
+ resultField.setHTML(safeHtmlBuilder.toSafeHtml());
+ resultField.setVisible(true);
+
+ Command sayComplete = new Command() {
+ public void execute() {
+ try {
+ getWizardWindow().close(false);
+ Log.info("fire Aborted");
+
+ getWizardWindow().fireAborted();
+
+ } catch (Exception e) {
+ Log.error("fire Aborted :" + e.getLocalizedMessage());
+ }
+ }
+ };
+
+ getWizardWindow().setNextButtonCommand(sayComplete);
+
+ setNextButtonVisible(true);
+ getWizardWindow().setEnableNextButton(true);
+ forceLayout();
+
+ }
+
+ @Override
+ public void operationPutInBackground() {
+ SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
+ safeHtmlBuilder
+ .appendHtmlConstant("Operation in Background
");
+ resultField.setHTML(safeHtmlBuilder.toSafeHtml());
+ resultField.setVisible(true);
+
+ Command sayComplete = new Command() {
+ public void execute() {
+ try {
+ getWizardWindow().close(false);
+ Log.info("fire Operation In Background");
+
+ getWizardWindow().firePutInBackground();
+
+ } catch (Exception e) {
+ Log.error("fire Operation In Background :"
+ + e.getLocalizedMessage());
+ }
+ }
+ };
+
+ getWizardWindow().setNextButtonCommand(sayComplete);
+
+ setNextButtonVisible(true);
+ getWizardWindow().setEnableNextButton(true);
+ forceLayout();
+
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateExportRegistrySelectionCard.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateExportRegistrySelectionCard.java
new file mode 100644
index 0000000..eb050f9
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateExportRegistrySelectionCard.java
@@ -0,0 +1,223 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.td.sdmxexportwidget.client.template;
+
+import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
+import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
+import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXTemplateExportSession;
+import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource;
+import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
+import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
+import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
+
+import com.allen_sauer.gwt.log.client.Log;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.NodeList;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.HasValue;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.sencha.gxt.core.client.util.ToggleGroup;
+import com.sencha.gxt.widget.core.client.container.MarginData;
+import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
+import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
+import com.sencha.gxt.widget.core.client.form.FieldLabel;
+import com.sencha.gxt.widget.core.client.form.Radio;
+import com.sencha.gxt.widget.core.client.form.TextField;
+
+/**
+ *
+ * @author "Giancarlo Panichi" g.panichi@isti.cnr.it
+ *
+ */
+public class SDMXTemplateExportRegistrySelectionCard extends WizardCard {
+
+ private SDMXTemplateExportSession sdmxTemplateExportSession;
+ private SDMXTemplateExportRegistrySelectionCard thisCard;
+
+ final TextField url = new TextField();
+
+ public SDMXTemplateExportRegistrySelectionCard(final SDMXTemplateExportSession sdmxTemplateExportSession) {
+ super("SDMX Registry selection", "");
+ thisCard = this;
+ SDMXRegistrySource sdmxRegistrySource=new SDMXRegistrySource();
+ sdmxTemplateExportSession.setSource(sdmxRegistrySource);
+ this.sdmxTemplateExportSession = sdmxTemplateExportSession;
+
+ VerticalPanel registrySelectionPanel = new VerticalPanel();
+ registrySelectionPanel.setStylePrimaryName(res.wizardCSS()
+ .getImportSelectionSources());
+
+ Radio radioStandardRegistry = new Radio();
+
+ radioStandardRegistry
+ .setBoxLabel("Internal SDMX Registry"
+ + "
Select this if you want use the Internal Registry
");
+ radioStandardRegistry.setValue(true);
+ radioStandardRegistry.setName("Default");
+ radioStandardRegistry.setStylePrimaryName(res.wizardCSS()
+ .getImportSelectionSource());
+
+ Radio radioUrlRegistry = new Radio();
+ radioUrlRegistry
+ .setBoxLabel("Another SDMX Registry
");
+ radioUrlRegistry.setName("Url");
+ radioUrlRegistry.setStylePrimaryName(res.wizardCSS()
+ .getImportSelectionSource());
+ radioUrlRegistry.disable();
+ radioUrlRegistry.setVisible(false);
+
+
+ url.setName("sdmxRegistryUrlInpuntField");
+ url.setId("sdmxRegistryUrlInputFieldId");
+ url.setStylePrimaryName(res.wizardCSS()
+ .getSDMXRegistryUrlInputStyle());
+
+ final VerticalLayoutContainer vcontainer = new VerticalLayoutContainer();
+ vcontainer.add(new FieldLabel(url, "URL"), new VerticalLayoutData(-1,
+ -1));
+ vcontainer.setStylePrimaryName(res.wizardCSS()
+ .getSDMXRegistryUrlStyle());
+ vcontainer.setVisible(false);
+
+ NodeList nodel = radioUrlRegistry.getElement()
+ .getElementsByTagName("SPAN");
+ Element span = nodel.getItem(0);
+ span.appendChild(vcontainer.getElement());
+
+ registrySelectionPanel.add(radioStandardRegistry);
+ registrySelectionPanel.add(radioUrlRegistry);
+
+ // we can set name on radios or use toggle group
+ ToggleGroup toggle = new ToggleGroup();
+ toggle.add(radioStandardRegistry);
+ toggle.add(radioUrlRegistry);
+
+ toggle.addValueChangeHandler(new ValueChangeHandler>() {
+
+
+ public void onValueChange(ValueChangeEvent> event) {
+ try {
+ ToggleGroup group = (ToggleGroup) event.getSource();
+ Radio radio = (Radio) group.getValue();
+ Log.info("Registry Selected:" + radio.getName());
+ if (radio.getName().compareTo("Url") == 0) {
+ vcontainer.setVisible(true);
+ NodeList nodel = radio.getElement()
+ .getElementsByTagName("SPAN");
+ Element span = nodel.getItem(0);
+ span.appendChild(vcontainer.getElement());
+
+ Log.info("SDMXRegistry Url");
+ Log.info("Input value: " + url.getCurrentValue());
+ SDMXRegistrySource r = ((SDMXRegistrySource) sdmxTemplateExportSession
+ .getSource());
+ r.setUrl(null);
+ Log.info("" + sdmxTemplateExportSession.getSource());
+ } else {
+ vcontainer.setVisible(false);
+ Log.info("SDMXRegistry Default");
+ SDMXRegistrySource r = ((SDMXRegistrySource) sdmxTemplateExportSession
+ .getSource());
+ r.setUrl(null);
+ Log.info("Input value: " + url.getCurrentValue());
+ Log.info("" + sdmxTemplateExportSession.getSource());
+ }
+ } catch (Exception e) {
+ Log.error("ToggleGroup: onValueChange "
+ + e.getLocalizedMessage());
+ }
+
+ }
+ });
+
+ setCenterWidget(registrySelectionPanel, new MarginData(0));
+
+ }
+
+ @Override
+ public void setup() {
+ Command sayNextCard = new Command() {
+ public void execute() {
+ try {
+ Log.info("Input value: " + url.getCurrentValue());
+ if (sdmxTemplateExportSession.getSource() instanceof SDMXRegistrySource) {
+ ((SDMXRegistrySource) sdmxTemplateExportSession.getSource())
+ .setUrl(url.getCurrentValue());
+
+ TDGWTServiceAsync.INSTANCE.setSDMXRegistrySource(
+ ((SDMXRegistrySource)sdmxTemplateExportSession.getSource()), new AsyncCallback() {
+
+ public void onFailure(Throwable caught) {
+ if (caught instanceof TDGWTSessionExpiredException) {
+ getEventBus()
+ .fireEvent(
+ new SessionExpiredEvent(
+ SessionExpiredType.EXPIREDONSERVER));
+ } else {
+ Log.error("SDMXRegistrySource do not stored "
+ + caught.getLocalizedMessage());
+ showErrorAndHide("Error", "SDMXRegistrySource do not stored."
+ ,caught.getLocalizedMessage(), caught);
+ }
+ }
+
+ public void onSuccess(Void result) {
+ Log.info("SDMXRegistrySource stored");
+ goNext();
+
+ }
+ });
+ } else {
+ Log.error("There is a problem in source selection.Expected SDMXRegistrySource, and found"
+ + sdmxTemplateExportSession.getSource());
+ }
+
+ } catch (Exception e) {
+ Log.error("sayNextCard :" + e.getLocalizedMessage());
+ }
+ }
+ };
+
+ getWizardWindow().setNextButtonCommand(sayNextCard);
+
+
+ Command sayPreviousCard = new Command() {
+ public void execute() {
+ try {
+ getWizardWindow().previousCard();
+ getWizardWindow().removeCard(thisCard);
+ Log.info("Remove SDMXTemplateRegistrySelectionCard");
+ } catch (Exception e) {
+ Log.error("sayPreviousCard :" + e.getLocalizedMessage());
+ }
+ }
+ };
+
+ getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
+
+ setEnableBackButton(false);
+ setEnableNextButton(true);
+ setBackButtonVisible(false);
+
+ }
+
+ protected void goNext() {
+ try {
+ SDMXTemplateExportAgenciesSelectionCard sdmxAgencyTypeCard = new SDMXTemplateExportAgenciesSelectionCard(
+ sdmxTemplateExportSession);
+ getWizardWindow().addCard(sdmxAgencyTypeCard);
+ Log.info("NextCard SDMXTemplateExportAgenciesSelectionCard ");
+ getWizardWindow().nextCard();
+ } catch (Exception e) {
+ Log.error("sayNextCard :" + e.getLocalizedMessage());
+ }
+ }
+
+
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateExportTableDetailCard.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateExportTableDetailCard.java
new file mode 100644
index 0000000..bac0186
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateExportTableDetailCard.java
@@ -0,0 +1,219 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.td.sdmxexportwidget.client.template;
+
+import org.gcube.portlets.user.td.gwtservice.shared.Constants;
+import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXTemplateExportSession;
+import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource;
+import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
+
+import com.allen_sauer.gwt.log.client.Log;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.sencha.gxt.widget.core.client.FramedPanel;
+import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
+import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
+import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
+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.form.FieldLabel;
+import com.sencha.gxt.widget.core.client.form.FieldSet;
+import com.sencha.gxt.widget.core.client.form.TextField;
+
+/**
+ *
+ * @author "Giancarlo Panichi" g.panichi@isti.cnr.it
+ *
+ */
+public class SDMXTemplateExportTableDetailCard extends WizardCard {
+
+ private final String TABLEDETAILPANELWIDTH = "100%";
+ private final String TABLEDETAILPANELHEIGHT = "100%";
+ private final String FORMWIDTH = "838px";
+
+ private SDMXTemplateExportSession sdmxTemplateExportSession;
+ private SDMXTemplateExportTableDetailCard thisCard;
+
+ private VerticalLayoutContainer p = new VerticalLayoutContainer();
+ private VerticalPanel tableDetailPanel;
+
+ private TextField id;
+ private TextField agencyId;
+ private TextField registryBaseUrl;
+ private TextField version;
+ private TextField templateName;
+ private TextField measureColumn;
+
+ public SDMXTemplateExportTableDetailCard(final SDMXTemplateExportSession sdmxTemplateExportSession) {
+ super("SDMX Table Detail", "");
+
+ this.sdmxTemplateExportSession = sdmxTemplateExportSession;
+ thisCard = this;
+
+ tableDetailPanel = new VerticalPanel();
+
+ tableDetailPanel.setSpacing(4);
+ tableDetailPanel.setWidth(TABLEDETAILPANELWIDTH);
+ tableDetailPanel.setHeight(TABLEDETAILPANELHEIGHT);
+
+ FramedPanel form = new FramedPanel();
+ form.setHeadingText("Details");
+ form.setWidth(FORMWIDTH);
+
+ FieldSet fieldSet = new FieldSet();
+ fieldSet.setHeadingText("Information");
+ fieldSet.setCollapsible(false);
+ form.add(fieldSet);
+
+ templateViewConfig();
+
+ fieldSet.add(p);
+
+ tableDetailPanel.add(form);
+ setContent(tableDetailPanel);
+
+ }
+
+ private void templateViewConfig() {
+ id = new TextField();
+ id.setAllowBlank(false);
+ id.setEmptyText("Enter Id...");
+ id.setValue(Constants.SDMX_TEMPLATE_EXPORT_DEFAULT_ID);
+ p.add(new FieldLabel(id, "Id"), new VerticalLayoutData(1, -1));
+
+ agencyId = new TextField();
+ agencyId.setVisible(true);
+ agencyId.setEmptyText("Enter Agency Id...");
+ if (sdmxTemplateExportSession.getAgency().getId() == null
+ || sdmxTemplateExportSession.getAgency().getId().isEmpty()) {
+ agencyId.setValue(Constants.SDMX_TEMPLATE_EXPORT_DEFAULT_AGENCY_ID);
+ } else {
+ agencyId.setValue(sdmxTemplateExportSession.getAgency().getId());
+ }
+
+ FieldLabel agencyNameLabel = new FieldLabel(agencyId, "Agency Id");
+ p.add(agencyNameLabel, new VerticalLayoutData(1, -1));
+
+ registryBaseUrl = new TextField();
+ registryBaseUrl.setVisible(false);
+ registryBaseUrl.setEmptyText("Enter Registry URL...");
+ String urlRegistry = ((SDMXRegistrySource) sdmxTemplateExportSession.getSource())
+ .getUrl();
+ if (urlRegistry == null || urlRegistry.isEmpty()) {
+ registryBaseUrl.setValue(null);
+ } else {
+ registryBaseUrl.setValue(urlRegistry);
+ }
+ FieldLabel registryBaseUrlLabel = new FieldLabel(registryBaseUrl,
+ "Registry URL");
+ registryBaseUrlLabel.setVisible(false);
+ p.add(registryBaseUrlLabel, new VerticalLayoutData(1, -1));
+
+ version = new TextField();
+ version.setAllowBlank(false);
+ version.setEmptyText("Enter Version...");
+ version.setValue(Constants.SDMX_TEMPLATE_EXPORT_DEFAULT_VERSION);
+ p.add(new FieldLabel(version, "Version"), new VerticalLayoutData(1, -1));
+
+
+ templateName = new TextField();
+ templateName.setValue(sdmxTemplateExportSession.getTemplateData().getName());
+ templateName.setReadOnly(true);
+ p.add(new FieldLabel(templateName, "Template"),
+ new VerticalLayoutData(1, -1));
+
+ measureColumn = new TextField();
+ measureColumn.setValue(sdmxTemplateExportSession.getObsValueColumn().getLabel());
+ measureColumn.setReadOnly(true);
+ p.add(new FieldLabel(measureColumn, "Measure Column"),
+ new VerticalLayoutData(1, -1));
+ }
+
+
+
+ @Override
+ public void setup() {
+ Command sayNextCard = new Command() {
+
+ public void execute() {
+ checkData();
+ }
+
+ };
+
+ getWizardWindow().setNextButtonCommand(sayNextCard);
+
+ Command sayPreviousCard = new Command() {
+ public void execute() {
+ try {
+ getWizardWindow().previousCard();
+ getWizardWindow().removeCard(thisCard);
+ Log.info("Remove SDMXTemplateExportTableDetailCard");
+ } catch (Exception e) {
+ Log.error("sayPreviousCard :" + e.getLocalizedMessage());
+ }
+ }
+ };
+
+ getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
+ getWizardWindow().setEnableNextButton(true);
+
+ }
+
+ protected void checkData() {
+ getWizardWindow().setEnableNextButton(false);
+ getWizardWindow().setEnableBackButton(false);
+ AlertMessageBox d;
+ HideHandler hideHandler = new HideHandler() {
+
+ public void onHide(HideEvent event) {
+ getWizardWindow().setEnableNextButton(true);
+ getWizardWindow().setEnableBackButton(false);
+
+ }
+ };
+
+ if (id.getValue() == null || id.getValue().isEmpty() || !id.isValid()
+ || version.getValue() == null || version.getValue().isEmpty()
+ || !version.isValid() || agencyId.getValue() == null
+ || agencyId.getValue().isEmpty() || !agencyId.isValid()) {
+
+ d = new AlertMessageBox("Attention!", "Fill in all fields");
+ d.addHideHandler(hideHandler);
+ d.show();
+ } else {
+ if (!version.getValue().matches("[0-9]+\\.[0-9]+")) {
+ d = new AlertMessageBox("Attention!",
+ "Version must match the regular expression [0-9]+\\.[0-9]+");
+ d.addHideHandler(hideHandler);
+ d.show();
+ } else {
+ id.setReadOnly(true);
+ registryBaseUrl.setReadOnly(true);
+ version.setReadOnly(true);
+ agencyId.setReadOnly(true);
+ goNext();
+ }
+ }
+
+ }
+
+ protected void goNext() {
+ try {
+ sdmxTemplateExportSession.setId(id.getCurrentValue());
+ sdmxTemplateExportSession.setAgencyId(agencyId.getCurrentValue());
+ sdmxTemplateExportSession.setVersion(version.getCurrentValue());
+ sdmxTemplateExportSession.setRegistryBaseUrl(registryBaseUrl.getCurrentValue());
+ SDMXTemplateExportOperationInProgressCard sdmxOperationInProgressCard = new SDMXTemplateExportOperationInProgressCard(
+ sdmxTemplateExportSession);
+ getWizardWindow().addCard(sdmxOperationInProgressCard);
+ Log.info("NextCard SDMXTemplateExportOperationInProgressCard");
+ getWizardWindow().nextCard();
+ } catch (Exception e) {
+ Log.error("sayNextCard :" + e.getLocalizedMessage());
+ }
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateExportWizard.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateExportWizard.java
new file mode 100644
index 0000000..31ae141
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateExportWizard.java
@@ -0,0 +1,41 @@
+package org.gcube.portlets.user.td.sdmxexportwidget.client.template;
+
+import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXTemplateExportSession;
+import org.gcube.portlets.user.td.wizardwidget.client.WizardWindow;
+
+import com.google.web.bindery.event.shared.EventBus;
+
+/**
+ *
+ * @author "Giancarlo Panichi" g.panichi@isti.cnr.it
+ *
+ * Entry point classes define onModuleLoad()
.
+ *
+ */
+public class SDMXTemplateExportWizard extends WizardWindow {
+
+ private SDMXTemplateExportSession sdmxTemplateExportSession;
+ private static final String WIDTH = "850px";
+ private static final String HEIGHT = "530px";
+
+ /**
+ * The id of the {@link CSVTarget} to use.
+ *
+ * @param targetId
+ */
+
+ public SDMXTemplateExportWizard(String title, final EventBus eventBus) {
+ super(title, eventBus);
+ setWidth(WIDTH);
+ setHeight(HEIGHT);
+
+ sdmxTemplateExportSession = new SDMXTemplateExportSession();
+
+ SDMXTemplateExportRegistrySelectionCard sdmxTemplateExportRegistrySelectionCard = new SDMXTemplateExportRegistrySelectionCard(
+ sdmxTemplateExportSession);
+ addCard(sdmxTemplateExportRegistrySelectionCard);
+ sdmxTemplateExportRegistrySelectionCard.setup();
+
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateSelectionCard.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateSelectionCard.java
new file mode 100644
index 0000000..5c17239
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTemplateSelectionCard.java
@@ -0,0 +1,99 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.td.sdmxexportwidget.client.template;
+
+import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXTemplateExportSession;
+import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData;
+import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
+
+import com.allen_sauer.gwt.log.client.Log;
+import com.google.gwt.event.logical.shared.SelectionEvent;
+import com.google.gwt.event.logical.shared.SelectionHandler;
+import com.google.gwt.user.client.Command;
+
+/**
+ *
+ * @author "Giancarlo Panichi" g.panichi@isti.cnr.it
+ *
+ */
+public class SDMXTemplateSelectionCard extends WizardCard {
+
+ private SDMXTemplateSelectionCard thisCard;
+ private SDMXTemplateExportSession sdmxTemplateExportSession;
+ private SDMXTmplateExportTemplateSelectionPanel sdmxTemplateExportTemplateSelectionPanel;
+
+ public SDMXTemplateSelectionCard(
+ final SDMXTemplateExportSession sdmxTemplateExportSession) {
+ super("SDMX Template selection", "");
+
+ this.sdmxTemplateExportSession = sdmxTemplateExportSession;
+ thisCard = this;
+
+ this.sdmxTemplateExportTemplateSelectionPanel = new SDMXTmplateExportTemplateSelectionPanel(thisCard, res);
+
+ sdmxTemplateExportTemplateSelectionPanel
+ .addSelectionHandler(new SelectionHandler() {
+
+ public void onSelection(SelectionEvent event) {
+ if (sdmxTemplateExportTemplateSelectionPanel.getSelectedItem() != null) {
+ sdmxTemplateExportSession
+ .setTemplateData(sdmxTemplateExportTemplateSelectionPanel
+ .getSelectedItem());
+ getWizardWindow().setEnableNextButton(true);
+ } else {
+ sdmxTemplateExportSession
+ .setTemplateData(null);
+ getWizardWindow().setEnableNextButton(false);
+ }
+ }
+
+ });
+
+ setContent(sdmxTemplateExportTemplateSelectionPanel);
+
+ }
+
+ @Override
+ public void setup() {
+ Command sayNextCard = new Command() {
+
+ public void execute() {
+ SDMXTemplateExportMeasureColumnSelectionCard sdmxTemplateExportMeasureColumnSelectionCard = new SDMXTemplateExportMeasureColumnSelectionCard(
+ sdmxTemplateExportSession);
+ getWizardWindow().addCard(sdmxTemplateExportMeasureColumnSelectionCard);
+ Log.info("NextCard SDMXTemplateExportMeasureColumnSelectionCard");
+ getWizardWindow().nextCard();
+ }
+
+ };
+
+ getWizardWindow().setNextButtonCommand(sayNextCard);
+
+ Command sayPreviousCard = new Command() {
+ public void execute() {
+ try {
+ getWizardWindow().previousCard();
+ getWizardWindow().removeCard(thisCard);
+ Log.info("Remove SDMXTemplateExportTemplateSelectionCard");
+ } catch (Exception e) {
+ Log.error("sayPreviousCard :" + e.getLocalizedMessage());
+ }
+ }
+ };
+
+ getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
+
+
+ if (sdmxTemplateExportTemplateSelectionPanel == null
+ || sdmxTemplateExportTemplateSelectionPanel.getSelectedItem() == null) {
+ setEnableNextButton(false);
+ } else {
+ setEnableNextButton(true);
+ }
+
+
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTmplateExportTemplateSelectionPanel.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTmplateExportTemplateSelectionPanel.java
new file mode 100644
index 0000000..a4245a2
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/template/SDMXTmplateExportTemplateSelectionPanel.java
@@ -0,0 +1,268 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.td.sdmxexportwidget.client.template;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
+import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
+import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData;
+import org.gcube.portlets.user.td.sdmxexportwidget.client.properties.TemplateDataProperties;
+import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
+import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
+import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
+import org.gcube.portlets.user.td.wizardwidget.client.dataresource.ResourceBundle;
+
+import com.allen_sauer.gwt.log.client.Log;
+import com.google.gwt.cell.client.DateCell;
+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.event.dom.client.KeyUpEvent;
+import com.google.gwt.event.dom.client.KeyUpHandler;
+import com.google.gwt.event.logical.shared.HasSelectionHandlers;
+import com.google.gwt.event.logical.shared.SelectionHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.sencha.gxt.core.client.IdentityValueProvider;
+import com.sencha.gxt.core.client.Style.SelectionMode;
+import com.sencha.gxt.data.client.loader.RpcProxy;
+import com.sencha.gxt.data.shared.ListStore;
+import com.sencha.gxt.data.shared.ModelKeyProvider;
+import com.sencha.gxt.data.shared.Store;
+import com.sencha.gxt.data.shared.Store.StoreFilter;
+import com.sencha.gxt.data.shared.loader.ListLoadConfig;
+import com.sencha.gxt.data.shared.loader.ListLoadResult;
+import com.sencha.gxt.data.shared.loader.ListLoadResultBean;
+import com.sencha.gxt.data.shared.loader.ListLoader;
+import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding;
+import com.sencha.gxt.widget.core.client.ContentPanel;
+import com.sencha.gxt.widget.core.client.button.TextButton;
+import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
+import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
+import com.sencha.gxt.widget.core.client.event.SelectEvent;
+import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
+import com.sencha.gxt.widget.core.client.form.TextField;
+import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel;
+import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
+import com.sencha.gxt.widget.core.client.grid.ColumnModel;
+import com.sencha.gxt.widget.core.client.grid.Grid;
+import com.sencha.gxt.widget.core.client.toolbar.LabelToolItem;
+import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
+
+/**
+ *
+ * @author "Giancarlo Panichi" g.panichi@isti.cnr.it
+ *
+ */
+public class SDMXTmplateExportTemplateSelectionPanel extends ContentPanel
+ implements HasSelectionHandlers {
+
+ private static final DateTimeFormat sdf = DateTimeFormat
+ .getFormat("yyyy-MM-dd HH:mm");
+
+ private Grid grid;
+ private ResourceBundle res;
+
+ private WizardCard parent;
+
+ public SDMXTmplateExportTemplateSelectionPanel(WizardCard parent,
+ ResourceBundle res) {
+ this.parent = parent;
+ this.res = res;
+ setHeaderVisible(false);
+ create();
+ }
+
+ protected void create() {
+
+ ToolBar toolBar = new ToolBar();
+ toolBar.add(new LabelToolItem("Search: "));
+ final TextField searchField = new TextField();
+ toolBar.add(searchField);
+
+ TextButton btnReload = new TextButton();
+ // btnReload.setText("Reload");
+ btnReload.setIcon(res.refresh16());
+ btnReload.setToolTip("Reload");
+ toolBar.add(btnReload);
+
+ IdentityValueProvider identity = new IdentityValueProvider();
+ final CheckBoxSelectionModel sm = new CheckBoxSelectionModel(
+ identity);
+
+ TemplateDataProperties properties = GWT
+ .create(TemplateDataProperties.class);
+
+ ColumnConfig nameColumn = new ColumnConfig(
+ properties.name(), 50, "Name");
+ ColumnConfig categoryColumn = new ColumnConfig(
+ properties.category(), 50, "Category");
+ ColumnConfig ownerLoginColumn = new ColumnConfig(
+ properties.ownerLogin(), 50, "Owner");
+ ColumnConfig agencyColumn = new ColumnConfig(
+ properties.agency(), 50, "Agency");
+ ColumnConfig descriptionColumn = new ColumnConfig(
+ properties.description(), 50, "Description");
+ ColumnConfig creationDateColumn = new ColumnConfig(
+ properties.creationDate(), 50, "Creation Date");
+ creationDateColumn.setCell(new DateCell(sdf));
+
+ List> l = new ArrayList>();
+ l.add(nameColumn);
+ l.add(categoryColumn);
+ l.add(ownerLoginColumn);
+ l.add(agencyColumn);
+ l.add(descriptionColumn);
+ l.add(creationDateColumn);
+
+ ColumnModel cm = new ColumnModel(l);
+
+ final ExtendedListStore store = new ExtendedListStore(
+ properties.id());
+
+ searchField.addKeyUpHandler(new KeyUpHandler() {
+
+ public void onKeyUp(KeyUpEvent event) {
+ Log.trace("searchTerm: " + searchField.getCurrentValue());
+ store.applyFilters();
+ }
+ });
+
+ store.addFilter(new StoreFilter() {
+
+ public boolean select(Store store,
+ TemplateData parent, TemplateData item) {
+ String searchTerm = searchField.getCurrentValue();
+ if (searchTerm == null)
+ return true;
+ return SDMXTmplateExportTemplateSelectionPanel.this.select(
+ item, searchTerm);
+ }
+ });
+
+ store.setEnableFilters(true);
+
+ RpcProxy> proxy = new RpcProxy>() {
+
+ public void load(ListLoadConfig loadConfig,
+ final AsyncCallback> callback) {
+ loadData(loadConfig, callback);
+ }
+ };
+ final ListLoader> loader = new ListLoader>(
+ proxy);
+
+ loader.setRemoteSort(false);
+ loader.addLoadHandler(new LoadResultListStoreBinding>(
+ store));
+
+ grid = new Grid(store, cm) {
+
+ protected void onAfterFirstAttach() {
+ super.onAfterFirstAttach();
+ Scheduler.get().scheduleDeferred(new ScheduledCommand() {
+ public void execute() {
+ loader.load();
+ }
+ });
+ }
+ };
+
+ sm.setSelectionMode(SelectionMode.SINGLE);
+ grid.setLoader(loader);
+ grid.setSelectionModel(sm);
+ grid.getView().setAutoExpandColumn(nameColumn);
+ grid.getView().setStripeRows(true);
+ grid.getView().setColumnLines(true);
+ grid.getView().setAutoFill(true);
+ grid.setBorders(false);
+ grid.setLoadMask(true);
+ grid.setColumnReordering(true);
+
+ SelectHandler sh = new SelectHandler() {
+ public void onSelect(SelectEvent event) {
+ loader.load();
+ }
+ };
+
+ btnReload.addSelectHandler(sh);
+
+ VerticalLayoutContainer con = new VerticalLayoutContainer();
+ con.add(toolBar, new VerticalLayoutData(1, -1));
+ con.add(grid, new VerticalLayoutData(1, 1));
+ setWidget(con);
+ }
+
+ protected boolean select(TemplateData item, String searchTerm) {
+ if (item.getName() != null
+ && item.getName().toLowerCase()
+ .contains(searchTerm.toLowerCase()))
+ return true;
+ if (item.getCategory() != null
+ && item.getCategory().toLowerCase()
+ .contains(searchTerm.toLowerCase()))
+ return true;
+ if (item.getOwnerLogin() != null
+ && item.getOwnerLogin().toLowerCase()
+ .contains(searchTerm.toLowerCase()))
+ return true;
+ if (item.getDescription() != null
+ && item.getDescription().toLowerCase()
+ .contains(searchTerm.toLowerCase()))
+ return true;
+ return false;
+ }
+
+ protected void loadData(ListLoadConfig loadConfig,
+ final AsyncCallback> callback) {
+ TDGWTServiceAsync.INSTANCE
+ .getTemplatesForDSDExport(new AsyncCallback>() {
+
+ public void onFailure(Throwable caught) {
+ if (caught instanceof TDGWTSessionExpiredException) {
+ parent.getEventBus()
+ .fireEvent(
+ new SessionExpiredEvent(
+ SessionExpiredType.EXPIREDONSERVER));
+ } else {
+ Log.error("No templates retrieved");
+ }
+ callback.onFailure(caught);
+ }
+
+ public void onSuccess(ArrayList result) {
+ Log.trace("loaded " + result.size() + " templates");
+ callback.onSuccess(new ListLoadResultBean(
+ result));
+ }
+ });
+ }
+
+ public HandlerRegistration addSelectionHandler(
+ SelectionHandler handler) {
+ return grid.getSelectionModel().addSelectionHandler(handler);
+ }
+
+ public TemplateData getSelectedItem() {
+ return grid.getSelectionModel().getSelectedItem();
+ }
+
+ protected class ExtendedListStore extends ListStore {
+
+ public ExtendedListStore(ModelKeyProvider super M> keyProvider) {
+ super(keyProvider);
+ }
+
+ public void applyFilters() {
+ super.applyFilters();
+ }
+
+ }
+
+}