com.intellij.json.JsonFileType Java Examples

The following examples show how to use com.intellij.json.JsonFileType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NewClassDialog.java    From json2java4idea with Apache License 2.0 6 votes vote down vote up
private void createUIComponents() {
    final EditorFactory editorFactory = EditorFactory.getInstance();
    jsonDocument = editorFactory.createDocument(EMPTY_TEXT);
    jsonEditor = editorFactory.createEditor(jsonDocument, project, JsonFileType.INSTANCE, false);

    final EditorSettings settings = jsonEditor.getSettings();
    settings.setWhitespacesShown(true);
    settings.setLineMarkerAreaShown(false);
    settings.setIndentGuidesShown(false);
    settings.setLineNumbersShown(true);
    settings.setFoldingOutlineShown(false);
    settings.setRightMarginShown(false);
    settings.setVirtualSpace(false);
    settings.setWheelFontChangeEnabled(false);
    settings.setUseSoftWraps(false);
    settings.setAdditionalColumnsCount(0);
    settings.setAdditionalLinesCount(1);

    final EditorColorsScheme colorsScheme = jsonEditor.getColorsScheme();
    colorsScheme.setColor(EditorColors.CARET_ROW_COLOR, null);

    jsonEditor.getContentComponent().setFocusable(true);
    jsonPanel = (JPanel) jsonEditor.getComponent();
}
 
Example #2
Source File: SchemaIDLTypeDefinitionRegistry.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
public SchemaIDLTypeDefinitionRegistry(Project project) {
    this.project = project;
    scope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(project), GraphQLFileType.INSTANCE);
    introspectionScope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(project), JsonFileType.INSTANCE);
    psiManager = PsiManager.getInstance(project);
    graphQLEndpointNamedTypeRegistry = JSGraphQLEndpointNamedTypeRegistry.getService(project);
    graphQLPsiSearchHelper = GraphQLPsiSearchHelper.getService(project);
    graphQLConfigManager = GraphQLConfigManager.getService(project);
    graphQLInjectionSearchHelper = ServiceManager.getService(GraphQLInjectionSearchHelper.class);
    project.getMessageBus().connect().subscribe(GraphQLSchemaChangeListener.TOPIC, new GraphQLSchemaEventListener() {
        @Override
        public void onGraphQLSchemaChanged(Integer schemaVersion) {
            scopeToRegistry.clear();
        }
    });
}
 
Example #3
Source File: BsConfigJson.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
public static boolean isBsConfigJson(@NotNull VirtualFile virtualFile) {
    if (virtualFile.getFileType() instanceof JsonFileType) {
        try {
            FileContent fileContent = FileContentImpl.createByFile(virtualFile);
            return createFilePattern().accepts(fileContent);
        } catch (IOException e) {
            return false;
        }
    }
    return false;
}
 
Example #4
Source File: EsyPackageJson.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
public static boolean isEsyPackageJson(@NotNull VirtualFile virtualFile) {
    if (virtualFile.getFileType() instanceof JsonFileType) {
        try {
            FileContent fileContent = FileContentImpl.createByFile(virtualFile);
            return createFilePattern().accepts(fileContent);
        } catch (IOException e) {
            return false;
        }
    }
    return false;
}
 
Example #5
Source File: FormatterTest.java    From json2java4idea with Apache License 2.0 5 votes vote down vote up
@Test
public void formatShouldReformatText() throws Exception {
    getApplication().invokeAndWait(() -> {
        // exercise
        final Formatter underTest = new Formatter(fileFactory, JsonFileType.INSTANCE);
        final String actual = underTest.format("{\"key\":\"value\",\"array\":[\"foo\",\"bar\"]}");

        // verify
        assertThat(actual)
                .isEqualTo("{\n  \"key\": \"value\",\n  \"array\": [\n    \"foo\",\n    \"bar\"\n  ]\n}");
    });
}
 
