Example usage for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor

List of usage examples for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor

Introduction

In this page you can find the example usage for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor.

Prototype

public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file, int logicalLine,
            int logicalColumn) 

Source Link

Usage

From source file:com.android.tools.idea.editors.manifest.ManifestPanel.java

License:Apache License

private void goToDeclaration(Node element) {
    List<? extends Actions.Record> records = ManifestUtils.getRecords(myManifest, element);
    for (Actions.Record record : records) {
        SourceFilePosition sourceFilePosition = ManifestUtils.getActionLocation(myFacet.getModule(), record);
        SourceFile sourceFile = sourceFilePosition.getFile();
        if (!SourceFile.UNKNOWN.equals(sourceFile)) {
            File ioFile = sourceFile.getSourceFile();
            if (ioFile != null) {
                VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(ioFile);
                assert file != null;
                int line = -1;
                int column = 0;
                SourcePosition sourcePosition = sourceFilePosition.getPosition();
                if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
                    line = sourcePosition.getStartLine();
                    column = sourcePosition.getStartColumn();
                }//w  ww . j  av  a2s . com
                Project project = myFacet.getModule().getProject();
                OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, line, column);
                FileEditorManager.getInstance(project).openEditor(descriptor, true);
                break;
            }
        }
    }
}

From source file:com.android.tools.idea.gradle.invoker.messages.GradleBuildTreeStructure.java

License:Apache License

@Override
public void addMessage(@NotNull ErrorTreeElementKind kind, @NotNull String[] text,
        @Nullable VirtualFile underFileGroup, @Nullable VirtualFile file, int line, int column,
        @Nullable Object data) {/*from   ww  w . j a va 2  s. c om*/
    if (underFileGroup != null || file != null) {
        if (file == null)
            line = column = -1;

        int uiLine = line < 0 ? -1 : line + 1;
        int uiColumn = column < 0 ? -1 : column + 1;

        VirtualFile group = underFileGroup != null ? underFileGroup : file;
        VirtualFile nav = file != null ? file : underFileGroup;

        addNavigatableMessage(group.getPresentableUrl(), new OpenFileDescriptor(myProject, nav, line, column),
                kind, text, data, createExportPrefix(uiLine), createRendererPrefix(uiLine, uiColumn), group);
        return;
    }

    addSimpleMessage(kind, text, data);
}

From source file:com.android.tools.idea.gradle.messages.Message.java

License:Apache License

public Message(@NotNull Project project, @NotNull String groupName, @NotNull Type type,
        @NotNull VirtualFile file, int line, int column, @NotNull String... text) {
    this(groupName, type, new OpenFileDescriptor(project, file, line, column), file, line, column, text);
}

From source file:com.android.tools.idea.gradle.project.sync.errors.GradleDslMethodNotFoundErrorHandler.java

License:Apache License

private static void openFile(@NotNull VirtualFile virtualFile, @NotNull NotificationData notification,
        @NotNull Project project) {/*from  ww  w . j a v a  2 s. co m*/
    int line = notification.getLine() - 1;
    int column = notification.getColumn() - 1;

    line = line < 0 ? -1 : line; // NotificationData uses 1-based offsets, while OpenFileDescriptor 0-based.
    column = column < 0 ? -1 : column + 1;
    new OpenFileDescriptor(project, virtualFile, line, column).navigate(true);
}

From source file:com.android.tools.idea.gradle.project.sync.messages.SyncMessage.java

License:Apache License

public SyncMessage(@NotNull Project project, @NotNull String group, @NotNull MessageType type,
        @NotNull PositionInFile position, @NotNull String... text) {
    this(group, type, new OpenFileDescriptor(project, position.file, position.line, position.column), text,
            position);//from   w w  w.j a  v a 2  s .com
}

From source file:com.android.tools.idea.gradle.service.notification.errors.GradleDslMethodNotFoundErrorHandler.java

License:Apache License

