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.

StructureView.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * ******************************************************************/
  13. package org.aspectj.ajde.ui;
  14. import org.aspectj.asm.IProgramElement;
  15. /**
  16. * @author Mik Kersten
  17. */
  18. public abstract class StructureView {
  19. private IStructureViewNode rootNode = null;
  20. private IStructureViewNode activeNode = null;
  21. protected StructureViewProperties viewProperties = null;
  22. protected StructureViewRenderer renderer = null;
  23. public StructureViewProperties getViewProperties() {
  24. return viewProperties;
  25. }
  26. public IStructureViewNode getRootNode() {
  27. return rootNode;
  28. }
  29. public void setRootNode(IStructureViewNode rootNode) {
  30. this.rootNode = rootNode;
  31. }
  32. public void setViewProperties(StructureViewProperties viewProperties) {
  33. this.viewProperties = viewProperties;
  34. }
  35. public void setRenderer(StructureViewRenderer renderer) {
  36. this.renderer = renderer;
  37. }
  38. protected void notifyViewUpdated() {
  39. if (renderer != null) renderer.updateView(this);
  40. }
  41. /**
  42. * @return the view node corresponding to the active ProgramElementNode or null
  43. */
  44. public IStructureViewNode getActiveNode() {
  45. if (activeNode != null
  46. && activeNode.getStructureNode()!=null) {
  47. return activeNode;
  48. } else {
  49. return null;
  50. }
  51. }
  52. /**
  53. * Searches from the root node of the view down in order to find matches.
  54. *
  55. * @return the first match
  56. */
  57. public IStructureViewNode findCorrespondingViewNode(IProgramElement node) {
  58. return findCorrespondingViewNodeHelper(rootNode, node);
  59. }
  60. private IStructureViewNode findCorrespondingViewNodeHelper(IStructureViewNode node, IProgramElement pNode) {
  61. if (node != null
  62. && node.getStructureNode() != null
  63. && node.getStructureNode().equals(pNode)
  64. && node.getKind() == IStructureViewNode.Kind.DECLARATION) {
  65. return node;
  66. }
  67. if (node != null && node.getChildren() != null) {
  68. for (Object o : node.getChildren()) {
  69. IStructureViewNode foundNode = findCorrespondingViewNodeHelper((IStructureViewNode) o, pNode);
  70. if (foundNode != null) return foundNode;
  71. }
  72. }
  73. return null;
  74. }
  75. public void setActiveNode(IStructureViewNode activeNode) {
  76. this.activeNode = activeNode;
  77. if (renderer != null) renderer.setActiveNode(activeNode);
  78. }
  79. public void setActiveNode(IStructureViewNode activeNode, int sourceLine) {
  80. this.activeNode = activeNode;
  81. if (renderer != null) renderer.setActiveNode(activeNode, sourceLine);
  82. }
  83. }