View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.component;
21  
22  import org.apache.myfaces.tobago.component.SupportsMarkup;
23  import org.apache.myfaces.tobago.component.TreeModelBuilder;
24  import org.apache.myfaces.tobago.config.Configurable;
25  import org.apache.myfaces.tobago.event.TreeExpansionListener;
26  import org.apache.myfaces.tobago.event.TreeMarkedListener;
27  import org.apache.myfaces.tobago.internal.util.Deprecation;
28  import org.apache.myfaces.tobago.model.MixedTreeModel;
29  import org.apache.myfaces.tobago.model.TreeDataModel;
30  import org.apache.myfaces.tobago.model.TreePath;
31  import org.apache.myfaces.tobago.util.ComponentUtils;
32  
33  import javax.faces.component.UIData;
34  import javax.faces.context.FacesContext;
35  import javax.faces.el.MethodBinding;
36  import javax.swing.tree.TreeNode;
37  import java.io.IOException;
38  import java.util.List;
39  
40  public abstract class AbstractUITreeNode
41      extends AbstractUIColumn implements SupportsMarkup, TreeModelBuilder, Configurable {
42  
43    @Override
44    public void encodeBegin(final FacesContext facesContext) throws IOException {
45      final TreeDataModel model = ComponentUtils.findAncestor(this, AbstractUIData.class).getTreeDataModel();
46      model.setRowClientId(getClientId(facesContext));
47  
48      super.encodeBegin(facesContext);
49    }
50  
51    /**
52     * Returns the level of the tree node inside of the virtual tree. The root node has level 0.
53     * The children of the root note have level 1, and so on.
54     */
55    public int getLevel() {
56      final TreeDataModel model = ComponentUtils.findAncestor(this, AbstractUIData.class).getTreeDataModel();
57      return model.getLevel();
58    }
59  
60    public List<Boolean> getJunctions() {
61      final TreeDataModel model = ComponentUtils.findAncestor(this, AbstractUIData.class).getTreeDataModel();
62      return model.getJunctions();
63    }
64  
65    public boolean isFolder() {
66      final TreeDataModel model = ComponentUtils.findAncestor(this, AbstractUIData.class).getTreeDataModel();
67      return model.isFolder();
68    }
69  
70    public TreePath getPath() {
71      final TreeDataModel model = ComponentUtils.findAncestor(this, AbstractUIData.class).getTreeDataModel();
72      return model.getPath();
73    }
74  
75    public String nodeStateId(final FacesContext facesContext) {
76      final String clientId = getClientId(facesContext);
77      final UIData data = ComponentUtils.findAncestor(this, UIData.class);
78      final String dataId = data.getClientId(facesContext);
79      return clientId.substring(dataId.length() + 1);
80    }
81  
82    // ///////////////////////////////////////////////////////////////////////////////////////////////////////////
83    // below only deprecated
84  
85    /**
86     * @deprecated since 2.0.0
87     */
88    @Deprecated
89    protected TreeNode getRowData() {
90      final UIData data = ComponentUtils.findAncestor(this, UIData.class);
91      final Object rowData = data.getRowData();
92      return (TreeNode) rowData;
93    }
94  
95    /**
96     * @deprecated since 2.0.0
97     */
98    @Deprecated
99    public void buildTreeModelBegin(final FacesContext facesContext, final MixedTreeModel model) {
100     Deprecation.LOG.error("Doesn't work anymore.");
101   }
102 
103   /**
104    * @deprecated since 2.0.0
105    */
106   @Deprecated
107   public void buildTreeModelChildren(final FacesContext facesContext, final MixedTreeModel model) {
108     Deprecation.LOG.error("Doesn't work anymore.");
109   }
110 
111   /**
112    * @deprecated since 2.0.0
113    */
114   @Deprecated
115   public void buildTreeModelEnd(final FacesContext facesContext, final MixedTreeModel model) {
116     Deprecation.LOG.error("Doesn't work anymore.");
117   }
118 
119   /**
120    * @deprecated since 2.0.0
121    */
122   @Deprecated
123   public int getDepth() {
124     Deprecation.LOG.error("Doesn't work anymore.");
125     return 1;
126   }
127 
128   /**
129    * @deprecated since 2.0.0
130    */
131   @Deprecated
132   public void setDepth(final int depth) {
133     Deprecation.LOG.error("Doesn't work anymore.");
134   }
135 
136   /**
137    * @deprecated since 2.0.0
138    */
139   @Deprecated
140   public void setFolder(final boolean folder) {
141     Deprecation.LOG.error("Doesn't work anymore.");
142   }
143 
144   /**
145    * @deprecated since 2.0.0
146    */
147   @Deprecated
148   public void setPath(final TreePath path) {
149     Deprecation.LOG.error("Doesn't work anymore.");
150   }
151 
152   /**
153    * @deprecated since 2.0.0
154    */
155   @Deprecated
156   public void setJunctions(final List<Boolean> junctions) {
157     Deprecation.LOG.error("Doesn't work anymore.");
158   }
159 
160   /**
161    * @deprecated since 2.0.0
162    */
163   @Deprecated
164   public boolean isHasNextSibling() {
165     Deprecation.LOG.error("Doesn't work anymore.");
166     return false;
167   }
168 
169   /**
170    * @deprecated since 2.0.0
171    */
172   @Deprecated
173   public void setHasNextSibling(final boolean hasNextSibling) {
174     Deprecation.LOG.error("Doesn't work anymore.");
175   }
176 
177   /**
178    * @deprecated since 2.0.0
179    */
180   @Deprecated
181   public MethodBinding getTreeExpansionListener(){
182       Deprecation.LOG.error("treeExpansionListener!");
183       return null;
184     }
185 
186   /**
187    * @deprecated since 2.0.0
188    */
189   @Deprecated
190   public void setTreeExpansionListener(final MethodBinding treeExpansionListener){
191         Deprecation.LOG.error("treeExpansionListener!");
192       }
193 
194   /**
195    * @deprecated since 2.0.0
196    */
197   @Deprecated
198   public void addTreeExpansionListener(final TreeExpansionListener listener) {
199     Deprecation.LOG.error("treeExpansionListener!");
200   }
201 
202   /**
203    * @deprecated since 2.0.0
204    */
205   @Deprecated
206   public TreeExpansionListener[] getTreeExpansionListeners() {
207     Deprecation.LOG.error("treeExpansionListener!");
208     return null;
209   }
210 
211   /**
212    * @deprecated since 2.0.0
213    */
214   @Deprecated
215   public void removeStateChangeListener(final TreeExpansionListener listener) {
216     Deprecation.LOG.error("treeExpansionListener!");
217   }
218 
219   /**
220    * @deprecated since 2.0.0
221    */
222   @Deprecated
223   public  MethodBinding getTreeMarkedListener(){
224         Deprecation.LOG.error("treeMarkedListener!");
225         return null;
226       }
227 
228   /**
229    * @deprecated since 2.0.0
230    */
231   @Deprecated
232   public  void setTreeMarkedListener(final MethodBinding treeMarkedListener){
233           Deprecation.LOG.error("treeMarkedListener!");
234         }
235 
236   /**
237    * @deprecated since 2.0.0
238    */
239   @Deprecated
240   public void addTreeMarkedListener(final TreeMarkedListener listener) {
241     Deprecation.LOG.error("treeMarkedListener!");
242   }
243 
244   /**
245    * @deprecated since 2.0.0
246    */
247   @Deprecated
248   public TreeMarkedListener[] getTreeMarkedListeners() {
249     Deprecation.LOG.error("treeMarkedListener!");
250     return null;
251   }
252 
253   /**
254    * @deprecated since 2.0.0
255    */
256   @Deprecated
257   public void removeStateChangeListener(final TreeMarkedListener listener) {
258     Deprecation.LOG.error("treeMarkedListener!");
259   }
260 
261   /**
262    * @deprecated since 2.0.0
263    */
264   @Deprecated
265   public boolean isMarked() {
266     Deprecation.LOG.error("The marked attribute is no longer supported, please use a tree state!");
267     return false;
268   }
269 
270   /**
271    * @deprecated since 2.0.0
272    */
273   @Deprecated
274   public void setMarked(final boolean b) {
275     Deprecation.LOG.error("The marked attribute is no longer supported, please use a tree state!");
276   }
277 
278   /**
279    * @deprecated since 2.0.0
280    */
281   @Deprecated
282   public boolean isExpanded() {
283     Deprecation.LOG.error("The expanded attribute is no longer supported, please use a tree state!");
284     return false;
285   }
286 
287   /**
288    * @deprecated since 2.0.0
289    */
290   @Deprecated
291   public void setExpanded(final boolean expanded) {
292     Deprecation.LOG.error("The expanded attribute is no longer supported, please use a tree state!");
293   }
294 
295   /**
296    * @deprecated since 2.0.0
297    */
298   @Deprecated
299   public boolean isSelected() {
300     Deprecation.LOG.error("The selected attribute is no longer supported, please use a tree select!");
301     return false;
302   }
303 
304   /**
305    * @deprecated since 2.0.0
306    */
307   @Deprecated
308   public void setSelected(final boolean selected) {
309     Deprecation.LOG.error("The selected attribute is no longer supported, please use a tree select!");
310   }
311 }