uploadFormPanel.setMethod( FormPanel.METHOD_POST );
HorizontalPanel panel = new HorizontalPanel();
uploadFormPanel.setWidget( panel );
final FileUpload upload = new FileUpload();
upload.setName( HTMLFileManagerFields.FILE_UPLOAD_FIELD_NAME_IMPORT );
panel.add( upload );
panel.add( new Label( constants.Import() + ":" ) );
ImageButton ok = new ImageButton( "images/upload.gif" );
ok.addClickListener( new ClickListener() {
public void onClick(Widget sender) {
uploadFormPanel.setAction( GWT.getModuleBaseURL() + "backup?packageImport=true&importAsNew=" + !overWriteCheckBox.isChecked() );
doImportFile( uploadFormPanel );
}
private void doImportFile(final FormPanel uploadFormPanel) {
if ( (overWriteCheckBox.isChecked() && Window.confirm(constants.ImportPackageConfirm())) || !overWriteCheckBox.isChecked() ) {
LoadingPopup.showMessage(constants.ImportingPackage());
uploadFormPanel.submit();
}
}
} );
panel.add( ok );
uploadFormPanel.addFormHandler( new FormHandler() {
public void onSubmitComplete(FormSubmitCompleteEvent event) {
if ( event.getResults().indexOf( "OK" ) > -1 ) { //NON-NLS
Window.alert(constants.PackageImportDone());
} else {
ErrorPopup.showMessage(constants.PackageImportFailed());
}
LoadingPopup.close();
}
public void onSubmit(FormSubmitEvent event) {
if ( upload.getFilename().length() == 0 ) {
Window.alert(constants.PackageExportNoName());
event.setCancelled( true );
} else if ( !upload.getFilename().endsWith( ".xml" ) ) { //NON-NLS
Window.alert(constants.PackageExportName());
event.setCancelled( true );
}
}