Example #6
Source File: ParametersPanel.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
private void setupFileSpecificEditor(Project project, VirtualFile cypherFile) {
    if (project == null || cypherFile == null) {
        return;
    }
    try {
        String params = FileUtil.getParams(cypherFile);
        LightVirtualFile lightVirtualFile = new LightVirtualFile("", JsonFileType.INSTANCE, params);
        Document document = FileDocumentManager.getInstance().getDocument(lightVirtualFile);
        fileSpecificParamEditor = createEditor(project, document);
        VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileListener() {
            @Override
            public void contentsChanged(@NotNull VirtualFileEvent event) {
                if (event.getFile().equals(cypherFile) && document != null) {
                    FileUtil.setParams(cypherFile, document.getText());
                }
            }
        });
        JLabel jLabel = new JLabel("<html>Parameters for data source <b>" +
                getTabTitle(cypherFile) + "</b>:</html>");
        jLabel.setIcon(ICON_HELP);
        jLabel.setToolTipText("Enter parameters in JSON format. Will be applied to <b>" + getTabTitle(cypherFile) +
                "</b> data source when executed");
        fileSpecificParamEditor.setHeaderComponent(jLabel);
        if (document != null) {
            setInitialContent(document);
        }
        graphConsoleView.getFileSpecificParametersTab().add(fileSpecificParamEditor.getComponent(), BorderLayout.CENTER);
    } catch (Throwable e) {
        Throwables.throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example #7
Source File: JSGraphQLExecuteEditorAction.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
private boolean isQueryableFile(Project project, VirtualFile virtualFile) {
    if(virtualFile != null) {
        if(virtualFile.getFileType() == GraphQLFileType.INSTANCE) {
            return true;
        }
        if(GraphQLFileType.isGraphQLScratchFile(project, virtualFile)) {
            return true;
        }
        if(virtualFile.getFileType() == JsonFileType.INSTANCE && Boolean.TRUE.equals(virtualFile.getUserData(JSGraphQLLanguageUIProjectService.IS_GRAPH_QL_VARIABLES_VIRTUAL_FILE))) {
            return true;
        }
    }
    return false;
}
 
Example #8
Source File: GraphQLFindUsagesUtil.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
public GraphQLFindUsagesUtil() {
    includedFileTypes.add(GraphQLFileType.INSTANCE);
    includedFileTypes.add(JsonFileType.INSTANCE);
    final GraphQLFindUsagesFileTypeContributor[] contributors = Extensions.getExtensions(GraphQLFindUsagesFileTypeContributor.EP_NAME);
    for (GraphQLFindUsagesFileTypeContributor contributor : contributors) {
        includedFileTypes.addAll(contributor.getFileTypes());
    }
}
 
Example #9
Source File: NamespaceIndex.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return file -> file.getFileType() instanceof DuneFileType || (file.getFileType() instanceof JsonFileType && "bsconfig.json".equals(file.getName()));
}
 
Example #10
Source File: ProjectModule.java    From json2java4idea with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Provides
@Named("Json")
public Formatter provideJsonFormatter(@Nonnull PsiFileFactory fileFactory) {
    return new Formatter(fileFactory, JsonFileType.INSTANCE);
}
 
Example #11
Source File: ParametersPanel.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
private static Editor createEditor(Project project, Document document) {
    return EditorFactory.getInstance().createEditor(document, project, JsonFileType.INSTANCE, false);
}
 
