Rename svn component

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-import-widget@83969 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2013-10-24 10:32:40 +00:00
commit ce748b0a3f
59 changed files with 4056 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="com.google.gwt.eclipse.core.launch.gwtJUnit">
<stringAttribute key="com.google.gwt.eclipse.core.LOG_LEVEL" value="INFO"/>
<booleanAttribute key="com.google.gwt.eclipse.core.NOT_HEADLESS" value="false"/>
<stringAttribute key="com.google.gwt.eclipse.core.OUT_DIR" value="www-test"/>
<booleanAttribute key="com.google.gwt.eclipse.core.STANDARDS_MODE" value="false"/>
<stringAttribute key="com.google.gwt.eclipse.core.STYLE" value="OBFUSCATED"/>
<stringAttribute key="com.google.gwt.eclipse.core.WEB_MODE" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/CSVImportWizardTD/src/test/java/org/gcube/portlets/user/csvimportwizardtd/client/GwtTestCSVImportWizardTD.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="com.google.gdt.eclipse.maven.mavenClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.gcube.portlets.user.csvimportwizardtd.client.GwtTestCSVImportWizardTD"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="CSVImportWizardTD"/>
</launchConfiguration>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="com.google.gwt.eclipse.core.launch.gwtJUnit">
<stringAttribute key="com.google.gwt.eclipse.core.LOG_LEVEL" value="INFO"/>
<booleanAttribute key="com.google.gwt.eclipse.core.NOT_HEADLESS" value="false"/>
<stringAttribute key="com.google.gwt.eclipse.core.OUT_DIR" value="www-test"/>
<booleanAttribute key="com.google.gwt.eclipse.core.STANDARDS_MODE" value="false"/>
<stringAttribute key="com.google.gwt.eclipse.core.STYLE" value="OBFUSCATED"/>
<stringAttribute key="com.google.gwt.eclipse.core.WEB_MODE" value="true"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/CSVImportWizardTD/src/test/java/org/gcube/portlets/user/csvimportwizardtd/client/GwtTestCSVImportWizardTD.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="com.google.gdt.eclipse.maven.mavenClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.gcube.portlets.user.csvimportwizardtd.client.GwtTestCSVImportWizardTD"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="CSVImportWizardTD"/>
</launchConfiguration>

313
pom.xml Normal file
View File

@ -0,0 +1,313 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-csv-import-widget</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>tabular-data-csv-import-widget</name>
<description>tabular-data-csv-import-widget that allows csv import from file and workspace</description>
<scm>
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/CSVImportWizardTD</url>
</scm>
<developers>
<developer>
<name>Giancarlo Panichi</name>
<email>g.panichi@isti.cnr.it</email>
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
</developer>
</developers>
<properties>
<distroDirectory>${project.basedir}/distro</distroDirectory>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<release.date>2013-10-18</release.date>
<templatesDirectory>templates</templatesDirectory>
<distroDirectory>distro</distroDirectory>
<configDirectory>config</configDirectory>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.5.1</gwtVersion>
<!-- To make this work on gwt-run you need to set up global env vars. on
MacOSX edit this file /etc/launchd.conf and put "setenv GLOBUS_LOCATION /Users/massi/portal/Portal-Bundle/gCore"
on Linux? -->
<GLOBUS_LOCATION>${env.GLOBUS_LOCATION}</GLOBUS_LOCATION>
<!-- GWT needs at least java 1.5 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<profiles>
<profile>
<id>localRun</id>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<classifier>sources</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sencha.gxt</groupId>
<artifactId>gxt</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.gcube.data.publishing</groupId>
<artifactId>sdmx-registry-client-gcube</artifactId>
<version>[3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.data.analysis.tabulardata</groupId>
<artifactId>service-client-mock</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<!-- tabular-data-gwt-service -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-gwt-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- LOGGING -->
<dependency>
<groupId>com.allen-sauer.gwt.log</groupId>
<artifactId>gwt-log</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
<!-- TODO check if needed -->
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.16</version>
</dependency>
</dependencies>
</plugin>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtVersion}</version>
<executions>
<execution>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>CSVImportWizardTD.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<module>org.gcube.portlets.user.csvimportwizardtd.CSVImportWizardTD</module>
</configuration>
</plugin>
<!-- Maven -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${configDirectory}</outputDirectory>
<resources>
<resource>
<directory>${templatesDirectory}</directory>
<includes>
<include>profile.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-distro-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${distroDirectory}</outputDirectory>
<resources>
<resource>
<directory>${templatesDirectory}</directory>
<excludes>
<exclude>profile.xml</exclude>
<exclude>descriptor.xml</exclude>
</excludes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>${distroDirectory}</directory>
<includes>
<include>**</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${configDirectory}</directory>
<includes>
<include>**</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${templatesDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@ -0,0 +1,419 @@
package org.gcube.portlets.user.csvimportwizardtd.client;
import java.util.ArrayList;
import org.gcube.portlets.user.csvimportwizardtd.client.csvgrid.CSVGrid;
import org.gcube.portlets.user.csvimportwizardtd.client.general.WizardCard;
import org.gcube.portlets.user.csvimportwizardtd.client.util.ErrorMessageBox;
import org.gcube.portlets.user.td.gxtservice.client.rpc.TDGXTServiceAsync;
import org.gcube.portlets.user.td.gxtservice.shared.csv.AvailableCharsetList;
import org.gcube.portlets.user.td.gxtservice.shared.csv.CSVImportSession;
import org.gcube.portlets.user.td.gxtservice.shared.csv.CSVRowError;
import org.gcube.portlets.user.td.gxtservice.shared.file.HeaderPresence;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
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.HTML;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
import com.sencha.gxt.core.client.util.Padding;
import com.sencha.gxt.core.client.util.ToggleGroup;
import com.sencha.gxt.data.shared.LabelProvider;
import com.sencha.gxt.data.shared.StringLabelProvider;
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.FieldLabel;
import com.sencha.gxt.widget.core.client.form.FormPanel;
import com.sencha.gxt.widget.core.client.form.Radio;
import com.sencha.gxt.widget.core.client.form.SimpleComboBox;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.form.validator.MaxLengthValidator;
import com.sencha.gxt.widget.core.client.tips.ToolTip;
import com.sencha.gxt.widget.core.client.tips.ToolTipConfig;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CSVConfigCard extends WizardCard {
private static final String DEFAULT_DELIMETER = ",";
private static final String DEFAULT_COMMENT = "#";
protected CSVImportSession csvImportSession;
protected SimpleComboBox<String> encodings;
protected SimpleComboBox<HeaderPresence> header;
protected TextField customDelimiterField;
protected Radio otherDelimiter;
protected Radio commaDelimiter;
protected Radio spaceDelimiter;
protected Radio tabDelimiter;
protected Radio semicoloDelimiter;
protected TextField commentField;
protected CsvCheckPanel csvCheckPanel;
protected CSVGrid csvSample;
public CSVConfigCard(final CSVImportSession csvImportSession) {
super("CSV configuration", "");
if (csvImportSession == null) {
Log.error("CSVImportSession is null");
}
this.csvImportSession = csvImportSession;
FormPanel panel = createPanel();
setContent(panel);
}
protected FormPanel createPanel() {
FormPanel panel = new FormPanel();
panel.setLabelWidth(90);
panel.getElement().setPadding(new Padding(5));
VerticalLayoutContainer content = new VerticalLayoutContainer();
panel.add(content);
encodings = new SimpleComboBox<String>(
new StringLabelProvider<String>());
encodings.setToolTip("The CSV file encoding");
encodings.setTabIndex(0);
encodings.setEditable(false);
encodings.setForceSelection(true);
encodings.setTriggerAction(TriggerAction.ALL);
encodings.addSelectionHandler(new SelectionHandler<String>() {
@Override
public void onSelection(SelectionEvent<String> event) {
updateGrid();
}
});
content.add(new FieldLabel(encodings, "File encoding"));
LabelProvider<HeaderPresence> labelProvider = new LabelProvider<HeaderPresence>() {
@Override
public String getLabel(HeaderPresence item) {
return item.getLabel();
}
};
header = new SimpleComboBox<HeaderPresence>(labelProvider);
header.setToolTip("The CSV file header");
header.setTabIndex(0);
header.setEditable(false);
header.setForceSelection(true);
header.setTriggerAction(TriggerAction.ALL);
for (HeaderPresence headerPresence : HeaderPresence.values())
header.add(headerPresence);
header.setValue(HeaderPresence.NONE);
header.addSelectionHandler(new SelectionHandler<HeaderPresence>() {
@Override
public void onSelection(SelectionEvent<HeaderPresence> event) {
updateGrid();
}
});
content.add(new FieldLabel(header, "Header"));
commaDelimiter = new Radio();
commaDelimiter.setBoxLabel("Comma");
commaDelimiter.setValue(true);
spaceDelimiter = new Radio();
spaceDelimiter.setBoxLabel("Space");
tabDelimiter = new Radio();
tabDelimiter.setBoxLabel("Tab");
semicoloDelimiter = new Radio();
semicoloDelimiter.setBoxLabel("Semicolon");
otherDelimiter = new Radio();
otherDelimiter.setBoxLabel("Other delimiter");
customDelimiterField = new TextField();
customDelimiterField.setEnabled(false);
customDelimiterField.setValue(DEFAULT_DELIMETER);
customDelimiterField.setAllowBlank(false);
customDelimiterField.setWidth(20);
ToggleGroup delimitersGroup = new ToggleGroup();
delimitersGroup.add(commaDelimiter);
delimitersGroup.add(spaceDelimiter);
delimitersGroup.add(tabDelimiter);
delimitersGroup.add(semicoloDelimiter);
delimitersGroup.add(otherDelimiter);
delimitersGroup
.addValueChangeHandler(new ValueChangeHandler<HasValue<Boolean>>() {
@Override
public void onValueChange(
ValueChangeEvent<HasValue<Boolean>> event) {
customDelimiterField.setEnabled(otherDelimiter
.getValue());
if (!otherDelimiter.getValue())
customDelimiterField.clearInvalid();
else
customDelimiterField.validate();
if (otherDelimiter.getValue()
&& !customDelimiterField.isValid())
return;
updateGrid();
}
});
HorizontalPanel delimitersPanel = new HorizontalPanel();
delimitersPanel.add(commaDelimiter);
delimitersPanel.add(spaceDelimiter);
delimitersPanel.add(tabDelimiter);
delimitersPanel.add(semicoloDelimiter);
delimitersPanel.add(otherDelimiter);
delimitersPanel.add(customDelimiterField);
new ToolTip(delimitersPanel, new ToolTipConfig(
"The delimiter use to delimit the CSV fields"));
content.add(new FieldLabel(delimitersPanel, "Delimiter"));
commentField = new TextField();
commentField.setToolTip("The character used as comment line prefix");
commentField.setValue(DEFAULT_COMMENT);
commentField.setAllowBlank(false);
commentField.getValidators().add(new MaxLengthValidator(1));
commentField.setWidth(20);
commentField.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if (commentField.isValid())
updateGrid();
}
});
content.add(new FieldLabel(commentField, "Comment"));
csvSample = new CSVGrid();
content.add(csvSample, new VerticalLayoutData(1, -1));
content.add(new HTML("<BR>"));
csvCheckPanel = new CsvCheckPanel();
content.add(csvCheckPanel);
csvCheckPanel.getCheckConfiguration().addSelectHandler(
new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
checkConfiguration();
}
});
csvCheckPanel.getSkipInvalidCheckBox().addChangeHandler(
new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
boolean skip = csvCheckPanel.getSkipInvalidCheckBox()
.getValue();
setEnableNextButton(skip);
CSVConfigCard.this.csvImportSession
.setSkipInvalidLines(skip);
}
});
return panel;
}
protected void checkConfiguration() {
csvCheckPanel.setActiveCheckingPanel();
csvCheckPanel.getCheckConfiguration().setEnabled(false);
TDGXTServiceAsync.INSTANCE.checkCSV(100,
new AsyncCallback<ArrayList<CSVRowError>>() {
@Override
public void onFailure(Throwable caught) {
ErrorMessageBox
.showError(
"An error occured checking the file",
"Please retry, if the error perstists change the CSV configuration",
"");
}
@Override
public void onSuccess(ArrayList<CSVRowError> errors) {
csvCheckPanel.getCheckConfiguration().setEnabled(true);
if (errors.size() == 0) {
setCheckCorrectMessage();
} else {
setCheckErrorMessage(errors);
}
}
});
}
protected void updateGrid() {
GWT.log("Started updating GRID");
resetCheckMessage();
csvSample.mask("Updating...");
GWT.log("updating CSV config");
HeaderPresence headerPresence = header.getCurrentValue();
char delimiter = getSelectedDelimiter();
String encoding = encodings.getCurrentValue();
char commentChar = commentField.getValue().charAt(0);
TDGXTServiceAsync.INSTANCE.configureCSVParser(encoding, headerPresence,
delimiter, commentChar, new AsyncCallback<ArrayList<String>>() {
@Override
public void onFailure(Throwable caught) {
Log.error("Failed updating CSV config", caught);
setEnableNextButton(false);
ErrorMessageBox
.showError(
"An error occured checking the file",
"Please retry, if the error perstists change the CSV configuration",
caught.getLocalizedMessage());
}
@Override
public void onSuccess(ArrayList<String> result) {
Log.info("CSV header getted");
csvImportSession.setHeaders(result);
for (String name : result)
Log.info("Column HEADER: " + name);
// csvImportSession.getId()
csvSample.configureColumns(result);
csvSample.unmask();
setEnableNextButton(false);
}
});
}
protected char getSelectedDelimiter() {
if (otherDelimiter.getValue())
return customDelimiterField.getValue().charAt(0);
if (commaDelimiter.getValue())
return ',';
if (spaceDelimiter.getValue())
return ' ';
if (tabDelimiter.getValue())
return '\t';
if (semicoloDelimiter.getValue())
return ';';
return DEFAULT_DELIMETER.charAt(0);
}
@Override
public void setup() {
setEnableBackButton(false);
setEnableNextButton(false);
encodings.focus();
TDGXTServiceAsync.INSTANCE
.getAvailableCharset(new AsyncCallback<AvailableCharsetList>() {
@Override
public void onSuccess(AvailableCharsetList result) {
GWT.log("CharsetInfo: "
+ result.getCharsetList().size()
+ " charset, default: "
+ result.getDefaultCharset());
for (String charset : result.getCharsetList())
encodings.add(charset);
encodings.setValue(result.getDefaultCharset());
updateGrid();
}
/**
* {@inheritDoc}
*/
@Override
public void onFailure(Throwable caught) {
GWT.log("Error loading charset list", caught);
showErrorAndHide("Error loading charset list",
"Error loading charset list", "", caught);
}
});
resetCheckMessage();
Command sayNextCard = new Command() {
@Override
public void execute() {
CSVTableDetailCard csvTableDetailCard = new CSVTableDetailCard(
csvImportSession);
getWizardWindow()
.addCard(csvTableDetailCard);
Log.info("NextCard SDMXTableDetailCard");
getWizardWindow().nextCard();
}
};
getWizardWindow().setNextButtonCommand(sayNextCard);
}
protected void resetCheckMessage() {
csvCheckPanel.setActiveInfoPanel();
}
protected void setCheckErrorMessage(ArrayList<CSVRowError> errors) {
csvCheckPanel.setActiveFailure(errors);
setEnableNextButton(false);
}
protected void setCheckCorrectMessage() {
csvCheckPanel.setActiveSuccess();
setEnableNextButton(true);
}
@Override
public void dispose() {
csvImportSession
.setColumnToImportMask(csvSample.getImportColumnsMask());
}
}

