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
;
18 import com
.intellij
.openapi
.help
.HelpManager
;
19 import com
.intellij
.openapi
.project
.Project
;
20 import com
.intellij
.openapi
.ui
.DialogWrapper
;
21 import com
.intellij
.openapi
.ui
.Messages
;
22 import com
.intellij
.openapi
.util
.Disposer
;
23 import org
.jetbrains
.annotations
.NonNls
;
24 import org
.jetbrains
.annotations
.Nullable
;
25 import org
.jetbrains
.idea
.svn
.SvnBundle
;
26 import org
.jetbrains
.idea
.svn
.SvnVcs
;
27 import org
.jetbrains
.idea
.svn
.dialogs
.browser
.UrlOpeningExpander
;
28 import org
.tmatesoft
.svn
.core
.SVNException
;
29 import org
.tmatesoft
.svn
.core
.SVNURL
;
30 import org
.tmatesoft
.svn
.core
.internal
.util
.SVNEncodingUtil
;
31 import org
.tmatesoft
.svn
.core
.io
.SVNRepository
;
34 import javax
.swing
.event
.DocumentEvent
;
35 import javax
.swing
.event
.DocumentListener
;
36 import javax
.swing
.event
.TreeSelectionEvent
;
37 import javax
.swing
.event
.TreeSelectionListener
;
41 * Created by IntelliJ IDEA.
45 * To change this template use File | Settings | File Templates.
47 public class SelectLocationDialog
extends DialogWrapper
{
48 private Project myProject
;
49 private RepositoryBrowserComponent myRepositoryBrowser
;
51 private String myDstName
;
52 private String myDstLabel
;
53 private JTextField myDstText
;
54 private boolean myIsShowFiles
;
56 @NonNls private static final String HELP_ID
= "vcs.subversion.common";
59 public static String
selectLocation(Project project
, String url
) {
61 SVNURL
.parseURIEncoded(url
);
62 SelectLocationDialog dialog
= new SelectLocationDialog(project
, url
);
64 if (!dialog
.isOK()) return null;
65 return dialog
.getSelectedURL();
66 } catch (SVNException e
) {
67 Messages
.showErrorDialog(project
, SvnBundle
.message("select.location.invalid.url.message", url
),
68 SvnBundle
.message("dialog.title.select.repository.location"));
73 public SelectLocationDialog(Project project
, String url
) throws SVNException
{
74 this(project
, url
, null, null, true);
77 public SelectLocationDialog(Project project
, String url
,
78 String dstLabel
, String dstName
, boolean showFiles
) throws SVNException
{
81 myDstLabel
= dstLabel
;
83 myURL
= SVNURL
.parseURIEncoded(url
);
84 myIsShowFiles
= showFiles
;
85 setTitle(SvnBundle
.message("dialog.title.select.repository.location"));
86 getHelpAction().setEnabled(true);
90 protected void doHelpAction() {
91 HelpManager
.getInstance().invokeHelp(HELP_ID
);
94 protected Action
[] createActions() {
95 return new Action
[]{getOKAction(), getCancelAction(), getHelpAction()};
98 protected String
getDimensionServiceKey() {
99 return "svn.repositoryBrowser";
102 protected void init() {
104 String urlString
= myURL
.toString();
106 SVNRepository repos
= SvnVcs
.getInstance(myProject
).createRepository(urlString
);
107 myURL
= repos
.getRepositoryRoot(true);
108 repos
.closeSession();
109 } catch (SVNException e
) {
110 // show error dialog.
112 myRepositoryBrowser
.setRepositoryURL(myURL
, myIsShowFiles
, new UrlOpeningExpander
.Factory(urlString
, urlString
));
113 myRepositoryBrowser
.addChangeListener(new TreeSelectionListener() {
114 public void valueChanged(TreeSelectionEvent e
) {
115 getOKAction().setEnabled(isOKActionEnabled());
121 protected void dispose() {
123 Disposer
.dispose(myRepositoryBrowser
);
126 protected JComponent
createCenterPanel() {
127 JPanel panel
= new JPanel();
128 panel
.setLayout(new GridBagLayout());
130 GridBagConstraints gc
= new GridBagConstraints();
131 gc
.insets
= new Insets(2, 2, 2, 2);
136 gc
.anchor
= GridBagConstraints
.WEST
;
137 gc
.fill
= GridBagConstraints
.BOTH
;
142 myRepositoryBrowser
= new RepositoryBrowserComponent(SvnVcs
.getInstance(myProject
));
143 panel
.add(myRepositoryBrowser
, gc
);
144 if (myDstName
!= null) {
148 gc
.fill
= GridBagConstraints
.NONE
;
152 JLabel dstLabel
= new JLabel(myDstLabel
);
153 panel
.add(dstLabel
, gc
);
157 gc
.fill
= GridBagConstraints
.HORIZONTAL
;
159 myDstText
= new JTextField();
160 myDstText
.setText(myDstName
);
161 myDstText
.selectAll();
162 panel
.add(myDstText
, gc
);
164 myDstText
.getDocument().addDocumentListener(new DocumentListener() {
165 public void insertUpdate(DocumentEvent e
) {
166 getOKAction().setEnabled(isOKActionEnabled());
169 public void removeUpdate(DocumentEvent e
) {
170 getOKAction().setEnabled(isOKActionEnabled());
173 public void changedUpdate(DocumentEvent e
) {
174 getOKAction().setEnabled(isOKActionEnabled());
178 dstLabel
.setLabelFor(myDstText
);
183 panel
.add(new JSeparator(), gc
);
189 public JComponent
getPreferredFocusedComponent() {
190 return (JComponent
)myRepositoryBrowser
.getPreferredFocusedComponent();
193 public boolean shouldCloseOnCross() {
197 public boolean isOKActionEnabled() {
198 boolean ok
= myRepositoryBrowser
.getSelectedURL() != null;
199 if (ok
&& myDstText
!= null) {
200 return myDstText
.getText().trim().length() > 0;
205 public String
getDestinationName() {
206 return SVNEncodingUtil
.uriEncode(myDstText
.getText().trim());
209 public String
getSelectedURL() {
210 return myRepositoryBrowser
.getSelectedURL();
213 public SVNURL
getSelectedSVNURL() {
214 return myRepositoryBrowser
.getSelectedSVNURL();