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
.ui
.OrderPanel
;
22 import com
.intellij
.ui
.OrderPanelListener
;
23 import com
.intellij
.util
.ArrayUtil
;
24 import org
.jetbrains
.annotations
.NonNls
;
25 import org
.jetbrains
.idea
.svn
.SvnBundle
;
29 import java
.awt
.event
.ActionEvent
;
30 import java
.awt
.event
.ActionListener
;
34 * Created by IntelliJ IDEA.
38 * To change this template use File | Settings | File Templates.
40 public class SelectFilesDialog
extends DialogWrapper
implements ActionListener
{
42 private final String
[] myFiles
;
43 private FilesList myFilesList
;
44 private JButton mySelectAllButton
;
45 private JButton myDeselectAllButton
;
46 private final String myLabel
;
47 private final String myHelpID
;
49 public SelectFilesDialog(final Project project
, String label
, String title
, String actionName
, String
[] paths
,
50 @NonNls String helpID
) {
53 setOKButtonText(actionName
);
59 getHelpAction().setEnabled(myHelpID
!= null);
64 protected void doHelpAction() {
65 if (myHelpID
!= null) {
66 HelpManager
.getInstance().invokeHelp(myHelpID
);
70 protected Action
[] createActions() {
71 return new Action
[]{getOKAction(), getCancelAction(), getHelpAction()};
74 protected void init() {
77 mySelectAllButton
.addActionListener(this);
78 myDeselectAllButton
.addActionListener(this);
80 myFilesList
.addListener(new OrderPanelListener() {
81 public void entryMoved() {
82 getOKAction().setEnabled(isOKActionEnabled());
87 protected String
getDimensionServiceKey() {
88 return "svn.selectFilesDialog";
91 public boolean shouldCloseOnCross() {
95 public JComponent
getPreferredFocusedComponent() {
99 public boolean isOKActionEnabled() {
100 return myFilesList
.getSelectedPaths().length
> 0;
103 protected JComponent
createCenterPanel() {
104 JPanel panel
= new JPanel(new BorderLayout(5,5));
106 JLabel label
= new JLabel(myLabel
);
107 panel
.add(label
, BorderLayout
.NORTH
);
109 myFilesList
= new FilesList(myFiles
);
110 myFilesList
.setCheckboxColumnName("");
111 myFilesList
.setEntriesEditable(false);
112 for (int i
= 0; i
< myFiles
.length
; i
++) {
113 myFilesList
.add(myFiles
[i
]);
115 Font font
= myFilesList
.getFont();
116 FontMetrics fm
= myFilesList
.getFontMetrics(font
);
117 int height
= fm
.getHeight();
118 myFilesList
.setPreferredSize(new Dimension(myFilesList
.getPreferredSize().width
, height
*7));
119 panel
.add(new JScrollPane(myFilesList
), BorderLayout
.CENTER
);
121 JPanel buttonsPanel
= new JPanel(new FlowLayout(FlowLayout
.LEFT
));
122 mySelectAllButton
= new JButton(SvnBundle
.message("button.text.select.all"));
123 myDeselectAllButton
= new JButton(SvnBundle
.message("button.text.deselect.all"));
125 buttonsPanel
.add(mySelectAllButton
);
126 buttonsPanel
.add(myDeselectAllButton
);
128 panel
.add(buttonsPanel
, BorderLayout
.SOUTH
);
132 public void actionPerformed(ActionEvent e
) {
133 for (int i
= 0; i
< myFiles
.length
; i
++) {
134 myFilesList
.setChecked(myFiles
[i
], e
.getSource() == mySelectAllButton
);
136 myFilesList
.refresh();
137 setOKActionEnabled(isOKActionEnabled());
140 public String
[] getSelectedPaths() {
141 return myFilesList
.getSelectedPaths();
144 private class FilesList
extends OrderPanel
{
146 private final Map mySelectedFiles
;
148 protected FilesList(String
[] files
) {
149 super(String
.class, true);
150 mySelectedFiles
= new TreeMap();
151 for (int i
= 0; i
< files
.length
; i
++) {
152 mySelectedFiles
.put(files
[i
], Boolean
.TRUE
);
155 public boolean isCheckable(final Object entry
) {
158 public boolean isChecked(final Object entry
) {
159 return Boolean
.TRUE
.equals(mySelectedFiles
.get(entry
));
161 public void setChecked(final Object entry
, final boolean checked
) {
162 mySelectedFiles
.put(entry
, checked ? Boolean
.TRUE
: Boolean
.FALSE
);
163 getOKAction().setEnabled(isOKActionEnabled());
166 public void refresh() {
168 for (Iterator paths
= mySelectedFiles
.keySet().iterator(); paths
.hasNext();) {
169 String path
= (String
)paths
.next();
174 public String
[] getSelectedPaths() {
175 Collection selected
= new TreeSet();
176 for (Iterator paths
= mySelectedFiles
.keySet().iterator(); paths
.hasNext();) {
177 String path
= (String
)paths
.next();
178 if (isChecked(path
)) {
182 return (String
[])ArrayUtil
.toStringArray(selected
);