From a0f42ede052b0861fae8e8cee1e79c7236eb6fee Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 12 Nov 2014 14:00:45 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-resources-widget@101599 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 57 ++-- .../td/resourceswidget/ColumnWidget.gwt.xml | 3 +- .../client/ResourcesPanel.java | 296 +++++++++++++----- .../client/save/DestinationSelectionCard.java | 164 ++++++++++ .../client/save/DownloadFileCard.java | 61 ++++ .../client/save/OperationInProgressCard.java | 177 +++++++++++ .../client/save/SaveResourceWizard.java | 34 ++ .../client/save/WorkSpaceSelectionCard.java | 191 +++++++++++ .../client/workspace/WorkspacePanel.java | 47 +++ .../resourceswidget/ResourcesWidget.gwt.xml | 1 + 10 files changed, 928 insertions(+), 103 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/DestinationSelectionCard.java create mode 100644 src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/DownloadFileCard.java create mode 100644 src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/OperationInProgressCard.java create mode 100644 src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/SaveResourceWizard.java create mode 100644 src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/WorkSpaceSelectionCard.java create mode 100644 src/main/java/org/gcube/portlets/user/td/resourceswidget/client/workspace/WorkspacePanel.java diff --git a/pom.xml b/pom.xml index c29e263..4a72d10 100644 --- a/pom.xml +++ b/pom.xml @@ -111,23 +111,7 @@ 3.0.1 - - - - - org.gcube.portlets.user - tabular-data-gwt-service - [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) - provided - - + org.gcube.portlets.user @@ -135,9 +119,44 @@ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) provided - - + + + org.gcube.portlets.user + tabular-data-gwt-service + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + provided + + + + + org.gcube.portlets.user + tabular-data-wizard-widget + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + provided + + + + + org.gcube.portlets.widgets + workspace-light-tree + [2.13.0-SNAPSHOT, 3.0.0-SNAPSHOT) + provided + + + org.gcube.common + home-library + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + provided + + + org.gcube.portlets.user + gcube-widgets + provided + + + + com.allen-sauer.gwt.log diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/ColumnWidget.gwt.xml b/src/main/java/org/gcube/portlets/user/td/resourceswidget/ColumnWidget.gwt.xml index 309634c..40997a7 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/ColumnWidget.gwt.xml +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/ColumnWidget.gwt.xml @@ -18,7 +18,8 @@ - + + diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesPanel.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesPanel.java index 232ac0d..2c4291b 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesPanel.java @@ -13,21 +13,25 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.RemoveResourceS import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTD; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType; +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.StringResourceTD; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.TableResourceTD; import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession; import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo; import org.gcube.portlets.user.td.resourceswidget.client.properties.ResourceTDDescriptorProperties; import org.gcube.portlets.user.td.resourceswidget.client.resources.ResourceBundle; +import org.gcube.portlets.user.td.resourceswidget.client.save.SaveResourceWizard; import org.gcube.portlets.user.td.resourceswidget.client.utils.UtilsGXT3; 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.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType; +import org.gcube.portlets.user.td.wizardwidget.client.WizardListener; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.cell.client.AbstractCell; import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.RunAsyncCallback; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.event.logical.shared.SelectionEvent; @@ -92,8 +96,11 @@ public class ResourcesPanel extends FramedPanel { private boolean drawed = false; private Menu contextMenu; private MenuItem openItem; + private MenuItem saveItem; private MenuItem removeItem; - private RemoveResourceSession removeResourceSession; + + private RemoveResourceSession removeResourceSession; + private SaveResourceSession saveResourceSession; public ResourcesPanel(ResourcesDialog parent, TRId trId, EventBus eventBus) { super(); @@ -166,82 +173,92 @@ public class ResourcesPanel extends FramedPanel { @Override public void render(Context context, ResourceTDDescriptor value, SafeHtmlBuilder sb) { - String data= - "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "
Name: "+SafeHtmlUtils.htmlEscape(value.getName())+ - - "
Description: "+SafeHtmlUtils.htmlEscape(value.getDescription())+ - - "
Creation Date: "+ - SafeHtmlUtils.htmlEscape(value.getCreationDate())+ - - "
Creator Id: "+new SafeHtmlBuilder().append(value.getCreatorId()).toSafeHtml().asString()+ - - "
Type: " + String data = "" + + "" + + "" + + "" + ""; + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + ""; ResourceTD resource = value.getResourceTD(); - String resourceData=""; + String resourceData = ""; if (resource instanceof InternalURITD) { InternalURITD internalURITD = (InternalURITD) resource; - resourceData= - "" - + "" - + "" + ""; + resourceData = "" + + "" + + "" + ""; - } else { if (resource instanceof StringResourceTD) { StringResourceTD stringResourceTD = (StringResourceTD) resource; - resourceData= - "" - + "" - + "" + ""; + resourceData = "" + + "" + + "" + ""; } else { if (resource instanceof TableResourceTD) { TableResourceTD tableResourceTD = (TableResourceTD) resource; - resourceData= - "" - + "" - + "" + ""; + resourceData = "" + + "" + + "" + ""; } else { } } } - sb.appendHtmlConstant(data+resourceData+"
Name: " + + SafeHtmlUtils.htmlEscape(value.getName()) + - SafeHtmlUtils.htmlEscape(value.getResourceType().toString())+"
Description: " + + SafeHtmlUtils.htmlEscape(value + .getDescription()) + + + + "
Creation Date: " + + SafeHtmlUtils.htmlEscape(value + .getCreationDate()) + + + + "
Creator Id: " + + new SafeHtmlBuilder() + .append(value.getCreatorId()) + .toSafeHtml().asString() + + + + "
Type: " + + SafeHtmlUtils.htmlEscape(value + .getResourceType().toString()) + + "
File Id: "+SafeHtmlUtils.htmlEscape(internalURITD.getFileId())+ - "
File Id: " + + SafeHtmlUtils.htmlEscape(internalURITD + .getFileId()) + "
Value: "+ - SafeHtmlUtils.htmlEscape( - stringResourceTD - .getStringValue())+ - "
Value: " + + SafeHtmlUtils + .htmlEscape(stringResourceTD + .getStringValue()) + + "
Table Id: "+ - new SafeHtmlBuilder().append(tableResourceTD - .getTableId()).toSafeHtml().asString()+ - - "
Table Id: " + + new SafeHtmlBuilder() + .append(tableResourceTD + .getTableId()) + .toSafeHtml().asString() + + + "
"); + sb.appendHtmlConstant(data + resourceData + "
"); } @@ -254,7 +271,9 @@ public class ResourcesPanel extends FramedPanel { @Override public void render(Context context, String value, SafeHtmlBuilder sb) { - sb.appendHtmlConstant(""+SafeHtmlUtils.htmlEscape(value)+""); + sb.appendHtmlConstant("" + + SafeHtmlUtils.htmlEscape(value) + ""); } @@ -267,44 +286,45 @@ public class ResourcesPanel extends FramedPanel { @Override public void render(Context context, ResourceTDType value, SafeHtmlBuilder sb) { - String head=(""); + sb.appendHtmlConstant(head + bodyC + "' >"); } }); @@ -390,6 +410,21 @@ public class ResourcesPanel extends FramedPanel { }); + saveItem = new MenuItem(); + saveItem.setText("Save"); + saveItem.setIcon(ResourceBundle.INSTANCE.save()); + saveItem.addSelectionHandler(new SelectionHandler() { + + @Override + public void onSelection(SelectionEvent event) { + ResourceTDDescriptor selected = grid.getSelectionModel() + .getSelectedItem(); + Log.debug("selected: " + selected); + requestSave(selected); + } + + }); + removeItem = new MenuItem(); removeItem.setText("Delete"); removeItem.setIcon(ResourceBundle.INSTANCE.delete()); @@ -419,6 +454,7 @@ public class ResourcesPanel extends FramedPanel { switch (resourceTDType) { case CHART: contextMenu.clear(); + contextMenu.add(saveItem); contextMenu.add(removeItem); grid.setContextMenu(contextMenu); break; @@ -429,6 +465,7 @@ public class ResourcesPanel extends FramedPanel { break; case CSV: contextMenu.clear(); + contextMenu.add(saveItem); contextMenu.add(removeItem); grid.setContextMenu(contextMenu); break; @@ -439,6 +476,7 @@ public class ResourcesPanel extends FramedPanel { break; case JSON: contextMenu.clear(); + contextMenu.add(saveItem); contextMenu.add(removeItem); grid.setContextMenu(contextMenu); break; @@ -468,6 +506,97 @@ public class ResourcesPanel extends FramedPanel { } + protected void requestSave(ResourceTDDescriptor resourceTDDescriptor) { + switch (resourceTDDescriptor.getResourceType()) { + case CHART: + requestSaveResource(resourceTDDescriptor, ".png", "image/png"); + break; + case CODELIST: + break; + case CSV: + requestSaveResource(resourceTDDescriptor, ".csv", "text/csv"); + break; + case GUESSER: + break; + case JSON: + requestSaveResource(resourceTDDescriptor, ".json", + "application/json"); + break; + case MAP: + break; + case SDMX: + break; + default: + break; + + } + + } + + protected void requestSaveResource( + ResourceTDDescriptor resourceTDDescriptor, String extension, + String mimeType) { + + InternalURITD internalURITD; + ResourceTD resource = resourceTDDescriptor.getResourceTD(); + if (resource instanceof InternalURITD) { + internalURITD=(InternalURITD)resource; + } else { + UtilsGXT3.alert("Attention", "This resource does not have valid internal URI!"); + Log.debug("Attention, this resource does not have valid Internal URI!"); + return; + } + Log.debug("InteranlURI: "+internalURITD); + + saveResourceSession = new SaveResourceSession(); + saveResourceSession.setMimeType(mimeType); + saveResourceSession.setExtension(extension); + saveResourceSession.setFileName(resourceTDDescriptor.getName() + + extension); + saveResourceSession.setFileDescription(resourceTDDescriptor + .getDescription()); + saveResourceSession.setUri(internalURITD.getUri()); + + GWT.runAsync(new RunAsyncCallback() { + + public void onSuccess() { + + SaveResourceWizard saveResourceWizard = new SaveResourceWizard( + saveResourceSession, "Save Resource", eventBus); + + saveResourceWizard.addListener(new WizardListener() { + + public void failed(String title, String message, + Throwable throwable) { + Log.debug(title + ", " + message); + } + + public void completed(TRId id) { + Log.debug("Save Resource Completed"); + + } + + @Override + public void putInBackground() { + Log.debug("PutInBakground"); + } + + public void aborted() { + Log.debug("Save Resource Aborted"); + } + }); + + saveResourceWizard.show(); + } + + public void onFailure(Throwable reason) { + Log.error("Async code loading failed", reason); + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } + }); + } + protected void requestRemove(ResourceTDDescriptor resourceTDDescriptor) { removeResourceSession = new RemoveResourceSession(trId, @@ -489,7 +618,8 @@ public class ResourcesPanel extends FramedPanel { Log.error("Error removing the resource: " + caught.getLocalizedMessage()); UtilsGXT3.alert("Error", - "Error removing the resource: "+caught.getLocalizedMessage()); + "Error removing the resource: " + + caught.getLocalizedMessage()); } } } @@ -497,7 +627,7 @@ public class ResourcesPanel extends FramedPanel { public void onSuccess(Void v) { Log.debug("Resource removed"); grid.getLoader().load(); - //UtilsGXT3.info("Resource", "Resource Removed!"); + // UtilsGXT3.info("Resource", "Resource Removed!"); } }); @@ -613,11 +743,11 @@ public class ResourcesPanel extends FramedPanel { public void onSuccess(ArrayList result) { Log.debug("loaded " + result.size()); - try{ + try { callback.onSuccess(new ListLoadResultBean( - result)); - } catch(Throwable e){ - Log.debug("Error: "+e.getLocalizedMessage()); + result)); + } catch (Throwable e) { + Log.debug("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } } diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/DestinationSelectionCard.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/DestinationSelectionCard.java new file mode 100644 index 0000000..d93ff32 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/DestinationSelectionCard.java @@ -0,0 +1,164 @@ +/** + * + */ +package org.gcube.portlets.user.td.resourceswidget.client.save; + + + + +import org.gcube.portlets.user.td.gwtservice.shared.destination.FileDestination; +import org.gcube.portlets.user.td.gwtservice.shared.destination.WorkspaceDestination; +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession; +import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; + +import com.allen_sauer.gwt.log.client.Log; +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.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.form.Radio; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class DestinationSelectionCard extends WizardCard { + + protected final SaveResourceSession saveResourceSession; + protected DestinationSelectionCard thisCard; + + final FileDestination fileDestination = FileDestination.INSTANCE; + final WorkspaceDestination workspaceDestination = WorkspaceDestination.INSTANCE; + + public DestinationSelectionCard(final SaveResourceSession saveResourceSession) { + super("Destination selection", ""); + thisCard=this; + this.saveResourceSession = saveResourceSession; + // Default + saveResourceSession.setDestination(workspaceDestination); + + VerticalPanel destinationSelectionPanel = new VerticalPanel(); + destinationSelectionPanel.setStylePrimaryName(res.wizardCSS() + .getImportSelectionSources()); + + Radio radioWorkspaceDestination = new Radio(); + radioWorkspaceDestination.setBoxLabel("

" + + workspaceDestination.getName() + "
" + + workspaceDestination.getDescription() + "

"); + radioWorkspaceDestination.setName(workspaceDestination.getName()); + radioWorkspaceDestination.setStylePrimaryName(res.wizardCSS() + .getImportSelectionSource()); + radioWorkspaceDestination.setValue(true); + + + Radio radioFileDestination = new Radio(); + radioFileDestination.setBoxLabel("

" + + fileDestination.getName() + "
" + + fileDestination.getDescription() + "

"); + radioFileDestination.setName(fileDestination.getName()); + radioFileDestination.setStylePrimaryName(res.wizardCSS() + .getImportSelectionSource()); + radioFileDestination.disable(); + + destinationSelectionPanel.add(radioWorkspaceDestination); + destinationSelectionPanel.add(radioFileDestination); + + + // we can set name on radios or use toggle group + ToggleGroup toggle = new ToggleGroup(); + toggle.add(radioWorkspaceDestination); + toggle.add(radioFileDestination); + + toggle.addValueChangeHandler(new ValueChangeHandler>() { + + + public void onValueChange(ValueChangeEvent> event) { + try { + ToggleGroup group = (ToggleGroup) event.getSource(); + Radio radio = (Radio) group.getValue(); + Log.info("Source Selected:" + radio.getName()); + if (radio.getName().compareTo(workspaceDestination.getName()) == 0) { + saveResourceSession.setDestination(workspaceDestination); + } else { + if (radio.getName().compareTo(fileDestination.getName()) == 0) { + saveResourceSession.setDestination(fileDestination); + } else { + + } + + } + + } catch (Exception e) { + Log.error("ToggleGroup: onValueChange " + + e.getLocalizedMessage()); + } + + } + }); + + setContent(destinationSelectionPanel); + + } + + @Override + public void setup() { + Log.debug("Setup Card"); + Command sayNextCard = new Command() { + public void execute() { + try { + String destinationId = saveResourceSession.getDestination().getId(); + if (destinationId == null || destinationId.isEmpty()) { + Log.error("Export Source Id: " + destinationId); + } else { + if (destinationId.compareTo("File") == 0) { + Log.info("NextCard DownloadFileCard"); + DownloadFileCard downloadFileCard = new DownloadFileCard( + saveResourceSession); + getWizardWindow().addCard(downloadFileCard); + getWizardWindow().nextCard(); + } else { + if (destinationId.compareTo("Workspace") == 0) { + Log.info("NextCard WorkspaceSelectionCard"); + WorkSpaceSelectionCard workspaceSelectionCard = new WorkSpaceSelectionCard( + saveResourceSession); + getWizardWindow().addCard( + workspaceSelectionCard); + getWizardWindow().nextCard(); + } else { + Log.debug("No destination selected and no card loaded"); + } + } + } + } 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 DestinationSelectionCard"); + } catch (Exception e) { + Log.error("sayPreviousCard :" + e.getLocalizedMessage()); + } + } + }; + + getWizardWindow().setPreviousButtonCommand(sayPreviousCard); + + setEnableBackButton(false); + setEnableNextButton(true); + + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/DownloadFileCard.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/DownloadFileCard.java new file mode 100644 index 0000000..670f4fc --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/DownloadFileCard.java @@ -0,0 +1,61 @@ +/** + * + */ +package org.gcube.portlets.user.td.resourceswidget.client.save; + + +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession; +import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.user.client.Command; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class DownloadFileCard extends WizardCard { + protected SaveResourceSession saveResourceSession; + protected DownloadFileCard thisCard; + + public DownloadFileCard(final SaveResourceSession saveResourceSession) { + super("Download File", ""); + this.thisCard = this; + this.saveResourceSession = saveResourceSession; + + + + //setContent(); + + } + + @Override + public void setup() { + Command sayNextCard = new Command() { + + public void execute() { + } + + }; + + getWizardWindow().setNextButtonCommand(sayNextCard); + + Command sayPreviousCard = new Command() { + public void execute() { + try { + getWizardWindow().previousCard(); + getWizardWindow().removeCard(thisCard); + Log.info("Remove DownloadFileCard"); + } catch (Exception e) { + Log.error("sayPreviousCard :" + e.getLocalizedMessage()); + } + } + }; + + getWizardWindow().setPreviousButtonCommand(sayPreviousCard); + getWizardWindow().setEnableNextButton(false); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/OperationInProgressCard.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/OperationInProgressCard.java new file mode 100644 index 0000000..745e999 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/OperationInProgressCard.java @@ -0,0 +1,177 @@ +/** + * + */ +package org.gcube.portlets.user.td.resourceswidget.client.save; + +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession; +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.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.FlexTable; +import com.sencha.gxt.core.client.util.Margins; +import com.sencha.gxt.widget.core.client.FramedPanel; +import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData; +import com.sencha.gxt.widget.core.client.container.HtmlLayoutContainer; +import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer; +import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer.VBoxLayoutAlign; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class OperationInProgressCard extends WizardCard { + + protected OperationInProgressCard thisCard; + protected SaveResourceSession saveResourceSession; + protected HtmlLayoutContainer resultField; + + public OperationInProgressCard(final SaveResourceSession saveResourceSession) { + super("Save", ""); + + this.saveResourceSession = saveResourceSession; + thisCard = this; + + VBoxLayoutContainer operationInProgressPanel = new VBoxLayoutContainer(); + operationInProgressPanel.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER); + + final FlexTable description = new FlexTable(); + // FlexCellFormatter cellFormatter = description.getFlexCellFormatter(); + description.setCellSpacing(10); + description.setCellPadding(4); + description.setBorderWidth(0); + + // display:block;vertical-align:text-top; + description.setHTML(0, 0, + "Destination: "); + description.setText(0, 1, saveResourceSession.getDestination().getName()); + description.setHTML(1, 0, + "File Name: "); + description.setText(1, 1, saveResourceSession.getFileName()); + + description.setHTML(2, 0, + "File Description: "); + description.setText(2, 1, saveResourceSession.getFileDescription()); + + FramedPanel summary = new FramedPanel(); + summary.setHeadingText("Save Summary"); + summary.setWidth(400); + summary.add(description); + operationInProgressPanel.add(summary, new BoxLayoutData(new Margins(20, + 5, 10, 5))); + + resultField = new HtmlLayoutContainer("
"); + + operationInProgressPanel.add(resultField, new BoxLayoutData( + new Margins(10, 5, 10, 5))); + + setContent(operationInProgressPanel); + resultField.setVisible(false); + + } + + public void saveResource() { + TDGWTServiceAsync.INSTANCE.saveResource(saveResourceSession, + new AsyncCallback() { + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + getEventBus() + .fireEvent( + new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + if (caught instanceof TDGWTIsLockedException) { + Log.error(caught.getLocalizedMessage()); + + } else { + Log.error("Error saving the resource: " + + caught.getLocalizedMessage()); + + } + } + operationFailed(caught, caught.getLocalizedMessage(), caught.getLocalizedMessage()); + } + + public void onSuccess(Void v) { + Log.debug("Resource saved"); + operationComplete(); + } + + }); + + + + } + + @Override + public void setup() { + getWizardWindow().setEnableBackButton(false); + setBackButtonVisible(false); + setNextButtonVisible(false); + getWizardWindow().setEnableNextButton(false); + getWizardWindow().setNextButtonToFinish(); + saveResource(); + } + + public void operationComplete() { + + 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); + getWizardWindow().fireCompleted(null); + + } catch (Exception e) { + Log.error("fire Complete :" + e.getLocalizedMessage()); + } + } + }; + + getWizardWindow().setNextButtonCommand(sayComplete); + + setNextButtonVisible(true); + getWizardWindow().setEnableNextButton(true); + + forceLayout(); + + } + + + 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 Save", + reason,caught); + } + + forceLayout(); + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/SaveResourceWizard.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/SaveResourceWizard.java new file mode 100644 index 0000000..a3c95b9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/SaveResourceWizard.java @@ -0,0 +1,34 @@ +package org.gcube.portlets.user.td.resourceswidget.client.save; + +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession; +import org.gcube.portlets.user.td.wizardwidget.client.WizardWindow; + +import com.google.web.bindery.event.shared.EventBus; + +/** + * + */ +public class SaveResourceWizard extends WizardWindow { + + protected SaveResourceSession saveResourceSession; + + /** + * The id of the {@link CSVTarget} to use. + * + * @param targetId + */ + + public SaveResourceWizard(SaveResourceSession saveResourceSession, + String title, EventBus eventBus) { + super(title, eventBus); + + this.saveResourceSession = saveResourceSession; + + DestinationSelectionCard destinationSelectionCard = new DestinationSelectionCard( + saveResourceSession); + addCard(destinationSelectionCard); + destinationSelectionCard.setup(); + + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/WorkSpaceSelectionCard.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/WorkSpaceSelectionCard.java new file mode 100644 index 0000000..287a23d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/WorkSpaceSelectionCard.java @@ -0,0 +1,191 @@ +/** + * + */ +package org.gcube.portlets.user.td.resourceswidget.client.save; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession; +import org.gcube.portlets.user.td.resourceswidget.client.workspace.WorkspacePanel; +import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; +import org.gcube.portlets.widgets.lighttree.client.Item; +import org.gcube.portlets.widgets.lighttree.client.ItemType; +import org.gcube.portlets.widgets.lighttree.client.event.ItemSelectionEvent; +import org.gcube.portlets.widgets.lighttree.client.event.ItemSelectionHandler; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.user.client.Command; +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.TextField; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class WorkSpaceSelectionCard extends WizardCard { + + protected SaveResourceSession saveResourceSession; + protected WorkSpaceSelectionCard thisCard; + protected TextField fileName; + protected TextField fileDescription; + + protected Item item; + protected VerticalLayoutContainer p; + protected WorkspacePanel wpanel; + + public WorkSpaceSelectionCard(final SaveResourceSession saveResourceSession) { + super("Save in Workspace", ""); + + this.saveResourceSession = saveResourceSession; + thisCard = this; + + FramedPanel formPanel = new FramedPanel(); + formPanel.setHeaderVisible(false); + p = new VerticalLayoutContainer(); + formPanel.setWidget(p); + + fileName = new TextField(); + fileName.setAllowBlank(false); + fileName.setWidth("410px"); + fileName.setValue(saveResourceSession.getFileName()); + p.add(new FieldLabel(fileName, "File Name"), new VerticalLayoutData(-1, + -1)); + + fileDescription = new TextField(); + fileDescription.setAllowBlank(false); + fileDescription.setWidth("410px"); + fileDescription.setValue(saveResourceSession.getFileDescription()); + p.add(new FieldLabel(fileDescription, "File Description"), + new VerticalLayoutData(-1, -1)); + + Log.debug("Set Workspace Panel"); + wpanel = new WorkspacePanel(); + wpanel.setSpWidth("410px"); + wpanel.setSpHeight("330px"); + List lItemType = new ArrayList(); + lItemType.add(ItemType.ROOT); + lItemType.add(ItemType.FOLDER); + wpanel.setShowableTypes(lItemType); + wpanel.setSelectableTypes(lItemType); + wpanel.addSelectionHandler(new ItemSelectionHandler() { + + public void onSelection(ItemSelectionEvent event) { + item = event.getSelectedItem(); + Log.debug("Selected Item:" + item); + if (item.getType() == ItemType.FOLDER + || item.getType() == ItemType.ROOT) { + thisCard.saveResourceSession.setItemId(item.getId()); + } else { + thisCard.saveResourceSession.setItemId(null); + Log.debug("Item type:" + item.getType()); + } + } + }); + p.add(new FieldLabel(wpanel, "Folder"), new VerticalLayoutData(-1, -1)); + wpanel.loadTree(); + setContent(formPanel); + + } + + protected void checkExportData() { + Log.debug("File Name:" + fileName.getCurrentValue() + " Item id: " + + saveResourceSession.getItemId()); + wpanel.disable(); + fileName.disable(); + getWizardWindow().setEnableNextButton(false); + getWizardWindow().setEnableBackButton(false); + AlertMessageBox d; + HideHandler hideHandler = new HideHandler() { + + public void onHide(HideEvent event) { + wpanel.enable(); + getWizardWindow().setEnableNextButton(true); + getWizardWindow().setEnableBackButton(true); + fileName.enable(); + } + }; + if (fileName.getCurrentValue() != null + && !fileName.getCurrentValue().isEmpty() && fileName.validate()) { + if (fileDescription.getCurrentValue() != null + && !fileDescription.getCurrentValue().isEmpty() + && fileDescription.validate()) { + + if (saveResourceSession.getItemId() != null) { + saveResourceSession.setFileName(fileName.getCurrentValue()); + saveResourceSession.setFileDescription(fileDescription + .getCurrentValue()); + goNext(); + } else { + d = new AlertMessageBox("Attention", "No folder selected"); + d.addHideHandler(hideHandler); + d.setModal(false); + d.show(); + + } + } else { + d = new AlertMessageBox("Attention", + "No valid file description"); + d.addHideHandler(hideHandler); + d.setModal(false); + d.show(); + + } + } else { + d = new AlertMessageBox("Attention", "No valid file name"); + d.addHideHandler(hideHandler); + d.setModal(false); + d.show(); + } + + } + + @Override + public void setup() { + Log.debug("WorkSpaceSelectionCard Call Setup "); + Command sayNextCard = new Command() { + + public void execute() { + Log.debug("WorkSpaceSelectionCard Call sayNextCard:" + wpanel); + checkExportData(); + } + + }; + + getWizardWindow().setNextButtonCommand(sayNextCard); + + Command sayPreviousCard = new Command() { + public void execute() { + try { + getWizardWindow().previousCard(); + getWizardWindow().removeCard(thisCard); + Log.debug("Remove WorkSpaceSelectionCard"); + } catch (Exception e) { + Log.error("sayPreviousCard :" + e.getLocalizedMessage()); + } + } + }; + + getWizardWindow().setPreviousButtonCommand(sayPreviousCard); + getWizardWindow().setEnableNextButton(true); + getWizardWindow().setEnableBackButton(true); + + } + + protected void goNext() { + OperationInProgressCard csvOperationInProgressCard = new OperationInProgressCard( + saveResourceSession); + getWizardWindow().addCard(csvOperationInProgressCard); + Log.info("NextCard OperationInProgressCard"); + getWizardWindow().nextCard(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/workspace/WorkspacePanel.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/workspace/WorkspacePanel.java new file mode 100644 index 0000000..2f2e507 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/workspace/WorkspacePanel.java @@ -0,0 +1,47 @@ +package org.gcube.portlets.user.td.resourceswidget.client.workspace; + +import org.gcube.portlets.widgets.lighttree.client.WorkspaceLightTreePanel; + +import com.allen_sauer.gwt.log.client.Log; +import com.sencha.gxt.widget.core.client.box.AutoProgressMessageBox; +import com.sencha.gxt.widget.core.client.event.DisableEvent; +import com.sencha.gxt.widget.core.client.event.EnableEvent; + +public class WorkspacePanel extends WorkspaceLightTreePanel { + + AutoProgressMessageBox box; + + public void setSpWidth(String w) { + sp.setWidth(w); + + } + + public void setSpHeight(String h) { + sp.setHeight(h); + } + + public void disable() { + Log.debug("WorkspacePanel Disable"); + fireEvent(new DisableEvent()); + } + + public void enable() { + Log.debug("WorkspacePanel Enable"); + fireEvent(new EnableEvent()); + } + + public void startWaiting() { + box= new AutoProgressMessageBox("Loading", + "Retriving data from workspace, please wait..."); + box.setProgressText("Loading..."); + box.setModal(false); + box.auto(); + box.show(); + + } + + public void endWaiting() { + box.hide(); + } + +} diff --git a/src/main/resources/org/gcube/portlets/user/td/resourceswidget/ResourcesWidget.gwt.xml b/src/main/resources/org/gcube/portlets/user/td/resourceswidget/ResourcesWidget.gwt.xml index 89555c0..331e887 100644 --- a/src/main/resources/org/gcube/portlets/user/td/resourceswidget/ResourcesWidget.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/td/resourceswidget/ResourcesWidget.gwt.xml @@ -19,6 +19,7 @@ +