public void createFolder() throws Exception {

    try {

      Collection<UIRepositoryDirectory> directories = folderTree.getSelectedItems();
      if ( directories == null || directories.size() == 0 ) {
        return;
      }
      UIRepositoryDirectory selectedFolder = directories.iterator().next();

      // First, ask for a name for the folder
      XulPromptBox prompt = promptForName( null );
      prompt.addDialogCallback( new XulDialogCallback<String>() {
        public void onClose( XulComponent component, Status status, String value ) {
          if ( status == Status.ACCEPT ) {
            newName = value;
          } else {
            newName = null;
          }
        }

        public void onError( XulComponent component, Throwable err ) {
          throw new RuntimeException( err );
        }
      } );

      prompt.open();

      if ( newName != null ) {
        if ( selectedFolder == null ) {
          selectedFolder = repositoryDirectory;
        }
        if ( newName.equals( "." ) || newName.equals( ".." ) ) {
          throw new Exception( BaseMessages.getString( PKG, "BrowserController.InvalidFolderName" ) );
        }
        //Do an explicit check here to see if the folder already exists in the ui
        //This is to prevent a double message being sent in case the folder does
        //not exist in the ui but does exist in the repo (PDI-5202)
        boolean folderExistsInUI = selectedFolder.contains( newName );
        if ( folderExistsInUI ) {
          throw new Exception(
            BaseMessages.getString(
              PKG,
              "BrowserController.DirAlreadyExistsInUI",
              newName
            )
          );
        }
        //PDI-5202
        String newNameInRepo = selectedFolder.checkDirNameExistsInRepo( newName );
        if ( newNameInRepo != null ) {
          messageBox.setTitle( BaseMessages.getString( PKG, "Dialog.Warning" ) );
          messageBox.setAcceptLabel( BaseMessages.getString( PKG, "Dialog.Ok" ) );
          messageBox.setMessage(
            BaseMessages.getString(
              PKG,
              "BrowserController.DirAlreadyExistsInRepository",
              newNameInRepo
            )
          );
          messageBox.open();
          newName = newNameInRepo;
        }
        UIRepositoryDirectory newDir = selectedFolder.createFolder( newName );
        dirMap.put( newDir.getObjectId(), newDir );

        directoryBinding.fireSourceChanged();
        selectedItemsBinding.fireSourceChanged();

        this.folderTree.setSelectedItems( Collections.singletonList( selectedFolder ) );

      }
      newName = null;
    } catch ( Exception e ) {
      if ( mainController == null || !mainController.handleLostRepository( e ) ) {
        confirm( BaseMessages.getString( PKG, "Dialog.Error" ), e.getLocalizedMessage() );
      }
    }
  }
@Test
  public void shouldNotCreateFolderOnCloseCreationDialog() throws Exception {
    XulPromptBox prompt = new XulPromptBoxMock( XulDialogCallback.Status.CANCEL );
    when( document.createElement( PROMPTBOX ) ).thenReturn( prompt );

    controller.createFolder();

    assertTrue( directoryMap.isEmpty() );
    verify( selectedFolder, never() ).createFolder( anyString() );
    verify( directoryBinding, never() ).fireSourceChanged();
    verify( selectedItemsBinding, never() ).fireSourceChanged();
  }