2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.cvsSupport2
.checkout
;
18 import com
.intellij
.CvsBundle
;
19 import com
.intellij
.cvsSupport2
.config
.CvsApplicationLevelConfiguration
;
20 import com
.intellij
.cvsSupport2
.cvsBrowser
.CvsElement
;
21 import com
.intellij
.cvsSupport2
.cvsExecution
.CvsOperationExecutor
;
22 import com
.intellij
.cvsSupport2
.cvsExecution
.CvsOperationExecutorCallback
;
23 import com
.intellij
.cvsSupport2
.cvsExecution
.ModalityContext
;
24 import com
.intellij
.cvsSupport2
.cvshandlers
.CommandCvsHandler
;
25 import com
.intellij
.cvsSupport2
.cvshandlers
.CvsHandler
;
26 import com
.intellij
.cvsSupport2
.ui
.experts
.checkout
.CheckoutWizard
;
27 import com
.intellij
.openapi
.project
.Project
;
28 import com
.intellij
.openapi
.ui
.Messages
;
29 import com
.intellij
.openapi
.vcs
.CheckoutProvider
;
30 import com
.intellij
.openapi
.vcs
.VcsConfiguration
;
31 import com
.intellij
.openapi
.vfs
.VirtualFileManager
;
32 import org
.jetbrains
.annotations
.NotNull
;
36 public class CvsCheckoutProvider
implements CheckoutProvider
{
37 public void doCheckout(@NotNull final Project project
, final CheckoutProvider
.Listener listener
) {
39 final File checkoutDirectory
;
40 final CvsElement
[] selectedElements
;
42 CheckoutWizard checkoutWizard
= new CheckoutWizard(project
);
43 checkoutWizard
.show();
44 if (!checkoutWizard
.isOK()) return;
45 final boolean useAlternateCheckoutPath
= checkoutWizard
.useAlternativeCheckoutLocation();
46 checkoutDirectory
= checkoutWizard
.getCheckoutDirectory();
48 selectedElements
= checkoutWizard
.getSelectedElements();
49 final CvsHandler checkoutHandler
= CommandCvsHandler
.createCheckoutHandler(
50 checkoutWizard
.getSelectedConfiguration(),
51 collectCheckoutPaths(selectedElements
),
53 useAlternateCheckoutPath
,
54 CvsApplicationLevelConfiguration
.getInstance().MAKE_CHECKED_OUT_FILES_READONLY
, VcsConfiguration
.getInstance(project
).getCheckoutOption());
56 final CvsOperationExecutor executor
= new CvsOperationExecutor(null);
57 executor
.performActionSync(checkoutHandler
, new CvsOperationExecutorCallback() {
58 public void executionFinished(boolean successfully
) {
59 if (!executor
.hasNoErrors()) {
60 Messages
.showErrorDialog(CvsBundle
.message("message.error.checkout", executor
.getResult().composeError().getLocalizedMessage()),
61 CvsBundle
.message("operation.name.check.out.project"));
64 refreshAfterCheckout(listener
, selectedElements
, checkoutDirectory
, useAlternateCheckoutPath
);
66 public void executionFinishedSuccessfully() {
68 public void executeInProgressAfterAction(ModalityContext modaityContext
) {
73 public void refreshAfterCheckout(final Listener listener
, final CvsElement
[] selectedElements
, final File checkoutDirectory
,
74 final boolean useAlternateCheckoutPath
) {
75 VirtualFileManager
.getInstance().refresh(true, new Runnable() {
77 // shouldn't hold write action when calling this (IDEADEV-20086)
78 for (CvsElement element
: selectedElements
) {
79 File path
= useAlternateCheckoutPath ? checkoutDirectory
: new File(checkoutDirectory
, element
.getCheckoutPath());
80 listener
.directoryCheckedOut(path
);
82 listener
.checkoutCompleted();
87 private static String
[] collectCheckoutPaths(final CvsElement
[] mySelectedElements
) {
88 String
[] checkoutPaths
= new String
[mySelectedElements
.length
];
89 for (int i
= 0; i
< mySelectedElements
.length
; i
++) {
90 CvsElement selectedElement
= mySelectedElements
[i
];
91 checkoutPaths
[i
] = selectedElement
.getCheckoutPath();
96 public String
getVcsName() {