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.9KB

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