use of com.intellij.util.containers.Convertor in project intellij-community by JetBrains.
the class MavenSelectProjectPopup method attachToButton.
public static void attachToButton(@NotNull final MavenProjectsManager projectsManager, @NotNull final JButton button, @NotNull final Consumer<MavenProject> callback) {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<MavenProject> projectList = projectsManager.getProjects();
if (projectList.isEmpty()) {
JBPopupFactory.getInstance().createMessage("Maven projects not found").showUnderneathOf(button);
return;
}
DefaultMutableTreeNode root = buildTree(projectList);
final Map<MavenProject, String> projectsNameMap = MavenProjectNamer.generateNameMap(projectList);
final Tree projectTree = new Tree(root);
projectTree.setRootVisible(false);
projectTree.setCellRenderer(new NodeRenderer() {
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (value instanceof DefaultMutableTreeNode) {
MavenProject mavenProject = (MavenProject) ((DefaultMutableTreeNode) value).getUserObject();
value = projectsNameMap.get(mavenProject);
setIcon(MavenIcons.MavenProject);
}
super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
}
});
new TreeSpeedSearch(projectTree, new Convertor<TreePath, String>() {
@Override
public String convert(TreePath o) {
Object lastPathComponent = o.getLastPathComponent();
if (!(lastPathComponent instanceof DefaultMutableTreeNode))
return null;
Object userObject = ((DefaultMutableTreeNode) lastPathComponent).getUserObject();
//noinspection SuspiciousMethodCalls
return projectsNameMap.get(userObject);
}
});
final Ref<JBPopup> popupRef = new Ref<>();
final Runnable clickCallBack = () -> {
TreePath path = projectTree.getSelectionPath();
if (path == null)
return;
Object lastPathComponent = path.getLastPathComponent();
if (!(lastPathComponent instanceof DefaultMutableTreeNode))
return;
Object object = ((DefaultMutableTreeNode) lastPathComponent).getUserObject();
// may be it's the root
if (object == null)
return;
callback.consume((MavenProject) object);
popupRef.get().closeOk(null);
};
projectTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
clickCallBack.run();
e.consume();
}
}
});
JBPopup popup = new PopupChooserBuilder(projectTree).setTitle("Select maven project").setResizable(true).setItemChoosenCallback(clickCallBack).setAutoselectOnMouseMove(true).setCloseOnEnter(false).createPopup();
popupRef.set(popup);
popup.showUnderneathOf(button);
}
private DefaultMutableTreeNode buildTree(List<MavenProject> projectList) {
MavenProject[] projects = projectList.toArray(new MavenProject[projectList.size()]);
Arrays.sort(projects, new MavenProjectNamer.MavenProjectComparator());
Map<MavenProject, DefaultMutableTreeNode> projectsToNode = new HashMap<>();
for (MavenProject mavenProject : projects) {
projectsToNode.put(mavenProject, new DefaultMutableTreeNode(mavenProject));
}
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
for (MavenProject mavenProject : projects) {
DefaultMutableTreeNode parent;
MavenProject aggregator = projectsManager.findAggregator(mavenProject);
if (aggregator != null) {
parent = projectsToNode.get(aggregator);
} else {
parent = root;
}
parent.add(projectsToNode.get(mavenProject));
}
return root;
}
});
}
use of com.intellij.util.containers.Convertor in project intellij-community by JetBrains.
the class FavoritesManager method removeRoot.
public synchronized boolean removeRoot(@NotNull String name, @NotNull List<AbstractTreeNode> elements) {
final Convertor<AbstractTreeNode, AbstractUrl> convertor = new Convertor<AbstractTreeNode, AbstractUrl>() {
@Override
public AbstractUrl convert(AbstractTreeNode obj) {
return createUrlByElement(obj.getValue(), myProject);
}
};
boolean result = true;
for (AbstractTreeNode element : elements) {
final List<AbstractTreeNode> path = TaskDefaultFavoriteListProvider.getPathToUsualNode(element);
result &= findListToRemoveFrom(name, path.subList(1, path.size()), convertor);
}
return result;
}
use of com.intellij.util.containers.Convertor in project intellij-community by JetBrains.
the class LayoutTree method configureUiHelper.
@Override
protected void configureUiHelper(TreeUIHelper helper) {
final Convertor<TreePath, String> convertor = new Convertor<TreePath, String>() {
@Override
public String convert(final TreePath path) {
final SimpleNode node = getNodeFor(path);
if (node instanceof PackagingElementNode) {
return ((PackagingElementNode<?>) node).getElementPresentation().getSearchName();
}
return "";
}
};
new TreeSpeedSearch(this, convertor, true);
}
use of com.intellij.util.containers.Convertor in project intellij-community by JetBrains.
the class NewMappings method removeRedundantMappings.
// todo area for optimization
private void removeRedundantMappings() {
final LocalFileSystem lfs = LocalFileSystem.getInstance();
final AllVcsesI allVcses = AllVcses.getInstance(myProject);
for (Iterator<String> iterator = myVcsToPaths.keySet().iterator(); iterator.hasNext(); ) {
final String vcsName = iterator.next();
final Collection<VcsDirectoryMapping> mappings = myVcsToPaths.get(vcsName);
final List<Pair<VirtualFile, VcsDirectoryMapping>> objects = ObjectsConvertor.convert(mappings, new Convertor<VcsDirectoryMapping, Pair<VirtualFile, VcsDirectoryMapping>>() {
public Pair<VirtualFile, VcsDirectoryMapping> convert(final VcsDirectoryMapping dm) {
VirtualFile vf = lfs.findFileByPath(dm.getDirectory());
if (vf == null) {
vf = lfs.refreshAndFindFileByPath(dm.getDirectory());
}
return vf == null ? null : Pair.create(vf, dm);
}
}, ObjectsConvertor.NOT_NULL);
final List<Pair<VirtualFile, VcsDirectoryMapping>> filteredFiles;
// todo static
final Convertor<Pair<VirtualFile, VcsDirectoryMapping>, VirtualFile> fileConvertor = new Convertor<Pair<VirtualFile, VcsDirectoryMapping>, VirtualFile>() {
public VirtualFile convert(Pair<VirtualFile, VcsDirectoryMapping> o) {
return o.getFirst();
}
};
if (StringUtil.isEmptyOrSpaces(vcsName)) {
filteredFiles = AbstractVcs.filterUniqueRootsDefault(objects, fileConvertor);
} else {
final AbstractVcs<?> vcs = allVcses.getByName(vcsName);
if (vcs == null) {
VcsBalloonProblemNotifier.showOverChangesView(myProject, "VCS plugin not found for mapping to : '" + vcsName + "'", MessageType.ERROR);
continue;
}
filteredFiles = vcs.filterUniqueRoots(objects, fileConvertor);
}
final List<VcsDirectoryMapping> filteredMappings = ObjectsConvertor.convert(filteredFiles, new Convertor<Pair<VirtualFile, VcsDirectoryMapping>, VcsDirectoryMapping>() {
public VcsDirectoryMapping convert(final Pair<VirtualFile, VcsDirectoryMapping> o) {
return o.getSecond();
}
});
// to calculate what had been removed
mappings.removeAll(filteredMappings);
if (filteredMappings.isEmpty()) {
iterator.remove();
} else {
mappings.clear();
mappings.addAll(filteredMappings);
}
}
sortedMappingsByMap();
}
use of com.intellij.util.containers.Convertor in project intellij-community by JetBrains.
the class GitOutgoingChangesProvider method getOutgoingChanges.
public Pair<VcsRevisionNumber, List<CommittedChangeList>> getOutgoingChanges(final VirtualFile vcsRoot, final boolean findRemote) throws VcsException {
LOG.debug("getOutgoingChanges root: " + vcsRoot.getPath());
final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, findRemote);
if (searcher.getLocal() == null || searcher.getRemote() == null) {
return new Pair<>(null, Collections.<CommittedChangeList>emptyList());
}
final GitRevisionNumber base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
if (base == null) {
return new Pair<>(null, Collections.<CommittedChangeList>emptyList());
}
final List<GitCommittedChangeList> lists = GitUtil.getLocalCommittedChanges(myProject, vcsRoot, new Consumer<GitSimpleHandler>() {
public void consume(final GitSimpleHandler handler) {
handler.addParameters(base.asString() + "..HEAD");
}
});
return new Pair<>(base, ObjectsConvertor.convert(lists, new Convertor<GitCommittedChangeList, CommittedChangeList>() {
@Override
public CommittedChangeList convert(GitCommittedChangeList o) {
return o;
}
}));
}
Aggregations