Example #12
Source File: JSGraphQLLanguageUIProjectService.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
private JComponent createHeaderComponent(FileEditor fileEditor, Editor editor, VirtualFile file) {

        final JSGraphQLEditorHeaderComponent headerComponent = new JSGraphQLEditorHeaderComponent();

        // variables & settings actions
        final DefaultActionGroup settingsActions = new DefaultActionGroup();
        settingsActions.add(new GraphQLEditConfigAction());
        settingsActions.add(new JSGraphQLToggleVariablesAction());

        final JComponent settingsToolbar = createToolbar(settingsActions);
        headerComponent.add(settingsToolbar, BorderLayout.WEST);

        // query execute
        final DefaultActionGroup queryActions = new DefaultActionGroup();
        final AnAction executeGraphQLAction = ActionManager.getInstance().getAction(JSGraphQLExecuteEditorAction.class.getName());
        queryActions.add(executeGraphQLAction);
        final JComponent queryToolbar = createToolbar(queryActions);

        // configured endpoints combo box
        final List<GraphQLConfigEndpoint> endpoints = GraphQLConfigManager.getService(myProject).getEndpoints(file);
        final JSGraphQLEndpointsModel endpointsModel = new JSGraphQLEndpointsModel(endpoints, PropertiesComponent.getInstance(myProject));
        final ComboBox endpointComboBox = new ComboBox(endpointsModel);
        endpointComboBox.setToolTipText("GraphQL endpoint");
        editor.putUserData(JS_GRAPH_QL_ENDPOINTS_MODEL, endpointsModel);
        final JPanel endpointComboBoxPanel = new JPanel(new BorderLayout());
        endpointComboBoxPanel.setBorder(BorderFactory.createEmptyBorder(1, 2, 2, 2));
        endpointComboBoxPanel.add(endpointComboBox);

        // splitter to resize endpoints
        final OnePixelSplitter splitter = new OnePixelSplitter(false, .25F);
        splitter.setBorder(BorderFactory.createEmptyBorder());
        splitter.setFirstComponent(endpointComboBoxPanel);
        splitter.setSecondComponent(queryToolbar);
        splitter.setHonorComponentsMinimumSize(true);
        splitter.setAndLoadSplitterProportionKey("JSGraphQLEndpointSplitterProportion");
        splitter.setOpaque(false);
        splitter.getDivider().setOpaque(false);

        headerComponent.add(splitter, BorderLayout.CENTER);

        // variables editor
        final LightVirtualFile virtualFile = new LightVirtualFile(GRAPH_QL_VARIABLES_JSON, JsonFileType.INSTANCE, "");
        final FileEditor variablesFileEditor = PsiAwareTextEditorProvider.getInstance().createEditor(myProject, virtualFile);
        final EditorEx variablesEditor = (EditorEx) ((TextEditor) variablesFileEditor).getEditor();
        virtualFile.putUserData(IS_GRAPH_QL_VARIABLES_VIRTUAL_FILE, Boolean.TRUE);
        variablesEditor.setPlaceholder("{ variables }");
        variablesEditor.setShowPlaceholderWhenFocused(true);
        variablesEditor.getSettings().setRightMarginShown(false);
        variablesEditor.getSettings().setAdditionalLinesCount(0);
        variablesEditor.getSettings().setShowIntentionBulb(false);
        variablesEditor.getSettings().setFoldingOutlineShown(false);
        variablesEditor.getSettings().setLineNumbersShown(false);
        variablesEditor.getSettings().setLineMarkerAreaShown(false);
        variablesEditor.getSettings().setCaretRowShown(false);
        variablesEditor.putUserData(JS_GRAPH_QL_ENDPOINTS_MODEL, endpointsModel);

        // hide variables by default
        variablesEditor.getComponent().setVisible(false);

        // link the query and variables editor together
        variablesEditor.putUserData(GRAPH_QL_QUERY_EDITOR, editor);
        editor.putUserData(GRAPH_QL_VARIABLES_EDITOR, variablesEditor);

        final NonOpaquePanel variablesPanel = new NonOpaquePanel(variablesFileEditor.getComponent());
        variablesPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));

        Disposer.register(fileEditor, variablesFileEditor);

        headerComponent.add(variablesPanel, BorderLayout.SOUTH);

        return headerComponent;
    }
 
