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) 

Source Link

Usage

From source file:ariba.ideplugin.idea.GotoComponent.java

License:Apache License

private void openFile(Project project, Vector components) {
    // open the first one by default
    VirtualFile javaFile = (VirtualFile) components.firstElement();
    OpenFileDescriptor fd = new OpenFileDescriptor(project, javaFile);
    Editor newEditor = FileEditorManager.getInstance(project).openTextEditor(fd, true);
    if (newEditor == null) {
        showError("Can't open editor", project);
    }/* w  w  w . ja  v a2 s  . c o m*/
}

From source file:ariba.ideplugin.idea.ToggleAction.java

License:Apache License

/**
 * Switch between an awl page and the corresponding java page.
 * @param event occurred//from w w  w.j  a  va2 s  .  c  o  m
 */
public void actionPerformed(AnActionEvent event) {
    LOG.info("User performed ToggleAction!");
    Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT);

    if (project != null) {

        VirtualFile[] selectedFile = FileEditorManager.getInstance(project).getSelectedFiles();

        if (selectedFile.length == 0) {
            error(project, "No file is currently selected");
            return;
        }
        VirtualFile currEditorFile = selectedFile[0];

        if (currEditorFile != null) {

            String extension = currEditorFile.getExtension();

            String pairName;
            VirtualFile pairFile;

            if ("awl".equals(extension) || "htm".equals(extension)) {
                pairName = currEditorFile.getNameWithoutExtension() + ".java";
                pairFile = currEditorFile.getParent().findChild(pairName);

                if (pairFile == null) {
                    pairName = currEditorFile.getNameWithoutExtension() + ".groovy";
                    pairFile = currEditorFile.getParent().findChild(pairName);
                }

                if (pairFile == null) {
                    error(project, "Could not find .java or .groovy file for " + currEditorFile.getName());
                    return;
                }
            } else if ("java".equals(extension) || "groovy".equals(extension)) {
                pairName = currEditorFile.getNameWithoutExtension() + ".awl";
                pairFile = currEditorFile.getParent().findChild(pairName);

                if (pairFile == null) {
                    pairName = currEditorFile.getNameWithoutExtension() + ".htm";
                    pairFile = currEditorFile.getParent().findChild(pairName);
                }

                if (pairFile == null) {
                    error(project, "Could not find .awl or .htm file for " + currEditorFile.getName());
                    return;
                }
            } else {
                error(project, "Unexpected file type: " + extension);
                return;
            }

            OpenFileDescriptor fd = new OpenFileDescriptor(project, pairFile);

            if (fd != null) {
                FileEditorManager manager = FileEditorManager.getInstance(project);
                Editor e = manager.openTextEditor(fd, true);
                if (e == null) {
                    error(project, "Editor is null");
                }
            } else {
                error(project, "Unable to open file: " + pairName);
            }
        } else {
            error(project, "No file is currently selected");
        }
    }
}

From source file:com.android.tools.idea.apk.viewer.AnalyzeApkAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();/*w  w  w .  j  ava 2 s .c  o  m*/
    if (project == null) {
        Logger.getInstance(AnalyzeApkAction.class).warn("Unable to obtain project from event");
        return;
    }

    // find the apk to open
    VirtualFile vf = promptUserForApk(project);
    if (vf == null) {
        return;
    }

    OpenFileDescriptor fd = new OpenFileDescriptor(project, vf);
    FileEditorManager.getInstance(project).openEditor(fd, true);
}

From source file:com.android.tools.idea.editors.hierarchyview.HierarchyViewCaptureTask.java

License:Apache License

@Override
public void onSuccess() {
    if (myError != null) {
        Messages.showErrorDialog("Error obtaining view hierarchy: " + StringUtil.notNullize(myError), TITLE);
        return;//from  ww w  .ja v a2s .  c om
    }

    CaptureService service = CaptureService.getInstance(myProject);
    try {
        Capture capture = service.createCapture(HierarchyViewCaptureType.class, myData,
                service.getSuggestedName(myClient));
        final VirtualFile file = capture.getFile();
        file.refresh(true, false, new Runnable() {
            @Override
            public void run() {
                UIUtil.invokeLaterIfNeeded(new Runnable() {
                    @Override
                    public void run() {
                        OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, file);
                        FileEditorManager.getInstance(myProject).openEditor(descriptor, true);
                    }
                });
            }
        });
    } catch (IOException e) {
        Messages.showErrorDialog("Error creating hierarchy view capture: " + e, TITLE);
    }
}

From source file:com.android.tools.idea.editors.strings.StringResourceEditorProvider.java

License:Apache License

public static void openEditor(@NotNull final Module module) {
    final VirtualFile vf = StringsVirtualFile.getStringsVirtualFile(module);
    if (vf != null) {
        ApplicationManager.getApplication().invokeLater(() -> {
            Project project = module.getProject();
            OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vf);
            FileEditorManager.getInstance(project).openEditor(descriptor, true);
        });/*from www  .  j  av  a  2 s.c  om*/
    }
}

