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 org
.jetbrains
.idea
.svn
.dialogs
.browser
;
18 import com
.intellij
.openapi
.fileChooser
.FileChooser
;
19 import com
.intellij
.openapi
.fileChooser
.FileChooserDescriptor
;
20 import com
.intellij
.openapi
.options
.ConfigurationException
;
21 import com
.intellij
.openapi
.project
.Project
;
22 import com
.intellij
.openapi
.ui
.DialogWrapper
;
23 import com
.intellij
.openapi
.ui
.FixedSizeButton
;
24 import com
.intellij
.openapi
.vcs
.checkout
.CheckoutStrategy
;
25 import com
.intellij
.openapi
.vfs
.VirtualFile
;
26 import org
.jetbrains
.annotations
.NonNls
;
27 import org
.jetbrains
.annotations
.NotNull
;
28 import org
.jetbrains
.annotations
.Nullable
;
29 import org
.jetbrains
.idea
.svn
.DepthCombo
;
30 import org
.jetbrains
.idea
.svn
.SvnBundle
;
31 import org
.jetbrains
.idea
.svn
.revision
.SvnSelectRevisionPanel
;
32 import org
.jetbrains
.idea
.svn
.update
.SvnRevisionPanel
;
33 import org
.tmatesoft
.svn
.core
.SVNDepth
;
34 import org
.tmatesoft
.svn
.core
.SVNURL
;
35 import org
.tmatesoft
.svn
.core
.wc
.SVNRevision
;
38 import javax
.swing
.event
.ListSelectionEvent
;
39 import javax
.swing
.event
.ListSelectionListener
;
41 import java
.awt
.event
.ActionEvent
;
42 import java
.awt
.event
.ActionListener
;
44 import java
.util
.ArrayList
;
45 import java
.util
.Collections
;
46 import java
.util
.List
;
48 public class CheckoutOptionsDialog
extends DialogWrapper
{
49 private JCheckBox myExternalsCheckbox
;
50 private JLabel myUrlLabel
;
51 private JPanel myTopPanel
;
52 private SvnSelectRevisionPanel svnSelectRevisionPanel
;
53 private DepthCombo myDepthCombo
;
54 private JLabel myDepthLabel
;
55 private JList myLocalTargetList
;
56 private FixedSizeButton mySelectTarget
;
57 private final String myRelativePath
;
59 public CheckoutOptionsDialog(Project project
, SVNURL url
, File target
, final VirtualFile root
, final String relativePath
) {
61 myRelativePath
= relativePath
;
62 final String urlText
= url
.toString();
63 myUrlLabel
.setText(urlText
);
65 fillTargetList(target
);
66 validateTargetSelected();
68 mySelectTarget
.addActionListener(new ActionListener() {
69 public void actionPerformed(final ActionEvent e
) {
70 // choose directory here/
71 FileChooserDescriptor fcd
= new FileChooserDescriptor(false, true, false, false, false, false);
72 fcd
.setShowFileSystemRoots(true);
73 fcd
.setTitle(SvnBundle
.message("checkout.directory.chooser.title"));
74 fcd
.setDescription(SvnBundle
.message("checkout.directory.chooser.prompt"));
75 fcd
.setHideIgnored(false);
76 VirtualFile
[] files
= FileChooser
.chooseFiles(getContentPane(), fcd
, null);
77 if (files
.length
!= 1 || files
[0] == null) {
80 fillTargetList(new File(files
[0].getPath()));
81 validateTargetSelected();
84 myLocalTargetList
.addListSelectionListener(new ListSelectionListener() {
85 public void valueChanged(final ListSelectionEvent e
) {
86 validateTargetSelected();
90 svnSelectRevisionPanel
.setRoot(root
);
91 svnSelectRevisionPanel
.setProject(project
);
92 svnSelectRevisionPanel
.setUrlProvider(new SvnRevisionPanel
.UrlProvider() {
93 public String
getUrl() {
98 setTitle(SvnBundle
.message("checkout.options.dialog.title"));
99 myDepthLabel
.setLabelFor(myDepthCombo
);
103 private void validateTargetSelected() {
104 Object
[] objects
= myLocalTargetList
.getSelectedValues();
105 boolean disable
= objects
== null || objects
.length
!= 1;
106 setOKActionEnabled(! disable
);
109 private void fillTargetList(final File target
) {
110 final DefaultListModel listModel
= new DefaultListModel();
111 final List
<CheckoutStrategy
> strategies
= new ArrayList
<CheckoutStrategy
>();
112 Collections
.addAll(strategies
, CheckoutStrategy
.createAllStrategies(target
, new File(myRelativePath
), false));
113 strategies
.add(new SvnTrunkCheckoutStrategy(target
, new File(myRelativePath
), false));
114 final List
<File
> targets
= new ArrayList
<File
>(5);
115 for (CheckoutStrategy strategy
: strategies
) {
116 final File result
= strategy
.getResult();
117 if (result
!= null && (! targets
.contains(result
))) {
121 Collections
.sort(targets
);
122 for (File file
: targets
) {
123 listModel
.addElement(file
);
125 myLocalTargetList
.setModel(listModel
);
126 myLocalTargetList
.setVisibleRowCount(4);
127 myLocalTargetList
.setMinimumSize(new Dimension(20, 80));
128 myLocalTargetList
.setSelectedValue(target
, true);
129 if (myLocalTargetList
.getSelectedValues() == null && (! targets
.isEmpty())) {
130 myLocalTargetList
.setSelectedIndex(0);
135 protected String
getDimensionServiceKey() {
136 return "svn4idea.checkout.options";
140 public File
getTarget() {
141 Object
[] objects
= myLocalTargetList
.getSelectedValues();
142 return (objects
== null) || (objects
.length
!= 1) ?
null : (File
) objects
[0];
145 public SVNDepth
getDepth() {
146 return myDepthCombo
.getSelectedItem();
149 public boolean isIgnoreExternals() {
150 return !myExternalsCheckbox
.isSelected();
154 protected JComponent
createCenterPanel() {
159 public SVNRevision
getRevision() throws ConfigurationException
{
160 return svnSelectRevisionPanel
.getRevision();
163 private void createUIComponents() {
164 mySelectTarget
= new FixedSizeButton(20);