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
.application
.ApplicationManager
;
19 import com
.intellij
.openapi
.application
.ModalityState
;
20 import com
.intellij
.openapi
.progress
.ProgressManager
;
21 import com
.intellij
.openapi
.progress
.Task
;
22 import com
.intellij
.openapi
.project
.Project
;
23 import com
.intellij
.openapi
.ui
.DialogWrapper
;
24 import com
.intellij
.openapi
.ui
.MultiLineLabelUI
;
25 import com
.intellij
.openapi
.util
.io
.FileUtil
;
26 import com
.intellij
.openapi
.vcs
.ProjectLevelVcsManager
;
27 import com
.intellij
.openapi
.vcs
.VcsDirectoryMapping
;
28 import com
.intellij
.ui
.table
.TableView
;
29 import com
.intellij
.util
.messages
.MessageBusConnection
;
30 import com
.intellij
.util
.messages
.Topic
;
31 import com
.intellij
.util
.ui
.ColumnInfo
;
32 import com
.intellij
.util
.ui
.ListTableModel
;
33 import org
.jetbrains
.idea
.svn
.*;
36 import javax
.swing
.event
.ListSelectionEvent
;
37 import javax
.swing
.event
.ListSelectionListener
;
38 import java
.awt
.event
.ActionEvent
;
39 import java
.awt
.event
.ActionListener
;
41 import java
.util
.ArrayList
;
42 import java
.util
.Collection
;
43 import java
.util
.Collections
;
44 import java
.util
.List
;
46 public class SvnMapDialog
extends DialogWrapper
{
47 private JPanel myContentPane
;
48 private TableView
<WCInfo
> myTableView
;
49 private JButton myChangeFormatButton
;
50 private JButton myCorrectButton
;
51 private JLabel myWarningLabel
;
52 private JButton myRefresh
;
53 private ListTableModel
<WCInfo
> myTableModel
;
55 private final Project myProject
;
56 private final ActionListener myChangeFormatListener
;
57 private MessageBusConnection myMessageBusConnection
;
59 public SvnMapDialog(final Project project
) {
63 setTitle(SvnBundle
.message("dialog.show.svn.map.title"));
66 final SvnVcs vcs
= SvnVcs
.getInstance(myProject
);
67 final List
<WCInfo
> infoList
= vcs
.getAllWcInfos();
68 myTableModel
.setItems(infoList
);
70 final boolean promptForCorrection
= vcs
.getSvnFileUrlMapping().rootsDiffer();
71 if (promptForCorrection
) {
72 myWarningLabel
.setText(SvnBundle
.message("action.working.copies.map.correct.warning.text"));
73 myWarningLabel
.setUI(new MultiLineLabelUI());
74 myCorrectButton
.addActionListener(new ActionListener() {
75 public void actionPerformed(final ActionEvent e
) {
76 correctMappings(vcs
, infoList
);
80 myCorrectButton
.setVisible(promptForCorrection
);
81 myWarningLabel
.setVisible(promptForCorrection
);
83 myTableView
.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
84 public void valueChanged(final ListSelectionEvent e
) {
85 final Collection
<WCInfo
> selected
= myTableView
.getSelection();
86 myChangeFormatButton
.setEnabled((selected
.size() == 1) &&
87 (! ProjectLevelVcsManager
.getInstance(project
).isBackgroundVcsOperationRunning()));
91 myChangeFormatListener
= new ActionListener() {
92 public void actionPerformed(final ActionEvent e
) {
93 final Collection
<WCInfo
> selected
= myTableView
.getSelection();
94 if (selected
.size() != 1) {
97 final WCInfo wcInfo
= selected
.iterator().next();
98 File path
= new File(wcInfo
.getPath());
99 if (! wcInfo
.isIsWcRoot()) {
100 path
= SvnUtil
.getWorkingCopyRoot(path
);
103 ChangeFormatDialog dialog
= new ChangeFormatDialog(project
, path
, false, ! wcInfo
.isIsWcRoot());
104 dialog
.setData(true, wcInfo
.getFormat().getOption());
106 if (! dialog
.isOK()) {
109 final String newMode
= dialog
.getUpgradeMode();
110 if (! wcInfo
.getFormat().getOption().equals(newMode
)) {
111 final WorkingCopyFormat newFormat
= WorkingCopyFormat
.getInstance(newMode
);
112 final Task
.Backgroundable task
= new SvnFormatWorker(project
, newFormat
, wcInfo
);
114 ProgressManager
.getInstance().run(task
);
118 myChangeFormatButton
.addActionListener(myChangeFormatListener
);
120 myChangeFormatButton
.setEnabled((myTableView
.getSelection().size() == 1) &&
121 (! ProjectLevelVcsManager
.getInstance(project
).isBackgroundVcsOperationRunning()));
123 myRefresh
.addActionListener(new ActionListener() {
124 public void actionPerformed(final ActionEvent e
) {
125 final SvnVcs vcs
= SvnVcs
.getInstance(myProject
);
126 subscribeToUpdates(vcs
);
127 vcs
.invokeRefreshSvnRoots(false);
128 myRefresh
.setEnabled(false);
129 /*final List<WCInfo> infoList = vcs.getAllWcInfos();
130 myTableModel.setItems(infoList);
131 myTableView.repaint();*/
137 protected String
getHelpId() {
138 return "reference.vcs.svn.working.copies.information";
141 private void subscribeToUpdates(final SvnVcs vcs
) {
142 if (myMessageBusConnection
== null) {
143 myMessageBusConnection
= myProject
.getMessageBus().connect(getDisposable());
144 final ModalityState state
= ModalityState
.current();
145 myMessageBusConnection
.subscribe(SvnVcs
.ROOTS_RELOADED
, new Runnable() {
147 ApplicationManager
.getApplication().invokeLater(new Runnable() {
149 final List
<WCInfo
> infoList
= vcs
.getAllWcInfos();
150 myTableModel
.setItems(infoList
);
151 myRefresh
.setEnabled(true);
152 myTableView
.repaint();
160 private void correctMappings(final SvnVcs vcs
, final List
<WCInfo
> infos
) {
161 final ProjectLevelVcsManager manager
= ProjectLevelVcsManager
.getInstance(vcs
.getProject());
162 final List
<VcsDirectoryMapping
> mappings
= manager
.getDirectoryMappings();
163 final List
<VcsDirectoryMapping
> newMappings
= new ArrayList
<VcsDirectoryMapping
>();
164 final String svnVcsName
= vcs
.getName();
165 for (VcsDirectoryMapping mapping
: mappings
) {
166 if (! svnVcsName
.equals(mapping
.getVcs())) {
167 newMappings
.add(mapping
);
170 for (WCInfo info
: infos
) {
171 newMappings
.add(new VcsDirectoryMapping(FileUtil
.toSystemIndependentName(info
.getPath()), svnVcsName
));
173 manager
.setDirectoryMappings(newMappings
);
175 // table did not changed
176 myCorrectButton
.setVisible(false);
177 myWarningLabel
.setVisible(false);
180 public static final Topic
<Runnable
> WC_CONVERTED
= new Topic
<Runnable
>("WC_CONVERTED", Runnable
.class);
182 protected JComponent
createCenterPanel() {
183 return myContentPane
;
186 private void createUIComponents() {
187 myTableModel
= new ListTableModel
<WCInfo
>(new ColumnInfo
[]{WC_ROOT_PATH
, WC_URL
, WC_COPY_ROOT
, WC_FORMAT
, WC_TYPE
}, Collections
.<WCInfo
>emptyList(), 0);
188 myTableView
= new TableView
<WCInfo
>(myTableModel
);
191 private static final ColumnInfo
<WCInfo
, String
> WC_ROOT_PATH
= new ColumnInfo
<WCInfo
, String
>(SvnBundle
.message("dialog.show.svn.map.table.header.column.wcpath.title")) {
192 public String
valueOf(final WCInfo info
) {
193 return info
.getPath();
196 private static final ColumnInfo
<WCInfo
, String
> WC_URL
= new ColumnInfo
<WCInfo
, String
>(SvnBundle
.message("dialog.show.svn.map.table.header.column.wcurl.title")) {
197 public String
valueOf(final WCInfo info
) {
198 return info
.getUrl().toString();
201 private static final ColumnInfo
<WCInfo
, String
> WC_COPY_ROOT
= new ColumnInfo
<WCInfo
, String
>(SvnBundle
.message("dialog.show.svn.map.table.header.column.wcroot.title")) {
202 public String
valueOf(final WCInfo info
) {
203 return info
.isIsWcRoot() ?
"yes" : "no";
206 private static final ColumnInfo
<WCInfo
, String
> WC_FORMAT
= new ColumnInfo
<WCInfo
, String
>(SvnBundle
.message("dialog.show.svn.map.table.header.column.format.title")) {
207 public String
valueOf(final WCInfo info
) {
208 final WorkingCopyFormat format
= info
.getFormat();
209 return SvnUtil
.formatRepresentation(format
);
212 private static final ColumnInfo
<WCInfo
, String
> WC_TYPE
= new ColumnInfo
<WCInfo
, String
>("Type") {
213 public String
valueOf(final WCInfo info
) {
214 final NestedCopyType type
= info
.getType();
215 return type
== null ?
"" : type
.getName();