Example #13
Source File: JSGraphQLLanguageUIProjectService.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
private void createToolWindowResultEditor(ToolWindow toolWindow) {

        final LightVirtualFile virtualFile = new LightVirtualFile("GraphQL.result.json", JsonFileType.INSTANCE, "");
        fileEditor = PsiAwareTextEditorProvider.getInstance().createEditor(myProject, virtualFile);

        if (fileEditor instanceof TextEditor) {
            final Editor editor = ((TextEditor) fileEditor).getEditor();
            final EditorEx editorEx = (EditorEx) editor;

            // set read-only mode
            editorEx.setViewer(true);
            editorEx.getSettings().setShowIntentionBulb(false);
            editor.getSettings().setAdditionalLinesCount(0);
            editor.getSettings().setCaretRowShown(false);
            editor.getSettings().setBlinkCaret(false);

            // query result header
            final JSGraphQLEditorHeaderComponent header = new JSGraphQLEditorHeaderComponent();

            querySuccessLabel = new JBLabel();
            querySuccessLabel.setVisible(false);
            querySuccessLabel.setIconTextGap(0);
            header.add(querySuccessLabel, BorderLayout.WEST);

            queryResultLabel = new JBLabel("", null, SwingConstants.LEFT);
            queryResultLabel.setBorder(new EmptyBorder(4, 6, 4, 6));
            queryResultLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            queryResultLabel.setVisible(false);
            queryResultLabel.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    final String fileUrl = (String) queryResultLabel.getClientProperty(FILE_URL_PROPERTY);
                    if (fileUrl != null) {
                        final VirtualFile queryFile = VirtualFileManager.getInstance().findFileByUrl(fileUrl);
                        if (queryFile != null) {
                            final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
                            fileEditorManager.openFile(queryFile, true, true);
                        }
                    }
                }
            });
            header.add(queryResultLabel, BorderLayout.CENTER);

            // finally set the header as permanent such that it's restored after searches
            editor.setHeaderComponent(header);
            editorEx.setPermanentHeaderComponent(header);
        }

        final ContentImpl content = new ContentImpl(fileEditor.getComponent(), "Query result", true);
        content.setCloseable(false);
        content.setShouldDisposeContent(false);
        toolWindow.getContentManager().addContent(content);
        Disposer.register(content, fileEditor);
    }
 
Example #14
Source File: GraphQLConfigPackageSet.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
/**
 * Gets whether a file is included.
 * Based on graphl-config: https://github.com/kamilkisiela/graphql-config/blob/b6785a7f0c1b84010cd6e9b94797796254d527b9/src/GraphQLProjectConfig.ts#L56
 * Note: Scratch files are always considered to be included since they are associated with a configuration package set but have a path that lies the project sources
 */
public boolean includesVirtualFile(@NotNull VirtualFile file) {
    if(file.getFileType() == ScratchFileType.INSTANCE) {
        // if a scratch file has been associated with a configuration it is considered to be included
        return true;
    }
    if(file.equals(configEntryFile.getVirtualFile())) {
        // the "entry" file is always considered included
        return true;
    }
    if(JsonFileType.INSTANCE.equals(file.getFileType())) {
        // the only JSON file that can be considered included is an introspection JSON file referenced as schemaPath
        if (schemaFilePath == null && Boolean.TRUE.equals(file.getUserData(GraphQLSchemaKeys.IS_GRAPHQL_INTROSPECTION_JSON))) {
            // new file created from introspection, so update schemaFilePath accordingly
            updateSchemaFilePath();
        }
        return file.getPath().equals(schemaFilePath);
    }
    final PsiFile jsonIntrospectionFile = file.getUserData(GraphQLSchemaKeys.GRAPHQL_INTROSPECTION_SDL_TO_JSON);
    if (jsonIntrospectionFile != null && jsonIntrospectionFile.getVirtualFile() != null) {
        // the file is the in-memory SDL derived from a JSON introspection file, so it's included if the JSON file is set as the schemaPath
        return jsonIntrospectionFile.getVirtualFile().getPath().equals(schemaFilePath);
    }

    String inclusionPath = file.getPath();
    if (file instanceof LightVirtualFile) {
        // the light file is potentially derived from a file on disk, so we should use the physical path to check for inclusion
        final VirtualFile originalFile = ((LightVirtualFile) file).getOriginalFile();
        if (originalFile != null) {
            inclusionPath = originalFile.getPath();
        }
    }

    return includesFilePath.computeIfAbsent(inclusionPath, filePath -> {
        if (filePath.equals(schemaFilePath)) {
            // fast-path for always including the schema file if present
            return true;
        }
        final String relativePath;
        if (filePath.startsWith(configBaseDirPath)) {
            relativePath = StringUtils.removeStart(filePath, configBaseDirPath);
        } else {
            // the file is outside the config base dir, so it's not included
            return false;
        }
        return (!hasIncludes || matchesGlobs(relativePath, this.configData.includes)) && !matchesGlobs(relativePath, this.configData.excludes);
    });
}
 
Example #15
Source File: GraphQLConfigFileTypeFactory.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
@Override
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
    consumer.consume(JsonFileType.INSTANCE, "graphqlconfig");
}