}
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 );
VerticalPanel panel = new VerticalPanel();
uploadFormPanel.setWidget( panel );
final FileUpload upload = new FileUpload();
upload.setName( HTMLFileManagerFields.CLASSIC_DRL_IMPORT );
panel.add( upload );
HorizontalPanel hp = new HorizontalPanel();
Button create = new Button( constants.Import() );
ClickHandler okClickHandler = new ClickHandler() {
public void onClick(ClickEvent arg0) {
if ( Window.confirm( constants.ImportMergeWarning() ) ) {
uploadFormPanel.submit();
}
}
};
create.addClickHandler(okClickHandler);
hp.add(create);
Button cancel = new Button( constants.Cancel() );
cancel.addClickHandler( new ClickHandler() {
public void onClick(ClickEvent arg0) {
parent.hide();
}
} );
hp.add(cancel);
panel.add( hp );
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 ) {
LoadingPopup.close();
packageNamePopup.show();
} else {
ErrorPopup.showMessage( Format.format( constants.UnableToImportIntoThePackage0(),
event.getResults() ) );
}
LoadingPopup.close();
}
} );
uploadFormPanel.addSubmitHandler( new SubmitHandler() {
public void onSubmit(SubmitEvent event) {
if ( upload.getFilename().length() == 0 ) {
LoadingPopup.close();
Window.alert( constants.YouDidNotChooseADrlFileToImport() );
event.cancel();
} else if ( !upload.getFilename().endsWith( ".drl" ) ) { //NON-NLS
LoadingPopup.close();
Window.alert( constants.YouCanOnlyImportDrlFiles() );
event.cancel();
} else if ( packageName.getText() != null && !packageName.getText().equals( "" ) ) {
LoadingPopup.showMessage( constants.ImportingDRLPleaseWait() );
uploadFormPanel.setAction( uploadFormPanel.getAction() + "?packageName=" + packageName.getText() );
} else {
LoadingPopup.showMessage( constants.CreatingPackagePleaseWait() );
}
}
} );