Example usage for com.intellij.openapi.actionSystem ActionPlaces STRUCTURE_VIEW_POPUP

List of usage examples for com.intellij.openapi.actionSystem ActionPlaces STRUCTURE_VIEW_POPUP

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem ActionPlaces STRUCTURE_VIEW_POPUP.

Prototype

String STRUCTURE_VIEW_POPUP

To view the source code for com.intellij.openapi.actionSystem ActionPlaces STRUCTURE_VIEW_POPUP.

Click Source Link

Usage

From source file:com.intellij.debugger.actions.ToggleFieldBreakpointAction.java

License:Apache License

@Override
public void update(AnActionEvent event) {
    SourcePosition place = getPlace(event);
    boolean toEnable = place != null;

    Presentation presentation = event.getPresentation();
    if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace())
            || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace())
            || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
        presentation.setVisible(toEnable);
    } else if (DebuggerAction.isContextView(event)) {
        presentation.setText(DebuggerBundle.message("action.add.field.watchpoint.text"));
        Project project = event.getData(CommonDataKeys.PROJECT);
        if (project != null && place != null) {
            Document document = PsiDocumentManager.getInstance(project).getDocument(place.getFile());
            if (document != null) {
                final int offset = place.getOffset();
                final BreakpointManager breakpointManager = (DebuggerManagerEx.getInstanceEx(project))
                        .getBreakpointManager();
                final Breakpoint fieldBreakpoint = offset >= 0
                        ? breakpointManager.findBreakpoint(document, offset, FieldBreakpoint.CATEGORY)
                        : null;//from w ww  . ja  va  2s  . com
                if (fieldBreakpoint != null) {
                    presentation.setEnabled(false);
                    return;
                }
            }
        }
    }
    presentation.setVisible(toEnable);
}

From source file:com.intellij.debugger.actions.ToggleFieldBreakpointAction.java

License:Apache License

@Nullable
public static SourcePosition getPlace(AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    final Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return null;
    }/*from  ww  w.  j  a  v  a 2  s.co m*/
    if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace())
            || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace())
            || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
        final PsiElement psiElement = event.getData(CommonDataKeys.PSI_ELEMENT);
        if (psiElement instanceof PsiField) {
            return SourcePosition.createFromElement(psiElement);
        }
        return null;
    }

    final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext);
    if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
        final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext);
        final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
        if (debugProcess != null) { // if there is an active debugsession
            final Ref<SourcePosition> positionRef = new Ref<SourcePosition>(null);
            debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) {
                public Priority getPriority() {
                    return Priority.HIGH;
                }

                public void threadAction() {
                    ApplicationManager.getApplication().runReadAction(new Runnable() {
                        public void run() {
                            final FieldDescriptorImpl descriptor = (FieldDescriptorImpl) selectedNode
                                    .getDescriptor();
                            positionRef.set(descriptor.getSourcePosition(project, debuggerContext));
                        }
                    });
                }
            });
            final SourcePosition sourcePosition = positionRef.get();
            if (sourcePosition != null) {
                return sourcePosition;
            }
        }
    }

    if (DebuggerAction.isContextView(event)) {
        DebuggerTree tree = DebuggerTree.DATA_KEY.getData(dataContext);
        if (tree != null && tree.getSelectionPath() != null) {
            DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent());
            if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl) {
                Field field = ((FieldDescriptorImpl) node.getDescriptor()).getField();
                DebuggerSession session = tree.getDebuggerContext().getDebuggerSession();
                PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project,
                        (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project));
                if (psiClass != null) {
                    psiClass = (PsiClass) psiClass.getNavigationElement();
                    final PsiField psiField = psiClass.findFieldByName(field.name(), true);
                    if (psiField != null) {
                        return SourcePosition.createFromElement(psiField);
                    }
                }
            }
        }
        return null;
    }

    Editor editor = event.getData(CommonDataKeys.EDITOR);
    if (editor == null) {
        editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    }
    if (editor != null) {
        final Document document = editor.getDocument();
        PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
        if (file != null) {
            final VirtualFile virtualFile = file.getVirtualFile();
            FileType fileType = virtualFile != null ? virtualFile.getFileType() : null;
            if (fileType == JavaFileType.INSTANCE || fileType == JavaClassFileType.INSTANCE) {
                final PsiField field = FieldBreakpoint.findField(project, document,
                        editor.getCaretModel().getOffset());
                if (field != null) {
                    return SourcePosition.createFromElement(field);
                }
            }
        }
    }
    return null;
}

