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
.ui
.experts
;
18 import com
.intellij
.cvsSupport2
.config
.CvsRootConfiguration
;
19 import com
.intellij
.cvsSupport2
.connections
.CvsEnvironment
;
20 import com
.intellij
.cvsSupport2
.cvsBrowser
.CvsElement
;
21 import com
.intellij
.cvsSupport2
.cvsBrowser
.CvsTree
;
22 import com
.intellij
.cvsSupport2
.cvsBrowser
.LoginAbortedException
;
23 import com
.intellij
.cvsSupport2
.cvsExecution
.ModalityContextImpl
;
24 import com
.intellij
.cvsSupport2
.cvsoperations
.common
.LoginPerformer
;
25 import com
.intellij
.openapi
.application
.ModalityState
;
26 import com
.intellij
.openapi
.project
.Project
;
27 import com
.intellij
.openapi
.util
.Comparing
;
28 import com
.intellij
.openapi
.util
.Ref
;
29 import com
.intellij
.openapi
.vcs
.VcsException
;
30 import com
.intellij
.util
.Consumer
;
34 import java
.util
.Collections
;
35 import java
.util
.Observable
;
36 import java
.util
.Observer
;
41 public class SelectCvsElementStep
extends WizardStep
{
42 private CvsTree myCvsTree
;
43 private CvsRootConfiguration myConfiguration
;
44 private final SelectCVSConfigurationStep mySelectCVSConfigurationStep
;
45 private final Project myProject
;
46 private final boolean myShowFiles
;
47 private final int mySelectionMode
;
48 private final boolean myAllowRootSelection
;
49 private final boolean myShowModules
;
51 public SelectCvsElementStep(String title
, CvsWizard wizard
,
53 SelectCVSConfigurationStep selectCVSConfigurationStep
,
56 boolean allowRootSelection
, boolean showModules
) {
58 myShowModules
= showModules
;
59 mySelectCVSConfigurationStep
= selectCVSConfigurationStep
;
61 myShowFiles
= showFiles
;
62 mySelectionMode
= selectionMode
;
63 myAllowRootSelection
= allowRootSelection
;
67 public boolean nextIsEnabled() {
68 return myCvsTree
.getCurrentSelection().length
> 0;
71 private boolean isLogged(final CvsRootConfiguration selectedConfiguration
) {
72 final Ref
<Boolean
> errors
= new Ref
<Boolean
>();
73 final LoginPerformer
.MyProjectKnown performer
= new LoginPerformer
.MyProjectKnown(
74 myProject
, Collections
.<CvsEnvironment
>singletonList(selectedConfiguration
),
75 new Consumer
<VcsException
>() {
76 public void consume(VcsException e
) {
77 errors
.set(Boolean
.TRUE
);
80 /*final boolean logged = performer.loginAll(
81 new ModalityContextImpl(ModalityState.stateForComponent(mySelectCVSConfigurationStep.getComponent()), false), false);*/
82 final boolean logged
= performer
.loginAll(new ModalityContextImpl(ModalityState
.current(), false), false);
83 if ((! logged
) || (! errors
.isNull())) {
90 public boolean preNextCheck() {
91 CvsRootConfiguration selectedConfiguration
= mySelectCVSConfigurationStep
.getSelectedConfiguration();
92 return isLogged(selectedConfiguration
);
95 public boolean setActive() {
96 CvsRootConfiguration selectedConfiguration
=
97 mySelectCVSConfigurationStep
.getSelectedConfiguration();
99 if (myCvsTree
== null || !Comparing
.equal(myConfiguration
, selectedConfiguration
)) {
100 myConfiguration
= selectedConfiguration
;
101 if (myConfiguration
== null) return false;
102 if (myCvsTree
!= null) myCvsTree
.dispose();
104 new CvsTree(myConfiguration
, myProject
, myShowFiles
, mySelectionMode
, myAllowRootSelection
, myShowModules
);
105 getStepComponent().removeAll();
106 getStepComponent().add(myCvsTree
, BorderLayout
.CENTER
);
110 catch (LoginAbortedException ex
) {
114 myCvsTree
.addSelectionObserver(new Observer() {
115 public void update(Observable o
, Object arg
) {
116 if (CvsTree
.SELECTION_CHANGED
.equals(arg
)) {
117 getWizard().updateStep();
119 else if (CvsTree
.LOGIN_ABORTED
.equals(arg
)) {
121 SwingUtilities
.invokeLater(new Runnable() {
123 getWizard().goToPrevious();
134 protected void dispose() {
135 if (myCvsTree
!= null) {
136 myCvsTree
.deactivated();
140 public CvsElement
getSelectedCvsElement() {
141 CvsElement
[] selection
= myCvsTree
.getCurrentSelection();
142 if (selection
.length
== 0) return null;
146 protected JComponent
createComponent() {
147 return new JPanel(new BorderLayout());
150 public CvsElement
[] getSelectedCvsElements() {
151 return myCvsTree
.getCurrentSelection();
154 public Component
getPreferredFocusedComponent() {
155 return myCvsTree
.getTree();