View Javadoc

1   package de.matthias_burbach.mosaique.swing;
2   
3   
4   import javax.swing.tree.DefaultTreeModel;
5   
6   import de.matthias_burbach.mosaique.core.model.AbstractFileItem;
7   import de.matthias_burbach.mosaique.core.model.Definition;
8   import de.matthias_burbach.mosaique.core.model.Insert;
9   import de.matthias_burbach.mosaique.core.model.TilesContext;
10  
11  /***
12   * @author Matthias Burbach
13   */
14  public class InsertNode extends AbstractFileItemNode {
15      /***
16       * The insert tag to display.
17       */
18      private Insert insert;
19  
20      /***
21       * The tiles context of the Jsp that embodies this insert tag.
22       */
23      private TilesContext tilesContext;
24  
25      /***
26       * The tree model to delegate change operations to.
27       */
28      private DefaultTreeModel treeModel;
29  
30      /***
31       * @param insert The insert tag to display.
32       * @param tilesContext The Tiles context used when the Tile is inserted by
33       *                     the insert element being displayed.
34       * @param treeModel The tree model to delegate change operations to.
35       */
36      public InsertNode(
37              final Insert insert,
38              final TilesContext tilesContext,
39              final DefaultTreeModel treeModel) {
40          this.insert = insert;
41          this.tilesContext = tilesContext;
42          this.treeModel = treeModel;
43      }
44  
45      /*
46       * (non-Javadoc)
47       * @see de.matthias_burbach.mosaique.swing.BaseMutableTreeNode
48       *          #initChildren()
49       */
50      /***
51       * {@inheritDoc}
52       */
53      protected void initChildren() {
54          Definition definition = insert.getDefinition(tilesContext);
55          if (definition != null) {
56              DefinitionNode child =
57                  new DefinitionNode(definition, insert.getPuts(), treeModel);
58              add(child);
59          }
60      }
61  
62      /*
63       * (non-Javadoc)
64       * @see de.matthias_burbach.mosaique.swing.AbstractFileItemNode
65       *          #getFileItem()
66       */
67      /***
68       * {@inheritDoc}
69       */
70      public AbstractFileItem getFileItem() {
71          return insert;
72      }
73  
74      /*(non-Javadoc)
75       * @see javax.swing.tree.TreeNode#isLeaf()
76       */
77      /***
78       * {@inheritDoc}
79       */
80      public boolean isLeaf() {
81          boolean result = true;
82          Definition definition = insert.getDefinition(tilesContext);
83          if (definition != null) {
84              result = false;
85          }
86          return result;
87      }
88  
89      /***
90       * @return The insert of this node.
91       */
92      public Insert getInsert() {
93          return insert;
94      }
95  
96      /*(non-Javadoc)
97       * @see java.lang.Object#toString()
98       */
99      /***
100      * {@inheritDoc}
101      */
102     public String toString() {
103         return insert.getAttribute();
104     }
105 }