Giancarlo Panichi 2014-11-12 14:00:45 +00:00
parent 7b943807a3
commit a0f42ede05
10 changed files with 928 additions and 103 deletions

31
pom.xml
View File

@ -111,14 +111,14 @@
<version>3.0.1</version>
</dependency>
<!--
<!-- tabular-data-widget-common-event -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-widget-common-event</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
-->
<!-- tabular-data-gwt-service -->
<dependency>
@ -128,14 +128,33 @@
<scope>provided</scope>
</dependency>
<!-- tabular-data-widget-common-event -->
<!-- tabular-data-wizard-widget -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-widget-common-event</artifactId>
<artifactId>tabular-data-wizard-widget</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<!-- WSLT dependencies -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-light-tree</artifactId>
<version>[2.13.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>provided</scope>
</dependency>
<!-- LOGGING -->

View File

@ -18,6 +18,7 @@
<inherits name='com.sencha.gxt.ui.GXT' />
<inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" />
<inherits name='org.gcube.portlets.user.td.gwtservice.TDGWTService' />
<inherits name='org.gcube.portlets.user.td.wizardwidget.Wizard' />
<!-- Specify the app entry point class. -->
<!-- <entry-point class='org.gcube.portlets.user.td.resourceswidget.client.ResourcesWidgetEntry' /> -->

View File

@ -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 SaveResourceSession saveResourceSession;
public ResourcesPanel(ResourcesDialog parent, TRId trId, EventBus eventBus) {
super();
@ -166,73 +173,83 @@ public class ResourcesPanel extends FramedPanel {
@Override
public void render(Context context,
ResourceTDDescriptor value, SafeHtmlBuilder sb) {
String data=
"<table style='font-family: tahoma, arial, verdana, sans-serif;"
String data = "<table style='font-family: tahoma, arial, verdana, sans-serif;"
+ "width: 100%; border: none;"
+ "font-size: 12px; margin:2px; text-align: left;'>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Name: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"+SafeHtmlUtils.htmlEscape(value.getName())+
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ SafeHtmlUtils.htmlEscape(value.getName())
+
"</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Description: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"+SafeHtmlUtils.htmlEscape(value.getDescription())+
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ SafeHtmlUtils.htmlEscape(value
.getDescription())
+
"</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creation Date: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"+
SafeHtmlUtils.htmlEscape(value.getCreationDate())+
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ SafeHtmlUtils.htmlEscape(value
.getCreationDate())
+
"</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creator Id: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"+new SafeHtmlBuilder().append(value.getCreatorId()).toSafeHtml().asString()+
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ new SafeHtmlBuilder()
.append(value.getCreatorId())
.toSafeHtml().asString()
+
"</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Type: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+
SafeHtmlUtils.htmlEscape(value.getResourceType().toString())+"</td>" + "</tr>";
+ SafeHtmlUtils.htmlEscape(value
.getResourceType().toString())
+ "</td>" + "</tr>";
ResourceTD resource = value.getResourceTD();
String resourceData = "";
if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource;
resourceData=
"<tr>"
resourceData = "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>File Id: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"+SafeHtmlUtils.htmlEscape(internalURITD.getFileId())+
"</td>" + "</tr>";
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ SafeHtmlUtils.htmlEscape(internalURITD
.getFileId()) + "</td>" + "</tr>";
} else {
if (resource instanceof StringResourceTD) {
StringResourceTD stringResourceTD = (StringResourceTD) resource;
resourceData=
"<tr>"
resourceData = "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Value: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"+
SafeHtmlUtils.htmlEscape(
stringResourceTD
.getStringValue())+
"</td>" + "</tr>";
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ SafeHtmlUtils
.htmlEscape(stringResourceTD
.getStringValue())
+ "</td>" + "</tr>";
} else {
if (resource instanceof TableResourceTD) {
TableResourceTD tableResourceTD = (TableResourceTD) resource;
resourceData=
"<tr>"
resourceData = "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Table Id: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"+
new SafeHtmlBuilder().append(tableResourceTD
.getTableId()).toSafeHtml().asString()+
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ new SafeHtmlBuilder()
.append(tableResourceTD
.getTableId())
.toSafeHtml().asString() +
"</td>" + "</tr>";
@ -254,7 +271,9 @@ public class ResourcesPanel extends FramedPanel {
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<span title='"+SafeHtmlUtils.htmlEscape(value)+"'>"+SafeHtmlUtils.htmlEscape(value)+"</span>");
sb.appendHtmlConstant("<span title='"
+ SafeHtmlUtils.htmlEscape(value) + "'>"
+ SafeHtmlUtils.htmlEscape(value) + "</span>");
}
@ -267,40 +286,41 @@ public class ResourcesPanel extends FramedPanel {
@Override
public void render(Context context, ResourceTDType value,
SafeHtmlBuilder sb) {
String head=("<img title='"+SafeHtmlUtils.htmlEscape(value.toString())+"' src='");
String head = ("<img title='"
+ SafeHtmlUtils.htmlEscape(value.toString()) + "' src='");
String bodyC;
switch (value) {
case CHART:
bodyC=SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE.chart()
.getSafeUri().asString());
bodyC = SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE
.chart().getSafeUri().asString());
break;
case CODELIST:
bodyC=SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE.codelist()
.getSafeUri().asString());
bodyC = SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE
.codelist().getSafeUri().asString());
break;
case CSV:
bodyC=SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE.csv().getSafeUri()
.asString());
bodyC = SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE
.csv().getSafeUri().asString());
break;
case GUESSER:
bodyC=SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE.resources()
.getSafeUri().asString());
bodyC = SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE
.resources().getSafeUri().asString());
break;
case JSON:
bodyC=SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE.json()
.getSafeUri().asString());
bodyC = SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE
.json().getSafeUri().asString());
break;
case MAP:
bodyC=SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE.gis().getSafeUri()
.asString());
bodyC = SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE
.gis().getSafeUri().asString());
break;
case SDMX:
bodyC=SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE.sdmx()
.getSafeUri().asString());
bodyC = SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE
.sdmx().getSafeUri().asString());
break;
default:
bodyC=SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE.resources()
.getSafeUri().asString());
bodyC = SafeHtmlUtils.htmlEscape(ResourceBundle.INSTANCE
.resources().getSafeUri().asString());
break;
}
@ -390,6 +410,21 @@ public class ResourcesPanel extends FramedPanel {
});
saveItem = new MenuItem();
saveItem.setText("Save");
saveItem.setIcon(ResourceBundle.INSTANCE.save());
saveItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> 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());
}
}
}

