use of com.intellij.ide.projectView.impl.ModuleGroup in project intellij-community by JetBrains.
the class ModuleStructureConfigurable method addModuleNode.
private void addModuleNode(final Module module) {
final TreePath selectionPath = myTree.getSelectionPath();
MyNode parent = null;
if (selectionPath != null) {
MyNode selected = (MyNode) selectionPath.getLastPathComponent();
final Object o = selected.getConfigurable().getEditableObject();
if (o instanceof ModuleGroup) {
myContext.myModulesConfigurator.getModuleModel().setModuleGroupPath(module, ((ModuleGroup) o).getGroupPath());
parent = selected;
} else if (o instanceof Module) {
//create near selected
final ModifiableModuleModel modifiableModuleModel = myContext.myModulesConfigurator.getModuleModel();
final String[] groupPath = modifiableModuleModel.getModuleGroupPath((Module) o);
if (groupPath != null) {
modifiableModuleModel.setModuleGroupPath(module, groupPath);
parent = findNodeByObject(myRoot, new ModuleGroup(Arrays.asList(groupPath)));
}
}
}
if (parent == null)
parent = myRoot;
MyNode node = createModuleNode(module, getModuleGrouper());
TreeUtil.insertNode(node, parent, getTreeModel(), getNodeComparator());
selectNodeInTree(node);
final ProjectStructureDaemonAnalyzer daemonAnalyzer = myContext.getDaemonAnalyzer();
daemonAnalyzer.queueUpdate(new ModuleProjectStructureElement(myContext, module));
//missing modules added
daemonAnalyzer.queueUpdateForAllElementsWithErrors();
}
use of com.intellij.ide.projectView.impl.ModuleGroup in project intellij-community by JetBrains.
the class DirectoryChooserModuleTreeView method addItem.
@Override
public void addItem(DirectoryChooser.ItemWrapper itemWrapper) {
myItems.add(itemWrapper);
final PsiDirectory directory = itemWrapper.getDirectory();
final Module module = myFileIndex.getModuleForFile(directory.getVirtualFile());
DefaultMutableTreeNode node = myModuleNodes.get(module);
if (node == null) {
node = new DefaultMutableTreeNode(module, true);
final List<String> groupPath = module != null ? myModuleGrouper.getGroupPath(module) : null;
if (groupPath == null || groupPath.isEmpty()) {
insertNode(node, myRootNode);
} else {
final DefaultMutableTreeNode parentNode = ModuleGroupUtil.buildModuleGroupPath(new ModuleGroup(groupPath), myRootNode, myModuleGroupNodes, parentChildRelation -> insertNode(parentChildRelation.getChild(), parentChildRelation.getParent()), moduleGroup -> new DefaultMutableTreeNode(moduleGroup, true));
insertNode(node, parentNode);
}
myModuleNodes.put(module, node);
}
final DefaultMutableTreeNode itemNode = new DefaultMutableTreeNode(itemWrapper, false);
myItemNodes.put(itemWrapper, itemNode);
insertNode(itemNode, node);
((DefaultTreeModel) myTree.getModel()).nodeStructureChanged(node);
}
use of com.intellij.ide.projectView.impl.ModuleGroup in project intellij-community by JetBrains.
the class AddToFavoritesAction method createNodes.
@NotNull
public static Collection<AbstractTreeNode> createNodes(Project project, Module moduleContext, Object object, boolean inProjectView, ViewSettings favoritesConfig) {
if (project == null)
return Collections.emptyList();
ArrayList<AbstractTreeNode> result = new ArrayList<>();
for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
final AbstractTreeNode treeNode = provider.createNode(project, object, favoritesConfig);
if (treeNode != null) {
result.add(treeNode);
return result;
}
}
final PsiManager psiManager = PsiManager.getInstance(project);
final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
AbstractProjectViewPane pane = ProjectView.getInstance(project).getProjectViewPaneById(currentViewId);
//on psi elements
if (object instanceof PsiElement[]) {
for (PsiElement psiElement : (PsiElement[]) object) {
addPsiElementNode(psiElement, project, result, favoritesConfig);
}
return result;
}
//on psi element
if (object instanceof PsiElement) {
Module containingModule = null;
if (inProjectView && ProjectView.getInstance(project).isShowModules(currentViewId)) {
if (pane != null && pane.getSelectedDescriptor() != null && pane.getSelectedDescriptor().getElement() instanceof AbstractTreeNode) {
AbstractTreeNode abstractTreeNode = ((AbstractTreeNode) pane.getSelectedDescriptor().getElement());
while (abstractTreeNode != null && !(abstractTreeNode.getParent() instanceof AbstractModuleNode)) {
abstractTreeNode = abstractTreeNode.getParent();
}
if (abstractTreeNode != null) {
containingModule = ((AbstractModuleNode) abstractTreeNode.getParent()).getValue();
}
}
}
addPsiElementNode((PsiElement) object, project, result, favoritesConfig);
return result;
}
if (object instanceof VirtualFile[]) {
for (VirtualFile vFile : (VirtualFile[]) object) {
PsiElement element = psiManager.findFile(vFile);
if (element == null)
element = psiManager.findDirectory(vFile);
addPsiElementNode(element, project, result, favoritesConfig);
}
return result;
}
//on form in editor
if (object instanceof VirtualFile) {
final VirtualFile vFile = (VirtualFile) object;
final PsiFile psiFile = psiManager.findFile(vFile);
addPsiElementNode(psiFile, project, result, favoritesConfig);
return result;
}
//on module groups
if (object instanceof ModuleGroup[]) {
for (ModuleGroup moduleGroup : (ModuleGroup[]) object) {
result.add(new ProjectViewModuleGroupNode(project, moduleGroup, favoritesConfig));
}
return result;
}
//on module nodes
if (object instanceof Module)
object = new Module[] { (Module) object };
if (object instanceof Module[]) {
for (Module module1 : (Module[]) object) {
result.add(new ProjectViewModuleNode(project, module1, favoritesConfig));
}
return result;
}
//on library group node
if (object instanceof LibraryGroupElement[]) {
for (LibraryGroupElement libraryGroup : (LibraryGroupElement[]) object) {
result.add(new LibraryGroupNode(project, libraryGroup, favoritesConfig));
}
return result;
}
//on named library node
if (object instanceof NamedLibraryElement[]) {
for (NamedLibraryElement namedLibrary : (NamedLibraryElement[]) object) {
result.add(new NamedLibraryElementNode(project, namedLibrary, favoritesConfig));
}
return result;
}
return result;
}
use of com.intellij.ide.projectView.impl.ModuleGroup in project intellij-community by JetBrains.
the class MoveModulesToSubGroupAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
final List<String> newGroup;
if (myModuleGroup != null) {
String message = IdeBundle.message("prompt.specify.name.of.module.subgroup", myModuleGroup.presentableText(), whatToMove(modules));
String subgroup = Messages.showInputDialog(message, IdeBundle.message("title.module.sub.group"), Messages.getQuestionIcon());
if (subgroup == null || "".equals(subgroup.trim()))
return;
newGroup = ContainerUtil.append(myModuleGroup.getGroupPathList(), subgroup);
} else {
String message = IdeBundle.message("prompt.specify.module.group.name", whatToMove(modules));
String group = Messages.showInputDialog(message, IdeBundle.message("title.module.group"), Messages.getQuestionIcon());
if (group == null || "".equals(group.trim()))
return;
newGroup = Collections.singletonList(group);
}
doMove(modules, new ModuleGroup(newGroup), dataContext);
}
use of com.intellij.ide.projectView.impl.ModuleGroup in project intellij-community by JetBrains.
the class AbstractProjectNode method modulesAndGroups.
protected Collection<AbstractTreeNode> modulesAndGroups(Module[] modules) {
Map<String, List<Module>> groups = new THashMap<>();
List<Module> nonGroupedModules = new ArrayList<>(Arrays.asList(modules));
for (final Module module : modules) {
final String[] path = ModuleManager.getInstance(getProject()).getModuleGroupPath(module);
if (path != null) {
final String topLevelGroupName = path[0];
groups.computeIfAbsent(topLevelGroupName, k -> new ArrayList<>()).add(module);
nonGroupedModules.remove(module);
}
}
List<AbstractTreeNode> result = new ArrayList<>();
try {
for (String groupPath : groups.keySet()) {
result.add(createModuleGroupNode(new ModuleGroup(Collections.singletonList(groupPath))));
}
for (Module module : nonGroupedModules) {
result.add(createModuleGroup(module));
}
} catch (Exception e) {
LOG.error(e);
return new ArrayList<>();
}
return result;
}
Aggregations