}
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.INSTANCE.upload() ) );
ImageButton ok = new ImageButton( DroolsGuvnorImages.INSTANCE.upload(),
Constants.INSTANCE.Import() );
ClickHandler okClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
if ( Window.confirm( Constants.INSTANCE.ImportMergeWarning() ) ) {
LoadingPopup.showMessage( Constants.INSTANCE.ImportingDRLPleaseWait() );
uploadFormPanel.submit();
}
}
};
ok.addClickHandler( okClickHandler );
panel.add( ok );
final FormStylePopup packageNamePopup = new FormStylePopup( DroolsGuvnorImages.INSTANCE.packageLarge(),
Constants.INSTANCE.PackageName() );
HorizontalPanel packageNamePanel = new HorizontalPanel();
packageNamePopup.addRow( new Label( Constants.INSTANCE.ImportedDRLContainsNoNameForThePackage() ) );
final TextBox packageName = new TextBox();
packageNamePanel.add( new Label( Constants.INSTANCE.PackageName() + ":" ) );
packageNamePanel.add( packageName );
Button uploadWithNameButton = new Button( Constants.INSTANCE.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.INSTANCE.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.INSTANCE.UnableToImportIntoThePackage0( event.getResults() ) );
}
LoadingPopup.close();
}
} );
uploadFormPanel.addSubmitHandler( new SubmitHandler() {
public void onSubmit(SubmitEvent event) {
if ( upload.getFilename().length() == 0 ) {
Window.alert( Constants.INSTANCE.YouDidNotChooseADrlFileToImport() );
event.cancel();
} else if ( !upload.getFilename().endsWith( ".drl" ) ) { //NON-NLS
Window.alert( Constants.INSTANCE.YouCanOnlyImportDrlFiles() );
event.cancel();
} else if ( packageName.getText() != null && !packageName.getText().equals( "" ) ) {
uploadFormPanel.setAction( uploadFormPanel.getAction() + "?packageName=" + packageName.getText() );
} else {
LoadingPopup.showMessage( Constants.INSTANCE.CreatingPackagePleaseWait() );
}
}
} );