2 * Copyright 2000-2015 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.intellij.xdebugger.impl.ui.tree;
18 import com.intellij.ide.dnd.DnDAction;
19 import com.intellij.ide.dnd.DnDDragStartBean;
20 import com.intellij.ide.dnd.DnDSource;
21 import com.intellij.ide.dnd.aware.DnDAwareTree;
22 import com.intellij.openapi.Disposable;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.util.Disposer;
25 import com.intellij.openapi.util.Pair;
26 import com.intellij.ui.ScrollPaneFactory;
27 import com.intellij.ui.treeStructure.Tree;
28 import com.intellij.xdebugger.XDebuggerBundle;
29 import com.intellij.xdebugger.XSourcePosition;
30 import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
31 import com.intellij.xdebugger.impl.frame.XValueMarkers;
32 import com.intellij.xdebugger.impl.ui.DebuggerUIUtil;
33 import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
34 import org.jetbrains.annotations.NonNls;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
44 public class XDebuggerTreePanel implements DnDSource {
45 private final XDebuggerTree myTree;
46 private final JPanel myMainPanel;
48 public XDebuggerTreePanel(final @NotNull Project project, final @NotNull XDebuggerEditorsProvider editorsProvider,
49 @NotNull Disposable parentDisposable, final @Nullable XSourcePosition sourcePosition,
50 @NotNull @NonNls final String popupActionGroupId, @Nullable XValueMarkers<?, ?> markers) {
51 myTree = new XDebuggerTree(project, editorsProvider, sourcePosition, popupActionGroupId, markers);
52 myMainPanel = new JPanel(new BorderLayout());
53 myMainPanel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
54 Disposer.register(parentDisposable, myTree);
57 public XDebuggerTree getTree() {
61 public JPanel getMainPanel() {
66 public boolean canStartDragging(final DnDAction action, final Point dragOrigin) {
67 return getNodesToDrag().length > 0;
70 private XValueNodeImpl[] getNodesToDrag() {
71 return myTree.getSelectedNodes(XValueNodeImpl.class, new Tree.NodeFilter<XValueNodeImpl>() {
73 public boolean accept(final XValueNodeImpl node) {
74 return DebuggerUIUtil.hasEvaluationExpression(node.getValueContainer());
80 public DnDDragStartBean startDragging(final DnDAction action, final Point dragOrigin) {
81 return new DnDDragStartBean(getNodesToDrag());
85 public Pair<Image, Point> createDraggedImage(final DnDAction action, final Point dragOrigin) {
86 XValueNodeImpl[] nodes = getNodesToDrag();
87 if (nodes.length == 1) {
88 return DnDAwareTree.getDragImage(myTree, nodes[0].getPath(), dragOrigin);
90 return DnDAwareTree.getDragImage(myTree, XDebuggerBundle.message("xdebugger.drag.text.0.elements", nodes.length), dragOrigin);
94 public void dragDropEnd() {
98 public void dropActionChanged(final int gestureModifiers) {