View File

@ -0,0 +1,89 @@
package org.gcube.portlets.user.csvimportwizardtd.client;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gxtservice.shared.csv.CSVRowError;
import com.google.gwt.core.client.GWT;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.ModelKeyProvider;
import com.sencha.gxt.data.shared.PropertyAccess;
import com.sencha.gxt.widget.core.client.Window;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
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.grid.ColumnConfig;
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
import com.sencha.gxt.widget.core.client.grid.Grid;
/**
* @author Federico De Faveri defaveri@isti.cnr.it
*
*/
public class CSVErrorWindow extends Window {
private static final CSVRowErrorProperties props = GWT.create(CSVRowErrorProperties.class);
protected Grid<CSVRowError> grid;
protected ListStore<CSVRowError> store;
public CSVErrorWindow()
{
setHeadingText("CSV error details");
setModal(true);
setBlinkModal(true);
setWidth(600);
setHeight(350);
createGrid();
add(grid);
TextButton close = new TextButton("Close");
close.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
hide();
}
});
addButton(close);
setButtonAlign(BoxLayoutPack.CENTER);
}
protected void createGrid()
{
ArrayList<ColumnConfig<CSVRowError, ?>> columns = new ArrayList<ColumnConfig<CSVRowError, ?>>();
columns.add(new ColumnConfig<CSVRowError, Integer>(props.lineNumber(), 30, "# line"));
columns.add(new ColumnConfig<CSVRowError, String>(props.lineValue(), 60, "Line"));
columns.add(new ColumnConfig<CSVRowError, String>(props.errorDescription(), 160, "Error"));
ColumnModel<CSVRowError> columnModel = new ColumnModel<CSVRowError>(columns);
store = new ListStore<CSVRowError>(props.id());
grid = new Grid<CSVRowError>(store, columnModel);
grid.getView().setForceFit(true);
}
public void updateGrid(ArrayList<CSVRowError> errors)
{
store.clear();
store.addAll(errors);
}
protected interface CSVRowErrorProperties extends PropertyAccess<CSVRowError> {
ModelKeyProvider<CSVRowError> id();
ValueProvider<CSVRowError, Integer> lineNumber();
ValueProvider<CSVRowError, String> lineValue();
ValueProvider<CSVRowError, String> errorDescription();
}
}

View File

@ -0,0 +1,73 @@
package org.gcube.portlets.user.csvimportwizardtd.client;
import org.gcube.portlets.user.csvimportwizardtd.client.general.WizardWindow;
import org.gcube.portlets.user.td.gxtservice.shared.csv.CSVImportSession;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.Command;
/**
*
*/
public class CSVImportWizardTD extends WizardWindow {
protected CSVImportSession importSession;
private CSVImportWizardTD wizard;
/**
* The id of the {@link CSVTarget} to use.
* @param targetId
*/
public CSVImportWizardTD(String title) {
super(title);
setWidth(550);
setHeight(520);
importSession= new CSVImportSession();
this.wizard=this;
SourceSelectionCard sourceSelection= new SourceSelectionCard(importSession);
addCard(sourceSelection);
Command sayNextCard = new Command() {
public void execute() {
try {
String sourceId = importSession.getSource().getId();
if (sourceId == null || sourceId.isEmpty()) {
Log.error("CSV Import Source Id: " + sourceId);
wizard.showErrorAndHide("CSV Import Source Id is"+sourceId,"Error in source selection", "Error in source Selection",new Throwable("CSV Import Source Id is"+sourceId));
} else {
if (sourceId.compareTo("File") == 0) {
CSVUploadFileCard csvUploadFileCard = new CSVUploadFileCard(importSession);
wizard.addCard(csvUploadFileCard);
Log.info("NextCard CSVUploadFileCard");
wizard.nextCard();
} else {
if (sourceId.compareTo("Workspace") == 0) {
} else {
}
}
}
} catch (Exception e) {
Log.error("sayNextCard :" + e.getLocalizedMessage());
wizard.showErrorAndHide("CSV Import error creating next card","CSV Import error creating next card", "CSV Import error creating next card",e);
}
}
};
this.setNextButtonCommand(sayNextCard);
}
}

View File

@ -0,0 +1,13 @@
package org.gcube.portlets.user.csvimportwizardtd.client;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.EntryPoint;
public class CSVImportWizardTDEntry implements EntryPoint {
@Override
public void onModuleLoad() {
CSVImportWizardTD importWizard= new CSVImportWizardTD("CSVImport");
Log.info(importWizard.getId());
}
}

View File

