uploadFormPanel.setMethod( FormPanel.METHOD_POST );
HorizontalPanel panel = new HorizontalPanel();
uploadFormPanel.setWidget( panel );
final FileUpload upload = new FileUpload();
upload.setName( HTMLFileManagerFields.CLASSIC_DRL_IMPORT );
panel.add( upload );
panel.add( new Label( constants.upload() ) );
ImageButton ok = new ImageButton( "images/upload.gif",
constants.Import() ); //NON-NLS
ClickListener okClickListener = new ClickListener() {
public void onClick(Widget sender) {
if ( Window.confirm( constants.ImportMergeWarning() ) ) {
LoadingPopup.showMessage( constants.ImportingDRLPleaseWait() );
uploadFormPanel.submit();
}
}
};
ok.addClickListener( okClickListener );
panel.add( ok );
final FormStylePopup packageNamePopup = new FormStylePopup( "images/package_large.png",
constants.PackageName() );
HorizontalPanel packageNamePanel = new HorizontalPanel();
packageNamePopup.addRow( new Label( constants.ImportedDRLContainsNoNameForThePackage() ) );
final TextBox packageName = new TextBox();
packageNamePanel.add( new Label( constants.PackageName() + ":" ) );
packageNamePanel.add( packageName );
Button uploadWithNameButton = new Button( constants.OK() );
uploadWithNameButton.addClickListener( okClickListener );
packageNamePanel.add( uploadWithNameButton );
packageNamePopup.addRow( packageNamePanel );
uploadFormPanel.addFormHandler( new FormHandler() {
public void onSubmitComplete(FormSubmitCompleteEvent event) {
if ( event.getResults().indexOf( "OK" ) > -1 ) { //NON-NLS
Window.alert( constants.PackageWasImportedSuccessfully() );
afterCreatedEvent.execute();
parent.hide();
if ( packageNamePopup != null ) {
packageNamePopup.hide();
}
} else if ( event.getResults().indexOf( "Missing package name." ) > -1 ) {
LoadingPopup.close();
packageNamePopup.show();
} else {
ErrorPopup.showMessage( Format.format( constants.UnableToImportIntoThePackage0(),
event.getResults() ) );
}
LoadingPopup.close();
}
public void onSubmit(FormSubmitEvent event) {
if ( upload.getFilename().length() == 0 ) {
Window.alert( constants.YouDidNotChooseADrlFileToImport() );
event.setCancelled( true );
} else if ( !upload.getFilename().endsWith( ".drl" ) ) { //NON-NLS
Window.alert( constants.YouCanOnlyImportDrlFiles() );
event.setCancelled( true );
} else if ( packageName.getText() != null && !packageName.getText().equals( "" ) ) {
uploadFormPanel.setAction( uploadFormPanel.getAction() + "?packageName=" + packageName.getText() );
}