View File

@ -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" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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("<p style='display:inline-table;'><b>"
+ workspaceDestination.getName() + "</b><br>"
+ workspaceDestination.getDescription() + "</p>");
radioWorkspaceDestination.setName(workspaceDestination.getName());
radioWorkspaceDestination.setStylePrimaryName(res.wizardCSS()
.getImportSelectionSource());
radioWorkspaceDestination.setValue(true);
Radio radioFileDestination = new Radio();
radioFileDestination.setBoxLabel("<p style='display:inline-table;'><b>"
+ fileDestination.getName() + "</b><br>"
+ fileDestination.getDescription() + "</p>");
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<HasValue<Boolean>>() {
public void onValueChange(ValueChangeEvent<HasValue<Boolean>> 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);
}
}

View File

@ -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" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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);
}
}

View File

@ -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" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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,
"<span style=\"font-weight:bold;\";>Destination: </span>");
description.setText(0, 1, saveResourceSession.getDestination().getName());
description.setHTML(1, 0,
"<span style=\"font-weight:bold;\";>File Name: </span>");
description.setText(1, 1, saveResourceSession.getFileName());
description.setHTML(2, 0,
"<span style=\"font-weight:bold;\";>File Description: </span>");
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("<div></div>");
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<Void>() {
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("<div style='text-align:center;font-size:large;font-weight:bold; color:#009900;'>Operation Completed</div>");
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("<div style='text-align:center;font-size:large;font-weight:bold;color:red;'>Operation Failed</div>");
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();
}
}

View File

@ -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();
}
}

View File

@ -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" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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<ItemType> lItemType = new ArrayList<ItemType>();
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();
}
}

View File

@ -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();
}
}

View File

@ -19,6 +19,7 @@
<inherits name='com.sencha.gxt.ui.GXT' />
<inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" />
<inherits name='org.gcube.portlets.user.td.gwtservice.TDGWTService' />
<inherits name='org.gcube.portlets.user.td.wizardwidget.Wizard' />
<!-- Specify the app entry point class. -->
<!-- <entry-point class='org.gcube.portlets.user.td.resourceswidget.client.ResourcesWidgetEntry' /> -->