View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the License); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.plugin.views.outline.items;
13  
14  import java.util.ArrayList;
15  import java.util.List;
16  
17  import org.eclipse.ui.views.properties.IPropertySource;
18  import org.w3c.dom.Node;
19  
20  public class OutlineItem extends Object {
21  
22      private static final List<OutlineItem> EMPTY_LIST = new ArrayList<OutlineItem>();
23  
24      /***
25       * Holds parent Outline item.
26       */
27      private OutlineItem parent;
28  
29      /***
30       * Holds node, which this outline item displays.
31       */
32      private Node model;
33  
34      protected IPropertySource propSource;
35  
36      /***
37       * Constructor.
38       * 
39       * @param model
40       */
41      public OutlineItem(Node model) {
42          super();
43          setModel(model);
44      }
45  
46      /***
47       * Constructor.
48       * @param model
49       * @param parent
50       */
51      public OutlineItem(Node model, OutlineItem parent) {
52          this(model);
53          setParent(parent);
54      }
55  
56      public void addChild(OutlineItem child) {
57      }
58  
59      protected IPropertySource createPropertySource() {
60          return null;
61      }
62  
63      public List<OutlineItem> getChildren() {
64          return EMPTY_LIST;
65      }
66  
67      public String getImageKey() {
68          return null;
69      }
70  
71      public Node getModel() {
72          return this.model;
73      }
74  
75      public OutlineItem getParent() {
76          return this.parent;
77      }
78  
79      public IPropertySource getPropertySource() {
80          if (this.propSource == null) {
81              setPropSource(createPropertySource());
82          }
83          return this.propSource;
84      }
85  
86      public boolean isLeaf() {
87          return getChildren().size() == 0;
88      }
89  
90      public void removeChild(OutlineItem child) {
91      }
92  
93      public void setModel(Node model) {
94          this.model = model;
95      }
96  
97      public void setParent(OutlineItem parent) {
98          this.parent = parent;
99      }
100 
101     @Override
102     public String toString() {
103         return "OutlineNode (model: " + getModel().toString().trim() + ")";
104     }
105 
106     /***
107      * @param propSource The propSource to set.
108      */
109     protected void setPropSource(IPropertySource propSource) {
110         this.propSource = propSource;
111     }
112 
113 }