BrightSide Workbench Full Report + Source Code
Elephant/elephant-alliance/src/main/java/org/turro/alliance/www/CategoriesTree.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.alliance.www;
20 
21 import java.util.List;
22 import org.turro.string.Strings;
23 import org.turro.alliance.db.AlliancePU;
24 import org.turro.alliance.db.entities.AxCategory;
25 import org.turro.collections.Item;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.elephant.context.IConstructor;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.elephant.util.Images;
30 import org.turro.jpa.content.TreeDaoContentIterator;
31 import org.turro.marker.ElephantMarker;
32 import org.turro.path.Path;
33 import org.turro.plugin.contacts.IContact;
34 import org.turro.visual.VisualElements;
35 
40 public class CategoriesTree extends TreeDaoContentIterator<Object, Object> {
41 
42  public CategoriesTree(IConstructor constructor, String context, IContact contact) {
43  super(new AlliancePU(), new ElephantMarker(constructor), context, contact);
44  }
45 
46  @Override
47  protected WhereClause getItemClause(String currPath) {
48  WhereClause wc = new WhereClause();
49  wc.addClause("select g from AxCategory g");
50  wc.addClause("where 1=1");
51  if(Strings.isBlank(currPath)) {
52  wc.addClause("and 1=2");
53  } else {
54  wc.addClause("and g.uniquePath = :pathName");
55  wc.addNamedValue("pathName", currPath);
56  }
57  return wc;
58  }
59 
60  @Override
61  protected Object getEntity(Object value) {
62  return value instanceof String ? getDao().find(AxCategory.class, Long.valueOf((String) value)) : value;
63  }
64 
65  @Override
66  protected WhereClause getChildrenClause(String currPath) {
67  WhereClause wc = new WhereClause();
68  wc.addClause("select g from AxCategory g");
69  wc.addClause("where 1=1");
70  if(Strings.isBlank(currPath)) {
71  wc.addClause("and g.parent is null");
72  } else {
73  wc.addClause("and g.parent.uniquePath = :pathName");
74  wc.addNamedValue("pathName", currPath);
75  }
76  wc.addClause("order by g.name");
77  return wc;
78  }
79 
80  @Override
81  protected WhereClause getLeafClause(String currPath) {
82  return null;
83  }
84 
85  @Override
86  protected Object getId(Object item) {
87  return item instanceof AxCategory ? ((AxCategory) item).getCategoryId() : new Path((String) item).getLastNode();
88  }
89 
90  @Override
91  protected Object getParentId(Object item) {
92  return item instanceof AxCategory ? ((AxCategory) item).getParent().getCategoryId() : new Path((String) item).getLastNode();
93  }
94 
95  public String getImageSrc(Item item) {
96  return ElephantContext.getRootWebPath() + Images.getImage("group");
97  }
98 
99  public String getFolderImageSrc() {
100  return ElephantContext.getRootWebPath() + Images.getImage("group");
101  }
102 
103  public String getCssClass(Item item) {
104  AxCategory cat = (AxCategory) item.getValue();
105  String selected = getSelectedItem();
106  String path = cat.getUniquePath();
107  if(path == null || selected == null) {
108  return "";
109  } else if(path.equals(selected)) {
110  return "active";
111  } else if(selected.startsWith(path)) {
112  return "inpath";
113  } else {
114  return "";
115  }
116  }
117 
118  @Override
119  protected void prepareTree(ElephantMarker marker, List<Item<Object, Object>> items) {
120  String selPath = getSelectedItem();
121  if(Strings.isBlank(selPath) && !items.isEmpty()) {
122  selPath = ((AxCategory) ((Item) items.iterator().next()).getValue()).getUniquePath();
123  setSelectedItem(selPath);
124  }
125  marker.put("selpath", selPath);
126  }
127 
128  @Override
129  protected void prepareItem(ElephantMarker marker, Object item) {
130  // do nothing
131  }
132 
133  @Override
134  protected String getTemplateRoot() {
135  return "alliance/category";
136  }
137 
138  @Override
139  protected Object doVotesCtrl(Object e) {
140  return null;
141  }
142 
143  @Override
144  protected Object doInterestCtrl(Object e) {
145  return null;
146  }
147 
148  @Override
149  protected Object doCommentsCtrl(Object e) {
150  return null;
151  }
152 
153  @Override
154  protected Object doAttachmentsCtrl(Object e) {
155  return null;
156  }
157 
158  @Override
159  protected Object doFilesCtrl(Object e) {
160  return null;
161  }
162 
163  @Override
164  protected Object doDescriptionsCtrl(Object e) {
165  return null;
166  }
167 
168  @Override
169  protected Object doPollsCtrl(Object e) {
170  return null;
171  }
172 
173  @Override
174  protected VisualElements loadVisuals() {
175  return null;
176  }
177 
178 }
void addNamedValue(String name, Object value)
static String getImage(String image)
Definition: Images.java:36
Object put(Object key, Object value)