@ -0,0 +1,168 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client;
import org.gcube.portlets.user.csvimportwizardtd.client.general.WizardCard;
import org.gcube.portlets.user.td.gxtservice.shared.TabResource;
import org.gcube.portlets.user.td.gxtservice.shared.csv.CSVImportSession;
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.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.FieldLabel;
import com.sencha.gxt.widget.core.client.form.FieldSet;
import com.sencha.gxt.widget.core.client.form.TextArea;
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 CSVTableDetailCard extends WizardCard {
protected CSVImportSession importSession;
protected CSVTableDetailCard thisCard;
protected VerticalLayoutContainer p;
protected VerticalPanel tableDetailPanel;
protected TextField name;
protected TextArea description;
protected TextArea rights;
protected TextField agencyName;
protected TextButton checkButton;
// protected ComboBox<Agencies> combo=null;
TabResource detail = new TabResource();
public CSVTableDetailCard(final CSVImportSession importSession) {
super("Tabular Resource Detail", "");
this.importSession = importSession;
thisCard = this;
tableDetailPanel = new VerticalPanel();
tableDetailPanel.setSpacing(4);
tableDetailPanel.setWidth("100%");
tableDetailPanel.setHeight("100%");
FramedPanel form2 = new FramedPanel();
form2.setHeadingText("Details");
// form2.setWidth(350);
FieldSet fieldSet = new FieldSet();
fieldSet.setHeadingText("Information");
fieldSet.setCollapsible(false);
form2.add(fieldSet);
p = new VerticalLayoutContainer();
fieldSet.add(p);
name = new TextField();
name.setAllowBlank(false);
name.setEmptyText("Enter a name...");
name.setValue(importSession.getLocalFileName());
name.setAllowBlank(false);
p.add(new FieldLabel(name, "Name"), new VerticalLayoutData(1, -1));
description = new TextArea();
description.setAllowBlank(false);
description.setEmptyText("Enter a description...");
description.setValue("File CSV");
description.setAllowBlank(false);
p.add(new FieldLabel(description, "Description"),
new VerticalLayoutData(1, -1));
rights = new TextArea();
rights.setEmptyText("Enter rights...");
rights.setAllowBlank(false);
p.add(new FieldLabel(rights, "Rights"), new VerticalLayoutData(1, -1));
checkButton = new TextButton("Save");
checkButton.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
checkData();
}
});
form2.addButton(checkButton);
tableDetailPanel.add(form2);
setContent(tableDetailPanel);
}
protected void checkData() {
if (name.getValue() == null || name.getValue().isEmpty()
|| description.getValue() == null
|| description.getValue().isEmpty()
|| rights.getValue() == null || rights.getValue().isEmpty()
) {
return;
} else {
name.setReadOnly(true);
description.setReadOnly(true);
rights.setReadOnly(true);
checkButton.disable();
getWizardWindow().setEnableNextButton(true);
}
}
@Override
public void setup() {
Command sayNextCard = new Command() {
@Override
public void execute() {
detail.setName(name.getCurrentValue());
// detail.setAgency(combo.getSelectedText());
detail.setAgency(agencyName.getCurrentValue());
detail.setDescription(description.getCurrentValue());
detail.setRight(rights.getCurrentValue());
importSession.setTabResource(detail);
/*
* SDMXOperationInProgressCard sdmxOperationInProgressCard = new
* SDMXOperationInProgressCard( importSession);
* getWizardWindow() .addCard(sdmxOperationInProgressCard);
* Log.info("NextCard SDMXOperationInProgressCard");
* getWizardWindow().nextCard();
*/
}
};
getWizardWindow().setNextButtonCommand(sayNextCard);
Command sayPreviousCard = new Command() {
public void execute() {
try {
getWizardWindow().previousCard();
getWizardWindow().removeCard(thisCard);
Log.info("Remove SDMXTableDetailCard");
} catch (Exception e) {
Log.error("sayPreviousCard :" + e.getLocalizedMessage());
}
}
};
getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
getWizardWindow().setEnableNextButton(false);
}
}

View File

@ -0,0 +1,65 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client;
import org.gcube.portlets.user.csvimportwizardtd.client.general.WizardCard;
import org.gcube.portlets.user.td.gxtservice.shared.csv.CSVImportSession;
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 CSVUploadFileCard extends WizardCard {
protected CSVImportSession importSession;
protected FileUploadPanel fileUploadPanel;
protected CSVUploadFileCard thisCard;
public CSVUploadFileCard(final CSVImportSession importSession) {
super("CSV Import File Upload", "");
this.thisCard = this;
this.importSession = importSession;
this.fileUploadPanel = new FileUploadPanel(res, thisCard);
setContent(fileUploadPanel);
}
@Override
public void setup() {
Command sayNextCard = new Command() {
@Override
public void execute() {
CSVConfigCard csvConfigCard = new CSVConfigCard(importSession);
getWizardWindow().addCard(csvConfigCard);
Log.info("NextCard CSVConfigCard");
getWizardWindow().nextCard();
}
};
getWizardWindow().setNextButtonCommand(sayNextCard);
Command sayPreviousCard = new Command() {
public void execute() {
try {
getWizardWindow().previousCard();
getWizardWindow().removeCard(thisCard);
Log.info("Remove CSVUploadFileCard");
} catch (Exception e) {
Log.error("sayPreviousCard :" + e.getLocalizedMessage());
}
}
};
getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
getWizardWindow().setEnableNextButton(false);
}
}

View File

@ -0,0 +1,190 @@
package org.gcube.portlets.user.csvimportwizardtd.client;
import java.util.ArrayList;
import org.gcube.portlets.user.csvimportwizardtd.client.dataresource.ResourceBundle;
import org.gcube.portlets.user.td.gxtservice.shared.csv.CSVRowError;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.CardLayoutContainer;
import com.sencha.gxt.widget.core.client.form.CheckBox;
import com.sencha.gxt.widget.core.client.tips.ToolTip;
import com.sencha.gxt.widget.core.client.tips.ToolTipConfig;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CsvCheckPanel extends VerticalPanel {
public static final int ERROR_LIMIT = 50;
protected static final Image successImage = new Image(ResourceBundle.INSTANCE.csvCheckSuccess());
protected static final Image failureImage = new Image(ResourceBundle.INSTANCE.csvCheckFailure());
protected static final Image informationImage = new Image(ResourceBundle.INSTANCE.information());
protected static final Image loadingImage = new Image(ResourceBundle.INSTANCE.loading());
protected CardLayoutContainer messagePanel;
protected HorizontalPanel checkMessagePanel;
protected HorizontalPanel failureMessagePanel;
protected HorizontalPanel successMessagePanel;
protected HorizontalPanel infoMessagePanel;
protected TextButton checkConfiguration;
protected TextButton showErrorButton;
protected CheckBox skipInvalidCheckBox;
protected Anchor errorAnchor;
protected CSVErrorWindow errorWindow = new CSVErrorWindow();
public CsvCheckPanel()
{
setSpacing(2);
HorizontalPanel checkPanel = new HorizontalPanel();
checkPanel.setSpacing(4);
checkConfiguration = new TextButton("Check configuration");
checkPanel.add(checkConfiguration);
messagePanel = createMessagesPanel();
checkPanel.add(messagePanel);
add(checkPanel);
HorizontalPanel skipPanel = new HorizontalPanel();
skipPanel.setSpacing(4);
skipInvalidCheckBox = new CheckBox();
skipInvalidCheckBox.setBoxLabel("Skip invalid lines");
skipPanel.add(skipInvalidCheckBox);
add(skipPanel);
setActiveInfoPanel();
}
/**
* @return
*/
public TextButton getCheckConfiguration() {
return checkConfiguration;
}
/**
* @return the skipInvalidCheckBox
*/
public CheckBox getSkipInvalidCheckBox() {
return skipInvalidCheckBox;
}
protected CardLayoutContainer createMessagesPanel()
{
CardLayoutContainer messagesPanel = new CardLayoutContainer();
infoMessagePanel = createInfoPanel();
messagesPanel.add(infoMessagePanel);
checkMessagePanel = createCheckPanel();
messagesPanel.add(checkMessagePanel);
failureMessagePanel = createFailurePanel();
messagesPanel.add(failureMessagePanel);
successMessagePanel = createSuccessPanel();
messagesPanel.add(successMessagePanel);
return messagesPanel;
}
public void setActiveInfoPanel()
{
messagePanel.setActiveWidget(infoMessagePanel);
skipInvalidCheckBox.setVisible(false);
}
public void setActiveCheckingPanel()
{
messagePanel.setActiveWidget(checkMessagePanel);
skipInvalidCheckBox.setVisible(false);
}
public void setActiveSuccess()
{
messagePanel.setActiveWidget(successMessagePanel);
skipInvalidCheckBox.setVisible(false);
}
public void setActiveFailure(ArrayList<CSVRowError> errors)
{
if (errors.size() >= ERROR_LIMIT) errorAnchor.setHTML("Failed (more than "+ERROR_LIMIT+" errors)");
else errorAnchor.setHTML("Failed ("+errors.size()+" errors)");
errorWindow.updateGrid(errors);
skipInvalidCheckBox.setValue(false);
skipInvalidCheckBox.setVisible(true);
messagePanel.setActiveWidget(failureMessagePanel);
}
protected HorizontalPanel createInfoPanel()
{
HorizontalPanel infoPanel = new HorizontalPanel();
infoPanel.setSpacing(2);
infoPanel.add(informationImage);
HTML message = new HTML("Check the configuration before submit it");
infoPanel.add(message);
return infoPanel;
}
protected HorizontalPanel createCheckPanel()
{
HorizontalPanel checkPanel = new HorizontalPanel();
checkPanel.setSpacing(2);
checkPanel.add(loadingImage);
checkPanel.add(new HTML("Checking the configuration..."));
return checkPanel;
}
protected HorizontalPanel createFailurePanel()
{
HorizontalPanel failurePanel = new HorizontalPanel();
failurePanel.setSpacing(2);
new ToolTip(failurePanel, new ToolTipConfig("Click to obtain more information"));
failurePanel.add(failureImage);
errorAnchor = new Anchor("Failed");
errorAnchor.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
errorWindow.show();
}
});
failurePanel.add(errorAnchor);
return failurePanel;
}
protected HorizontalPanel createSuccessPanel()
{
HorizontalPanel successPanel = new HorizontalPanel();
successPanel.setSpacing(2);
successPanel.add(successImage);
successPanel.add(new HTML("Correct."));
return successPanel;
}
}

View File

@ -0,0 +1,198 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client;
import org.gcube.portlets.user.csvimportwizardtd.client.dataresource.ResourceBundle;
import org.gcube.portlets.user.csvimportwizardtd.client.general.WizardCard;
import org.gcube.portlets.user.csvimportwizardtd.client.progress.FileUploadProgressBarUpdater;
import org.gcube.portlets.user.csvimportwizardtd.client.progress.FileUploadProgressListener;
import org.gcube.portlets.user.csvimportwizardtd.client.progress.FileUploadProgressUpdater;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.sencha.gxt.core.client.Style.HideMode;
import com.sencha.gxt.core.client.util.Padding;
import com.sencha.gxt.widget.core.client.ProgressBar;
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
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.event.ShowEvent;
import com.sencha.gxt.widget.core.client.event.ShowEvent.ShowHandler;
import com.sencha.gxt.widget.core.client.form.FieldLabel;
import com.sencha.gxt.widget.core.client.form.FileUploadField;
import com.sencha.gxt.widget.core.client.form.FormPanel;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class FileUploadPanel extends FormPanel {
protected static final String UPLOAD_SERVLET = "LocalUploadServlet";
public static final int STATUS_POLLING_DELAY = 1000;
protected ResourceBundle res;
protected FileUploadField fileUploadField;
protected TextButton uploadButton;
protected FileUploadProgressUpdater progressUpdater;
protected ProgressBar uploadProgressBar;
protected TextButton cancelButton;
public FileUploadPanel(ResourceBundle res, final WizardCard card)
{
this.res=res;
setId("LocalUploadPanel");
setLabelAlign(LabelAlign.TOP);
getElement().setPadding(new Padding(5));
addShowHandler(new ShowHandler() {
@Override
public void onShow(ShowEvent event) {
doLayout();
}
});
setAction(GWT.getModuleBaseURL()+UPLOAD_SERVLET);
setWidth("100%");
setEncoding(Encoding.MULTIPART);
setMethod(Method.POST);
VerticalLayoutContainer content = new VerticalLayoutContainer();
content.setWidth("100%");
add(content);
fileUploadField = new FileUploadField();
fileUploadField.setName("uploadFormElement");
fileUploadField.setWidth("100%");
content.add(new FieldLabel(fileUploadField, "Select the csv file to import"), new VerticalLayoutData(-2, -1));
uploadButton = new TextButton("Upload");
content.add(uploadButton, new VerticalLayoutData(-1, -1));
fileUploadField.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
uploadButton.setEnabled(fileUploadField.isValid());
}
});
uploadProgressBar = new ProgressBar();
uploadProgressBar.setHideMode(HideMode.VISIBILITY);
uploadProgressBar.getElement().setPadding(new Padding(3, 0, 5, 0));
content.add(uploadProgressBar, new VerticalLayoutData(-2, -1));
uploadProgressBar.hide();
cancelButton = new TextButton("Cancel");
cancelButton.hide();
content.add(cancelButton, new VerticalLayoutData(-1, -1));
uploadButton.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
Log.info("request upload");
if (fileUploadField.getValue()==null || fileUploadField.getValue().equals("")){
Log.info("fileUploadField is null or empty");
AlertMessageBox alertMessageBox = new AlertMessageBox("CSV file missing", "Please specify a CSV file.");
alertMessageBox.show();
return;
} else {
Log.info("startUpload call");
startUpload();
}
}
});
progressUpdater = new FileUploadProgressUpdater();
progressUpdater.addListener(new FileUploadProgressBarUpdater(uploadProgressBar));
progressUpdater.addListener(new FileUploadProgressListener() {
@Override
public void operationUpdate(float elaborated) {
// TODO Auto-generated method stub
}
@Override
public void operationInitializing() {
// TODO Auto-generated method stub
}
@Override
public void operationFailed(Throwable caught, String reason,
String failureDetails) {
card.showErrorAndHide("Error uploading the csv file", reason, failureDetails, caught);
}
@Override
public void operationComplete() {
card.setEnableNextButton(true);
cancelButton.disable();
}
});
}
protected void startUpload()
{
disableUpload();
//we update the action url with the session id
//this is necessary in order to let the servlet retrieve the session id before the POST request parsing
StringBuilder actionUrl = new StringBuilder();
actionUrl.append(GWT.getModuleBaseURL());
//actionUrl.append(UPLOAD_SERVLET+"?sessionId=");
actionUrl.append(UPLOAD_SERVLET);
/*if(session==null){
Log.info("No valid Session");
AlertMessageBox alertMessageBox = new AlertMessageBox("No session valid", "Error generating the session");
alertMessageBox.show();
return;
}*/
//actionUrl.append(session.getId());
setAction(actionUrl.toString());
Log.info("Start Upload action Url "+actionUrl.toString());
submit();
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
}
protected void disableUpload()
{
fileUploadField.disable();
uploadButton.disable();
uploadProgressBar.show();
cancelButton.show();
}
}