From source file:com.android.tools.idea.editors.strings.StringResourceEditorProvider.java

License:Apache License

public static void openEditor(@NotNull final Project project, @NotNull VirtualFile file) {
    VirtualFile stringsFile = StringsVirtualFile.getInstance(project, file);
    assert stringsFile != null;

    ApplicationManager.getApplication().invokeLater(() -> {
        OpenFileDescriptor descriptor = new OpenFileDescriptor(project, stringsFile);
        FileEditorManager.getInstance(project).openEditor(descriptor, true);
    });/*from   w  w w. jav a2  s .co m*/
}

From source file:com.android.tools.idea.editors.theme.ThemeEditorTable.java

License:Apache License

private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
    if (row < 0 || column < 0) {
        return null;
    }/*from w w w .  ja  v  a 2s . c o m*/

    TableModel rawModel = getModel();
    if (!(rawModel instanceof AttributesTableModel)) {
        return null;
    }

    final AttributesTableModel model = (AttributesTableModel) rawModel;
    AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));

    if (contents instanceof AttributesTableModel.AttributeContents) {
        final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;

        final EditedStyleItem item = attribute.getValue();
        if (item == null) {
            return null;
        }

        final JBPopupMenu popupMenu = new JBPopupMenu();
        if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
            popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    myGoToListener.goTo(item);
                }
            });
        } else {
            final ResourceResolver resolver = myContext.getResourceResolver();
            assert resolver != null;
            final Project project = myContext.getProject();
            final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
            final File file = new File(resourceValue.getValue());

            final VirtualFileManager manager = VirtualFileManager.getInstance();
            final VirtualFile virtualFile = file.exists()
                    ? manager.findFileByUrl("file://" + file.getAbsolutePath())
                    : null;
            if (virtualFile != null) {
                popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
                        FileEditorManager.getInstance(project).openEditor(descriptor, true);
                    }
                });
            }
        }

        myJavadocAction.setCurrentItem(item);
        popupMenu.add(myJavadocAction);

        final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
        if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
            popupMenu.add(new AbstractAction("Reset value") {
                @Override
                public void actionPerformed(ActionEvent e) {
                    selectedStyle.removeAttribute(item.getQualifiedName());
                    model.fireTableCellUpdated(attribute.getRowIndex(), 0);
                }
            });
        }

        return popupMenu;
    } else if (contents instanceof AttributesTableModel.ParentAttribute) {
        final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
        if (parentStyle == null) {
            return null;
        }

        final JBPopupMenu menu = new JBPopupMenu();
        menu.add(new AbstractAction(GO_TO_DECLARATION) {
            @Override
            public void actionPerformed(ActionEvent e) {
                myGoToListener.goToParent();
            }
        });

        return menu;
    }

    return null;
}

From source file:com.android.tools.idea.editors.theme.ThemeEditorUtils.java

License:Apache License

public static void openThemeEditor(@NotNull final Project project) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override// www  .j av  a 2s  .  c  o  m
        public void run() {
            ThemeEditorVirtualFile file = ThemeEditorVirtualFile.getThemeEditorFile(project);
            OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file);
            FileEditorManager.getInstance(project).openEditor(descriptor, true);
        }
    });
}

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

License:Apache License

@NotNull
private static NotificationHyperlink getGradleSettingsHyperlink(@NotNull Project project) {
    if (isUsingWrapper(project)) {
        GradleWrapper gradleWrapper = GradleWrapper.find(project);
        if (gradleWrapper != null) {
            VirtualFile propertiesFile = gradleWrapper.getPropertiesFile();
            if (propertiesFile != null) {
                return new NotificationHyperlink("open.wrapper.file", "Open Gradle wrapper file") {
                    @Override//from  w w w .j a va 2  s. co m
                    protected void execute(@NotNull Project project) {
                        OpenFileDescriptor descriptor = new OpenFileDescriptor(project, propertiesFile);
                        FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
                    }
                };
            }
        }
    }
    return new OpenGradleSettingsHyperlink();
}

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

License:Apache License

@NotNull
private static NotificationHyperlink getGradleSettingsHyperlink(@NotNull Project project) {
    if (isUsingWrapper(project)) {
        File wrapperPropertiesFile = findWrapperPropertiesFile(project);
        if (wrapperPropertiesFile != null) {
            final VirtualFile virtualFile = findFileByIoFile(wrapperPropertiesFile, true);
            if (virtualFile != null) {
                return new NotificationHyperlink("open.wrapper.file", "Open Gradle wrapper file") {
                    @Override//from   w w w.j  ava2s .  c om
                    protected void execute(@NotNull Project project) {
                        OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
                        FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
                    }
                };
            }
        }
    }
    return new OpenGradleSettingsHyperlink();
}