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.

SwingTreeViewNode.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.swing;
  14. import java.util.ArrayList;
  15. import java.util.Iterator;
  16. import java.util.List;
  17. import javax.swing.tree.DefaultMutableTreeNode;
  18. import org.aspectj.ajde.ui.AbstractIcon;
  19. import org.aspectj.ajde.ui.IStructureViewNode;
  20. import org.aspectj.ajde.ui.StructureViewNodeFactory;
  21. //import org.aspectj.ajde.ui.IStructureViewNode.Kind;
  22. import org.aspectj.asm.IProgramElement;
  23. import org.aspectj.asm.IRelationship;
  24. /**
  25. * @author Mik Kersten
  26. */
  27. public class SwingTreeViewNode extends DefaultMutableTreeNode implements IStructureViewNode {
  28. private static final long serialVersionUID = 4957761341510335532L;
  29. private String relationshipName;
  30. private IProgramElement programElement;
  31. private AbstractIcon icon;
  32. private IStructureViewNode.Kind kind;
  33. /**
  34. * Create a declaration node.
  35. */
  36. public SwingTreeViewNode(IProgramElement programElement, AbstractIcon icon, List children) {
  37. super(programElement, true);
  38. this.programElement = programElement;
  39. this.icon = icon;
  40. this.kind = Kind.DECLARATION;
  41. if (children != null) {
  42. for (Object o : children) {
  43. SwingTreeViewNode child = (SwingTreeViewNode) o;
  44. if (StructureViewNodeFactory.acceptNode(programElement, child.getStructureNode())) {
  45. super.add(child);
  46. }
  47. }
  48. }
  49. }
  50. /**
  51. * Create a relationship node.
  52. */
  53. public SwingTreeViewNode(IRelationship relationship, AbstractIcon icon) {
  54. super(null, true);
  55. this.icon = icon;
  56. this.kind = Kind.RELATIONSHIP;
  57. this.relationshipName = relationship.getName();
  58. }
  59. /**
  60. * Create a link.
  61. */
  62. public SwingTreeViewNode(IProgramElement programElement, AbstractIcon icon) {
  63. super(programElement, false);
  64. this.programElement = programElement;
  65. this.kind = Kind.LINK;
  66. this.icon = icon;
  67. }
  68. public IProgramElement getStructureNode() {
  69. return programElement;
  70. }
  71. public AbstractIcon getIcon() {
  72. return icon;
  73. }
  74. public void add(IStructureViewNode child) {
  75. super.add((DefaultMutableTreeNode)child);
  76. }
  77. public void add(IStructureViewNode child, int position) {
  78. super.insert((DefaultMutableTreeNode)child, position);
  79. }
  80. public void remove(IStructureViewNode child) {
  81. super.remove((DefaultMutableTreeNode)child);
  82. }
  83. public List getChildren() {
  84. if (children == null) {
  85. return new ArrayList();
  86. } else {
  87. return children;
  88. }
  89. }
  90. public Kind getKind() {
  91. return kind;
  92. }
  93. public String getRelationshipName() {
  94. return relationshipName;
  95. }
  96. public String toString() {
  97. if (kind == IStructureViewNode.Kind.RELATIONSHIP) {
  98. return relationshipName;
  99. } else if (kind == IStructureViewNode.Kind.LINK) {
  100. return programElement.toLinkLabelString();
  101. } else {
  102. return programElement.toLabelString();
  103. }
  104. }
  105. }