Example usage for com.intellij.openapi.actionSystem DataConstants EDITOR

List of usage examples for com.intellij.openapi.actionSystem DataConstants EDITOR

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem DataConstants EDITOR.

Prototype

String EDITOR

To view the source code for com.intellij.openapi.actionSystem DataConstants EDITOR.

Click Source Link

Document

Returns com.intellij.openapi.editor.Editor

Usage

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

License:Apache License

/**
 * Find the file corresponding to an awl tag. The AWL file defining this tag will
 * open.//w w  w . ja  v  a2s.c o  m
 * If the file does not exist the java file will open.
 *
 * @param event occurred
 */
public void actionPerformed(AnActionEvent event) {

    LOG.info("User performed GotoComponent!");
    Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT);

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

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

    // ignore if the file is not awl
    String currentFileExtension = currentFile.getExtension();
    if (!currentFileExtension.equals("awl") && !currentFileExtension.equals("htm")) {
        return;
    }

    Editor editor = (Editor) event.getDataContext().getData(DataConstants.EDITOR);
    ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
    Document document = editor.getDocument();
    CaretModel caret = editor.getCaretModel();

    String componentName = findComponentName(document, caret.getOffset());
    if (componentName == null) {
        showError("cannot figure out component name", project);
    } else {
        String javaFileName = componentName + ".java";
        String awlFileName = componentName + ".awl";

        // find components
        Vector components = new Vector();
        findComponents(rootManager, javaFileName, awlFileName, components);
        if (components.isEmpty()) {
            javaFileName = nameWithPrefix(componentName, "") + ".java";
            awlFileName = nameWithPrefix(componentName, "") + ".awl";
            findComponents(rootManager, javaFileName, awlFileName, components);
        }
        if (components.isEmpty()) {
            javaFileName = nameWithPrefix(componentName, "AW") + ".java";
            awlFileName = nameWithPrefix(componentName, "AW") + ".awl";
            findComponents(rootManager, javaFileName, awlFileName, components);
        }

        if (components.isEmpty()) {
            javaFileName = nameWithPrefix(componentName, "AWT") + ".java";
            awlFileName = nameWithPrefix(componentName, "AWT") + ".awl";
            findComponents(rootManager, javaFileName, awlFileName, components);
        }

        if (!components.isEmpty()) {
            openFile(project, components);
        } else {
            String errorMessage = "cannot find component " + componentName;
            showError(errorMessage, project);
        }
    }
}

From source file:org.dubik.codecompletionlive.actions.CodeCompletionLiveAction.java

License:Apache License

public void actionPerformed(final AnActionEvent event) {
    final Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT);
    if (project == null)
        return;//from  ww w.j ava  2  s  .  c  o  m

    final PsiFile psiFile = (PsiFile) event.getDataContext().getData(DataConstants.PSI_FILE);
    if (psiFile == null)
        return;

    final Editor editor = (Editor) event.getDataContext().getData(DataConstants.EDITOR);
    if (editor == null)
        return;

    ApplicationManager.getApplication().invokeLater(new Runnable() {
        public void run() {
            CodeCompletionLiveActionExecutor executor = new CodeCompletionLiveActionExecutor(project, editor,
                    psiFile, event);
            executor.execute();
        }
    });
}