public void installDndSupport(ChangeListOwner owner) {
    myDragOwner = owner;
    myDropTarget = new DropTarget();
    myDndManager = DnDManager.getInstance();

    myDndManager.registerSource(this);
    myDndManager.registerTarget(myDropTarget, this);
  }
  @Override
  public void dispose() {
    if (myDropTarget != null) {
      myDndManager.unregisterSource(this);
      myDndManager.unregisterTarget(myDropTarget, this);

      myDropTarget = null;
      myDndManager = null;
      myDragOwner = null;
    }
  }
  public LayoutTreeComponent(
      ArtifactEditorImpl artifactsEditor,
      ComplexElementSubstitutionParameters substitutionParameters,
      ArtifactEditorContext context,
      Artifact originalArtifact,
      boolean sortElements) {
    myArtifactsEditor = artifactsEditor;
    mySubstitutionParameters = substitutionParameters;
    myContext = context;
    myOriginalArtifact = originalArtifact;
    mySortElements = sortElements;
    myTree = new LayoutTree(myArtifactsEditor);
    myTreeStructure = new LayoutTreeStructure();
    myBuilder = new LayoutTreeBuilder();
    Disposer.register(this, myTree);
    Disposer.register(this, myBuilder);

    myTree.addTreeSelectionListener(
        new TreeSelectionListener() {
          @Override
          public void valueChanged(TreeSelectionEvent e) {
            updatePropertiesPanel(false);
          }
        });
    createPropertiesPanel();
    myTreePanel = new JPanel(new BorderLayout());
    myTreePanel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
    myTreePanel.add(myPropertiesPanelWrapper, BorderLayout.SOUTH);
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
      DnDManager.getInstance().registerTarget(this, myTree);
    }
  }
 @Override
 public void dispose() {
   if (myDndManager != null) {
     if (myDropTarget != null) {
       myDndManager.unregisterTarget(myDropTarget, myTree);
       myDropTarget = null;
     }
     if (myDragSource != null) {
       myDndManager.unregisterSource(myDragSource, myTree);
       myDragSource = null;
     }
     myDndManager = null;
   }
   setTreeBuilder(null);
   myTree = null;
   myTreeStructure = null;
 }
Ejemplo n.º 5
0
  public LayoutTree(ArtifactEditorImpl artifactsEditor) {
    myArtifactsEditor = artifactsEditor;
    setRootVisible(true);
    setShowsRootHandles(false);
    setCellEditor(new LayoutTreeCellEditor());
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
      DnDManager.getInstance().registerSource(this);
    }

    // todo[nik,pegov] fix for tooltips in the tree. Otherwise tooltips will be ignored by
    // DnDEnabled
    setToolTipText("");
  }
  protected void enableDnD() {
    if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
      myDropTarget =
          new ProjectViewDropTarget(
              myTree,
              new Retriever() {
                @Override
                public PsiElement getPsiElement(@Nullable TreeNode node) {
                  return getPSIElement(getElementFromTreeNode(node));
                }

                @Override
                public Module getModule(TreeNode treeNode) {
                  return getNodeModule(getElementFromTreeNode(treeNode));
                }
              },
              myProject);
      myDragSource = new MyDragSource();
      myDndManager = DnDManager.getInstance();
      myDndManager.registerSource(myDragSource, myTree);
      myDndManager.registerTarget(myDropTarget, myTree);
    }
  }