View File

@ -0,0 +1,137 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client;
import org.gcube.portlets.user.csvimportwizardtd.client.general.WizardCard;
import org.gcube.portlets.user.td.gxtservice.shared.csv.CSVImportSession;
import org.gcube.portlets.user.td.gxtservice.shared.source.FileSource;
import org.gcube.portlets.user.td.gxtservice.shared.source.WorkspaceSource;
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 SourceSelectionCard extends WizardCard {
protected final CSVImportSession importSession;
final FileSource fileSource = FileSource.INSTANCE;
final WorkspaceSource workspaceSource = WorkspaceSource.INSTANCE;
public SourceSelectionCard(final CSVImportSession importSession) {
super("CSV source selection", "");
this.importSession = importSession;
// Default
importSession.setSource(fileSource);
VerticalPanel sourceSelectionPanel = new VerticalPanel();
sourceSelectionPanel.setStylePrimaryName(res.importCss()
.getImportSelectionSources());
Radio radioFileSource = new Radio();
radioFileSource.setBoxLabel("<p style='display:inline-table;'><b>"
+ fileSource.getName() + "</b><br>"
+ fileSource.getDescription() + "</p>");
radioFileSource.setName(fileSource.getName());
radioFileSource.setStylePrimaryName(res.importCss()
.getImportSelectionSource());
radioFileSource.setValue(true);
Radio radioSDMXRegistrySource = new Radio();
Radio radioWorkspaceSource = new Radio();
radioWorkspaceSource.setBoxLabel("<p style='display:inline-table;'><b>"
+ workspaceSource.getName() + "</b><br>"
+ workspaceSource.getDescription() + "</p>");
radioWorkspaceSource.setName(workspaceSource.getName());
radioWorkspaceSource.setStylePrimaryName(res.importCss()
.getImportSelectionSource());
radioWorkspaceSource.disable();
sourceSelectionPanel.add(radioFileSource);
sourceSelectionPanel.add(radioWorkspaceSource);
// we can set name on radios or use toggle group
ToggleGroup toggle = new ToggleGroup();
toggle.add(radioSDMXRegistrySource);
toggle.add(radioWorkspaceSource);
toggle.add(radioFileSource);
toggle.addValueChangeHandler(new ValueChangeHandler<HasValue<Boolean>>() {
@Override
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(workspaceSource.getName()) == 0) {
importSession.setSource(workspaceSource);
} else {
if (radio.getName().compareTo(fileSource.getName()) == 0) {
importSession.setSource(fileSource);
} else {
}
}
} catch (Exception e) {
Log.error("ToggleGroup: onValueChange "
+ e.getLocalizedMessage());
}
}
});
setContent(sourceSelectionPanel);
}
@Override
public void setup() {
Command sayNextCard = new Command() {
public void execute() {
try {
String sourceId = importSession.getSource().getId();
if (sourceId == null || sourceId.isEmpty()) {
Log.error("CSV Import Source Id: " + sourceId);
} else {
if (sourceId.compareTo("File") == 0) {
CSVUploadFileCard csvUploadFileCard = new CSVUploadFileCard( importSession);
getWizardWindow().addCard(csvUploadFileCard);
Log.info("NextCard CSVUploadFileCard");
getWizardWindow().nextCard();
} else {
if (sourceId.compareTo("Workspace") == 0) {
} else {
}
}
}
} catch (Exception e) {
Log.error("sayNextCard :" + e.getLocalizedMessage());
}
}
};
getWizardWindow().setNextButtonCommand(sayNextCard);
}
}

View File

@ -0,0 +1,119 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.csvgrid;
import java.util.ArrayList;
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRow;
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRowKeyProvider;
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRowValueProvider;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.RequestBuilder;
import com.sencha.gxt.core.client.IdentityValueProvider;
import com.sencha.gxt.data.client.loader.HttpProxy;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.loader.DataReader;
import com.sencha.gxt.data.shared.loader.ListLoadConfig;
import com.sencha.gxt.data.shared.loader.ListLoadResult;
import com.sencha.gxt.data.shared.loader.ListLoader;
import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding;
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.grid.RowNumberer;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CSVGrid extends Grid<CSVRow> {
private static final String csvImportFileServlet="CSVImportFileServlet";
protected CSVGridView gridViewSample;
public CSVGrid()
{
super(new ListStore<CSVRow>(new CSVRowKeyProvider()), new ColumnModel<CSVRow>(new ArrayList<ColumnConfig<CSVRow,?>>()));
setHeight(200);
setBorders(true);
getView().setStripeRows(true);
setLoadMask(true);
gridViewSample = new CSVGridView();
setView(gridViewSample);
getView().setEmptyText("No data to show");
setBorders(true);
}
public void configureColumns(ArrayList<String> columnNames)
{
ColumnModel<CSVRow> columnModel = createColumnModel(columnNames);
ListStore<CSVRow> store = createStore(columnNames);
reconfigure(store, columnModel);
getView().refresh(true);
}
protected ListStore<CSVRow> createStore(ArrayList<String> columnNames)
{
String path = GWT.getModuleBaseURL()+csvImportFileServlet;
Log.info("CSVImportFileServlet path:"+path);
// use a http proxy to get the data
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
HttpProxy<ListLoadConfig> proxy = new HttpProxy<ListLoadConfig>(builder);
// need a loader, proxy, and reader
DataReader<ListLoadResult<CSVRow>, String> reader = new CSVJsonReader();
final ListLoader<ListLoadConfig, ListLoadResult<CSVRow>> loader = new ListLoader<ListLoadConfig, ListLoadResult<CSVRow>>(proxy, reader);
ListStore<CSVRow> store = new ListStore<CSVRow>(new CSVRowKeyProvider());
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, CSVRow, ListLoadResult<CSVRow>>(store));
loader.load();
return store;
}
protected ColumnModel<CSVRow> createColumnModel(ArrayList<String> columnNames)
{
ArrayList<ColumnConfig<CSVRow, ?>> columns = new ArrayList<ColumnConfig<CSVRow, ?>>();
columns.add(new RowNumberer<CSVRow>(new IdentityValueProvider<CSVRow>()));
for (int i = 0; i<columnNames.size(); i++) {
String columnField = "field"+(i+1);
String columnName = columnNames.get(i);
ColumnConfig<CSVRow, String> columnConfig = new ColumnConfig<CSVRow, String>(new CSVRowValueProvider(columnField), 100, columnName);
columns.add(columnConfig);
}
return new ColumnModel<CSVRow>(columns);
}
/**
* Returns the import column mask.
* @return an array of boolean where the item is <code>true</code> if the column have to be imported, <code>false</code> otherwise.
*/
public boolean[] getImportColumnsMask()
{
boolean[] columnMask = new boolean[getColumnModel().getColumnCount()];
ArrayList<Integer> excluded = gridViewSample.getExcludedColumns();
for (int i = 0; i<columnMask.length; i++) columnMask[i] = !excluded.contains(i);
return columnMask;
}
}

View File

@ -0,0 +1,89 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.csvgrid;
import java.util.ArrayList;
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRow;
import org.gcube.portlets.user.csvimportwizardtd.client.dataresource.ResourceBundle;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.widget.core.client.grid.GridView;
import com.sencha.gxt.widget.core.client.grid.GridViewConfig;
import com.sencha.gxt.widget.core.client.menu.CheckMenuItem;
import com.sencha.gxt.widget.core.client.menu.Item;
import com.sencha.gxt.widget.core.client.menu.Menu;
/**
* @author Federico De Faveri defaveri@isti.cnr.it
*
*/
public class CSVGridView extends GridView<CSVRow> {
protected ArrayList<Integer> excludedColumns = new ArrayList<Integer>();
public CSVGridView()
{
setViewConfig(new GridViewConfig<CSVRow>() {
@Override
public String getRowStyle(CSVRow model, int rowIndex) {
return "";
}
@Override
public String getColStyle(CSVRow model, ValueProvider<? super CSVRow, ?> valueProvider, int rowIndex, int colIndex) {
return excludedColumns.contains(colIndex)?ResourceBundle.INSTANCE.importCss().getColumnExcluded():"";
}
});
}
@Override
protected Menu createContextMenu(final int colIndex) {
Menu menu = new Menu();
CheckMenuItem includeMenu = new CheckMenuItem("Include");
includeMenu.setGroup("include");
includeMenu.setChecked(!excludedColumns.contains(colIndex));
menu.add(includeMenu);
includeMenu.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
excludedColumns.remove(new Integer(colIndex));
refresh(false);
}
});
CheckMenuItem excludeMenu = new CheckMenuItem("Exclude");
excludeMenu.setGroup("include");
excludeMenu.setChecked(excludedColumns.contains(colIndex));
menu.add(excludeMenu);
excludeMenu.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
excludedColumns.add(colIndex);
refresh(false);
}
});
return menu;
}
/**
* Returns the excluded columns by index.
* @return an {@link ArrayList} of excluded column index.
*/
public ArrayList<Integer> getExcludedColumns() {
return excludedColumns;
}
}

