You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BrowserViewTreeListener.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * Helen Hawkins Converted to new interface (bug 148190)
  13. * ******************************************************************/
  14. package org.aspectj.ajde.ui.swing;
  15. import java.awt.event.ActionEvent;
  16. import java.awt.event.InputEvent;
  17. import java.awt.event.MouseEvent;
  18. import java.awt.event.MouseListener;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import javax.swing.AbstractAction;
  22. import javax.swing.JMenuItem;
  23. import javax.swing.JPopupMenu;
  24. import javax.swing.event.TreeSelectionEvent;
  25. import javax.swing.event.TreeSelectionListener;
  26. import org.aspectj.ajde.Ajde;
  27. import org.aspectj.asm.IProgramElement;
  28. /**
  29. * @author Mik Kersten
  30. */
  31. class BrowserViewTreeListener implements TreeSelectionListener, MouseListener {
  32. private StructureTree tree = null;
  33. public BrowserViewTreeListener(StructureTree tree) {
  34. this.tree = tree;
  35. }
  36. public void valueChanged(TreeSelectionEvent e) { }
  37. public void mouseEntered(MouseEvent e) { }
  38. public void mouseExited(MouseEvent e) { }
  39. public void mousePressed(MouseEvent e) { }
  40. public void mouseReleased(MouseEvent e) { }
  41. public void mouseClicked(MouseEvent e) {
  42. singleClickNavigation(e);
  43. //doubleClickNavigation(e);
  44. maybeShowPopup(e);
  45. }
  46. public void singleClickNavigation(MouseEvent e) {
  47. SwingTreeViewNode treeNode = (SwingTreeViewNode)tree.getLastSelectedPathComponent();
  48. if (treeNode != null && !e.isControlDown() && !e.isShiftDown() && e.getModifiers() != 4) {
  49. IProgramElement currNode = (IProgramElement)treeNode.getUserObject();
  50. if (currNode!=null && !e.isControlDown()
  51. && !e.isShiftDown() && e.getModifiers() != 4) {
  52. //AjdeUIManager.getDefault().getViewManager().showNodeInMasterView((ProgramElementNode)currNode);
  53. //if (AjdeUIManager.getDefault().getViewManager().isSplitViewMode()) {
  54. // AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView((ProgramElementNode)currNode);
  55. //}
  56. }
  57. // else if (currNode instanceof LinkNode) {
  58. //if (!AjdeUIManager.getDefault().getViewManager().isSplitViewMode()) {
  59. // AjdeUIManager.getDefault().getViewManager().showNodeInMasterView((LinkNode)currNode);
  60. //} else {
  61. // AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView(((LinkNode)currNode).getProgramElementNode());
  62. //}
  63. // }
  64. }
  65. }
  66. public void doubleClickNavigation(MouseEvent e) {
  67. // int clickCount = e.getClickCount();
  68. SwingTreeViewNode treeNode = (SwingTreeViewNode)tree.getLastSelectedPathComponent();
  69. if (treeNode != null) {
  70. IProgramElement currNode = (IProgramElement)treeNode.getUserObject();
  71. if (currNode!=null && !e.isControlDown() && !e.isShiftDown()
  72. && e.getModifiers() != 4) {
  73. //AjdeUIManager.getDefault().getViewManager().showNodeInMasterView(((LinkNode)currNode).getProgramElementNode());
  74. //AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView(((LinkNode)currNode).getProgramElementNode());
  75. }
  76. // else if (currNode instanceof LinkNode) {
  77. // if (clickCount == 1) {
  78. // //AjdeUIManager.getDefault().getViewManager().showLink((LinkNode)currNode);
  79. // } else if (clickCount == 2) {
  80. // //navigationAction((ProgramElementNode)((LinkNode)currNode).getProgramElementNode(), true, true);
  81. // }
  82. // }
  83. }
  84. }
  85. /**
  86. * @todo this should probably use <CODE>e.isPopupTrigger()</CODE> but that
  87. * doesn't work for some reason, so we just check if the right mouse button
  88. * has been clicked.
  89. */
  90. private void maybeShowPopup(MouseEvent e) {
  91. if (e.getModifiers() == InputEvent.BUTTON3_MASK && tree.getSelectionCount() > 0) {
  92. // TreePath[] selectionPaths = tree.getSelectionPaths();
  93. final List signatures = new ArrayList();
  94. // for (int i = 0; i < selectionPaths.length; i++) {
  95. // IProgramElement currNode = (IProgramElement)((SwingTreeViewNode)selectionPaths[i].getLastPathComponent()).getUserObject();
  96. //// if (currNode instanceof LinkNode || currNode instanceof IProgramElement) {
  97. //// signatures.add(currNode);
  98. //// }
  99. // }
  100. JPopupMenu popup = new JPopupMenu();
  101. JMenuItem showSourcesItem = new JMenuItem("Display sources", Ajde.getDefault().getIconRegistry().getStructureSwingIcon(IProgramElement.Kind.CODE));
  102. showSourcesItem.setFont(new java.awt.Font("Dialog", 0, 11));
  103. showSourcesItem.addActionListener(new AbstractAction() {
  104. private static final long serialVersionUID = 1L;
  105. public void actionPerformed(ActionEvent e) {
  106. //AjdeUIManager.getDefault().getViewManager().showSourcesNodes(signatures);
  107. // USED THE FOLLOWING FROM: BrowserViewManager:
  108. // public void showSourcesNodes(java.util.List nodes) {
  109. // for (Iterator it = nodes.iterator(); it.hasNext(); ) {
  110. // ProgramElementNode currNode = null;
  111. // IProgramElement IProgramElement = (IProgramElement)it.next();
  112. // if (IProgramElement instanceof LinkNode) {
  113. // currNode = ((LinkNode)IProgramElement).getProgramElementNode();
  114. // } else {
  115. // currNode = (ProgramElementNode)IProgramElement;
  116. // }
  117. // ISourceLocation sourceLoc = currNode.getSourceLocation();
  118. // if (null != sourceLoc) {
  119. // Ajde.getDefault().getEditorManager().addViewForSourceLine(
  120. // sourceLoc.getSourceFile().getAbsolutePath(),
  121. // sourceLoc.getLine());
  122. // }
  123. // }
  124. // }
  125. }
  126. });
  127. popup.add(showSourcesItem);
  128. popup.addSeparator();
  129. JMenuItem generatePCD = new JMenuItem("Pointcut Wizard (alpha)...", Ajde.getDefault().getIconRegistry().getStructureSwingIcon(IProgramElement.Kind.POINTCUT));
  130. generatePCD.setFont(new java.awt.Font("Dialog", 0, 11));
  131. generatePCD.addActionListener(new AbstractAction() {
  132. private static final long serialVersionUID = 1L;
  133. public void actionPerformed(ActionEvent e) {
  134. Ajde.getDefault().getViewManager().extractAndInsertSignatures(signatures, true);
  135. }
  136. });
  137. popup.add(generatePCD);
  138. popup.show(e.getComponent(), e.getX(), e.getY());
  139. }
  140. }
  141. }