Author: ilya_shaikovsky
Date: 2010-05-19 10:21:23 -0400 (Wed, 19 May 2010)
New Revision: 17127
Modified:
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/BaseDescriptor.java
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/DemoDescriptor.java
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/DemoNavigator.java
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/SampleDescriptor.java
Log:
https://jira.jboss.org/browse/RF-8663
Modified:
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/BaseDescriptor.java
===================================================================
---
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/BaseDescriptor.java 2010-05-19
14:12:29 UTC (rev 17126)
+++
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/BaseDescriptor.java 2010-05-19
14:21:23 UTC (rev 17127)
@@ -27,7 +27,6 @@
this.newItem = newItem;
}
- @XmlAttribute(name = "current")
public boolean isCurrentItem() {
return currentItem;
}
@@ -35,6 +34,7 @@
public void setCurrentItem(boolean currentItem) {
this.currentItem = currentItem;
}
+
@XmlElement
public String getId() {
return id;
Modified:
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/DemoDescriptor.java
===================================================================
---
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/DemoDescriptor.java 2010-05-19
14:12:29 UTC (rev 17126)
+++
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/DemoDescriptor.java 2010-05-19
14:21:23 UTC (rev 17127)
@@ -7,42 +7,18 @@
public class DemoDescriptor extends BaseDescriptor {
private static final String BASE_SAMPLES_DIR = "/richfaces/";
-
- private String page;
- private boolean current;
- private SampleDescriptor activeSample;
+ private String samplesFolder;
private List<SampleDescriptor> samples;
- private SampleDescriptor getSampleById(String id) {
+ public SampleDescriptor getSampleById(String id) {
for (SampleDescriptor sample : getSamples()) {
if (sample.getId().equals(id)) {
return sample;
}
}
- return null;
+ return samples.get(0);
}
-
- public void setActiveSampleById(String id) {
- setActiveSample(getSampleById(id));
- }
-
- public String getSampleURI() {
- return BASE_SAMPLES_DIR + activeSample.getSrc();
- }
-
- public String getDemoURI() {
- return BASE_SAMPLES_DIR + getPage();
- }
-
- @XmlElement
- public String getPage() {
- return page;
- }
-
- public void setPage(String page) {
- this.page = page;
- }
-
+
@XmlElementWrapper(name = "samples")
@XmlElement(name = "sample")
public List<SampleDescriptor> getSamples() {
@@ -53,20 +29,13 @@
this.samples = samples;
}
- public boolean isCurrent() {
- return current;
+ @XmlElement(name = "samples-folder")
+ public String getSamplesFolder() {
+ return samplesFolder;
}
- public void setCurrent(boolean current) {
- this.current = current;
+ public void setSamplesFolder(String samplesFolder) {
+ this.samplesFolder = samplesFolder;
}
- public SampleDescriptor getActiveSample() {
- return activeSample;
- }
-
- public void setActiveSample(SampleDescriptor activeSample) {
- this.activeSample = activeSample;
- }
-
}
Modified:
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/DemoNavigator.java
===================================================================
---
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/DemoNavigator.java 2010-05-19
14:12:29 UTC (rev 17126)
+++
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/DemoNavigator.java 2010-05-19
14:21:23 UTC (rev 17127)
@@ -9,71 +9,48 @@
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
-import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.event.ComponentSystemEvent;
-import javax.servlet.http.HttpServletRequest;
@ManagedBean
@SessionScoped
public class DemoNavigator {
-
- private static Converter demoViewConverter = new Converter() {
-
- public String getAsString(FacesContext context, UIComponent component, Object
value) {
- return (String) value;
- }
-
- public Object getAsObject(FacesContext context, UIComponent component, String
value) {
- NavigationHandler handler = context.getApplication().getNavigationHandler();
-
- if (handler instanceof ConfigurableNavigationHandler) {
- ConfigurableNavigationHandler navigationHandler =
(ConfigurableNavigationHandler) handler;
-
- NavigationCase navCase = navigationHandler.getNavigationCase(context,
null, "/richfaces/" + value);
-
- return navCase.getToViewId(context);
- }
-
- return null;
- }
- };
+ private static final String DEMO_VIEW_PARAMETER = "demo";
+ private static final String SAMPLE_VIEW_PARAMETER = "sample";
@ManagedProperty(value = "#{navigationParser.groupsList}")
private List<GroupDescriptor> groups;
private DemoDescriptor currentDemo = null;
- private String currentSample;
-
- private String demoName;
-
+ private SampleDescriptor currentSample = null;
+ private String sample;
+ private String demo;
+
public DemoDescriptor getCurrentDemo() {
- String id = getDemoParam("demo");
- if (id != null) {
- setCurrentDemo(findDemoById(id));
- } else {
- String uri = getDemoUri();
- setCurrentDemo(findDemoByUri(uri));
- }
- // set active sample for current component if any
- if (null != currentDemo) {
- if (null != currentSample) {
- currentDemo.setActiveSampleById(currentSample);
- } else {
- currentDemo.setActiveSample(currentDemo.getSamples().get(0));
- currentSample = currentDemo.getActiveSample().getId();
+ String id = getViewParameter(DEMO_VIEW_PARAMETER);
+ if (currentDemo == null || !currentDemo.getId().equals(id)) {
+ if (id != null) {
+ currentDemo = findDemoById(id);
}
+ if (currentDemo == null) {
+ currentDemo = groups.get(0).getDemos().get(0);
+ }
}
-
return currentDemo;
}
-
- private String getDemoUri() {
- FacesContext fc = FacesContext.getCurrentInstance();
- return ((HttpServletRequest)
fc.getExternalContext().getRequest()).getRequestURI();
+
+ public SampleDescriptor getCurrentSample() {
+ String id = getViewParameter(SAMPLE_VIEW_PARAMETER);
+ if (currentSample == null || !currentSample.getId().equals(id)) {
+ if (id != null) {
+ currentSample = getCurrentDemo().getSampleById(id);
+ }
+ if (currentSample == null || id==null) {
+ currentSample = getCurrentDemo().getSamples().get(0);
+ }
+ }
+ return currentSample;
}
-
- private String getDemoParam(String name) {
+
+ private String getViewParameter(String name) {
FacesContext fc = FacesContext.getCurrentInstance();
String param = (String)
fc.getExternalContext().getRequestParameterMap().get(name);
if (param != null && param.trim().length() > 0) {
@@ -83,21 +60,6 @@
}
}
- public DemoDescriptor findDemoByUri(String uri) {
- Iterator<GroupDescriptor> it = groups.iterator();
- while (it.hasNext()) {
- GroupDescriptor group = it.next();
- Iterator<DemoDescriptor> dit = group.getDemos().iterator();
- while (dit.hasNext()) {
- DemoDescriptor demo = dit.next();
- if (uri.endsWith(demo.getDemoURI())) {
- return demo;
- }
- }
- }
- return null;
- }
-
public DemoDescriptor findDemoById(String id) {
Iterator<GroupDescriptor> it = groups.iterator();
while (it.hasNext()) {
@@ -113,11 +75,22 @@
return null;
}
- public void setCurrentDemo(DemoDescriptor currentDemo) {
- if (currentDemo == null) {
- this.currentDemo = (DemoDescriptor) groups.get(0).getDemos().get(0);
+ public String getSampleURI() {
+ DemoDescriptor currentDemo = getCurrentDemo();
+ FacesContext context = FacesContext.getCurrentInstance();
+
+ NavigationHandler handler = context.getApplication().getNavigationHandler();
+
+ if (handler instanceof ConfigurableNavigationHandler) {
+ ConfigurableNavigationHandler navigationHandler =
(ConfigurableNavigationHandler) handler;
+
+ NavigationCase navCase = navigationHandler.getNavigationCase(context, null,
currentDemo.getSamplesFolder()
+ + getCurrentSample().getId());
+
+ return navCase.getToViewId(context);
}
- this.currentDemo = currentDemo;
+
+ return null;
}
public List<GroupDescriptor> getGroups() {
@@ -128,27 +101,19 @@
this.groups = groups;
}
- public String getCurrentSample() {
- return currentSample;
+ public String getSample() {
+ return sample;
}
- public void setCurrentSample(String currentSample) {
- this.currentSample = currentSample;
+ public void setSample(String sample) {
+ this.sample = sample;
}
- public String getDemoName() {
- return demoName;
+ public String getDemo() {
+ return demo;
}
- public void setDemoName(String demoName) {
- this.demoName = demoName;
+ public void setDemo(String demo) {
+ this.demo = demo;
}
-
- public void preRenderEvent(ComponentSystemEvent event) {
- System.out.println("DemoNavigator.preRenderEvent()");
- }
-
- public Converter getDemoViewConverter() {
- return demoViewConverter;
- }
}
Modified:
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/SampleDescriptor.java
===================================================================
---
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/SampleDescriptor.java 2010-05-19
14:12:29 UTC (rev 17126)
+++
root/examples/richfaces-showcase/trunk/src/main/java/org/richfaces/demo/common/navigation/SampleDescriptor.java 2010-05-19
14:21:23 UTC (rev 17127)
@@ -1,16 +1,5 @@
package org.richfaces.demo.common.navigation;
-import javax.xml.bind.annotation.XmlElement;
-
-
public class SampleDescriptor extends BaseDescriptor{
- private String src;
- @XmlElement
- public String getSrc() {
- return src;
- }
- public void setSrc(String src) {
- this.src = src;
- }
}