Search in sources :

Example 1 with InternalModuleType

use of com.intellij.openapi.module.InternalModuleType in project intellij-community by JetBrains.

the class StructureViewWrapperImpl method rebuild.

public void rebuild() {
    if (myProject.isDisposed())
        return;
    Dimension referenceSize = null;
    if (myStructureView != null) {
        if (myStructureView instanceof StructureView.Scrollable) {
            referenceSize = ((StructureView.Scrollable) myStructureView).getCurrentSize();
        }
        myStructureView.storeState();
        Disposer.dispose(myStructureView);
        myStructureView = null;
        myFileEditor = null;
    }
    if (myModuleStructureComponent != null) {
        Disposer.dispose(myModuleStructureComponent);
        myModuleStructureComponent = null;
    }
    final ContentManager contentManager = myToolWindow.getContentManager();
    contentManager.removeAllContents(true);
    if (!isStructureViewShowing()) {
        return;
    }
    VirtualFile file = myFile;
    if (file == null) {
        final VirtualFile[] selectedFiles = FileEditorManager.getInstance(myProject).getSelectedFiles();
        if (selectedFiles.length > 0) {
            file = selectedFiles[0];
        }
    }
    String[] names = { "" };
    if (file != null && file.isValid()) {
        if (file.isDirectory()) {
            if (ProjectRootsUtil.isModuleContentRoot(file, myProject)) {
                Module module = ModuleUtilCore.findModuleForFile(file, myProject);
                if (module != null && !(ModuleUtil.getModuleType(module) instanceof InternalModuleType)) {
                    myModuleStructureComponent = new ModuleStructureComponent(module);
                    createSinglePanel(myModuleStructureComponent.getComponent());
                    Disposer.register(this, myModuleStructureComponent);
                }
            }
        } else {
            FileEditor editor = FileEditorManager.getInstance(myProject).getSelectedEditor(file);
            boolean needDisposeEditor = false;
            if (editor == null) {
                editor = createTempFileEditor(file);
                needDisposeEditor = true;
            }
            if (editor != null && editor.isValid()) {
                final StructureViewBuilder structureViewBuilder = editor.getStructureViewBuilder();
                if (structureViewBuilder != null) {
                    myStructureView = structureViewBuilder.createStructureView(editor, myProject);
                    myFileEditor = editor;
                    Disposer.register(this, myStructureView);
                    updateHeaderActions(myStructureView);
                    if (myStructureView instanceof StructureView.Scrollable) {
                        ((StructureView.Scrollable) myStructureView).setReferenceSizeWhileInitializing(referenceSize);
                    }
                    if (myStructureView instanceof StructureViewComposite) {
                        final StructureViewComposite composite = (StructureViewComposite) myStructureView;
                        final StructureViewComposite.StructureViewDescriptor[] views = composite.getStructureViews();
                        myPanels = new JPanel[views.length];
                        names = new String[views.length];
                        for (int i = 0; i < myPanels.length; i++) {
                            myPanels[i] = createContentPanel(views[i].structureView.getComponent());
                            names[i] = views[i].title;
                        }
                    } else {
                        createSinglePanel(myStructureView.getComponent());
                    }
                    myStructureView.restoreState();
                    myStructureView.centerSelectedRow();
                }
            }
            if (needDisposeEditor && editor != null) {
                Disposer.dispose(editor);
            }
        }
    }
    if (myModuleStructureComponent == null && myStructureView == null) {
        createSinglePanel(new JLabel(IdeBundle.message("message.nothing.to.show.in.structure.view"), SwingConstants.CENTER));
    }
    for (int i = 0; i < myPanels.length; i++) {
        final Content content = ContentFactory.SERVICE.getInstance().createContent(myPanels[i], names[i], false);
        contentManager.addContent(content);
        if (i == 0 && myStructureView != null) {
            Disposer.register(content, myStructureView);
        }
    }
    if (myPendingSelection != null) {
        Runnable selection = myPendingSelection;
        myPendingSelection = null;
        selection.run();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureViewComposite(com.intellij.ide.structureView.impl.StructureViewComposite) InternalModuleType(com.intellij.openapi.module.InternalModuleType) Module(com.intellij.openapi.module.Module)

Aggregations

StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 InternalModuleType (com.intellij.openapi.module.InternalModuleType)1 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1