Ejemplo n.º 7
0
  public PaletteGroupHeader(PaletteWindow paletteWindow, PaletteGroup group) {
    myPaletteWindow = paletteWindow;
    myGroup = group;
    if (group.getName() == null) {
      setVisible(false);
    } else {
      setText(group.getName());
    }
    setSelected(true);
    addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (myComponentList != null) {
              myComponentList.setVisible(isSelected());
            }
          }
        });

    addMouseListener(
        new PopupHandler() {
          public void invokePopup(Component comp, int x, int y) {
            myPaletteWindow.setLastFocusedGroup(PaletteGroupHeader.this);
            showGroupPopupMenu(comp, x, y);
          }
        });

    setIcon(UIUtil.getTreeCollapsedIcon());
    setSelectedIcon(UIUtil.getTreeExpandedIcon());
    setFont(getFont().deriveFont(Font.BOLD));
    setFocusPainted(false);
    setMargin(new Insets(0, 3, 0, 3));
    setOpaque(true);
    if (getBorder() instanceof CompoundBorder) { // from BasicLookAndFeel
      Dimension pref = getPreferredSize();
      pref.height -= 3;
      setPreferredSize(pref);
    }

    DnDManager.getInstance()
        .registerTarget(
            new DnDTarget() {
              public boolean update(DnDEvent aEvent) {
                setBorderPainted(true);
                aEvent.setDropPossible(aEvent.getAttachedObject() instanceof PaletteItem);
                return true;
              }

              public void drop(DnDEvent aEvent) {
                setBorderPainted(false);
                if (aEvent.getAttachedObject() instanceof PaletteItem) {
                  myGroup.handleDrop(
                      myPaletteWindow.getProject(), (PaletteItem) aEvent.getAttachedObject(), -1);
                }
              }

              public void cleanUpOnLeave() {
                setBorderPainted(false);
              }

              public void updateDraggedImage(Image image, Point dropPoint, Point imageOffset) {}
            },
            this);

    addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            myPaletteWindow.setLastFocusedGroup(PaletteGroupHeader.this);
          }
        });

    initActions();
  }
  public XWatchesViewImpl(
      @NotNull final XDebugSession session, final @NotNull XDebugSessionData sessionData) {
    mySession = session;
    mySessionData = sessionData;
    myTreePanel =
        new XDebuggerTreePanel(
            session.getProject(),
            session.getDebugProcess().getEditorsProvider(),
            this,
            null,
            XDebuggerActions.WATCHES_TREE_POPUP_GROUP,
            ((XDebugSessionImpl) session).getValueMarkers());

    ActionManager actionManager = ActionManager.getInstance();

    XDebuggerTree tree = myTreePanel.getTree();
    actionManager
        .getAction(XDebuggerActions.XNEW_WATCH)
        .registerCustomShortcutSet(CommonShortcuts.INSERT, tree);
    actionManager
        .getAction(XDebuggerActions.XREMOVE_WATCH)
        .registerCustomShortcutSet(CommonShortcuts.DELETE, tree);

    CustomShortcutSet f2Shortcut = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
    actionManager
        .getAction(XDebuggerActions.XEDIT_WATCH)
        .registerCustomShortcutSet(f2Shortcut, tree);

    DnDManager.getInstance().registerTarget(this, tree);
    myRootNode = new WatchesRootNode(tree, session, this, sessionData.getWatchExpressions());
    tree.setRoot(myRootNode, false);

    final ToolbarDecorator decorator =
        ToolbarDecorator.createDecorator(myTreePanel.getTree()).disableUpDownActions();
    decorator.setAddAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            executeAction(XDebuggerActions.XNEW_WATCH);
          }
        });
    decorator.setRemoveAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            executeAction(XDebuggerActions.XREMOVE_WATCH);
          }
        });
    CustomLineBorder border =
        new CustomLineBorder(
            CaptionPanel.CNT_ACTIVE_BORDER_COLOR,
            SystemInfo.isMac ? 1 : 0,
            0,
            SystemInfo.isMac ? 0 : 1,
            0);
    decorator.setToolbarBorder(border);
    myDecoratedPanel = decorator.createPanel();
    myDecoratedPanel.setBorder(null);

    myTreePanel.getTree().getEmptyText().setText(XDebuggerBundle.message("debugger.no.watches"));
  }
 @Override
 public void dispose() {
   DnDManager.getInstance().unregisterTarget(this, myTreePanel.getTree());
 }
  public MainWatchPanel(Project project, DebuggerStateManager stateManager) {
    super(project, stateManager);
    final WatchDebuggerTree watchTree = getWatchTree();

    final AnAction removeWatchesAction =
        ActionManager.getInstance().getAction(DebuggerActions.REMOVE_WATCH);
    removeWatchesAction.registerCustomShortcutSet(CommonShortcuts.DELETE, watchTree);

    final AnAction newWatchAction =
        ActionManager.getInstance().getAction(DebuggerActions.NEW_WATCH);
    newWatchAction.registerCustomShortcutSet(CommonShortcuts.INSERT, watchTree);

    final ClickListener mouseListener =
        new DoubleClickListener() {
          @Override
          protected boolean onDoubleClick(MouseEvent e) {
            AnAction editWatchAction =
                ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH);
            Presentation presentation = editWatchAction.getTemplatePresentation().clone();
            DataContext context = DataManager.getInstance().getDataContext(watchTree);

            AnActionEvent actionEvent =
                new AnActionEvent(
                    null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0);
            editWatchAction.actionPerformed(actionEvent);
            return true;
          }
        };
    ListenerUtil.addClickListener(watchTree, mouseListener);

    final AnAction editWatchAction =
        ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH);
    editWatchAction.registerCustomShortcutSet(
        new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)), watchTree);
    registerDisposable(
        new Disposable() {
          public void dispose() {
            ListenerUtil.removeClickListener(watchTree, mouseListener);
            removeWatchesAction.unregisterCustomShortcutSet(watchTree);
            newWatchAction.unregisterCustomShortcutSet(watchTree);
            editWatchAction.unregisterCustomShortcutSet(watchTree);
          }
        });

    DnDManager.getInstance()
        .registerTarget(
            new DnDNativeTarget() {
              public boolean update(final DnDEvent aEvent) {
                Object object = aEvent.getAttachedObject();
                if (object == null) return true;

                String add = DebuggerBundle.message("watchs.add.text");

                if (object.getClass().isArray()) {
                  Class<?> type = object.getClass().getComponentType();
                  if (DebuggerTreeNodeImpl.class.isAssignableFrom(type)) {
                    aEvent.setHighlighting(
                        myTree,
                        DnDEvent.DropTargetHighlightingType.RECTANGLE
                            | DnDEvent.DropTargetHighlightingType.TEXT);
                    aEvent.setDropPossible(
                        add,
                        new DropActionHandler() {
                          public void performDrop(final DnDEvent aEvent) {
                            addWatchesFrom((DebuggerTreeNodeImpl[]) aEvent.getAttachedObject());
                          }
                        });
                  }
                } else if (object instanceof EventInfo) {
                  EventInfo info = (EventInfo) object;
                  final String text = info.getTextForFlavor(DataFlavor.stringFlavor);
                  if (text != null) {
                    aEvent.setHighlighting(
                        myTree,
                        DnDEvent.DropTargetHighlightingType.RECTANGLE
                            | DnDEvent.DropTargetHighlightingType.TEXT);
                    aEvent.setDropPossible(
                        add,
                        new DropActionHandler() {
                          public void performDrop(final DnDEvent aEvent) {
                            addWatchesFrom(text);
                          }
                        });
                  }
                }

                return true;
              }

              public void drop(final DnDEvent aEvent) {}

              public void cleanUpOnLeave() {}

              public void updateDraggedImage(
                  final Image image, final Point dropPoint, final Point imageOffset) {}
            },
            myTree);
  }
 @Override
 public void dispose() {
   if (!ApplicationManager.getApplication().isUnitTestMode()) {
     DnDManager.getInstance().unregisterTarget(this, myTree);
   }
 }
