View Javadoc

1   package de.matthias_burbach.deputy.swing;
2   
3   import java.util.Iterator;
4   
5   import javax.swing.tree.DefaultTreeModel;
6   
7   import de.matthias_burbach.deputy.core.project.Project;
8   import de.matthias_burbach.deputy.core.project.ProjectConflictGroup;
9   
10  /***
11   * Displays one of the version conflicts of a project as a group of projects
12   * where all have the same group id and the same artifact id but different
13   * versions.
14   * <pre>
15   *     conflicts
16   *      |
17   *  *** - myartifactid1 ***
18   *         |
19   *         +  myartifactid1-version1
20   *         +  myartifactid1-version2
21   *         ...
22   *      - myartifactid2
23   *         |
24   *         +  myartifactid2-version1
25   *         +  myartifactid2-version2
26   *         ...
27   * </pre>
28   * @author Matthias Burbach
29   */
30  public class ConflictTreeNode extends BaseMutableTreeNode {
31      /***
32       * The project which occurs as dependency in multiple versions.
33       */
34      private Project project;
35  
36      /***
37       * The group of projects which all have the same group id and the same
38       * artifact id but which represent different versions.
39       */
40      private ProjectConflictGroup conflictGroup;
41  
42      /***
43       * The model of the tree this node is part of.
44       */
45      private DefaultTreeModel treeModel;
46  
47      /***
48       * Constructs a node.
49       *
50       * @param conflictGroup The group of projects which all have the same group
51       *                      id and the same artifact id but which represent
52       *                      different versions.
53       * @param treeModel The model of the tree this node is part of.
54       */
55      public ConflictTreeNode(
56              final ProjectConflictGroup conflictGroup,
57              final DefaultTreeModel treeModel) {
58          this.project =
59              (Project) conflictGroup.getProjects().get(0);
60          this.conflictGroup = conflictGroup;
61          this.treeModel = treeModel;
62      }
63  
64      /***
65       * @return The conflict group displayed by this node.
66       */
67      public ProjectConflictGroup getConflictGroup() {
68          return conflictGroup;
69      }
70  
71      /*
72       * (non-Javadoc)
73       * @see de.matthias_burbach.deputy.swing.BaseMutableTreeNode#initChildren()
74       */
75      /***
76       * {@inheritDoc}
77       */
78      protected void initChildren() {
79          for (Iterator iter = conflictGroup.getProjects().iterator();
80                  iter.hasNext();) {
81              Project projectVersion = (Project) iter.next();
82              ProjectTreeNode childNode =
83                  new ProjectTreeNode(
84                      projectVersion,
85                      treeModel);
86              add(childNode);
87          }
88      }
89  
90      /*(non-Javadoc)
91       * @see java.lang.Object#toString()
92       */
93      /***
94       * {@inheritDoc}
95       */
96      public String toString() {
97          return project.getArtifactId();
98      }
99  }