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
.progress
.ProgressManager
;
19 import com
.intellij
.openapi
.progress
.Task
;
20 import com
.intellij
.openapi
.project
.Project
;
21 import com
.intellij
.openapi
.ui
.DialogWrapper
;
22 import com
.intellij
.openapi
.ui
.MultiLineLabelUI
;
23 import com
.intellij
.openapi
.util
.io
.FileUtil
;
24 import com
.intellij
.openapi
.vcs
.ProjectLevelVcsManager
;
25 import com
.intellij
.openapi
.vcs
.VcsDirectoryMapping
;
26 import com
.intellij
.openapi
.application
.ApplicationManager
;
27 import com
.intellij
.openapi
.application
.ModalityState
;
28 import com
.intellij
.ui
.table
.TableView
;
29 import com
.intellij
.util
.messages
.Topic
;
30 import com
.intellij
.util
.messages
.MessageBusConnection
;
31 import com
.intellij
.util
.ui
.ColumnInfo
;
32 import com
.intellij
.util
.ui
.ListTableModel
;
33 import org
.jetbrains
.idea
.svn
.SvnBundle
;
34 import org
.jetbrains
.idea
.svn
.SvnUtil
;
35 import org
.jetbrains
.idea
.svn
.SvnVcs
;
36 import org
.jetbrains
.idea
.svn
.WorkingCopyFormat
;
39 import javax
.swing
.event
.ListSelectionEvent
;
40 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
.Collection
;
46 import java
.util
.Collections
;
47 import java
.util
.List
;
49 public class SvnMapDialog
extends DialogWrapper
{
50 private JPanel myContentPane
;
51 private TableView
<WCInfo
> myTableView
;
52 private JButton myChangeFormatButton
;
53 private JButton myCorrectButton
;
54 private JLabel myWarningLabel
;
55 private JButton myRefresh
;
56 private ListTableModel
<WCInfo
> myTableModel
;
58 private final Project myProject
;
59 private final ActionListener myChangeFormatListener
;
60 private MessageBusConnection myMessageBusConnection
;
62 public SvnMapDialog(final Project project
) {
66 setTitle(SvnBundle
.message("dialog.show.svn.map.title"));
69 final SvnVcs vcs
= SvnVcs
.getInstance(myProject
);
70 final List
<WCInfo
> infoList
= vcs
.getAllWcInfos();
71 myTableModel
.setItems(infoList
);
73 final boolean promptForCorrection
= vcs
.getSvnFileUrlMapping().rootsDiffer();
74 if (promptForCorrection
) {
75 myWarningLabel
.setText(SvnBundle
.message("action.working.copies.map.correct.warning.text"));
76 myWarningLabel
.setUI(new MultiLineLabelUI());
77 myCorrectButton
.addActionListener(new ActionListener() {
78 public void actionPerformed(final ActionEvent e
) {
79 correctMappings(vcs
, infoList
);
83 myCorrectButton
.setVisible(promptForCorrection
);
84 myWarningLabel
.setVisible(promptForCorrection
);
86 myTableView
.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
87 public void valueChanged(final ListSelectionEvent e
) {
88 final Collection
<WCInfo
> selected
= myTableView
.getSelection();
89 myChangeFormatButton
.setEnabled((selected
.size() == 1) &&
90 (! ProjectLevelVcsManager
.getInstance(project
).isBackgroundVcsOperationRunning()));
94 myChangeFormatListener
= new ActionListener() {
95 public void actionPerformed(final ActionEvent e
) {
96 final Collection
<WCInfo
> selected
= myTableView
.getSelection();
97 if (selected
.size() != 1) {
100 final WCInfo wcInfo
= selected
.iterator().next();
101 File path
= new File(wcInfo
.getPath());
102 if (! wcInfo
.isIsWcRoot()) {
103 path
= SvnUtil
.getWorkingCopyRoot(path
);
106 ChangeFormatDialog dialog
= new ChangeFormatDialog(project
, path
, false, ! wcInfo
.isIsWcRoot());
107 dialog
.setData(true, wcInfo
.getFormat().getOption());
109 if (! dialog
.isOK()) {
112 final String newMode
= dialog
.getUpgradeMode();
113 if (! wcInfo
.getFormat().getOption().equals(newMode
)) {
114 final WorkingCopyFormat newFormat
= WorkingCopyFormat
.getInstance(newMode
);
115 final Task
.Backgroundable task
= new SvnFormatWorker(project
, newFormat
, wcInfo
);
117 ProgressManager
.getInstance().run(task
);
121 myChangeFormatButton
.addActionListener(myChangeFormatListener
);
123 myChangeFormatButton
.setEnabled((myTableView
.getSelection().size() == 1) &&
124 (! ProjectLevelVcsManager
.getInstance(project
).isBackgroundVcsOperationRunning()));
126 myRefresh
.addActionListener(new ActionListener() {
127 public void actionPerformed(final ActionEvent e
) {
128 final SvnVcs vcs
= SvnVcs
.getInstance(myProject
);
129 subscribeToUpdates(vcs
);
130 vcs
.invokeRefreshSvnRoots(false);
131 myRefresh
.setEnabled(false);
132 /*final List<WCInfo> infoList = vcs.getAllWcInfos();
133 myTableModel.setItems(infoList);
134 myTableView.repaint();*/
140 protected String
getHelpId() {
141 return "reference.vcs.svn.working.copies.information";
144 private void subscribeToUpdates(final SvnVcs vcs
) {
145 if (myMessageBusConnection
== null) {
146 myMessageBusConnection
= myProject
.getMessageBus().connect(getDisposable());
147 final ModalityState state
= ModalityState
.current();
148 myMessageBusConnection
.subscribe(SvnVcs
.ROOTS_RELOADED
, new Runnable() {
150 ApplicationManager
.getApplication().invokeLater(new Runnable() {
152 final List
<WCInfo
> infoList
= vcs
.getAllWcInfos();
153 myTableModel
.setItems(infoList
);
154 myRefresh
.setEnabled(true);
155 myTableView
.repaint();
163 private void correctMappings(final SvnVcs vcs
, final List
<WCInfo
> infos
) {
164 final ProjectLevelVcsManager manager
= ProjectLevelVcsManager
.getInstance(vcs
.getProject());
165 final List
<VcsDirectoryMapping
> mappings
= manager
.getDirectoryMappings();
166 final List
<VcsDirectoryMapping
> newMappings
= new ArrayList
<VcsDirectoryMapping
>();
167 final String svnVcsName
= vcs
.getName();
168 for (VcsDirectoryMapping mapping
: mappings
) {
169 if (! svnVcsName
.equals(mapping
.getVcs())) {
170 newMappings
.add(mapping
);
173 for (WCInfo info
: infos
) {
174 newMappings
.add(new VcsDirectoryMapping(FileUtil
.toSystemIndependentName(info
.getPath()), svnVcsName
));
176 manager
.setDirectoryMappings(newMappings
);
178 // table did not changed
179 myCorrectButton
.setVisible(false);
180 myWarningLabel
.setVisible(false);
183 public static final Topic
<Runnable
> WC_CONVERTED
= new Topic
<Runnable
>("WC_CONVERTED", Runnable
.class);
185 protected JComponent
createCenterPanel() {
186 return myContentPane
;
189 private void createUIComponents() {
190 myTableModel
= new ListTableModel
<WCInfo
>(new ColumnInfo
[]{WC_ROOT_PATH
, WC_URL
, WC_COPY_ROOT
, WC_FORMAT
}, Collections
.<WCInfo
>emptyList(), 0);
191 myTableView
= new TableView
<WCInfo
>(myTableModel
);
194 private static final ColumnInfo
<WCInfo
, String
> WC_ROOT_PATH
= new ColumnInfo
<WCInfo
, String
>(SvnBundle
.message("dialog.show.svn.map.table.header.column.wcpath.title")) {
195 public String
valueOf(final WCInfo info
) {
196 return info
.getPath();
199 private static final ColumnInfo
<WCInfo
, String
> WC_URL
= new ColumnInfo
<WCInfo
, String
>(SvnBundle
.message("dialog.show.svn.map.table.header.column.wcurl.title")) {
200 public String
valueOf(final WCInfo info
) {
201 return info
.getUrl().toString();
204 private static final ColumnInfo
<WCInfo
, String
> WC_COPY_ROOT
= new ColumnInfo
<WCInfo
, String
>(SvnBundle
.message("dialog.show.svn.map.table.header.column.wcroot.title")) {
205 public String
valueOf(final WCInfo info
) {
206 return info
.isIsWcRoot() ?
"yes" : "no";
209 private static final ColumnInfo
<WCInfo
, String
> WC_FORMAT
= new ColumnInfo
<WCInfo
, String
>(SvnBundle
.message("dialog.show.svn.map.table.header.column.format.title")) {
211 public String
getName() {
212 return super.getName();
215 public String
valueOf(final WCInfo info
) {
216 final WorkingCopyFormat format
= info
.getFormat();
217 return SvnUtil
.formatRepresentation(format
);