Ejemplo n.º 12
0
 public void dispose() {
   if (!ApplicationManager.getApplication().isUnitTestMode()) {
     DnDManager.getInstance().unregisterSource(this);
   }
 }
  protected final JTree createTree(boolean dndAware) {
    final Tree tree;
    final NullableFunction<Object, PsiElement> toPsiConverter =
        o -> {
          if (o instanceof HierarchyNodeDescriptor) {
            return ((HierarchyNodeDescriptor) o).getContainingFile();
          }
          return null;
        };

    if (dndAware) {
      tree =
          new DnDAwareTree(new DefaultTreeModel(new DefaultMutableTreeNode(""))) {
            @Override
            public void removeNotify() {
              super.removeNotify();
              if (ScreenUtil.isStandardAddRemoveNotify(this))
                myRefreshAction.unregisterCustomShortcutSet(this);
            }

            @Override
            public boolean isFileColorsEnabled() {
              return ProjectViewTree.isFileColorsEnabledFor(this);
            }

            @Override
            public Color getFileColorFor(Object object) {
              return ProjectViewTree.getColorForObject(object, myProject, toPsiConverter);
            }
          };

      if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
        DnDManager.getInstance()
            .registerSource(
                new DnDSource() {
                  @Override
                  public boolean canStartDragging(final DnDAction action, final Point dragOrigin) {
                    return getSelectedElements().length > 0;
                  }

                  @Override
                  public DnDDragStartBean startDragging(
                      final DnDAction action, final Point dragOrigin) {
                    return new DnDDragStartBean(
                        new TransferableWrapper() {
                          @Override
                          public TreeNode[] getTreeNodes() {
                            return tree.getSelectedNodes(TreeNode.class, null);
                          }

                          @Override
                          public PsiElement[] getPsiElements() {
                            return getSelectedElements();
                          }

                          @Override
                          public List<File> asFileList() {
                            return PsiCopyPasteManager.asFileList(getPsiElements());
                          }
                        });
                  }

                  @Override
                  public Pair<Image, Point> createDraggedImage(
                      final DnDAction action, final Point dragOrigin) {
                    return null;
                  }

                  @Override
                  public void dragDropEnd() {}

                  @Override
                  public void dropActionChanged(final int gestureModifiers) {}
                },
                tree);
      }
    } else {
      tree =
          new Tree(new DefaultTreeModel(new DefaultMutableTreeNode(""))) {
            @Override
            public void removeNotify() {
              super.removeNotify();
              if (ScreenUtil.isStandardAddRemoveNotify(this))
                myRefreshAction.unregisterCustomShortcutSet(this);
            }

            @Override
            public boolean isFileColorsEnabled() {
              return ProjectViewTree.isFileColorsEnabledFor(this);
            }

            @Override
            public Color getFileColorFor(Object object) {
              return ProjectViewTree.getColorForObject(object, myProject, toPsiConverter);
            }
          };
    }
    configureTree(tree);
    EditSourceOnDoubleClickHandler.install(tree);
    myRefreshAction.registerShortcutOn(tree);

    return tree;
  }