View File

@ -0,0 +1,27 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.csvgrid;
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVData;
import org.gcube.portlets.user.csvimportwizardtd.client.data.CSVRow;
import com.sencha.gxt.data.shared.loader.DataReader;
import com.sencha.gxt.data.shared.loader.ListLoadResult;
import com.sencha.gxt.data.shared.loader.ListLoadResultBean;
/**
* @author "Federico De Faveri defaveri@isti.cnr.it"
*
*/
public class CSVJsonReader implements DataReader<ListLoadResult<CSVRow>, String> {
/**
* {@inheritDoc}
*/
@Override
public ListLoadResult<CSVRow> read(Object loadConfig, String json) {
CSVData data = CSVData.getCSVData(json);
return new ListLoadResultBean<CSVRow>(data.getRows());
}
}

View File

@ -0,0 +1,41 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.data;
import java.util.ArrayList;
import java.util.List;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
/**
* @author "Federico De Faveri defaveri@isti.cnr.it"
*
*/
public final class CSVData extends JavaScriptObject {
protected CSVData(){}
public static final native CSVData getCSVData(String json) /*-{
var data = eval('(' + json + ')');
return data;
}-*/;
public final List<CSVRow> getRows()
{
JsArray<CSVRow> jsRows = getJSRows();
List<CSVRow> rows = new ArrayList<CSVRow>(jsRows.length());
for (int i = 0; i < jsRows.length(); i++) {
rows.add(jsRows.get(i));
}
return rows;
}
protected final native JsArray<CSVRow> getJSRows() /*-{
return this['records'];
}-*/;
}

View File

@ -0,0 +1,33 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.data;
import com.google.gwt.core.client.JavaScriptObject;
/**
* @author "Federico De Faveri defaveri@isti.cnr.it"
*
*/
public final class CSVRow extends JavaScriptObject {
protected CSVRow(){}
/**
* @return the id
*/
public String getId() {
//FIXME
return getField("Id");
}
public native String getField(String column)
/*-{
return this[column];
}-*/;
}

View File

@ -0,0 +1,22 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.data;
import com.sencha.gxt.data.shared.ModelKeyProvider;
/**
* @author "Federico De Faveri defaveri@isti.cnr.it"
*
*/
public class CSVRowKeyProvider implements ModelKeyProvider<CSVRow> {
/**
* {@inheritDoc}
*/
@Override
public String getKey(CSVRow item) {
return item.getId();
}
}

View File

@ -0,0 +1,47 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.data;
import com.sencha.gxt.core.client.ValueProvider;
/**
* @author "Federico De Faveri defaveri@isti.cnr.it"
*
*/
public class CSVRowValueProvider implements ValueProvider<CSVRow, String> {
protected String column;
/**
* @param column
*/
public CSVRowValueProvider(String column) {
this.column = column;
}
/**
* {@inheritDoc}
*/
@Override
public String getValue(CSVRow row) {
return row.getField(column);
}
/**
* {@inheritDoc}
*/
@Override
public void setValue(CSVRow object, String value) {
}
/**
* {@inheritDoc}
*/
@Override
public String getPath() {
return column;
}
}

View File

@ -0,0 +1,39 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.dataresource;
import com.google.gwt.resources.client.CssResource;
/**
* @author Federico De Faveri defaveri@isti.cnr.it
*
*/
public interface CSVImportCSS extends CssResource {
@ClassName("wizard-title")
public String getWizardTitle();
@ClassName("wizard-footer")
public String getWizardFooter();
@ClassName("source-selection-hover")
public String getSourceSelectionHover();
@ClassName("column-excluded")
public String getColumnExcluded();
@ClassName("importSelection-sources")
public String getImportSelectionSources();
@ClassName("importSelection-source")
public String getImportSelectionSource();
@ClassName("sdmxRegistryUrlStyle")
public String getSDMXRegistryUrlStyle();
@ClassName("sdmxRegistryUrlInputStyle")
public String getSDMXRegistryUrlInputStyle();
}

View File

@ -0,0 +1,40 @@
package org.gcube.portlets.user.csvimportwizardtd.client.dataresource;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
public interface ResourceBundle extends ClientBundle {
public static final ResourceBundle INSTANCE=GWT.create(ResourceBundle.class);
@Source("resources/CSVImportWizardTD.css")
CSVImportCSS importCss();
@Source("resources/arrow-refresh.png")
ImageResource refresh();
@Source("resources/arrow-refresh_16.png")
ImageResource refresh_16();
@Source("resources/arrow-refresh_32.png")
ImageResource refresh32();
@Source("resources/accept.png")
ImageResource csvCheckSuccess();
@Source("resources/error.png")
ImageResource csvCheckFailure();
@Source("resources/loading.gif")
ImageResource loading();
@Source("resources/information.png")
ImageResource information();
}

View File

@ -0,0 +1,33 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.general;
import com.google.gwt.user.client.ui.HTML;
import com.sencha.gxt.widget.core.client.ContentPanel;
/**
* A simple wizard card.
* @author Federico De Faveri defaveri@isti.cnr.it
*/
public class SimpleWizardCard extends WizardCard {
/**
* Create a new simple wizard card.
* @param title the card title.
* @param footer the card footer.
* @param content the card content.
*/
public SimpleWizardCard(String title, String footer, String content) {
super(title, footer);
ContentPanel contentPanel = new ContentPanel();
contentPanel.setHeaderVisible(false);
HTML htmlContent = new HTML(content);
htmlContent.setStyleName("wizard-simple-content");
contentPanel.add(htmlContent);
setContent(contentPanel);
}
}

View File

@ -0,0 +1,273 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.general;
import org.gcube.portlets.user.csvimportwizardtd.client.dataresource.ResourceBundle;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.ui.HTML;
import com.sencha.gxt.widget.core.client.Component;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
/**
* Represents a Wizard Card.
* @author Federico De Faveri defaveri@isti.cnr.it
*/
public class WizardCard extends BorderLayoutContainer {
private WizardWindow wizardWindow;
protected ContentPanel titlePanel;
protected ContentPanel footerPanel;
protected boolean calculateFooter = false;
protected HTML titleHtml;
protected HTML footerHtml;
final protected ResourceBundle res=ResourceBundle.INSTANCE;
/**
* Creates a new wizard card.
* The footer is automatically calculated.
* @param title the card title.
*/
public WizardCard(String title) {
this(title,"");
calculateFooter = true;
}
/**
* Creates a new wizard card.
* @param title the card title.
* @param footer the card footer.
*/
public WizardCard(String title, String footer) {
Log.info(title);
res.importCss().ensureInjected();
//add the title panel
titlePanel = new ContentPanel();
titlePanel.setHeight(30);
titlePanel.setBodyStyle("background-color:#C3D9FF");
titlePanel.setHeaderVisible(false);
titleHtml = new HTML(title);
titleHtml.setStylePrimaryName(res.importCss().getWizardTitle());
titlePanel.add(titleHtml);
setNorthWidget(titlePanel, new BorderLayoutData(30));
//add the footer panel
footerPanel = new ContentPanel();
footerPanel.setHeight(30);
footerPanel.setBodyStyle("background-color:#CDEB8B");
footerPanel.setHeaderVisible(false);
footerHtml = new HTML(footer);
footerHtml.setStylePrimaryName(res.importCss().getWizardFooter());
footerPanel.add(footerHtml);
setSouthWidget(footerPanel, new BorderLayoutData(30));
}
/**
* {@inheritDoc}
*/
public void setTitle(String title)
{
titleHtml.setHTML("<h1>"+title+"</h1>");
}
/**
* Sets the card footer.
* @param footer the footer.
*/
public void setFooter(String footer)
{
footerHtml.setHTML("<p>"+footer+"</p>");
}
/**
* Sets the card content.
* @param content the card content.
*/
public void setContent(Component content)
{
setCenterWidget(content);
}
/**
* Sets the card content.
* @param content the card content.
*/
public void setContent(com.google.gwt.user.client.ui.Panel content)
{
setCenterWidget(content);
}
/**
* Enables the next button.
* @param enable <code>true</code> to enable it, <code>false</code> otherwise.
*/
public void setEnableNextButton(boolean enable)
{
if (wizardWindow!=null){
wizardWindow.setEnableNextButton(enable);
}
}
/**
* Enables the back button.
* @param enable <code>true</code> to enable the button, <code>false</code> otherwise.
*/
public void setEnableBackButton(boolean enable)
{
if (wizardWindow!=null){
wizardWindow.setEnableBackButton(enable);
}
}
/**
* Sets the next button label.
* @param text the button label.
*/
public void setNextButtonText(String text)
{
if (wizardWindow!=null){
wizardWindow.setNextButtonText(text);
}
}
/**
* Sets the back button label.
* @param text the button label.
*/
public void setBackButtonText(String text)
{
if (wizardWindow!=null){
wizardWindow.setBackButtonText(text);
}
}
/**
* Visible the next button.
* @param visible <code>true</code> to show the button, <code>false</code> otherwise.
*/
public void setNextButtonVisible(boolean visible)
{
if (wizardWindow!=null){
wizardWindow.setNextButtonVisible(visible);
}
}
/**
* Visible the back button.
* @param visible <code>true</code> to show the button, <code>false</code> otherwise.
*/
public void setBackButtonVisible(boolean visible)
{
if (wizardWindow!=null){
wizardWindow.setBackButtonVisible(visible);
}
}
public void setNextButtonToFinish()
{
if (wizardWindow!=null){
wizardWindow.setNextButtonToFinish();
}
}
/**
* Sets the WizardWindow for this import card.
* @param wizardWindow the WizardWindow.
*/
protected void setWizardWindow(WizardWindow wizardWindow)
{
this.wizardWindow = wizardWindow;
if (calculateFooter) {
StringBuilder footer = new StringBuilder();
footer.append("Step ");
footer.append(getCardPosition());
footer.append(" of ");
footer.append(getCardSize());
setFooter(footer.toString());
}
}
/**
* Returns the current wizard window.
* @return the wizard window.
*/
protected WizardWindow getWizardWindow()
{
if (wizardWindow==null) throw new IllegalStateException("No Wizard Window setup");
return wizardWindow;
}
public void addToWindowTitle(String toAdd)
{
wizardWindow.setTitle(wizardWindow.getOriginalTitle()+toAdd);
}
/**
* Called before the card is showed.
*/
public void setup()
{
}
/**
* Called when the card is disposed.
*/
public void dispose()
{}
/**
* Add a listener to the next button.
* @param listener the listener to add.
*/
public void addNextButtonListener(SelectHandler listener)
{
if (wizardWindow!=null){
wizardWindow.addNextButtonListener(listener);
}
}
/**
* Gets the number of cards in the wizard window.
* @return the number of cards.
*/
public int getCardSize()
{
return getWizardWindow().getCardStackSize();
}
/**
* Returns this card position on card list.
* @return the card position on the card stack.
*/
public int getCardPosition()
{
int indexPosition = getWizardWindow().getCardStack().indexOf(this);
return (indexPosition>=0)?indexPosition+1:indexPosition;
}
public void showErrorAndHide(String title, final String failureReason, final String failureDetails, final Throwable throwable)
{
wizardWindow.showErrorAndHide(title, failureReason, failureDetails, throwable);
}
public void hideWindow()
{
wizardWindow.hide();
}
}

