18 package org.turro.elephant.impl.navigation;
20 import java.io.IOException;
21 import java.io.PrintWriter;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.SortedSet;
25 import org.turro.elephant.context.Application;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.elephant.context.IConstructor;
28 import org.turro.elephant.impl.context.ContextAdapter;
29 import org.turro.elephant.web.ElContext;
30 import org.turro.elephant.web.ElContextMap;
41 protected int level, levelUsed, preloaded;
42 protected boolean dynamicLoad, showCurrent, showTitle, drawDecorators =
true;
77 public void draw() throws IOException {
84 out.print(
"<a href='" + ancestor1.getWebPath() +
"'>" + ancestor1.getName() +
"</a>");
87 out.print(
"<span id='ext_location'></span>");
92 int levelUsed =
level - 1;
93 ElContext previous = getPrevious(current),
94 next = getNext(current,
true);
96 out.print(
"<table width='100%'><tr><td width='35%' align='left'>");
97 if (previous !=
null && ((levelUsed > 0 && currLevel > levelUsed) || levelUsed == 0)) {
98 out.print(
"<span id='trav-previous'><a href='" + previous.
getWebPath() +
"'>" + previous.
getName() +
"</a></span>");
100 out.print(
"</td><td width='30%' align='center'>");
101 if (current.
getParent() !=
null && !current.
getParent().
equals(previous) && ((levelUsed > 0 && currLevel > levelUsed) || levelUsed == 0)) {
104 out.print(
"</td><td width='35%' align='right'>");
106 out.print(
"<span id='trav-next'><a href='" + next.getWebPath() +
"'>" + next.getName() +
"</a></span>");
108 out.print(
"</td></tr></table>");
110 out.print(
"<div class='context-title'>" + current.
getName() +
"</div>");
117 out.print(
"<div class='" +
cssClass +
"_top'><div></div></div>");
121 if (ctx.canDisplay()) {
122 renderContext(out, ctx, current);
123 doChildren(out, ctx, current, preloaded);
129 out.print(
"<div class='" +
cssClass +
"_bottom'><div></div></div>");
132 String offsetLeft =
"0";
134 out.print(
"<div class='" +
cssClass +
"_top'><div></div></div>");
138 if (ctx.canDisplay()) {
139 renderContext(out, ctx, current);
140 doChildren(out, ctx, current, preloaded);
146 out.print(
"<div class='" +
cssClass +
"_bottom'><div></div></div>");
161 public Collection<ContextNavigatorItem>
contexts() throws IOException {
162 ArrayList<ContextNavigatorItem> list =
new ArrayList<>();
163 if(current !=
null) {
165 if(elCurrent !=
null) {
171 int levelUsed =
level - 1;
173 next = elCurrent.
getNext(
true);
174 int currLevel = elCurrent.
getLevel();
175 if (previous !=
null && ((levelUsed > 0 && currLevel > levelUsed) || levelUsed == 0)) {
180 if (elCurrent.
getParent() !=
null && !elCurrent.
getParent().
equals(previous) && ((levelUsed > 0 && currLevel > levelUsed) || levelUsed == 0)) {
192 if (ctx.canDisplay()) {
198 if (ctx.canDisplay()) {
208 private void doChildren(PrintWriter out,
ElContext parent,
ElContext current,
int preload) {
209 if (preload <= 0 && !(showCurrent && parent.
inPath(current))) {
212 SortedSet<ElContext> children = parent.
getChildren();
213 if (children.size() > 0) {
215 for (ElContext ic : children) {
216 if (ic.canDisplay()) {
217 renderContext(out, ic, current);
218 doChildren(out, ic, current, preload - 1);
227 return "<div class='" +
cssClass +
"'>";
245 out.print(
"<li" + classCss +
">");
251 private ElContext getPrevious(ElContext current) {
252 if (current ==
null) {
255 if (current.getParent() !=
null) {
256 SortedSet<ElContext> siblings =
new ContextAdapter(current.getParent().getChildren()).getVisible();
257 for (ElContext ctx : siblings) {
258 if(current.equals(ctx) && !ctx.equals(siblings.first()) && ctx.canDisplay()) {
259 return getLastChildren(ctx);
262 return current.getParent();
267 private ElContext getLastChildren(ElContext current) {
268 SortedSet<ElContext> children =
new ContextAdapter(current.getChildren()).getVisible();
269 if(children.size() > 0) {
270 return getLastChildren(children.last());
275 private ElContext getNext(ElContext current,
boolean doChildren) {
276 if (current ==
null) {
280 SortedSet<ElContext> children =
new ContextAdapter(current.getChildren()).getVisible();
281 if (children.size() > 0) {
282 return children.first();
285 if (current.getParent() !=
null) {
286 SortedSet<ElContext> siblings =
new ContextAdapter(current.getParent().getChildren()).getVisible();
287 for (ElContext ctx : siblings) {
288 if (current.equals(ctx) && !ctx.equals(siblings.last())) {
293 return getNext(current.getParent(),
false);
306 if (nt.name().toLowerCase().equals(typeStr.toLowerCase())) {
321 return drawDecorators;
325 this.drawDecorators = drawDecorators;
333 this.preloaded = preloaded;
357 this.showCurrent = showCurrent;
365 this.showTitle = showTitle;
383 public void drawOptions(
boolean decorators,
int level,
int preloaded,
boolean current)
throws IOException {
394 public boolean hasOptions(
int level,
int preloaded,
boolean current)
throws IOException {
402 if (ctx.canDisplay()) {
432 public Collection<ContextNavigatorItem>
contextOptions(
int level,
int preloaded,
boolean current)
throws IOException {
IConstructor getConstructor()
static Application getApplication()
static String getRootWebPath()
TreeSet< ElContext > getVisible()
void setDrawDecorators(boolean drawDecorators)
SortedSet< ElContext > contexts
Collection< ContextNavigatorItem > contexts()
void setDynamicLoad(boolean dynamicLoad)
boolean isDrawDecorators()
void setShowCurrent(boolean showCurrent)
Collection< ContextNavigatorItem > contextOptions(int level, int preloaded, boolean current)
Collection< ContextNavigatorItem > contextTraversal()
void setType(NavigatorType type)
Collection< ContextNavigatorItem > contextTabulator(int level)
void setTypeString(String typeStr)
void setCssClass(String cssClass)
boolean hasOptions(int level, int preloaded, boolean current)
void drawTraversal(boolean title)
boolean somethingToShow()
void drawTabulator(int level)
Collection< ContextNavigatorItem > contextLocation()
Navigator(ElContext context)
void setPreloaded(int preloaded)
void setShowTitle(boolean showTitle)
void drawOptions(boolean decorators, int level, int preloaded, boolean current)
static ElContext getContext(IConstructor constructor)
static SortedSet< ElContext > getContexts(String from, int level)
TreeSet< ElContext > getChildren()
boolean equals(Object obj)
TreeSet< ElContext > getAncestors()
boolean inPath(ElContext context)
ElContext getNext(boolean doChildren)
TreeSet< ElContext > getVisibleChildren()
ElContext getCurrentContext()
void addOnLoadedJavaScript(String script)