@Override
public boolean handleError(@NotNull List<String> message, @NotNull ExternalSystemException error,
        @NotNull NotificationData notification, @NotNull Project project) {
    String firstLine = message.get(0);

    if (firstLine != null && firstLine.startsWith(GRADLE_DSL_METHOD_NOT_FOUND_ERROR_PREFIX)) {
        String filePath = notification.getFilePath();
        final VirtualFile virtualFile = filePath != null
                ? LocalFileSystem.getInstance().refreshAndFindFileByPath(filePath)
                : null;//from  w  ww  . j  a  v a 2 s . co m
        if (virtualFile != null && FN_BUILD_GRADLE.equals(virtualFile.getName())) {
            NotificationHyperlink gradleSettingsHyperlink = getGradleSettingsHyperlink(project);
            NotificationHyperlink applyGradlePluginHyperlink = getApplyGradlePluginHyperlink(virtualFile,
                    notification);

            String newMsg = firstLine + "\nPossible causes:<ul>" + String.format(
                    "<li>The project '%1$s' may be using a version of Gradle that does not contain the method.\n",
                    project.getName()) + gradleSettingsHyperlink.toHtml() + "</li>"
                    + "<li>The build file may be missing a Gradle plugin.\n"
                    + applyGradlePluginHyperlink.toHtml() + "</li>";
            String title = String.format(FAILED_TO_SYNC_GRADLE_PROJECT_ERROR_GROUP_FORMAT, project.getName());
            notification.setTitle(title);
            notification.setMessage(newMsg);
            notification.setNotificationCategory(NotificationCategory.convert(DEFAULT_NOTIFICATION_TYPE));

            addNotificationListener(notification, project, gradleSettingsHyperlink, applyGradlePluginHyperlink);
        } else if (virtualFile != null && notification.getLine() > 0 && notification.getNavigatable() == null) {
            OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile,
                    notification.getLine() - 1 /* lines are zero-based */, -1);
            notification.setNavigatable(descriptor);
        } else {
            updateNotification(notification, project, error.getMessage());
        }
        return true;
    }
    return false;
}

From source file:com.android.tools.idea.rendering.HtmlLinkManager.java

License:Apache License

private static boolean openEditor(@NotNull Project project, @NotNull PsiFile psiFile, int line, int column) {
    VirtualFile file = psiFile.getVirtualFile();
    if (file != null) {
        OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, line, column);
        return !FileEditorManager.getInstance(project).openEditor(descriptor, true).isEmpty();
    }//from   ww  w  .  j av  a  2 s  .co m

    return false;
}

From source file:com.armhold.wicketsource.FileNavigator.java

License:Apache License

private void navigate(Project project, VirtualFile file, int line) {
    OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, file, line, 0);
    if (openFileDescriptor.canNavigate()) {
        log.info("Trying to navigate to " + file.getPath() + ":" + line);
        openFileDescriptor.navigate(true);
        WindowManager.getInstance().suggestParentWindow(project).toFront();
    } else {//from  ww w  .  jav  a2s .c om
        log.info("Cannot navigate");
    }
}

From source file:com.facebook.buck.intellij.ideabuck.ui.BuckToolWindowFactory.java

License:Apache License

private void handleClickOnError(BuckTreeNodeDetailError node) {
    TreeNode parentNode = node.getParent();
    if (parentNode instanceof BuckTreeNodeFileError) {
        BuckTreeNodeFileError buckParentNode = (BuckTreeNodeFileError) parentNode;

        DataContext dataContext = DataManager.getInstance().getDataContext();
        Project project = DataKeys.PROJECT.getData(dataContext);

        String relativePath = buckParentNode.getFilePath().replace(project.getBasePath(), "");

        VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
        OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile, node.getLine() - 1,
                node.getColumn() - 1);/*  w  ww  . ja v  a2  s  . c  o  m*/
        openFileDescriptor.navigate(true);
    }
}

From source file:com.facebook.buck.intellij.ideabuck.ui.components.BuckTreeViewPanelImpl.java

License:Apache License

private static void handleClickOnError(BuckErrorItemNode node) {
    TreeNode parentNode = node.getParent();
    if (parentNode instanceof BuckFileErrorNode) {
        BuckFileErrorNode buckParentNode = (BuckFileErrorNode) parentNode;
        DataContext dataContext = DataManager.getInstance().getDataContext();
        Project project = DataKeys.PROJECT.getData(dataContext);

        String relativePath = buckParentNode.getText().replace(project.getBasePath(), "");

        VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
        if (virtualFile != null) {
            OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile,
                    node.getLine() - 1, node.getColumn() - 1);
            openFileDescriptor.navigate(true);
        }//from w ww. ja  v a 2  s .  c  o m
    }
}