Common updateContent method for Merge and UpdateTo dialog moved to HgUiUtil

*annotations added
*appropriate argument list changed, method became static
*tags/branches maps in HgBranchesAndTags simplify using container util maps
This commit is contained in:
Nadya Zabrodina
2013-08-21 20:30:33 +04:00
parent 2bb8b9c046
commit 3cd7a98eea
4 changed files with 22 additions and 42 deletions
@@ -24,6 +24,7 @@ import org.zmlx.hg4idea.command.HgHeadsCommand;
import org.zmlx.hg4idea.command.HgTagBranch;
import org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand;
import org.zmlx.hg4idea.util.HgBranchesAndTags;
import org.zmlx.hg4idea.util.HgUiUtil;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@@ -119,9 +120,9 @@ public class HgMergeDialog extends DialogWrapper {
private void updateRepository() {
VirtualFile repo = getRepository();
loadBranches(repo);
loadTags(repo);
loadBookmarks(repo);
HgUiUtil.loadContentToDialog(repo, branchesForRepos, branchSelector);
HgUiUtil.loadContentToDialog(repo, tagsForRepos, tagSelector);
HgUiUtil.loadContentToDialog(repo, bookmarksForRepos, bookmarkSelector);
loadHeads(repo);
}
@@ -132,21 +133,6 @@ public class HgMergeDialog extends DialogWrapper {
bookmarkSelector.setEnabled(bookmarkOption.isSelected());
}
private void loadBranches(VirtualFile root) {
assert branchesForRepos.get(root) != null : "No inforamtion about root " + root;
branchSelector.setModel(new DefaultComboBoxModel(branchesForRepos.get(root).toArray()));
}
private void loadTags(VirtualFile root) {
assert tagsForRepos.get(root) != null : "No inforamtion about root " + root;
tagSelector.setModel(new DefaultComboBoxModel(tagsForRepos.get(root).toArray()));
}
private void loadBookmarks(VirtualFile root) {
assert tagsForRepos.get(root) != null : "No inforamtion about root " + root;
bookmarkSelector.setModel(new DefaultComboBoxModel(bookmarksForRepos.get(root).toArray()));
}
private void loadHeads(final VirtualFile root) {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
@@ -19,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.command.HgTagBranch;
import org.zmlx.hg4idea.util.HgBranchesAndTags;
import org.zmlx.hg4idea.util.HgUiUtil;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@@ -130,27 +131,12 @@ public class HgUpdateToDialog extends DialogWrapper {
private void updateRepository() {
VirtualFile repo = hgRepositorySelectorComponent.getRepository();
loadBranches(repo);
loadTags(repo);
loadBookmarks(repo);
HgUiUtil.loadContentToDialog(repo, branchesForRepos, branchSelector);
HgUiUtil.loadContentToDialog(repo, tagsForRepos, tagSelector);
HgUiUtil.loadContentToDialog(repo, bookmarksForRepos, bookmarkSelector);
update();
}
private void loadBranches(VirtualFile root) {
assert branchesForRepos.get(root) != null : "No inforamtion about root " + root;
branchSelector.setModel(new DefaultComboBoxModel(branchesForRepos.get(root).toArray()));
}
private void loadTags(VirtualFile root) {
assert tagsForRepos.get(root) != null : "No inforamtion about root " + root;
tagSelector.setModel(new DefaultComboBoxModel(tagsForRepos.get(root).toArray()));
}
private void loadBookmarks(VirtualFile root) {
assert tagsForRepos.get(root) != null : "No inforamtion about root " + root;
bookmarkSelector.setModel(new DefaultComboBoxModel(bookmarksForRepos.get(root).toArray()));
}
protected JComponent createCenterPanel() {
return contentPanel;
}
@@ -16,7 +16,7 @@
package org.zmlx.hg4idea.util;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.HashMap;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.zmlx.hg4idea.command.HgTagBranch;
@@ -29,11 +29,9 @@ import java.util.Map;
public class HgBranchesAndTags {
@NotNull private final Map<VirtualFile, Collection<HgTagBranch>> branchesForRepos = new HashMap<VirtualFile, Collection<HgTagBranch>>();
@NotNull private final Map<VirtualFile, Collection<HgTagBranch>> tagsForRepos = new HashMap<VirtualFile, Collection<HgTagBranch>>();
@NotNull private final Map<VirtualFile, Collection<HgTagBranch>> bookmarks =
new java.util.HashMap<VirtualFile, Collection<HgTagBranch>>();
@NotNull private final Map<VirtualFile, Collection<HgTagBranch>> branchesForRepos = ContainerUtil.newHashMap();
@NotNull private final Map<VirtualFile, Collection<HgTagBranch>> tagsForRepos = ContainerUtil.newHashMap();
@NotNull private final Map<VirtualFile, Collection<HgTagBranch>> bookmarks = ContainerUtil.newHashMap();
@NotNull
public Map<VirtualFile, Collection<HgTagBranch>> getBranchesForRepos() {
@@ -21,12 +21,16 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgVcsMessages;
import org.zmlx.hg4idea.action.HgCommandResultNotifier;
import org.zmlx.hg4idea.command.HgTagBranch;
import org.zmlx.hg4idea.command.HgTagBranchCommand;
import org.zmlx.hg4idea.execution.HgCommandResult;
import javax.swing.*;
import java.util.Collection;
import java.util.Map;
/**
* @author Nadya Zabrodina
@@ -76,4 +80,10 @@ public class HgUiUtil {
}
}.queue();
}
public static void loadContentToDialog(@Nullable VirtualFile root, @NotNull Map<VirtualFile, Collection<HgTagBranch>> contentMap,
@NotNull JComboBox selector) {
assert contentMap.get(root) != null : "No information about root " + root;
selector.setModel(new DefaultComboBoxModel(contentMap.get(root).toArray()));
}
}