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

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

Introduction

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

Prototype

String PROJECT

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

Click Source Link

Document

Returns com.intellij.openapi.project.Project

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.//from w  w  w . j  a  v a2 s.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: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.advancedtools.cpp.utils.LM.java

public static void showAboutDialog(DataContext dataContext) {
    new LMDialog((Project) dataContext.getData(DataConstants.PROJECT)).show();
}

From source file:com.boxysystems.libraryfinder.view.intellij.actions.CloseWindowAction.java

License:Apache License

public void actionPerformed(AnActionEvent event) {
    Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT);
    LibraryFinderPlugin plugin = LibraryFinderPlugin.instance(project);
    ToolWindow toolWindow = plugin.getToolWindow();
    if (toolWindow != null) {
        toolWindow.hide(null);/*from w  w  w  . ja  v a2s.com*/
        toolWindow.setAvailable(false, null);
    }
}

From source file:com.boxysystems.libraryfinder.view.intellij.actions.LibraryFinderAction.java

License:Apache License

public void update(AnActionEvent anActionEvent) {
    Presentation presentation = anActionEvent.getPresentation();
    Project project = (Project) anActionEvent.getDataContext().getData(DataConstants.PROJECT);
    if (project != null) {
        presentation.setEnabled(true);//from w w w.  j a v  a  2s  .  c o m
        presentation.setVisible(true);
    } else {
        presentation.setEnabled(false);
        presentation.setVisible(false);
    }
}

From source file:com.boxysystems.libraryfinder.view.intellij.actions.LibraryFinderAction.java

License:Apache License

public void actionPerformed(AnActionEvent anActionEvent) {
    Project project = (Project) anActionEvent.getDataContext().getData(DataConstants.PROJECT);
    performAction(project, null, null, false);
}

From source file:com.boxysystems.libraryfinder.view.intellij.actions.RerunAction.java

License:Apache License

public void actionPerformed(AnActionEvent event) {
    Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT);
    LibraryFinderAction action = LibraryFinderAction.getInstance();
    action.executeAction(project);/*from  w ww .  j  av a 2 s .c om*/
}

From source file:com.echologic.xfiles.EditConfigurationsAction.java

License:Open Source License

public void actionPerformed(AnActionEvent event) {
    DataContext context = event.getDataContext();
    Project project = (Project) context.getData(DataConstants.PROJECT);
    XFilesConfigurable configurable = (XFilesConfigurable) project.getComponent(XFilesConfigurable.class);

    ShowSettingsUtil util = ShowSettingsUtil.getInstance();
    util.editConfigurable(project, configurable);
}

From source file:com.echologic.xfiles.RefreshAction.java

License:Open Source License

public void actionPerformed(AnActionEvent event) {
    log.debug("actionPerformed");

    if (filter == null) {
        log.debug("no filter selected");
        return;/*ww w  .ja v a2s  . c  om*/
    }

    long start = System.currentTimeMillis();

    final Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT);

    CountingFilterListener listener = new CountingFilterListener();
    filter.setListener(listener);

    XFilesContentIterator content = new XFilesContentIterator(project);
    content.setFilter(filter);
    content.iterate();

    listener.log();

    List included = content.getIncluded();

    model.clear();
    for (Iterator iterator = included.iterator(); iterator.hasNext();) {
        VirtualFile file = (VirtualFile) iterator.next();
        model.addElement(file);
    }

    long finish = System.currentTimeMillis();
    long delta = finish - start;

    WindowManager windowManager = WindowManager.getInstance();
    StatusBar statusBar = windowManager.getStatusBar(project);
    statusBar.setInfo(filter.getName() + " filter refreshed in " + delta + "ms; " + content + listener);

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

    if (files != null && files.length > 0)
        model.setSelectedItem(files[0]);
}

From source file:com.imaginea.kodebeagle.action.RefreshAction.java

License:Apache License

public final void init() throws IOException {
    DataContext dataContext = DataManager.getInstance().getDataContext();
    Project project = (Project) dataContext.getData(DataConstants.PROJECT);
    currentSettings = new Settings();
    if (project != null) {
        windowObjects.setProject(project);
        windowObjects.setDistance(currentSettings.getLimits().getLinesFromCursor());
        windowObjects.setSize(currentSettings.getLimits().getResultSize());
        windowObjects.setEsURL(currentSettings.getEsURLComboBoxModel().getSelectedEsURL());
        maxTinyEditors = currentSettings.getLimits().getTopCount();
        windowEditorOps.writeToDocument("", windowObjects.getWindowEditor().getDocument());
        runAction();//  ww  w .j  a v  a 2 s.co m
    } else {
        showHelpInfo(PROJECT_ERROR);
        goToAllPane();
    }
}