2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.jetbrains.python.debugger.containerview;
18 import com.intellij.openapi.actionSystem.AnActionEvent;
19 import com.intellij.openapi.actionSystem.DataContext;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree;
22 import com.intellij.xdebugger.impl.ui.tree.actions.XDebuggerTreeActionBase;
23 import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
24 import com.jetbrains.python.debugger.PyDebugValue;
25 import com.jetbrains.python.debugger.array.NumpyArrayTable;
26 import com.jetbrains.python.debugger.dataframe.DataFrameTable;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
30 import javax.swing.tree.TreePath;
36 public class PyViewNumericContainerAction extends XDebuggerTreeActionBase {
39 protected void perform(XValueNodeImpl node, @NotNull String nodeName, AnActionEvent e) {
40 Project p = e.getProject();
41 if (p != null && node != null && node.getValueContainer() instanceof PyDebugValue && node.isComputed()) {
42 PyDebugValue debugValue = (PyDebugValue)node.getValueContainer();
43 showNumericViewer(p, debugValue);
47 public static void showNumericViewer(Project project, PyDebugValue debugValue) {
48 String nodeType = debugValue.getType();
49 final ViewNumericContainerDialog dialog;
50 if ("ndarray".equals(nodeType)) {
51 dialog = new ViewNumericContainerDialog(project, (dialogWrapper) -> {
52 NumpyArrayTable arrayTable = new NumpyArrayTable(project, dialogWrapper, debugValue);
54 return arrayTable.getComponent().getMainPanel();
57 else if (("DataFrame".equals(nodeType))) {
58 dialog = new ViewNumericContainerDialog(project, (dialogWrapper) -> {
59 DataFrameTable dataFrameTable = new DataFrameTable(project, dialogWrapper, debugValue);
60 dataFrameTable.init();
61 return dataFrameTable.getComponent().getMainPanel();
65 throw new IllegalStateException("Cannot render node type: " + nodeType);
72 private static TreePath[] getSelectedPaths(DataContext dataContext) {
73 XDebuggerTree tree = XDebuggerTree.getTree(dataContext);
74 return tree == null ? null : tree.getSelectionPaths();
78 public void update(AnActionEvent e) {
79 e.getPresentation().setVisible(false);
80 TreePath[] paths = getSelectedPaths(e.getDataContext());
82 if (paths.length > 1) {
83 e.getPresentation().setVisible(false);
87 XValueNodeImpl node = getSelectedNode(e.getDataContext());
88 if (node != null && node.getValueContainer() instanceof PyDebugValue && node.isComputed()) {
89 PyDebugValue debugValue = (PyDebugValue)node.getValueContainer();
91 String nodeType = debugValue.getType();
92 if ("ndarray".equals(nodeType)) {
93 e.getPresentation().setText("View as Array");
94 e.getPresentation().setVisible(true);
96 else if (("DataFrame".equals(nodeType))) {
97 e.getPresentation().setText("View as DataFrame");
98 e.getPresentation().setVisible(true);
101 e.getPresentation().setVisible(false);
106 e.getPresentation().setVisible(false);