Search in sources :

Example 96 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project azure-tools-for-java by Microsoft.

the class UIHelperImpl method openMySQLPropertyView.

@Override
public void openMySQLPropertyView(@NotNull String id, @NotNull Object project) {
    EventUtil.executeWithLog(ActionConstants.MySQL.SHOW_PROPERTIES, (operation) -> {
        final ResourceId resourceId = ResourceId.fromString(id);
        final FileEditorManager fileEditorManager = getFileEditorManager(resourceId.subscriptionId(), resourceId.id(), (Project) project);
        if (fileEditorManager == null) {
            return;
        }
        LightVirtualFile itemVirtualFile = searchExistingFile(fileEditorManager, MySQLPropertyViewProvider.TYPE, resourceId.id());
        if (itemVirtualFile == null) {
            itemVirtualFile = createVirtualFile(resourceId.name(), resourceId.subscriptionId(), resourceId.id());
            itemVirtualFile.setFileType(new AzureFileType(MySQLPropertyViewProvider.TYPE, AzureIconLoader.loadIcon(AzureIconSymbol.MySQL.MODULE)));
        }
        FileEditor[] editors = fileEditorManager.openFile(itemVirtualFile, true, true);
        for (FileEditor editor : editors) {
            if (editor.getName().equals(MySQLPropertyView.ID) && editor instanceof MySQLPropertyView) {
                ((MySQLPropertyView) editor).onReadProperty(resourceId.subscriptionId(), resourceId.resourceGroupName(), resourceId.name());
            }
        }
    });
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TableFileEditor(com.microsoft.intellij.helpers.storage.TableFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) QueueFileEditor(com.microsoft.intellij.helpers.storage.QueueFileEditor) BlobExplorerFileEditor(com.microsoft.intellij.helpers.storage.BlobExplorerFileEditor) ResourceId(com.azure.resourcemanager.resources.fluentcore.arm.ResourceId) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) MySQLPropertyView(com.microsoft.azure.toolkit.intellij.mysql.MySQLPropertyView)

Example 97 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project azure-tools-for-java by Microsoft.

the class UIHelperImpl method openRedisPropertyView.