From source file:com.intellij.debugger.actions.ToggleMethodBreakpointAction.java

License:Apache License

@Nullable
private static PlaceInDocument getPlace(AnActionEvent event) {
    final Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return null;
    }//from  ww w .  j  a v  a 2s. co m

    PsiElement method = null;
    Document document = null;

    if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace())
            || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace())
            || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())
            || ActionPlaces.NAVIGATION_BAR.equals(event.getPlace())) {
        final PsiElement psiElement = event.getData(LangDataKeys.PSI_ELEMENT);
        if (psiElement instanceof PsiMethod) {
            final PsiFile containingFile = psiElement.getContainingFile();
            if (containingFile != null) {
                method = psiElement;
                document = PsiDocumentManager.getInstance(project).getDocument(containingFile);
            }
        }
    } else {
        Editor editor = event.getData(PlatformDataKeys.EDITOR);
        if (editor == null) {
            editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
        }
        if (editor != null) {
            document = editor.getDocument();
            PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
            if (file != null) {
                final VirtualFile virtualFile = file.getVirtualFile();
                FileType fileType = virtualFile != null ? virtualFile.getFileType() : null;
                if (fileType == JavaFileType.INSTANCE || fileType == JavaClassFileType.INSTANCE) {
                    method = findMethod(project, editor);
                }
            }
        }
    }

    if (method != null) {
        final PsiElement method1 = method;
        final Document document1 = document;

        return new PlaceInDocument() {
            public Document getDocument() {
                return document1;
            }

            public int getOffset() {
                return method1.getTextOffset();
            }
        };
    }
    return null;
}

From source file:com.intellij.ide.favoritesTreeView.actions.AddToFavoritesAction.java

License:Apache License

public static boolean canCreateNodes(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    if (e.getProject() == null) {
        return false;
    }// w  ww  . j  a  v  a 2  s  .c o  m
    if (e.getPlace().equals(ActionPlaces.FAVORITES_VIEW_POPUP)
            && FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext) == null) {
        return false;
    }
    final boolean inProjectView = e.getPlace().equals(ActionPlaces.J2EE_VIEW_POPUP)
            || e.getPlace().equals(ActionPlaces.STRUCTURE_VIEW_POPUP)
            || e.getPlace().equals(ActionPlaces.PROJECT_VIEW_POPUP);
    //com.intellij.openapi.actionSystem.ActionPlaces.USAGE_VIEW_TOOLBAR
    return getNodesToAdd(dataContext, inProjectView) != null;
}

From source file:com.intellij.ide.structureView.newStructureView.StructureViewComponent.java

License:Apache License

private void addTreeMouseListeners() {
    EditSourceOnDoubleClickHandler.install(getTree());
    CustomizationUtil.installPopupHandler(getTree(), IdeActions.GROUP_STRUCTURE_VIEW_POPUP,
            ActionPlaces.STRUCTURE_VIEW_POPUP);
}

From source file:org.intellij.plugins.junit.actions.ToggleTestCaseTestedClassActionHandler.java

License:Open Source License

private String getActionText() {
    String actionText = "";
    if (event.getPlace().equals(ActionPlaces.PROJECT_VIEW_POPUP)
            || event.getPlace().equals(ActionPlaces.STRUCTURE_VIEW_POPUP)) {
        actionText = "Go to ";
    }/*www.  ja v  a 2s.  c  om*/
    if (JUnitHelper.isUnitTest(getCurrentClass())) {
        actionText += "Tested Class";
    } else {
        actionText += "Test Class";
    }
    return actionText;
}