View File

@ -0,0 +1,33 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.general;
import org.gcube.portlets.user.td.gxtservice.shared.TRId;
/**
* @author "Federico De Faveri defaveri@isti.cnr.it"
*
*/
public interface WizardListener {
/**
* Called when the wizard is completed without errors
*/
public void completed(TRId id);
/**
* Called when the wizard has been aborted by the user.
*/
public void aborted();
/**
* Called when the something in the wizard is failed.
* @param throwable the exception or <code>null</code>.
* @param reason the failure reason or <code>null</code>.
* @param details the failure details or <code>null</code>.
*/
public void failed(Throwable throwable, String reason, String details);
}

View File

@ -0,0 +1,445 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.general;
import java.util.ArrayList;
import org.gcube.portlets.user.csvimportwizardtd.client.util.ErrorMessageBox;
import org.gcube.portlets.user.td.gxtservice.shared.TRId;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.Callback;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Widget;
import com.google.web.bindery.event.shared.SimpleEventBus;
import com.sencha.gxt.core.client.resources.ThemeStyles;
import com.sencha.gxt.widget.core.client.Dialog;
import com.sencha.gxt.widget.core.client.Window;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.CardLayoutContainer;
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.toolbar.FillToolItem;
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
/**
* A generic Wizard Window.
* @author Federico De Faveri defaveri@isti.cnr.it
*/
public class WizardWindow extends Window {
protected ArrayList<WizardCard> cardStack = new ArrayList<WizardCard>();
protected TextButton backButton;
protected TextButton nextButton;
protected String originalTitle;
protected boolean checkBeforeClose = true;
protected boolean nextCardFinish = false;
protected Command nextButtonAction = null;
protected Command previousButtonAction = null;
protected CardLayoutContainer cardContainer;
protected ArrayList<WizardListener> listeners;
protected SimpleEventBus eventBus;
/**
* Create a new Wizard Window with the specified title.
* @param title the wizard window title.
*/
public WizardWindow(String title)
{
super();
this.eventBus= new SimpleEventBus();
Log.info(title);
//setModal(true);
setResizable(true);
setCollapsible(true);
listeners = new ArrayList<WizardListener>();
setHeadingText(title);
this.originalTitle = title;
VerticalLayoutContainer container = new VerticalLayoutContainer();
cardContainer = new CardLayoutContainer();
container.add(cardContainer, new VerticalLayoutData(1, 1));
ToolBar toolbar = new ToolBar();
toolbar.addStyleName(ThemeStyles.getStyle().borderTop());
backButton = new TextButton("Back");
backButton.setEnabled(false);
backButton.setTabIndex(1001);
toolbar.add(backButton);
toolbar.add(new FillToolItem());
nextButton = new TextButton("Next");
nextButton.setTabIndex(1000);
toolbar.add(nextButton);
toolbar.setLayoutData(new VerticalLayoutData(1, -1));
container.add(toolbar);
SelectHandler selectionHandler = new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
TextButton button = (TextButton)event.getSource();
String btnID = button.getId();
if (btnID.equals(backButton.getId())) {
if(previousButtonAction!=null) previousButtonAction.execute();
else previousCard();
} else {
if (nextButtonAction!=null) nextButtonAction.execute();
else nextCard();
}
}
};
backButton.addSelectHandler(selectionHandler);
nextButton.addSelectHandler(selectionHandler);
setWidget(container);
}
/**
* {@inheritDoc}
*/
@Override
protected void initTools() {
super.initTools();
//we can't distinguish between hide and hide with button
/*closeBtn.removeAllListeners();
closeBtn.addListener(Events.Select, new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent ce) {
MessageBox.confirm("Confirm", "Are you sure to cancel the operation?", new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
if (be.getButtonClicked().getItemId().equals(Dialog.YES)) {
hide();
fireAborted();
}
}
});
}
});*/
}
public void addListener(WizardListener listener)
{
listeners.add(listener);
}
public void removeListener(WizardListener listener)
{
listeners.remove(listener);
}
/**
* Shows the next available card.
*/
public void nextCard()
{
Widget activeItem = cardContainer.getActiveWidget();
if (activeItem instanceof WizardCard) ((WizardCard)activeItem).dispose();
int cardPos = cardStack.indexOf(activeItem);
//NEXT ->
nextButton.setEnabled(true);
backButton.setEnabled(true);
int newPos=cardPos+1;
if (newPos == 0) {
//we are moving forward from the first card
backButton.setEnabled(false);
}
nextButtonAction=null;
previousButtonAction=null;
Log.info("cardStack size:"+cardStack.size());
WizardCard card = cardStack.get(newPos);
cardContainer.setActiveWidget(card);
doLayout();
if (card instanceof WizardCard) ((WizardCard)card).setup();
}
/**
* Shows the previous available card.
*/
public void previousCard()
{
Widget activeItem = cardContainer.getActiveWidget();
if (activeItem instanceof WizardCard) ((WizardCard)activeItem).dispose();
int cardPos = cardStack.indexOf(activeItem);
//BACK <-
nextButton.setEnabled(true);
backButton.setEnabled(true);
int newPos=cardPos-1;
if (newPos == 0) {
backButton.setEnabled(false);
}
nextButtonAction=null;
previousButtonAction=null;
WizardCard card = cardStack.get(newPos);
cardContainer.setActiveWidget(card);
doLayout();
if (card instanceof WizardCard) ((WizardCard)card).setup();
}
/**
* Returns the number of available cards.
* @return
*/
public int getCardStackSize()
{
return cardStack.size();
}
/**
* Returns the current active card.
* @return
*/
public int getCurrentCard()
{
return cardStack.indexOf(cardContainer.getActiveWidget());
}
public boolean checkBeforeClose()
{
return true;
}
public void close(boolean check) {
checkBeforeClose = check;
hide();
}
/**
* Sets the label of next button to "Finish" value and add a close command to it.
*/
public void setNextButtonToFinish()
{
nextButton.setText("Finish");
nextButtonAction = new Command() {
public void execute() {
close(false);
}
};
}
/**
* Set the command for the next button.
* @param command the command to execute.
*/
public void setNextButtonCommand(Command command)
{
nextButtonAction = command;
}
/**
* Set the command for the previous button.
* @param command the command to execute.
*/
public void setPreviousButtonCommand(Command command)
{
previousButtonAction = command;
}
/**
* {@inheritDoc}
*/
@Override
public void show() {
super.show();
Widget activeItem = cardContainer.getActiveWidget();
if (activeItem instanceof WizardCard) ((WizardCard)activeItem).setup();
}
/**
* Set the card list.
* @param cards
*/
public void setCards(ArrayList<WizardCard> cards)
{
for (WizardCard card:cards) {
addCard(card);
}
}
/**
* Adds a card to this wizard.
* @param card the card to add.
*/
public void addCard(WizardCard card)
{
card.setWizardWindow(this);
cardContainer.add(card);
cardStack.add(card);
}
/**
* Remove a card to this wizard.
* @param card the card to add.
*/
public void removeCard(WizardCard card)
{
cardContainer.remove(card);
cardStack.remove(card);
}
/**
* Enables the next button on the wizard.
* @param enable <code>true</code> to enable the next button, <code>false</code> otherwise.
*/
public void setEnableNextButton(boolean enable)
{
nextButton.setEnabled(enable);
}
/**
* Enables the back button on the wizard.
* @param enable <code>true</code> to enable the back button, <code>false</code> otherwise.
*/
public void setEnableBackButton(boolean enable)
{
backButton.setEnabled(enable);
}
/**
* Sets the next button label.
* @param text the button label.
*/
protected void setNextButtonText(String text)
{
nextButton.setText(text);
}
/**
* Sets the back button label.
* @param text the button label.
*/
protected void setBackButtonText(String text)
{
backButton.setText(text);
}
/**
* Sets visible next button.
* @param visible
*/
protected void setNextButtonVisible(boolean visible)
{
nextButton.setVisible(visible);
}
/**
* Sets visible back button.
* @param visible
*/
protected void setBackButtonVisible(boolean visible)
{
backButton.setVisible(visible);
}
/**
* Add a listener to the next button.
* @param listener the listener to add.
*/
protected void addNextButtonListener(SelectHandler listener)
{
nextButton.addSelectHandler(listener);
}
/**
* @return the originalTitle
*/
public String getOriginalTitle() {
return originalTitle;
}
/**
* Returns the card list.
* @return teh card list.
*/
public ArrayList<WizardCard> getCardStack()
{
return cardStack;
}
public void showErrorAndHide(String title, final String failureReason, final String failureDetails, final Throwable throwable)
{
ErrorMessageBox.showError(title, failureReason, failureDetails, new Callback<Dialog, Void>() {
@Override
public void onSuccess(Dialog result) {
}
@Override
public void onFailure(Void reason) {
hide();
fireFailed(throwable, failureReason, failureDetails);
}
});
}
public void fireCompleted(TRId id)
{
for (WizardListener listener:listeners) listener.completed(id);
}
public void fireAborted()
{
for (WizardListener listener:listeners) listener.aborted();
}
public void fireFailed(Throwable throwable, String reason, String details)
{
for (WizardListener listener:listeners) listener.failed(throwable, reason, details);
}
}

View File

@ -0,0 +1,87 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.progress;
import org.gcube.portlets.user.td.gxtservice.shared.TRId;
import com.allen_sauer.gwt.log.client.Log;
import com.sencha.gxt.widget.core.client.ProgressBar;
/**
* Updates a {@link ProgressBar} progress and text based on {@link CSVImportProgressListener} events.
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CSVImportProgressBarUpdater implements CSVImportProgressListener {
protected ProgressBar progressBar;
//protected FramedPanel operationResult;
//protected WizardWindow wizardWindow;
/**
* Creates a new {@link ProgressBar} updater.
* @param progressBar the {@link ProgressBar} to update.
*/
public CSVImportProgressBarUpdater(ProgressBar progressBar) {
this.progressBar = progressBar;
//this.wizardWindow = w;
//this.operationResult = operationResult;
}
/**
* {@inheritDoc}
*/
@Override
public void operationComplete(TRId trId) {// TODO Auto-generated method stub
Log.info("Import complete");
progressBar.updateProgress(1, "Import complete.");
/*final FlexTable descriptionResult = new FlexTable();
descriptionResult.setCellSpacing(10);
descriptionResult.setCellPadding(4);
descriptionResult.setBorderWidth(0);
descriptionResult.setText(0, 0, "Result: ");
descriptionResult.setText(0, 1, "Import complete");
operationResult.add(descriptionResult);
operationResult.setVisible(true);
*/
//wizardWindow.setEnableNextButton(true);
}
/**
* {@inheritDoc}
*/
@Override
public void operationFailed(Throwable caught, String reason, String failureDetails) {
Log.info("Import failed");
progressBar.updateText("Import failed.");
}
@Override
public void operationInitializing() {
Log.info("Inport inizializing");
progressBar.updateProgress(0, "initializing...");
}
@Override
public void operationUpdate(float elaborated) {
Log.info("Import elaborated: "+elaborated);
if (elaborated == 0) progressBar.updateProgress(0, "initializing...");
if (elaborated>0 && elaborated<1) {
Log.trace("progress "+elaborated);
int elab=new Float(elaborated*100).intValue();
progressBar.updateProgress(elaborated,elab+"% importing...");
}
if (elaborated == 1) progressBar.updateProgress(1, "completing...");
}
}

