public void doCheckout()

in plugin/src/com/microsoft/alm/plugin/idea/tfvc/ui/checkout/TfvcCheckoutModel.java [62:175]


    public void doCheckout(
            Project project,
            CheckoutProvider.Listener listener,
            ServerContext context,
            VirtualFile destinationParent,
            String directoryName,
            String parentDirectory,
            boolean isAdvancedChecked,
            boolean isTfvcServerCheckout) {
        final String workspaceName = directoryName;
        final String teamProjectName = getRepositoryName(context);
        final String localPath = Path.combine(parentDirectory, directoryName);
        Workspace.Location workspaceKind = isTfvcServerCheckout ? Workspace.Location.SERVER : Workspace.Location.LOCAL;
        final AtomicBoolean checkoutResult = new AtomicBoolean();
        (new Task.Backgroundable(project,
                TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_TFVC_CREATING_WORKSPACE),
                true, PerformInBackgroundOption.DEAF) {
            public void run(@NotNull final ProgressIndicator indicator) {
                IdeaHelper.setProgress(indicator, 0.10, TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_TFVC_PROGRESS_CREATING));

                // Create the workspace with default values
                final CreateWorkspaceCommand command = new CreateWorkspaceCommand(
                        context,
                        workspaceName,
                        TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_TFVC_WORKSPACE_COMMENT),
                        null,
                        null,
                        workspaceKind);
                try {
                    EULADialog.executeWithGuard(project, command::runSynchronously);
                } catch (final WorkspaceAlreadyExistsException e) {
                    logger.warn("Error creating workspace: " + LocalizationServiceImpl.getInstance().getExceptionMessage(e));
                    // TODO: allow user to change name in the flow instead of starting over
                    IdeaHelper.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            Messages.showErrorDialog(project, LocalizationServiceImpl.getInstance().getExceptionMessage(e), TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_TFVC_FAILED_TITLE));
                        }
                    });

                    // returning since the workspace failed to create so we can't proceed with the next steps
                    return;
                }

                IdeaHelper.setProgress(indicator, 0.20, TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_TFVC_PROGRESS_ADD_ROOT));

                // Map the project root to the local folder
                final String serverPath = VcsHelper.TFVC_ROOT + teamProjectName;
                try {
                    final UpdateWorkspaceMappingCommand mappingCommand = new UpdateWorkspaceMappingCommand(context, workspaceName,
                            new Workspace.Mapping(serverPath, localPath, false), false);
                    mappingCommand.runSynchronously();
                } catch (final RuntimeException e) {
                    logger.warn("Error while mapping workspace during creation", e);
                    IdeaHelper.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            Messages.showErrorDialog(project, LocalizationServiceImpl.getInstance().getExceptionMessage(e), TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_TFVC_FAILED_TITLE));
                        }
                    });

                    // mapping failed so delete the workspace to clean up and return
                    final DeleteWorkspaceCommand deleteWorkspaceCommand = new DeleteWorkspaceCommand(context, workspaceName);
                    deleteWorkspaceCommand.runSynchronously();
                    return;
                }

                IdeaHelper.setProgress(indicator, 0.30, TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_TFVC_PROGRESS_CREATE_FOLDER));

                // Ensure that the local folder exists
                final File file = new File(localPath);
                if (!file.mkdirs()) {
                    //TODO should we throw here?
                }

                // if advanced is set, then sync just some of the files (those that we need for IntelliJ)
                // Otherwise, sync all the files for the team project
                if (!isAdvancedChecked) {
                    IdeaHelper.setProgress(indicator, 0.50, TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_TFVC_PROGRESS_SYNC));
                    // Sync all files recursively
                    CommandUtils.syncWorkspace(context, localPath);
                }

                IdeaHelper.setProgress(indicator, 1.00, "", true);

                // No exception means that it was successful
                checkoutResult.set(true);
            }

            public void onSuccess() {
                if (checkoutResult.get()) {
                    // Check the isAdvanced flag
                    if (isAdvancedChecked) {
                        // The user wants to edit the workspace before syncing...
                        final RepositoryContext repositoryContext = RepositoryContext.createTfvcContext(localPath, workspaceName, teamProjectName, context.getServerUri());
                        final WorkspaceController controller = new WorkspaceController(project, repositoryContext, context, workspaceName);
                        if (controller.showModalDialog(false)) {
                            // Save and Sync the workspace (this will be backgrounded)
                            controller.saveWorkspace(localPath, true, new Runnable() {
                                @Override
                                public void run() {
                                    // Files are all synchronized, so trigger the VCS update
                                    UpdateVersionControlSystem(project, parentDirectory, directoryName, destinationParent, listener);
                                }
                            });
                        }
                    } else {
                        // We don't have to wait for the workspace to be updated, so just trigger the VCS update
                        UpdateVersionControlSystem(project, parentDirectory, directoryName, destinationParent, listener);
                    }
                }
            }
        }).queue();
    }