}
public static Widget newImportWidget(final Command afterCreatedEvent,
final FormStylePopup parent) {
final FormPanel uploadFormPanel = new FormPanel();
uploadFormPanel.setAction( GWT.getModuleBaseURL() + "package" );
uploadFormPanel.setEncoding( FormPanel.ENCODING_MULTIPART );
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(),
constants.Import() );
ClickHandler okClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
if ( Window.confirm( constants.ImportMergeWarning() ) ) {
LoadingPopup.showMessage( constants.ImportingDRLPleaseWait() );
uploadFormPanel.submit();
}
}
};
ok.addClickHandler( okClickHandler );
panel.add( ok );
final FormStylePopup packageNamePopup = new FormStylePopup( images.packageLarge(),
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.addClickHandler( okClickHandler );
packageNamePanel.add( uploadWithNameButton );
packageNamePopup.addRow( packageNamePanel );
uploadFormPanel.addSubmitCompleteHandler( new SubmitCompleteHandler() {
public void onSubmitComplete(SubmitCompleteEvent event) {
if ( event.getResults().indexOf( "OK" ) > -1 ) { //NON-NLS
LoadingPopup.close();
Window.alert( constants.PackageWasImportedSuccessfully() );
afterCreatedEvent.execute();
parent.hide();
if ( packageNamePopup != null ) {
packageNamePopup.hide();
}
} else if ( event.getResults().indexOf( "Missing package name." ) > -1 ) { //NON-NLS
LoadingPopup.close();
packageNamePopup.show();
} else {
ErrorPopup.showMessage( constants.UnableToImportIntoThePackage0( event.getResults() ) );
}
LoadingPopup.close();
}
} );
uploadFormPanel.addSubmitHandler( new SubmitHandler() {
public void onSubmit(SubmitEvent event) {
if ( upload.getFilename().length() == 0 ) {
Window.alert( constants.YouDidNotChooseADrlFileToImport() );
event.cancel();
} else if ( !upload.getFilename().endsWith( ".drl" ) ) { //NON-NLS
Window.alert( constants.YouCanOnlyImportDrlFiles() );
event.cancel();
} else if ( packageName.getText() != null && !packageName.getText().equals( "" ) ) {
uploadFormPanel.setAction( uploadFormPanel.getAction() + "?packageName=" + packageName.getText() );
} else {
LoadingPopup.showMessage( constants.CreatingPackagePleaseWait() );
}
}
} );