BrightSide Workbench Full Report + Source Code
DaoHtmlTree.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.jpa.iterator;
20 
21 import java.lang.reflect.ParameterizedType;
22 import java.util.List;
23 import org.turro.string.ObjectString;
24 import org.turro.string.Strings;
25 import org.turro.collections.Item;
26 import org.turro.elephant.calendar.ElephantCalendar;
27 import org.turro.elephant.context.IConstructor;
28 import org.turro.jpa.Dao;
29 import org.turro.marker.ElephantMarker;
30 import org.turro.visual.EmptyVisualElements;
31 import org.turro.visual.VisualElements;
32 
39 public abstract class DaoHtmlTree<E, ID> extends DaoTree<E, ID> {
40 
43 
44  private String treeTemplate, fullTemplate;
45  private ID itemID;
46  private final Class<ID> idClass;
47 
49  super(dao);
50  this.marker = marker;
51  this.constructor = marker.getConstructor();
52  this.idClass = (Class<ID>) ((ParameterizedType) getClass()
53  .getGenericSuperclass()).getActualTypeArguments()[1];
54  }
55 
56  public String getTreeTemplate() {
57  return Strings.isBlank(treeTemplate) ? "tree" : treeTemplate;
58  }
59 
60  public void setTreeTemplate(String treeTemplate) {
61  this.treeTemplate = treeTemplate;
62  }
63 
64  public String getFullTemplate() {
65  return Strings.isBlank(fullTemplate) ? "full" : fullTemplate;
66  }
67 
68  public void setFullTemplate(String fullTemplate) {
69  this.fullTemplate = fullTemplate;
70  }
71 
72  public void render() {
73  marker.put("iterator", this);
74  itemID = (ID) ObjectString.parseString(constructor.getParameter("item"), idClass, false);
75  if(itemID != null) {
76  renderItem(marker, getEntity(itemID));
77  } else {
78  if(!isEmpty()) {
79  renderTree(marker, getItems());
80  }
81  }
82  }
83 
84  public String parse() {
85  marker.put("iterator", this);
86  itemID = (ID) ObjectString.parseString(constructor.getParameter("item"), idClass, false);
87  if(itemID != null) {
88  return parseItem(marker, getEntity(itemID));
89  } else {
90  if(!isEmpty()) {
91  return parseTree(marker, getItems());
92  }
93  }
94  return "";
95  }
96 
97  /* Visuals */
98 
99  public VisualElements getVisuals() {
100  if(_visuals == null) {
101  _visuals = loadVisuals();
102  }
103  return _visuals;
104  }
105 
106  private VisualElements _visuals;
107 
108  protected VisualElements loadVisuals() {
109  return new EmptyVisualElements();
110  }
111 
112  /* End visuals */
113 
114  public void renderSelected() {}
115  public String parseSelected() { return ""; }
116 
117  protected abstract void renderTree(ElephantMarker marker, List<Item<E, ID>> items);
118  protected abstract void renderItem(ElephantMarker marker, E item);
119 
120  protected abstract String parseTree(ElephantMarker marker, List<Item<E, ID>> items);
121  protected abstract String parseItem(ElephantMarker marker, E item);
122 
123 }
DaoHtmlTree(Dao dao, ElephantMarker marker)
abstract String parseItem(ElephantMarker marker, E item)
void setTreeTemplate(String treeTemplate)
abstract String parseTree(ElephantMarker marker, List< Item< E, ID >> items)
abstract void renderItem(ElephantMarker marker, E item)
abstract void renderTree(ElephantMarker marker, List< Item< E, ID >> items)
void setFullTemplate(String fullTemplate)
Object put(Object key, Object value)