@Test public void shouldCreateFolderOnAcceptCreationDialog() throws Exception { XulPromptBox prompt = new XulPromptBoxMock( XulDialogCallback.Status.ACCEPT ); when( document.createElement( PROMPTBOX ) ).thenReturn( prompt ); controller.createFolder(); assertFalse( directoryMap.isEmpty() ); verify( selectedFolder ).createFolder( anyString() ); verify( directoryBinding ).fireSourceChanged(); verify( selectedItemsBinding ).fireSourceChanged(); }
public void createFolder() throws Exception { try { Collection<UIRepositoryDirectory> directories = folderTree.getSelectedItems(); if ( directories == null || directories.size() == 0 ) { return; } UIRepositoryDirectory selectedFolder = directories.iterator().next(); 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; } boolean folderExistsInUI = selectedFolder.contains( newName ); if ( folderExistsInUI ) { throw new Exception( BaseMessages.getString( PKG, "BrowserController.DirAlreadyExistsInUI", newName ) ); } 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 ) ) { messageBox.setTitle( BaseMessages.getString( PKG, "Dialog.Error" ) ); messageBox.setAcceptLabel( BaseMessages.getString( PKG, "Dialog.Ok" ) ); messageBox.setMessage( BaseMessages.getString( PKG, e.getLocalizedMessage() ) ); messageBox.open(); } } }
BrowseController extends AbstractXulEventHandler implements IUISupportController, IBrowseController { public void createFolder() throws Exception { try { Collection<UIRepositoryDirectory> directories = folderTree.getSelectedItems(); if ( directories == null || directories.size() == 0 ) { return; } UIRepositoryDirectory selectedFolder = directories.iterator().next(); 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; } boolean folderExistsInUI = selectedFolder.contains( newName ); if ( folderExistsInUI ) { throw new Exception( BaseMessages.getString( PKG, "BrowserController.DirAlreadyExistsInUI", newName ) ); } 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 ) ) { messageBox.setTitle( BaseMessages.getString( PKG, "Dialog.Error" ) ); messageBox.setAcceptLabel( BaseMessages.getString( PKG, "Dialog.Ok" ) ); messageBox.setMessage( BaseMessages.getString( PKG, e.getLocalizedMessage() ) ); messageBox.open(); } } } }
BrowseController extends AbstractXulEventHandler implements IUISupportController, IBrowseController { public void createFolder() throws Exception { try { Collection<UIRepositoryDirectory> directories = folderTree.getSelectedItems(); if ( directories == null || directories.size() == 0 ) { return; } UIRepositoryDirectory selectedFolder = directories.iterator().next(); 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; } boolean folderExistsInUI = selectedFolder.contains( newName ); if ( folderExistsInUI ) { throw new Exception( BaseMessages.getString( PKG, "BrowserController.DirAlreadyExistsInUI", newName ) ); } 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 ) ) { messageBox.setTitle( BaseMessages.getString( PKG, "Dialog.Error" ) ); messageBox.setAcceptLabel( BaseMessages.getString( PKG, "Dialog.Ok" ) ); messageBox.setMessage( BaseMessages.getString( PKG, e.getLocalizedMessage() ) ); messageBox.open(); } } } BrowseController(); }
BrowseController extends AbstractXulEventHandler implements IUISupportController, IBrowseController { public void createFolder() throws Exception { try { Collection<UIRepositoryDirectory> directories = folderTree.getSelectedItems(); if ( directories == null || directories.size() == 0 ) { return; } UIRepositoryDirectory selectedFolder = directories.iterator().next(); 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; } boolean folderExistsInUI = selectedFolder.contains( newName ); if ( folderExistsInUI ) { throw new Exception( BaseMessages.getString( PKG, "BrowserController.DirAlreadyExistsInUI", newName ) ); } 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 ) ) { messageBox.setTitle( BaseMessages.getString( PKG, "Dialog.Error" ) ); messageBox.setAcceptLabel( BaseMessages.getString( PKG, "Dialog.Ok" ) ); messageBox.setMessage( BaseMessages.getString( PKG, e.getLocalizedMessage() ) ); messageBox.open(); } } } BrowseController(); @SuppressWarnings( "deprecation" ) void init( Repository repository ); String getName(); UIRepositoryDirectory getRepositoryDirectory(); void expandAllFolders(); void collapseAllFolders(); void openContent(); void openContent( Object[] items ); void renameContent(); void deleteContent(); void createFolder(); void exportFolder(); void deleteFolder(); void renameFolder(); void onDragFromGlobalTree( DropEvent event ); void onDragFromLocalTable( DropEvent event ); void onDrop( DropEvent event ); void onDoubleClick( Object[] selectedItems ); List<UIRepositoryDirectory> getSelectedFolderItems(); void setSelectedFolderItems( List<UIRepositoryDirectory> selectedFolderItems ); List<UIRepositoryObject> getSelectedFileItems(); void setSelectedFileItems( List<UIRepositoryObject> selectedFileItems ); Binding getSelectedItemsBinding(); void setSelectedItemsBinding( Binding selectedItemsBinding ); void setRepositoryObjects( List<UIRepositoryObject> selectedFileItems ); List<UIRepositoryObject> getRepositoryObjects(); void setRepositoryItems( List<UIRepositoryObject> selectedItems ); List<UIRepositoryObject> getRepositoryItems(); List<UIRepositoryDirectory> getRepositoryDirectories(); void setRepositoryDirectories( List<UIRepositoryDirectory> selectedFolderItems ); UIRepositoryObjects getSelectedRepoDirChildren(); void addContextChangeVetoer( ContextChangeVetoer listener ); void removeContextChangeVetoer( ContextChangeVetoer listener ); }
BrowseController extends AbstractXulEventHandler implements IUISupportController, IBrowseController { public void createFolder() throws Exception { try { Collection<UIRepositoryDirectory> directories = folderTree.getSelectedItems(); if ( directories == null || directories.size() == 0 ) { return; } UIRepositoryDirectory selectedFolder = directories.iterator().next(); 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; } boolean folderExistsInUI = selectedFolder.contains( newName ); if ( folderExistsInUI ) { throw new Exception( BaseMessages.getString( PKG, "BrowserController.DirAlreadyExistsInUI", newName ) ); } 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 ) ) { messageBox.setTitle( BaseMessages.getString( PKG, "Dialog.Error" ) ); messageBox.setAcceptLabel( BaseMessages.getString( PKG, "Dialog.Ok" ) ); messageBox.setMessage( BaseMessages.getString( PKG, e.getLocalizedMessage() ) ); messageBox.open(); } } } BrowseController(); @SuppressWarnings( "deprecation" ) void init( Repository repository ); String getName(); UIRepositoryDirectory getRepositoryDirectory(); void expandAllFolders(); void collapseAllFolders(); void openContent(); void openContent( Object[] items ); void renameContent(); void deleteContent(); void createFolder(); void exportFolder(); void deleteFolder(); void renameFolder(); void onDragFromGlobalTree( DropEvent event ); void onDragFromLocalTable( DropEvent event ); void onDrop( DropEvent event ); void onDoubleClick( Object[] selectedItems ); List<UIRepositoryDirectory> getSelectedFolderItems(); void setSelectedFolderItems( List<UIRepositoryDirectory> selectedFolderItems ); List<UIRepositoryObject> getSelectedFileItems(); void setSelectedFileItems( List<UIRepositoryObject> selectedFileItems ); Binding getSelectedItemsBinding(); void setSelectedItemsBinding( Binding selectedItemsBinding ); void setRepositoryObjects( List<UIRepositoryObject> selectedFileItems ); List<UIRepositoryObject> getRepositoryObjects(); void setRepositoryItems( List<UIRepositoryObject> selectedItems ); List<UIRepositoryObject> getRepositoryItems(); List<UIRepositoryDirectory> getRepositoryDirectories(); void setRepositoryDirectories( List<UIRepositoryDirectory> selectedFolderItems ); UIRepositoryObjects getSelectedRepoDirChildren(); void addContextChangeVetoer( ContextChangeVetoer listener ); void removeContextChangeVetoer( ContextChangeVetoer listener );  }