performOperation( true );
}
}
protected void performOperation( boolean feedback ) {
final SolutionFolderActionEvent event = new SolutionFolderActionEvent();
event.setAction( this.getClass().getName() );
final TextBox folderNameTextBox = new TextBox();
folderNameTextBox.setTabIndex( 1 );
folderNameTextBox.setVisibleLength( 40 );
VerticalPanel vp = new VerticalPanel();
vp.add( new Label( Messages.getString( "newFolderName" ) ) ); //$NON-NLS-1$
vp.add( folderNameTextBox );
final PromptDialogBox newFolderDialog =
new PromptDialogBox(
Messages.getString( "newFolder" ), Messages.getString( "ok" ), Messages.getString( "cancel" ), false, true, vp ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
newFolderDialog.setFocusWidget( folderNameTextBox );
folderNameTextBox.setFocus( true );
final IDialogCallback callback = new IDialogCallback() {
public void cancelPressed() {
newFolderDialog.hide();
}
public void okPressed() {
if ( !NameUtils.isValidFolderName( folderNameTextBox.getText() ) ) {
event.setMessage( Messages.getString( "containsIllegalCharacters", folderNameTextBox.getText() ) );
EventBusUtil.EVENT_BUS.fireEvent( event );
return;
}
solutionPath = parentFolder.getPath() + "/" + URL.encodePathSegment( folderNameTextBox.getText() );
String createDirUrl = contextURL + "api/repo/dirs/" + SolutionBrowserPanel.pathToId( solutionPath ); //$NON-NLS-1$
RequestBuilder createDirRequestBuilder = new RequestBuilder( RequestBuilder.PUT, createDirUrl );
try {
createDirRequestBuilder.setHeader( "If-Modified-Since", "01 Jan 1970 00:00:00 GMT" );
createDirRequestBuilder.sendRequest( "", new RequestCallback() {
@Override
public void onError( Request createFolderRequest, Throwable exception ) {
MessageDialogBox dialogBox =
new MessageDialogBox(
Messages.getString( "error" ), Messages.getString( "couldNotCreateFolder", folderNameTextBox.getText() ), //$NON-NLS-1$ //$NON-NLS-2$
false, false, true );
dialogBox.center();
event.setMessage( Messages.getString( "couldNotCreateFolder", folderNameTextBox.getText() ) );
EventBusUtil.EVENT_BUS.fireEvent( event );
}
@Override
public void onResponseReceived( Request createFolderRequest, Response createFolderResponse ) {
if ( createFolderResponse.getStatusText().equalsIgnoreCase( "OK" ) ) { //$NON-NLS-1$
NewFolderCommand.this.callback.onHandle( solutionPath );
new RefreshRepositoryCommand().execute( false );
event.setMessage( "Success" );
FileChooserDialog.setIsDirty( Boolean.TRUE );
setBrowseRepoDirty( Boolean.TRUE );
EventBusUtil.EVENT_BUS.fireEvent( event );
} else {
event.setMessage(
StringUtils.isEmpty( createFolderResponse.getText() )
|| Messages.getString( createFolderResponse.getText() ) == null
? Messages.getString( "couldNotCreateFolder", folderNameTextBox.getText() ) //$NON-NLS-1$
: Messages.getString( createFolderResponse.getText(), folderNameTextBox.getText() )
);
EventBusUtil.EVENT_BUS.fireEvent( event );
}
}
} );
} catch ( RequestException e ) {
Window.alert( e.getLocalizedMessage() );
event.setMessage( e.getLocalizedMessage() );
EventBusUtil.EVENT_BUS.fireEvent( event );
}
}
};