View Javadoc

1   /* ==========================================================================
2    * Copyright 2003-2004 Mevenide Team
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   * =========================================================================
16   */
17  package org.mevenide.idea.util.ui.tree;
18  
19  import javax.swing.tree.DefaultMutableTreeNode;
20  import org.mevenide.idea.Res;
21  
22  /***
23   * @author Arik
24   */
25  public class GoalTreeNode extends DefaultMutableTreeNode {
26      private static final Res RES = Res.getInstance(GoalTreeNode.class);
27      private final String description;
28      private final String[] prereqs;
29  
30      public GoalTreeNode(final String pGoal) {
31          this(pGoal, null, null);
32      }
33  
34      public GoalTreeNode(final String pGoal, final String pDescription) {
35          this(pGoal, pDescription, null);
36      }
37  
38      public GoalTreeNode(final String pGoal, final String[] pPrereqs) {
39          this(pGoal, null, pPrereqs);
40      }
41  
42      public GoalTreeNode(final String pGoal,
43                          final String pDescription,
44                          final String[] pPrereqs) {
45          super(pGoal);
46  
47          if (pGoal == null || pGoal.trim().length() == 0)
48              throw new IllegalArgumentException(RES.get("empty.goal.name"));
49  
50          if (pDescription == null || pDescription.trim().length() == 0 || pDescription.equalsIgnoreCase(
51              "null"))
52              description = null;
53          else
54              description = pDescription;
55  
56          if (pPrereqs == null)
57              prereqs = new String[0];
58          else
59              prereqs = pPrereqs;
60      }
61  
62      public String getUserObject() {
63          return (String) super.getUserObject();
64      }
65  
66      public String getGoal() {
67          return getUserObject();
68      }
69  
70      public String getDescription() {
71          return description;
72      }
73  
74      public String[] getPrereqs() {
75          return prereqs;
76      }
77  
78      public String toString() {
79          if (description == null || description.trim().length() == 0)
80              return super.toString();
81          else
82              return super.toString() + " - " + description;
83      }
84  
85      @Override
86      public boolean getAllowsChildren() {
87          return false;
88      }
89  }