View File

@ -0,0 +1,42 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.progress;
import org.gcube.portlets.user.td.gxtservice.shared.TRId;
/**
* Defines a listener for operation progress.
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface CSVImportProgressListener {
/**
* Called when the operation is starting.
*/
public void operationInitializing();
/**
* Called when there is a progress for the operation.
* @param elaborated the elaborated part.
*/
public void operationUpdate(float elaborated);
/**
* Called when the operation is complete.
*/
public void operationComplete(TRId trId);
/**
* Called when the operation is failed.
* @param caught the failure exception.
* @param reason the failure reason.
*/
public void operationFailed(Throwable caught, String reason, String failureDetails);
}

View File

@ -0,0 +1,124 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.progress;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gxtservice.client.rpc.TDGXTServiceAsync;
import org.gcube.portlets.user.td.gxtservice.shared.TRId;
import org.gcube.portlets.user.td.gxtservice.shared.csv.CSVImportMonitor;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* This {@link Timer} retrieves {@link OperationProgress} from the specified {@link OperationProgressSource} with the scheduled interval.
* The retrieved information are spread to the subscribed {@link CSVImportProgressListener}.
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CSVImportProgressUpdater extends Timer {
protected ArrayList<CSVImportProgressListener> listeners = new ArrayList<CSVImportProgressListener>();
/**
* {@inheritDoc}
*/
@Override
public void run() {
Log.debug("requesting operation progress");
TDGXTServiceAsync.INSTANCE.getCSVImportMonitor(new AsyncCallback<CSVImportMonitor>() {
@Override
public void onFailure(Throwable caught) {
cancel();
Log.error("Error retrieving the operation state", caught);
String message = getStack(caught);
fireOperationFailed(caught, "Failed getting operation updates", message);
}
@Override
public void onSuccess(CSVImportMonitor result) {
Log.info("retrieved CSVImportMonitor: "+result.getState());
switch (result.getState()) {
case INPROGRESS:
fireOperationUpdate(result.getElaboratedLenght());
break;
case FAILED:
cancel();
fireOperationFailed(new Throwable("Failed Client Library Import") ,result.getFailureReason(), result.getFailureDetails());
break;
case COMPLETED:
cancel();
//Log.info("Import fisnish TableId :"+result.getTrId());
//fireOperationComplete(result.getTrId());
break;
default:
break;
}
}
});
}
protected String getStack(Throwable e)
{
String message = e.getLocalizedMessage()+" -> <br>";
Throwable c = e.getCause();
if (c!=null) message += getStack(c);
return message;
}
protected void fireOperationInitializing()
{
for (CSVImportProgressListener listener:listeners) listener.operationInitializing();
}
protected void fireOperationUpdate(float elaborated)
{
for (CSVImportProgressListener listener:listeners) listener.operationUpdate(elaborated);
}
protected void fireOperationComplete(TRId trId)
{
for (CSVImportProgressListener listener:listeners) listener.operationComplete(trId);
}
protected void fireOperationFailed(Throwable caught, String failure, String failureDetails)
{
for (CSVImportProgressListener listener:listeners) listener.operationFailed(caught, failure, failureDetails);
}
/**
* Add a new {@link CSVImportProgressListener} to this {@link CSVImportProgressUpdater}.
* @param listener the listener to add.
*/
public void addListener(CSVImportProgressListener listener)
{
listeners.add(listener);
}
/**
* Removes the specified {@link CSVImportProgressListener} from this {@link CSVImportProgressUpdater}.
* @param listener the listener to remove.
*/
public void removeListener(CSVImportProgressListener listener)
{
listeners.remove(listener);
}
}

View File

@ -0,0 +1,82 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.progress;
import com.allen_sauer.gwt.log.client.Log;
import com.sencha.gxt.widget.core.client.ProgressBar;
/**
* Updates a {@link ProgressBar} progress and text based on {@link CSVImportProgressListener} events.
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class FileUploadProgressBarUpdater implements FileUploadProgressListener {
protected ProgressBar progressBar;
/**
* Creates a new {@link ProgressBar} updater.
* @param progressBar the {@link ProgressBar} to update.
*/
public FileUploadProgressBarUpdater(ProgressBar progressBar) {
this.progressBar = progressBar;
//this.wizardWindow = w;
//this.operationResult = operationResult;
}
/**
* {@inheritDoc}
*/
@Override
public void operationComplete() {// TODO Auto-generated method stub
Log.info("File upload complete");
progressBar.updateProgress(1, "File upload complete.");
/*final FlexTable descriptionResult = new FlexTable();
descriptionResult.setCellSpacing(10);
descriptionResult.setCellPadding(4);
descriptionResult.setBorderWidth(0);
descriptionResult.setText(0, 0, "Result: ");
descriptionResult.setText(0, 1, "Import complete");
operationResult.add(descriptionResult);
operationResult.setVisible(true);
*/
//wizardWindow.setEnableNextButton(true);
}
/**
* {@inheritDoc}
*/
@Override
public void operationFailed(Throwable caught, String reason, String failureDetails) {
Log.info("File upload failed");
progressBar.updateText("File upload failed.");
}
@Override
public void operationInitializing() {
Log.info("File upload inizializing");
progressBar.updateProgress(0, "initializing...");
}
@Override
public void operationUpdate(float elaborated) {
Log.info("File upload elaborated: "+elaborated);
if (elaborated == 0) progressBar.updateProgress(0, "initializing...");
if (elaborated>0 && elaborated<1) {
Log.trace("progress "+elaborated);
int elab=new Float(elaborated*100).intValue();
progressBar.updateProgress(elaborated,elab+"% uploading...");
}
if (elaborated == 1) progressBar.updateProgress(1, "completing...");
}
}

View File

@ -0,0 +1,48 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.progress;
import com.allen_sauer.gwt.log.client.Log;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class FileUploadProgressCardUpdater implements FileUploadProgressListener {
/**
*
*/
public FileUploadProgressCardUpdater() {
}
@Override
public void operationComplete() {
Log.info("File upload complete");
}
/**
* {@inheritDoc}
*/
@Override
public void operationFailed(Throwable caught, String reason, String failureDetails) {
Log.info("File upload failed");
}
@Override
public void operationInitializing() {
Log.info("File upload inizializing");
}
@Override
public void operationUpdate(float elaborated) {
Log.info("File uploading: "+elaborated);
}
}

View File

@ -0,0 +1,41 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.progress;
/**
* Defines a listener for operation progress.
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface FileUploadProgressListener {
/**
* Called when the operation is starting.
*/
public void operationInitializing();
/**
* Called when there is a progress for the operation.
* @param elaborated the elaborated part.
*/
public void operationUpdate(float elaborated);
/**
* Called when the operation is complete.
*/
public void operationComplete();
/**
* Called when the operation is failed.
* @param caught the failure exception.
* @param reason the failure reason.
*/
public void operationFailed(Throwable caught, String reason, String failureDetails);
}

View File

@ -0,0 +1,125 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.progress;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gxtservice.client.rpc.TDGXTServiceAsync;
import org.gcube.portlets.user.td.gxtservice.shared.file.FileUploadMonitor;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* This {@link Timer} retrieves {@link OperationProgress} from the specified {@link OperationProgressSource} with the scheduled interval.
* The retrieved information are spread to the subscribed {@link CSVImportProgressListener}.
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class FileUploadProgressUpdater extends Timer {
protected ArrayList<FileUploadProgressListener> listeners = new ArrayList<FileUploadProgressListener>();
/**
* {@inheritDoc}
*/
@Override
public void run() {
Log.debug("requesting operation progress");
TDGXTServiceAsync.INSTANCE.getFileUploadMonitor(new AsyncCallback<FileUploadMonitor>() {
@Override
public void onFailure(Throwable caught) {
cancel();
Log.error("Error retrieving the operation state", caught);
String message = getStack(caught);
fireOperationFailed(caught, "Failed getting operation updates", message);
}
@Override
public void onSuccess(FileUploadMonitor result) {
Log.info("retrieved FileUploadMonitor: "+result.getState());
switch (result.getState()) {
case STARTED:
Log.info("File Upload Started");
break;
case INPROGRESS:
fireOperationUpdate(result.getElaboratedLenght());
break;
case FAILED:
cancel();
fireOperationFailed(new Throwable("Failed Client Library Import") ,result.getFailureReason(), result.getFailureDetails());
break;
case COMPLETED:
cancel();
Log.info("File Upload Completed");
fireOperationComplete();
break;
default:
break;
}
}
});
}
protected String getStack(Throwable e)
{
String message = e.getLocalizedMessage()+" -> <br>";
Throwable c = e.getCause();
if (c!=null) message += getStack(c);
return message;
}
protected void fireOperationInitializing()
{
for (FileUploadProgressListener listener:listeners) listener.operationInitializing();
}
protected void fireOperationUpdate(float elaborated)
{
for (FileUploadProgressListener listener:listeners) listener.operationUpdate(elaborated);
}
protected void fireOperationComplete()
{
for (FileUploadProgressListener listener:listeners) listener.operationComplete();
}
protected void fireOperationFailed(Throwable caught, String failure, String failureDetails)
{
for (FileUploadProgressListener listener:listeners) listener.operationFailed(caught, failure, failureDetails);
}
/**
* Add a new {@link CSVImportProgressListener} to this {@link FileUploadProgressUpdater}.
* @param listener the listener to add.
*/
public void addListener(FileUploadProgressListener listener)
{
listeners.add(listener);
}
/**
* Removes the specified {@link CSVImportProgressListener} from this {@link FileUploadProgressUpdater}.
* @param listener the listener to remove.
*/
public void removeListener(FileUploadProgressListener listener)
{
listeners.remove(listener);
}
}

View File