@Override
public void openRedisPropertyView(@NotNull RedisCacheNode node) {
    EventUtil.executeWithLog(TelemetryConstants.REDIS, TelemetryConstants.REDIS_READPROP, (operation) -> {
        String redisName = node.getName() != null ? node.getName() : RedisCacheNode.TYPE;
        String sid = node.getSubscriptionId();
        String resId = node.getResourceId();
        if (isSubscriptionIdAndResourceIdEmpty(sid, resId)) {
            return;
        }
        Project project = (Project) node.getProject();
        FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
        if (fileEditorManager == null) {
            showError(CANNOT_GET_FILE_EDITOR_MANAGER, UNABLE_TO_OPEN_EDITOR_WINDOW);
            return;
        }
        LightVirtualFile itemVirtualFile = searchExistingFile(fileEditorManager, RedisCachePropertyViewProvider.TYPE, resId);
        if (itemVirtualFile == null) {
            itemVirtualFile = createVirtualFile(redisName, sid, resId);
            itemVirtualFile.setFileType(new AzureFileType(RedisCachePropertyViewProvider.TYPE, AzureIconLoader.loadIcon(AzureIconSymbol.RedisCache.MODULE)));
        }
        FileEditor[] editors = fileEditorManager.openFile(itemVirtualFile, true, true);
        for (FileEditor editor : editors) {
            if (editor.getName().equals(RedisCachePropertyView.ID) && editor instanceof RedisCachePropertyView) {
                ((RedisCachePropertyView) editor).onReadProperty(sid, resId);
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TableFileEditor(com.microsoft.intellij.helpers.storage.TableFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) QueueFileEditor(com.microsoft.intellij.helpers.storage.QueueFileEditor) BlobExplorerFileEditor(com.microsoft.intellij.helpers.storage.BlobExplorerFileEditor) RedisCachePropertyView(com.microsoft.azure.toolkit.intellij.redis.RedisCachePropertyView) LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Example 98 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij by bazelbuild.

the class GlobFindUsagesTest method testInMemoryFileHandledGracefully.

// regression test for b/29267289
@Test
public void testInMemoryFileHandledGracefully() {
    createBuildFile(new WorkspacePath("java/com/google/BUILD"), "glob(['**/*.java'])");
    LightVirtualFile inMemoryFile = new LightVirtualFile("mockProjectViewFile", ProjectViewLanguage.INSTANCE, "");
    FileManager fileManager = ((PsiManagerEx) PsiManager.getInstance(getProject())).getFileManager();
    fileManager.setViewProvider(inMemoryFile, fileManager.createFileViewProvider(inMemoryFile, true));
    PsiFile psiFile = fileManager.findFile(inMemoryFile);
    FindUsages.findAllReferences(psiFile);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFile(com.intellij.psi.PsiFile) FileManager(com.intellij.psi.impl.file.impl.FileManager) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) Test(org.junit.Test)

Example 99 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij by bazelbuild.

the class ProjectViewElementGenerator method createDummyFile.

private static PsiFile createDummyFile(Project project, String contents) {
    PsiFileFactory factory = PsiFileFactory.getInstance(project);
    LightVirtualFile virtualFile = new LightVirtualFile(DUMMY_FILENAME, ProjectViewFileType.INSTANCE, contents);
    PsiFile psiFile = ((PsiFileFactoryImpl) factory).trySetupPsiForFile(virtualFile, ProjectViewLanguage.INSTANCE, false, true);
    assert psiFile != null;
    return psiFile;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) PsiFile(com.intellij.psi.PsiFile)

Example 100 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij by bazelbuild.

the class ProjectViewUi method createEditor.

private static EditorEx createEditor(String tooltip) {
    Project project = getProject();
    LightVirtualFile virtualFile = new LightVirtualFile("mockProjectViewFile", ProjectViewLanguage.INSTANCE, "");
    final Document document = ((EditorFactoryImpl) EditorFactory.getInstance()).createDocument(true);
    ((DocumentImpl) document).setAcceptSlashR(true);
    FileDocumentManagerImpl.registerDocument(document, virtualFile);
    FileManager fileManager = ((PsiManagerEx) PsiManager.getInstance(project)).getFileManager();
    fileManager.setViewProvider(virtualFile, fileManager.createFileViewProvider(virtualFile, true));
    if (project.isDefault()) {
        // Undo-redo doesn't work with the default project.
        // Explicitly turn it off to avoid error dialogs.
        UndoUtil.disableUndoFor(document);
    }
    EditorEx editor = (EditorEx) EditorFactory.getInstance().createEditor(document, project, ProjectViewFileType.INSTANCE, false);
    final EditorSettings settings = editor.getSettings();
    settings.setLineNumbersShown(false);
    settings.setLineMarkerAreaShown(false);
    settings.setFoldingOutlineShown(false);
    settings.setRightMarginShown(false);
    settings.setAdditionalPageAtBottom(false);
    editor.getComponent().setMinimumSize(getEditorSize());
    editor.getComponent().setPreferredSize(getEditorSize());
    editor.getComponent().setToolTipText(tooltip);
    editor.getComponent().setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    editor.getComponent().setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
    return editor;
}
Also used : Project(com.intellij.openapi.project.Project) EditorSettings(com.intellij.openapi.editor.EditorSettings) EditorEx(com.intellij.openapi.editor.ex.EditorEx) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Document(com.intellij.openapi.editor.Document) EditorFactoryImpl(com.intellij.openapi.editor.impl.EditorFactoryImpl) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) FileManager(com.intellij.psi.impl.file.impl.FileManager) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Aggregations

LightVirtualFile (com.intellij.testFramework.LightVirtualFile)102 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 NotNull (org.jetbrains.annotations.NotNull)14 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)13 Nullable (org.jetbrains.annotations.Nullable)13 PsiFile (com.intellij.psi.PsiFile)12 Project (com.intellij.openapi.project.Project)11 Document (com.intellij.openapi.editor.Document)9 FileEditor (com.intellij.openapi.fileEditor.FileEditor)8 FileType (com.intellij.openapi.fileTypes.FileType)8 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)7 FileManager (com.intellij.psi.impl.file.impl.FileManager)7 IpnbFile (org.jetbrains.plugins.ipnb.format.IpnbFile)7 BlobExplorerFileEditor (com.microsoft.intellij.helpers.storage.BlobExplorerFileEditor)6 QueueFileEditor (com.microsoft.intellij.helpers.storage.QueueFileEditor)6 TableFileEditor (com.microsoft.intellij.helpers.storage.TableFileEditor)6 Language (com.intellij.lang.Language)5 PsiFileFactoryImpl (com.intellij.psi.impl.PsiFileFactoryImpl)5 FileElement (com.intellij.psi.impl.source.tree.FileElement)5 FileViewProvider (com.intellij.psi.FileViewProvider)4