Search in sources :

Example 1 with ProjectView

use of com.intellij.ide.projectView.ProjectView in project intellij-plugins by StepicOrg.

the class NavigationUtils method collapseNonSelected.

private static void collapseNonSelected(@NotNull PsiFileSystemItem file) {
    ProjectView projectView = ProjectView.getInstance(file.getProject());
    if (projectView == null) {
        return;
    }
    AbstractProjectViewPane projectViewPane = projectView.getCurrentProjectViewPane();
    if (projectViewPane == null) {
        return;
    }
    JTree tree = projectViewPane.getTree();
    Set<TreePath> paths = new HashSet<>(TreeUtil.collectExpandedPaths(tree));
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
    DefaultMutableTreeNode selectionNode = findNodeWithObject(root, file);
    if (selectionNode != null) {
        List<TreePath> toCollapse = new ArrayList<>();
        TreePath selectedPath = getPathFromRoot(selectionNode);
        for (TreePath treePath : paths) {
            if (treePath.isDescendant(selectedPath)) {
                continue;
            }
            TreePath currPath = treePath;
            TreePath parent = treePath.getParentPath();
            while (parent != null) {
                if (parent.isDescendant(selectedPath)) {
                    toCollapse.add(currPath);
                    break;
                }
                currPath = parent;
                parent = parent.getParentPath();
            }
        }
        for (TreePath path : toCollapse) {
            tree.collapsePath(path);
            tree.fireTreeCollapsed(path);
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) ProjectView(com.intellij.ide.projectView.ProjectView) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) HashSet(java.util.HashSet)

Example 2 with ProjectView

use of com.intellij.ide.projectView.ProjectView in project intellij-community by JetBrains.

the class ContentRootDataService method importData.

@Override
public void importData(@NotNull Collection<DataNode<ContentRootData>> toImport, @Nullable ProjectData projectData, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    if (toImport.isEmpty()) {
        return;
    }
    boolean isNewlyImportedProject = project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) == Boolean.TRUE;
    boolean forceDirectoriesCreation = false;
    DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(toImport.iterator().next(), ProjectKeys.PROJECT);
    if (projectDataNode != null) {
        forceDirectoriesCreation = projectDataNode.getUserData(CREATE_EMPTY_DIRECTORIES) == Boolean.TRUE;
    }
    Set<Module> modulesToExpand = ContainerUtil.newTroveSet();
    MultiMap<DataNode<ModuleData>, DataNode<ContentRootData>> byModule = ExternalSystemApiUtil.groupBy(toImport, ModuleData.class);
    for (Map.Entry<DataNode<ModuleData>, Collection<DataNode<ContentRootData>>> entry : byModule.entrySet()) {
        Module module = entry.getKey().getUserData(AbstractModuleDataService.MODULE_KEY);
        module = module != null ? module : modelsProvider.findIdeModule(entry.getKey().getData());
        if (module == null) {
            LOG.warn(String.format("Can't import content roots. Reason: target module (%s) is not found at the ide. Content roots: %s", entry.getKey(), entry.getValue()));
            continue;
        }
        importData(modelsProvider, entry.getValue(), module, forceDirectoriesCreation);
        if (forceDirectoriesCreation || (isNewlyImportedProject && projectData != null && projectData.getLinkedExternalProjectPath().equals(ExternalSystemApiUtil.getExternalProjectPath(module)))) {
            modulesToExpand.add(module);
        }
    }
    if (!modulesToExpand.isEmpty()) {
        for (Module module : modulesToExpand) {
            String productionModuleName = modelsProvider.getProductionModuleName(module);
            if (productionModuleName == null || !modulesToExpand.contains(modelsProvider.findIdeModule(productionModuleName))) {
                VirtualFile[] roots = modelsProvider.getModifiableRootModel(module).getContentRoots();
                if (roots.length > 0) {
                    VirtualFile virtualFile = roots[0];
                    ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, () -> {
                        final ProjectView projectView = ProjectView.getInstance(project);
                        projectView.changeViewCB(ProjectViewPane.ID, null).doWhenProcessed(() -> projectView.selectCB(null, virtualFile, false));
                    });
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentRootData(com.intellij.openapi.externalSystem.model.project.ContentRootData) Collection(java.util.Collection) ProjectView(com.intellij.ide.projectView.ProjectView) Module(com.intellij.openapi.module.Module) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 3 with ProjectView

use of com.intellij.ide.projectView.ProjectView in project intellij-community by JetBrains.

the class ProjectViewSelectInGroupTarget method canSelect.

@Override
public boolean canSelect(SelectInContext context) {
    ProjectView projectView = ProjectView.getInstance(context.getProject());
    Collection<SelectInTarget> targets = projectView.getSelectInTargets();
    for (SelectInTarget projectViewTarget : targets) {
        if (projectViewTarget.canSelect(context))
            return true;
    }
    return false;
}
Also used : CompositeSelectInTarget(com.intellij.ide.CompositeSelectInTarget) SelectInTarget(com.intellij.ide.SelectInTarget) ProjectView(com.intellij.ide.projectView.ProjectView)

Example 4 with ProjectView

use of com.intellij.ide.projectView.ProjectView in project intellij-community by JetBrains.

the class ScopeTreeViewPanel method refreshScope.

public void refreshScope(@Nullable NamedScope scope) {
    FileTreeModelBuilder.clearCaches(myProject);
    if (scope == null) {
        //was deleted
        scope = CustomScopesProviderEx.getAllScope();
    }
    final NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, scope.getName(), myDependencyValidationManager);
    final PackageSet packageSet = scope.getValue() != null ? scope.getValue() : new InvalidPackageSet("");
    final DependenciesPanel.DependencyPanelSettings settings = new DependenciesPanel.DependencyPanelSettings();
    settings.UI_FILTER_LEGALS = true;
    settings.UI_GROUP_BY_SCOPE_TYPE = false;
    settings.UI_SHOW_FILES = true;
    final ProjectView projectView = ProjectView.getInstance(myProject);
    settings.UI_FLATTEN_PACKAGES = projectView.isFlattenPackages(ScopeViewPane.ID);
    settings.UI_COMPACT_EMPTY_MIDDLE_PACKAGES = projectView.isHideEmptyMiddlePackages(ScopeViewPane.ID);
    settings.UI_SHOW_MODULES = projectView.isShowModules(ScopeViewPane.ID);
    settings.UI_SHOW_MODULE_GROUPS = projectView.isShowModules(ScopeViewPane.ID);
    myBuilder = new FileTreeModelBuilder(myProject, new Marker() {

        @Override
        public boolean isMarked(VirtualFile file) {
            return packageSet != null && (packageSet instanceof PackageSetBase ? ((PackageSetBase) packageSet).contains(file, myProject, holder) : packageSet.contains(PackageSetBase.getPsiFile(file, myProject), holder));
        }
    }, settings);
    myTree.setPaintBusy(true);
    myBuilder.setTree(myTree);
    myTree.getEmptyText().setText("Loading...");
    myActionCallback = new ActionCallback();
    myTree.putClientProperty(TreeState.CALLBACK, new WeakReference<>(myActionCallback));
    myTree.setModel(myBuilder.build(myProject, true, () -> {
        myTree.setPaintBusy(false);
        myTree.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
        myActionCallback.setDone();
    }));
    ((PackageDependenciesNode) myTree.getModel().getRoot()).sortChildren();
    ((DefaultTreeModel) myTree.getModel()).reload();
    FileTreeModelBuilder.clearCaches(myProject);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionCallback(com.intellij.openapi.util.ActionCallback) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ProjectView(com.intellij.ide.projectView.ProjectView)

Example 5 with ProjectView

use of com.intellij.ide.projectView.ProjectView in project intellij-community by JetBrains.

the class ChangeProjectViewAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    ProjectView projectView = ProjectView.getInstance(project);
    projectView.changeView();
}
Also used : Project(com.intellij.openapi.project.Project) ProjectView(com.intellij.ide.projectView.ProjectView)

Aggregations

ProjectView (com.intellij.ide.projectView.ProjectView)19 NotNull (org.jetbrains.annotations.NotNull)8 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 SelectInTarget (com.intellij.ide.SelectInTarget)3 AbstractProjectViewPane (com.intellij.ide.projectView.impl.AbstractProjectViewPane)3 Module (com.intellij.openapi.module.Module)3 ActionCallback (com.intellij.openapi.util.ActionCallback)3 ToolWindow (com.intellij.openapi.wm.ToolWindow)3 CompositeSelectInTarget (com.intellij.ide.CompositeSelectInTarget)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)2 ArrayList (java.util.ArrayList)2 GuiTask (org.fest.swing.edt.GuiTask)2 Condition (org.fest.swing.timing.Condition)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 DataManager (com.intellij.ide.DataManager)1 PsiCopyPasteManager (com.intellij.ide.PsiCopyPasteManager)1 com.intellij.ide.dnd (com.intellij.ide.dnd)1 DnDAwareTree (com.intellij.ide.dnd.aware.DnDAwareTree)1