@ -0,0 +1,72 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.util;
import com.google.gwt.core.client.Callback;
import com.google.gwt.user.client.ui.Label;
import com.sencha.gxt.widget.core.client.Dialog;
import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
import com.sencha.gxt.widget.core.client.box.MessageBox;
import com.sencha.gxt.widget.core.client.event.HideEvent;
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ErrorMessageBox {
private static final String DETAILS = "Details";
public static void showError(String title, String failureReason, final String failureDetails)
{
showError(title, failureReason, failureDetails, new NOPCallBack<Dialog, Void>());
}
public static void showError(String title, String failureReason, final String failureDetails, final Callback<Dialog, Void> callback)
{
final MessageBox box = new MessageBox(title);
box.setMessage(failureReason);
box.addHideHandler(new HideHandler() {
@Override
public void onHide(HideEvent event) {
Dialog dialog = (Dialog) event.getSource();
if (dialog.getHideButton().getText().equals(DETAILS)){
//box.close();
showErrorDetails("Error details", failureDetails);
} else callback.onSuccess(dialog);
}
});
/*FIXME box.setIcon(MessageBox.ERROR);
box.getDialog().cancelText = DETAILS;
box.getDialog().setButtons(MessageBox.OKCANCEL);*/
box.show();
}
public static void showErrorDetails(String title, String failureDetails)
{
final Dialog simple = new Dialog();
simple.setHeadingText(title);
simple.setPredefinedButtons(PredefinedButton.OK);
simple.setBodyStyleName("pad-text");
simple.add(new Label("<PRE>"+failureDetails+"</PRE>"));
//simple.getItem(0).getFocusSupport().setIgnore(true);
//FIXME simple.setScrollMode(ScrollMode.AUTO);
simple.setHideOnButtonClick(true);
simple.setWidth(400);
simple.setHeight(400);
simple.show();
}
}

View File

@ -0,0 +1,35 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.util;
/**
* @author Federico De Faveri defaveri@isti.cnr.it
*
*/
public class Format {
/**
* Converts a file size into a {@link String} representation adding the misure unit.
* @param size the file size.
* @return the textual representation.
*/
public static String fileSize(long size) {
StringBuilder text = new StringBuilder();
if (size < 1024) {
text.append(size);
text.append(" bytes");
} else if (size < 1048576) {
text.append(Math.round(((size * 10) / 1024)) / 10);
text.append(" KB");
} else if (size < 1073741824) {
text.append(Math.round(((size * 10) / 1048576)) / 10);
text.append(" MB");
} else {
text.append(Math.round(((size * 10) / 1073741824)) / 10);
text.append(" GB");
}
return text.toString();
}
}

View File

@ -0,0 +1,20 @@
/**
*
*/
package org.gcube.portlets.user.csvimportwizardtd.client.util;
import com.google.gwt.core.client.Callback;
/**
* @author "Federico De Faveri defaveri@isti.cnr.it"
*
*/
public class NOPCallBack<T,F> implements Callback<T, F> {
@Override
public void onFailure(F reason) {}
@Override
public void onSuccess(T result) {}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='CSVImportWizardTD'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- We need the JUnit module in the main module, -->
<!-- otherwise eclipse complains (Google plugin bug?) -->
<inherits name='com.google.gwt.junit.JUnit' />
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<inherits name='com.sencha.gxt.ui.GXT' />
<inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" />
<inherits name='org.gcube.portlets.user.td.gxtservice.GXTService' />
<!-- Specify the app entry point class. -->
<!-- <entry-point class='org.gcube.portlets.user.SDMXImportWizardTD.client.SDMXImportWizardTDEntry' /> -->
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
<!-- <source path='org.gcube.data.analysis.tabulardata.operation.worker'/> -->
</module>

View File

@ -0,0 +1,2 @@
sendButton = Send
nameField = Enter your name

View File

@ -0,0 +1,2 @@
sendButton = Envoyer
nameField = Entrez votre nom

View File

@ -0,0 +1,54 @@
@CHARSET "UTF-8";
.wizard-title {
padding: 5px;
font-weight: bold;
font-size: small;
background-color: #C3D9FF;
}
.wizard-footer {
padding: 5px;
font-weight: bold;
font-size: small;
text-align: right;
background-color: #CDEB8B
}
.source-selection-hover:hover {
cursor: pointer;
}
.column-excluded {
background-color: #e6e0da !important;
color: #bfa698;
}
.importSelection-sources {
padding: 30px;
display: block;
margin-top: 20px;
}
.importSelection-source {
padding-bottom: 20px;
}
.sdmxRegistryUrlStyle {
padding-top:5px;
}
.sdmxRegistryUrlInputStyle {
width:300px!important;
}
input#sdmxRegistryUrlInputFieldId-input {
width:300px!important;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 984 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 572 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 701 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

View File

@ -0,0 +1,34 @@
/** Add css rules here for your application. */
/** Example rules used by the template application (remove for your app) */
h1 {
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
}
.sendButton {
display: block;
font-size: 16pt;
}
/** Most GWT widgets already have a style name defined */
.gwt-DialogBox {
width: 400px;
}
.dialogVPanel {
margin: 5px;
}
.serverResponseLabelError {
color: red;
}
/** Set ids using widget.getElement().setId("idOfElement") */
#closeButton {
margin: 15px 6px 6px;
}

View File

@ -0,0 +1,63 @@
<!doctype html>
<!-- The DOCTYPE declaration above will set the -->
<!-- browser's rendering engine into -->
<!-- "Standards Mode". Replacing this declaration -->
<!-- with a "Quirks Mode" doctype may lead to some -->
<!-- differences in layout. -->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- -->
<!-- Consider inlining CSS to reduce the number of requested files -->
<!-- -->
<link type="text/css" rel="stylesheet" href="SDMXImportWizardTD.css">
<!-- -->
<!-- Any title is fine -->
<!-- -->
<title>Web Application Starter Project</title>
<!-- -->
<!-- This script loads your compiled module. -->
<!-- If you add any GWT meta tags, they must -->
<!-- be added before this line. -->
<!-- -->
<script type="text/javascript" language="javascript" src="SDMXImportWizardTD/SDMXImportWizardTD.nocache.js"></script>
</head>
<!-- -->
<!-- The body can have arbitrary html, or -->
<!-- you can leave the body empty if you want -->
<!-- to create a completely dynamic UI. -->
<!-- -->
<body>
<!-- OPTIONAL: include this if you want history support -->
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
<!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>
<h1>Web Application Starter Project</h1>
<table align="center">
<tr>
<td colspan="2" style="font-weight:bold;">Please enter your name:</td>
</tr>
<tr>
<td id="nameFieldContainer"></td>
<td id="sendButtonContainer"></td>
</tr>
<tr>
<td colspan="2" style="color:red;" id="errorLabelContainer"></td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Servlets -->
<servlet>
<servlet-name>jUnitHostImpl</servlet-name>
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
</servlet>
<!-- Servlets Mapping -->
<servlet-mapping>
<servlet-name>jUnitHostImpl</servlet-name>
<url-pattern>CSVImportWizardTDManagerWidgets/junithost/*</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>CSVImportWizardTD.html</welcome-file>
</welcome-file-list>
</web-app>

View File

@ -0,0 +1,83 @@
package org.gcube.portlets.user.csvimportwizardtd.client;
import java.util.List;
import org.gcube.portlets.user.td.gxtservice.client.rpc.TDGXTService;
import org.gcube.portlets.user.td.gxtservice.client.rpc.TDGXTServiceAsync;
import org.gcube.portlets.user.td.gxtservice.shared.TabResource;
import com.google.gwt.core.client.GWT;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
/**
* GWT JUnit <b>integration</b> tests must extend GWTTestCase.
* Using <code>"GwtTest*"</code> naming pattern exclude them from running with
* surefire during the test phase.
*
* If you run the tests using the Maven command line, you will have to
* navigate with your browser to a specific url given by Maven.
* See http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html
* for details.
*/
public class GwtTestCSVImportWizardTD extends GWTTestCase {
/**
* Must refer to a valid module that sources this class.
*/
public String getModuleName() {
return "org.gcube.portlets.user.csvimportWizard.CSVImportWizardTDJUnit";
}
/**
* This test will send a request to the server
*/
public void testResource() {
// Create the service that we will test.
TDGXTServiceAsync tdGXTService = GWT.create(TDGXTService.class);
ServiceDefTarget target = (ServiceDefTarget) tdGXTService;
System.out.println(GWT.getModuleBaseURL() + "TDGXTService");
target.setServiceEntryPoint(GWT.getModuleBaseURL() + "TDGXTService");
// Since RPC calls are asynchronous, we will need to wait for a response
// after this test method returns. This line tells the test runner to wait
// up to 7 seconds before timing out.
delayTestFinish(7000);
// Send a request to the server.
tdGXTService.getTabularResources(new AsyncCallback<List<TabResource>>() {
@Override
public void onFailure(Throwable caught) {
// The request resulted in an unexpected error.
fail("Request failure: " + caught.getMessage());
}
@Override
public void onSuccess(List<TabResource> result) {
// Shows the first three resources.
int i=0;
for(TabResource tr:result){
i++;
System.out.println(tr.toString());
if(i>3){
break;
}
}
assertTrue(result.size()>0);
// Now that we have received a response, we need to tell the test runner
// that the test is complete. You must call finishTest() after an
// asynchronous test finishes successfully, or the test will time out.
finishTest();
}
});
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to="CSVImportWizardTDJUnit">
<!-- Inherit our applications main module. -->
<inherits name='org.gcube.portlets.user.td.gxtservice.GXTService' />
<!-- Specify the path to any remote services. -->
<servlet path="/TDGXTService"
class="org.gcube.portlets.user.td.gxtservice.server.TDGXTServiceImpl" />
<!-- Specify the paths for translatable code -->
<source path='client' />
</module>

0
templates/INSTALL Normal file
View File

6
templates/LICENSE Normal file
View File

@ -0,0 +1,6 @@
gCube System - License
------------------------------------------------------------
The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
The software and documentation is provided by its authors/distributors "as is" and no expressed or
implied warranty is given for its use, quality or fitness for a particular case.

1
templates/MAINTAINERS Normal file
View File

@ -0,0 +1 @@
Giancarlo Panichi (giancarlo.panichi@isti.cnr.it), CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"

40
templates/README Normal file
View File

@ -0,0 +1,40 @@
The gCube System - ${name}
------------------------------------------------------------
This work has been supported by the following European projects: iMarine (FP7-INFRASTRUCTURES-2011-2)
Authors
-------
Giancarlo Panichi (giancarlo.panichi@isti.cnr.it), CNR Pisa,
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"
Version and Release Date
------------------------
v. ${version} (${release.date})
Description
-----------
${project.description}
Download information
--------------------
Source code URL: ${scm.url}
Documentation
-------------
${project.description}
Licensing
---------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

6
templates/changelog.xml Normal file
View File

@ -0,0 +1,6 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-user.CSVImportWizardTD.1-0-0"
date="2013-10-18">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

39
templates/descriptor.xml Normal file
View File

@ -0,0 +1,39 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>INSTALL</include>
<include>MAINTAINERS</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/svnpath.txt</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
<file>
<source>${configDirectory}/profile.xml</source>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>target/${build.finalName}.${packaging}</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

29
templates/profile.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource>
<ID></ID>
<Type>Service</Type>
<Profile>
<Description>${project.description}</Description>
<Class>PortletsUser</Class>
<Name>${project.name}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>${project.description}</Description>
<Name>${project.name}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</MavenCoordinates>
<Type>library</Type>
<Files>
<File>${project.build.finalName}.${project.packaging}</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

1
templates/svnpath.txt Normal file
View File

@ -0,0 +1 @@
${scm.url}