Minor usability improvements for new commit dialog.
[fedora-idea.git] / source / com / intellij / openapi / vcs / changes / ui / CommitChangeListDialog.java
blobcd8625888f61858a8336855f7cc9d61d6feeed14
1 package com.intellij.openapi.vcs.changes.ui;
3 import com.intellij.openapi.actionSystem.*;
4 import com.intellij.openapi.application.ApplicationManager;
5 import com.intellij.openapi.application.ModalityState;
6 import com.intellij.openapi.localVcs.LocalVcs;
7 import com.intellij.openapi.localVcs.LvcsAction;
8 import com.intellij.openapi.progress.ProgressManager;
9 import com.intellij.openapi.project.Project;
10 import com.intellij.openapi.roots.ProjectFileIndex;
11 import com.intellij.openapi.roots.ProjectRootManager;
12 import com.intellij.openapi.ui.DialogWrapper;
13 import com.intellij.openapi.ui.InputException;
14 import com.intellij.openapi.ui.Messages;
15 import com.intellij.openapi.ui.Splitter;
16 import com.intellij.openapi.util.SystemInfo;
17 import com.intellij.openapi.vcs.*;
18 import com.intellij.openapi.vcs.changes.*;
19 import com.intellij.openapi.vcs.checkin.CheckinEnvironment;
20 import com.intellij.openapi.vcs.checkin.CheckinHandler;
21 import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory;
22 import com.intellij.openapi.vcs.checkin.VcsOperation;
23 import com.intellij.openapi.vcs.ui.CheckinDialog;
24 import com.intellij.openapi.vcs.ui.CommitMessage;
25 import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
26 import com.intellij.openapi.vfs.VirtualFile;
27 import com.intellij.openapi.vfs.VirtualFileManager;
28 import com.intellij.ui.ColoredListCellRenderer;
29 import com.intellij.ui.IdeBorderFactory;
30 import com.intellij.ui.SimpleTextAttributes;
31 import gnu.trove.THashSet;
32 import org.jetbrains.annotations.NonNls;
33 import org.jetbrains.annotations.Nullable;
35 import javax.swing.*;
36 import java.awt.*;
37 import java.awt.event.*;
38 import java.io.File;
39 import java.util.*;
40 import java.util.List;
42 /**
43 * @author max
45 public class CommitChangeListDialog extends DialogWrapper implements CheckinProjectPanel, DataProvider {
46 private CommitMessage myCommitMessageArea;
47 private JList myChangesList;
48 private Splitter myRootPane;
49 private JPanel myAdditionalOptionsPanel;
51 private Project myProject;
53 private ChangeList mySelectedChangeList;
54 private Collection<Change> myAllChanges;
55 private Collection<Change> myIncludedChanges;
57 private List<RefreshableOnComponent> myAdditionalComponents = new ArrayList<RefreshableOnComponent>();
58 private List<CheckinHandler> myHandlers = new ArrayList<CheckinHandler>();
59 private String myActionName;
60 private List<ChangeList> myChangeLists;
62 private static void commit(Project project, List<ChangeList> list, final List<Change> changes) {
63 new CommitChangeListDialog(project, list, changes).show();
66 public static void commitFile(Project project, VirtualFile file) {
67 final ChangeListManager manager = ChangeListManager.getInstance(project);
68 final Change change = manager.getChange(file);
69 if (change == null) {
70 Messages.showWarningDialog(project, "No changes for file: '" + file.getPresentableUrl() + "'.", "No Changes Detected");
71 return;
74 commit(project, Arrays.asList(manager.getChangeList(change)), Arrays.asList(change));
77 public static void commitFiles(final Project project, Collection<VirtualFile> directoriesOrFiles) {
78 final ChangeListManager manager = ChangeListManager.getInstance(project);
79 final Collection<Change> changes = new HashSet<Change>();
80 for (VirtualFile file : directoriesOrFiles) {
81 changes.addAll(manager.getChangesIn(file));
84 commitChanges(project, changes);
87 public static void commitPaths(final Project project, Collection<FilePath> paths) {
88 final ChangeListManager manager = ChangeListManager.getInstance(project);
89 final Collection<Change> changes = new HashSet<Change>();
90 for (FilePath path : paths) {
91 changes.addAll(manager.getChangesIn(path));
94 commitChanges(project, changes);
97 public static void commitChanges(final Project project, final Collection<Change> changes) {
98 final ChangeListManager manager = ChangeListManager.getInstance(project);
100 if (changes.isEmpty()) {
101 Messages.showWarningDialog(project, "No changes detected." , "No Changes Detected");
102 return;
105 Set<ChangeList> lists = new THashSet<ChangeList>();
106 for (Change change : changes) {
107 lists.add(manager.getChangeList(change));
110 commit(project, new ArrayList<ChangeList>(lists), new ArrayList<Change>(changes));
113 private CommitChangeListDialog(Project project, List<ChangeList> changeLists, final List<Change> changes) {
114 super(project, true);
115 myProject = project;
116 myChangeLists = changeLists;
117 myAllChanges = new ArrayList<Change>();
119 ChangeList initalListSelection = null;
120 for (ChangeList list : changeLists) {
121 myAllChanges.addAll(list.getChanges());
122 if (list.isDefault()) {
123 initalListSelection = list;
127 if (initalListSelection == null) {
128 initalListSelection = changeLists.get(0);
131 myIncludedChanges = new ArrayList<Change>(changes);
132 myActionName = "Commit Changes"; // TODO: should be customizable?
134 myAdditionalOptionsPanel = new JPanel();
135 myCommitMessageArea = new CommitMessage();
137 myChangesList = new JList(new DefaultListModel());
139 setSelectedList(initalListSelection);
141 setCommitMessage(CheckinDialog.getInitialMessage(getPaths(), project));
143 myChangesList.setCellRenderer(new MyListCellRenderer());
145 myAdditionalOptionsPanel.setLayout(new BorderLayout());
146 Box optionsBox = Box.createVerticalBox();
148 Box vcsCommitOptions = Box.createVerticalBox();
149 boolean hasVcsOptions = false;
150 final List<AbstractVcs> vcses = getAffectedVcses();
151 for (AbstractVcs vcs : vcses) {
152 final CheckinEnvironment checkinEnvironment = vcs.getCheckinEnvironment();
153 if (checkinEnvironment != null) {
154 final RefreshableOnComponent options = checkinEnvironment.createAdditionalOptionsPanelForCheckinProject(this);
155 if (options != null) {
156 JPanel vcsOptions = new JPanel(new BorderLayout());
157 vcsOptions.add(options.getComponent());
158 vcsOptions.setBorder(IdeBorderFactory.createTitledHeaderBorder(vcs.getDisplayName()));
159 vcsCommitOptions.add(vcsOptions);
160 myAdditionalComponents.add(options);
161 hasVcsOptions = true;
166 if (hasVcsOptions) {
167 vcsCommitOptions.add(Box.createVerticalGlue());
168 optionsBox.add(vcsCommitOptions);
171 boolean beforeVisible = false;
172 boolean afterVisible = false;
173 Box beforeBox = Box.createVerticalBox();
174 Box afterBox = Box.createVerticalBox();
175 final List<CheckinHandlerFactory> handlerFactories = ProjectLevelVcsManager.getInstance(project).getRegisteredCheckinHandlerFactories();
176 for (CheckinHandlerFactory factory : handlerFactories) {
177 final CheckinHandler handler = factory.createHandler(this);
178 myHandlers.add(handler);
179 final RefreshableOnComponent beforePanel = handler.getBeforeCheckinConfigurationPanel();
180 if (beforePanel != null) {
181 beforeBox.add(beforePanel.getComponent());
182 beforeVisible = true;
183 myAdditionalComponents.add(beforePanel);
186 final RefreshableOnComponent afterPanel = handler.getAfterCheckinConfigurationPanel();
187 if (afterPanel != null) {
188 afterBox.add(afterPanel.getComponent());
189 afterVisible = true;
190 myAdditionalComponents.add(afterPanel);
194 if (beforeVisible) {
195 beforeBox.add(Box.createVerticalGlue());
196 beforeBox.setBorder(IdeBorderFactory.createTitledHeaderBorder(VcsBundle.message("border.standard.checkin.options.group")));
197 optionsBox.add(beforeBox);
200 if (afterVisible) {
201 afterBox.add(Box.createVerticalGlue());
202 afterBox.setBorder(IdeBorderFactory.createTitledHeaderBorder(VcsBundle.message("border.standard.after.checkin.options.group")));
203 optionsBox.add(afterBox);
206 if (hasVcsOptions || beforeVisible || afterVisible) {
207 optionsBox.add(Box.createVerticalGlue());
208 myAdditionalOptionsPanel.add(optionsBox, BorderLayout.NORTH);
211 myChangesList.registerKeyboardAction(new ActionListener() {
212 public void actionPerformed(ActionEvent e) {
213 toggleSelection();
215 }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED);
217 final int checkboxWidth = new JCheckBox().getPreferredSize().width;
219 myChangesList.addMouseListener(new MouseAdapter() {
220 public void mouseClicked(MouseEvent e) {
221 final int idx = myChangesList.locationToIndex(e.getPoint());
222 if (idx >= 0) {
223 final Rectangle baseRect = myChangesList.getCellBounds(idx, idx);
224 baseRect.setSize(checkboxWidth, baseRect.height);
225 if (baseRect.contains(e.getPoint())) {
226 toggleChange((Change)myChangesList.getModel().getElementAt(idx));
232 setOKButtonText("Commit");
234 setTitle(myActionName);
236 restoreState();
238 init();
241 private void rebuildList() {
242 final DefaultListModel listModel = (DefaultListModel)myChangesList.getModel();
243 listModel.removeAllElements();
244 for (Change change : getCurrentDisplayedChanges()) {
245 listModel.addElement(change);
249 private boolean checkComment() {
250 if (VcsConfiguration.getInstance(myProject).FORCE_NON_EMPTY_COMMENT && (getCommitMessage().length() == 0)) {
251 int requestForCheckin = Messages.showYesNoDialog(VcsBundle.message("confirmation.text.check.in.with.empty.comment"),
252 VcsBundle.message("confirmation.title.check.in.with.empty.comment"),
253 Messages.getWarningIcon());
254 return requestForCheckin == OK_EXIT_CODE;
256 else {
257 return true;
261 public boolean runBeforeCommitHandlers() {
262 for (CheckinHandler handler : myHandlers) {
263 final CheckinHandler.ReturnResult result = handler.beforeCheckin();
264 if (result == CheckinHandler.ReturnResult.COMMIT) continue;
265 if (result == CheckinHandler.ReturnResult.CANCEL) return false;
266 if (result == CheckinHandler.ReturnResult.CLOSE_WINDOW) {
267 doCancelAction();
268 return false;
272 return true;
275 protected void doOKAction() {
276 if (!checkComment()) {
277 return;
280 VcsConfiguration.getInstance(myProject).saveCommitMessage(getCommitMessage());
281 try {
282 saveState();
284 if (!runBeforeCommitHandlers()) {
285 return;
288 doCommit();
290 super.doOKAction();
292 catch (InputException ex) {
293 ex.show();
297 private void doCommit() {
298 final Runnable checkinAction = new Runnable() {
299 public void run() {
300 final List<VcsException> vcsExceptions = new ArrayList<VcsException>();
301 Runnable checkinAction = new Runnable() {
302 public void run() {
303 try {
304 Map<AbstractVcs, List<Change>> changesByVcs = new HashMap<AbstractVcs, List<Change>>();
305 for (Change change : getCurrentIncludedChanges()) {
306 final AbstractVcs vcs = getVcsForChange(change);
307 if (vcs != null) {
308 List<Change> vcsChanges = changesByVcs.get(vcs);
309 if (vcsChanges == null) {
310 vcsChanges = new ArrayList<Change>();
311 changesByVcs.put(vcs, vcsChanges);
313 vcsChanges.add(change);
317 final List<FilePath> pathsToRefresh = new ArrayList<FilePath>();
319 for (AbstractVcs vcs : changesByVcs.keySet()) {
320 final CheckinEnvironment environment = vcs.getCheckinEnvironment();
321 if (environment != null) {
322 final List<Change> vcsChanges = changesByVcs.get(vcs);
323 List<FilePath> paths = new ArrayList<FilePath>();
324 for (Change change : vcsChanges) {
325 paths.add(getFilePath(change));
328 pathsToRefresh.addAll(paths);
330 vcsExceptions
331 .addAll(environment.commit(paths.toArray(new FilePath[paths.size()]), myProject, getCommitMessage()));
335 final LvcsAction lvcsAction = LocalVcs.getInstance(myProject).startAction(myActionName, "", true);
336 VirtualFileManager.getInstance().refresh(true, new Runnable() {
337 public void run() {
338 lvcsAction.finish();
339 FileStatusManager.getInstance(myProject).fileStatusesChanged();
340 for (FilePath path : pathsToRefresh) {
341 VcsDirtyScopeManager.getInstance(myProject).fileDirty(path);
345 AbstractVcsHelper.getInstance(myProject).showErrors(vcsExceptions, myActionName);
347 finally {
348 commitCompleted(vcsExceptions, VcsConfiguration.getInstance(myProject), myHandlers);
352 ProgressManager.getInstance().runProcessWithProgressSynchronously(checkinAction, myActionName, true, myProject);
356 AbstractVcsHelper.getInstance(myProject).optimizeImportsAndReformatCode(getVirtualFiles(),
357 VcsConfiguration.getInstance(myProject), checkinAction, true);
360 private static void commitCompleted(final List<VcsException> allExceptions,
361 VcsConfiguration config,
362 final List<CheckinHandler> checkinHandlers) {
363 final List<VcsException> errors = collectErrors(allExceptions);
364 final int errorsSize = errors.size();
365 final int warningsSize = allExceptions.size() - errorsSize;
367 if (errorsSize == 0) {
368 for (CheckinHandler handler : checkinHandlers) {
369 handler.checkinSuccessful();
372 else {
373 for (CheckinHandler handler : checkinHandlers) {
374 handler.checkinFailed(errors);
378 config.ERROR_OCCURED = errorsSize > 0;
381 ApplicationManager.getApplication().invokeLater(new Runnable() {
382 public void run() {
383 if (errorsSize > 0 && warningsSize > 0) {
384 Messages.showErrorDialog(VcsBundle.message("message.text.commit.failed.with.errors.and.warnings"),
385 VcsBundle.message("message.title.commit"));
387 else if (errorsSize > 0) {
388 Messages.showErrorDialog(VcsBundle.message("message.text.commit.failed.with.errors"), VcsBundle.message("message.title.commit"));
390 else if (warningsSize > 0) {
391 Messages
392 .showErrorDialog(VcsBundle.message("message.text.commit.finished.with.warnings"), VcsBundle.message("message.title.commit"));
396 }, ModalityState.NON_MMODAL);
400 private static List<VcsException> collectErrors(final List<VcsException> vcsExceptions) {
401 final ArrayList<VcsException> result = new ArrayList<VcsException>();
402 for (VcsException vcsException : vcsExceptions) {
403 if (!vcsException.isWarning()) {
404 result.add(vcsException);
407 return result;
410 @SuppressWarnings({"SuspiciousMethodCalls"})
411 private void toggleSelection() {
412 final Object[] values = myChangesList.getSelectedValues();
413 if (values != null) {
414 for (Object value : values) {
415 toggleChange((Change)value);
418 myChangesList.repaint();
421 private void toggleChange(Change value) {
422 if (myIncludedChanges.contains(value)) {
423 myIncludedChanges.remove(value);
425 else {
426 myIncludedChanges.add(value);
428 myChangesList.repaint();
431 private class ChangeListChooser extends JPanel {
432 public ChangeListChooser(List<ChangeList> lists) {
433 super(new BorderLayout());
434 final JComboBox chooser = new JComboBox(lists.toArray());
435 chooser.setRenderer(new ColoredListCellRenderer() {
436 protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
437 final ChangeList l = ((ChangeList)value);
438 append(l.getDescription(), l.isDefault() ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES);
442 chooser.addItemListener(new ItemListener() {
443 public void itemStateChanged(ItemEvent e) {
444 if (e.getStateChange() == ItemEvent.SELECTED) {
445 setSelectedList((ChangeList)chooser.getSelectedItem());
450 chooser.setSelectedItem(mySelectedChangeList);
451 chooser.setEditable(false);
452 chooser.setEnabled(lists.size() > 1);
453 add(chooser, BorderLayout.EAST);
455 JLabel label = new JLabel("Change list: ");
456 label.setDisplayedMnemonic('l');
457 label.setLabelFor(chooser);
458 add(label, BorderLayout.CENTER);
462 private void setSelectedList(final ChangeList list) {
463 mySelectedChangeList = list;
464 rebuildList();
467 private JComponent createToolbar() {
468 DefaultActionGroup toolBarGroup = new DefaultActionGroup();
469 final ShowDiffAction diffAction = new ShowDiffAction();
470 final MoveChangesToAnotherListAction moveAction = new MoveChangesToAnotherListAction() {
471 public void actionPerformed(AnActionEvent e) {
472 super.actionPerformed(e);
473 rebuildList();
477 diffAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D,
478 SystemInfo.isMac
479 ? KeyEvent.META_DOWN_MASK
480 : KeyEvent.CTRL_DOWN_MASK)), getRootPane());
482 moveAction.registerCustomShortcutSet(CommonShortcuts.getMove(), getRootPane());
484 toolBarGroup.add(diffAction);
485 toolBarGroup.add(moveAction);
487 return ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolBarGroup, true).getComponent();
491 @Nullable
492 protected JComponent createCenterPanel() {
493 myChangesList.setVisibleRowCount(10);
494 myRootPane = new Splitter(true);
495 myRootPane.setHonorComponentsMinimumSize(true);
496 final JScrollPane pane = new JScrollPane(myChangesList);
497 pane.setPreferredSize(new Dimension(400, 400));
499 JPanel topPanel = new JPanel(new BorderLayout());
501 JPanel listPanel = new JPanel(new BorderLayout());
502 listPanel.add(pane);
503 listPanel.setBorder(IdeBorderFactory.createTitledHeaderBorder("Changed Files"));
504 topPanel.add(listPanel, BorderLayout.CENTER);
506 JPanel headerPanel = new JPanel(new BorderLayout());
507 headerPanel.add(new ChangeListChooser(myChangeLists), BorderLayout.EAST);
508 headerPanel.add(createToolbar(), BorderLayout.WEST);
509 topPanel.add(headerPanel, BorderLayout.NORTH);
511 myRootPane.setFirstComponent(topPanel);
513 JPanel bottomPanel = new JPanel(new BorderLayout());
514 bottomPanel.add(myAdditionalOptionsPanel, BorderLayout.EAST);
515 bottomPanel.add(myCommitMessageArea, BorderLayout.CENTER);
517 myRootPane.setSecondComponent(bottomPanel);
518 myRootPane.setProportion(1);
519 return myRootPane;
522 private static FilePath getFilePath(final Change change) {
523 ContentRevision revision = change.getAfterRevision();
524 if (revision == null) revision = change.getBeforeRevision();
526 return revision.getFile();
529 private class MyListCellRenderer extends JPanel implements ListCellRenderer {
530 private final ColoredListCellRenderer myTextRenderer;
531 public final JCheckBox myCheckbox;
533 public MyListCellRenderer() {
534 super(new BorderLayout());
535 myCheckbox = new JCheckBox();
536 myTextRenderer = new ColoredListCellRenderer() {
537 protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
538 Change change = (Change)value;
539 final FilePath path = getFilePath(change);
540 setIcon(path.getFileType().getIcon());
541 append(path.getName(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, getColor(change), null));
542 append(" (" + path.getIOFile().getParentFile().getPath() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
545 private Color getColor(final Change change) {
546 final FilePath path = getFilePath(change);
547 final VirtualFile vFile = path.getVirtualFile();
548 if (vFile != null) {
549 return FileStatusManager.getInstance(myProject).getStatus(vFile).getColor();
551 return FileStatus.DELETED.getColor();
555 myCheckbox.setBackground(null);
556 setBackground(null);
558 add(myCheckbox, BorderLayout.WEST);
559 add(myTextRenderer, BorderLayout.CENTER);
562 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
563 myTextRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
564 myCheckbox.setSelected(myIncludedChanges.contains(value));
565 return this;
569 private Collection<Change> getCurrentDisplayedChanges() {
570 return filterBySelectedChangeList(myAllChanges);
573 private Collection<Change> getCurrentIncludedChanges() {
574 return filterBySelectedChangeList(myIncludedChanges);
577 private Collection<Change> filterBySelectedChangeList(final Collection<Change> changes) {
578 List<Change> filtered = new ArrayList<Change>();
579 final ChangeListManager manager = ChangeListManager.getInstance(myProject);
580 for (Change change : changes) {
581 if (manager.getChangeList(change) == mySelectedChangeList) {
582 filtered.add(change);
585 return filtered;
588 public List<AbstractVcs> getAffectedVcses() {
589 Set<AbstractVcs> result = new HashSet<AbstractVcs>();
590 for (Change change : myAllChanges) {
591 final AbstractVcs vcs = getVcsForChange(change);
592 if (vcs != null) {
593 result.add(vcs);
596 return new ArrayList<AbstractVcs>(result);
599 private AbstractVcs getVcsForChange(Change change) {
600 final FilePath filePath = getFilePath(change);
601 final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
602 final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
603 VirtualFile root = VcsDirtyScope.getRootFor(fileIndex, filePath);
604 if (root != null) {
605 return vcsManager.getVcsFor(root);
608 return null;
611 public Collection<VirtualFile> getRoots() {
612 final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
613 Set<VirtualFile> result = new HashSet<VirtualFile>();
614 for (Change change : getCurrentDisplayedChanges()) {
615 final FilePath filePath = getFilePath(change);
616 VirtualFile root = VcsDirtyScope.getRootFor(fileIndex, filePath);
617 if (root != null) {
618 result.add(root);
621 return result;
624 public JComponent getComponent() {
625 return myRootPane;
628 public boolean hasDiffs() {
629 return true;
632 public void addSelectionChangeListener(SelectionChangeListener listener) {
633 throw new UnsupportedOperationException();
636 public void removeSelectionChangeListener(SelectionChangeListener listener) {
637 throw new UnsupportedOperationException();
640 public Collection<VirtualFile> getVirtualFiles() {
641 List<VirtualFile> result = new ArrayList<VirtualFile>();
642 for (Change change: getCurrentIncludedChanges()) {
643 final FilePath path = getFilePath(change);
644 final VirtualFile vFile = path.getVirtualFile();
645 if (vFile != null) {
646 result.add(vFile);
650 return result;
653 public Collection<File> getFiles() {
654 List<File> result = new ArrayList<File>();
655 for (Change change: getCurrentIncludedChanges()) {
656 final FilePath path = getFilePath(change);
657 final File file = path.getIOFile();
658 if (file != null) {
659 result.add(file);
663 return result;
666 private FilePath[] getPaths() {
667 List<FilePath> result = new ArrayList<FilePath>();
668 for (Change change : getCurrentIncludedChanges()) {
669 result.add(getFilePath(change));
671 return result.toArray(new FilePath[result.size()]);
674 public Project getProject() {
675 return myProject;
678 public List<VcsOperation> getCheckinOperations(CheckinEnvironment checkinEnvironment) {
679 throw new UnsupportedOperationException();
682 public void setCommitMessage(final String currentDescription) {
683 myCommitMessageArea.setText(currentDescription);
684 myCommitMessageArea.requestFocusInMessage();
687 public String getCommitMessage() {
688 return myCommitMessageArea.getComment();
691 public void refresh() {
692 for (RefreshableOnComponent component : myAdditionalComponents) {
693 component.refresh();
697 public void saveState() {
698 for (RefreshableOnComponent component : myAdditionalComponents) {
699 component.saveState();
703 public void restoreState() {
704 for (RefreshableOnComponent component : myAdditionalComponents) {
705 component.restoreState();
709 @NonNls
710 protected String getDimensionServiceKey() {
711 return "CommitChangelistDialog";
714 public JComponent getPreferredFocusedComponent() {
715 if (VcsConfiguration.getInstance(myProject).PUT_FOCUS_INTO_COMMENT) {
716 return myCommitMessageArea.getTextField();
718 else {
719 return myChangesList;
723 private Change[] getSelectedChanges() {
724 final Object[] o = myChangesList.getSelectedValues();
725 final Change[] changes = new Change[o.length];
726 for (int i = 0; i < changes.length; i++) {
727 changes[i] = (Change)o[i];
729 return changes;
732 private ChangeList[] getSelectedChangeLists() {
733 return new ChangeList[] {mySelectedChangeList};
736 private VirtualFile[] getSelectedFiles() {
737 final Change[] changes = getSelectedChanges();
738 ArrayList<VirtualFile> files = new ArrayList<VirtualFile>();
739 for (Change change : changes) {
740 final ContentRevision afterRevision = change.getAfterRevision();
741 if (afterRevision != null) {
742 final VirtualFile file = afterRevision.getFile().getVirtualFile();
743 if (file != null && file.isValid()) {
744 files.add(file);
748 return files.toArray(new VirtualFile[files.size()]);
751 @Nullable
752 public Object getData(String dataId) {
753 if (CheckinProjectPanel.PANEL.equals(dataId)) {
754 return this;
756 else if (DataConstants.CHANGES.equals(dataId)) {
757 return getSelectedChanges();
759 else if (DataConstants.CHANGE_LISTS.equals(dataId)) {
760 return getSelectedChangeLists();
762 else if (DataConstants.VIRTUAL_FILE_ARRAY.equals(dataId)) {
763 return getSelectedFiles();
766 return null;