You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2014/07/09 14:07:29 UTC

svn commit: r1609121 - in /myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src: main/java/org/apache/myfaces/tobago/example/demo/ test/java/org/apache/myfaces/tobago/example/demo/

Author: lofwyr
Date: Wed Jul  9 12:07:29 2014
New Revision: 1609121

URL: http://svn.apache.org/r1609121
Log:
demo: fix navigation

Removed:
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationEvent.java
Modified:
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationNode.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/NavigationUnitTest.java

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationNode.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationNode.java?rev=1609121&r1=1609120&r2=1609121&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationNode.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationNode.java Wed Jul  9 12:07:29 2014
@@ -64,12 +64,6 @@ public class NavigationNode extends Defa
     return outcome;
   }
 
-/* TODO
- XXX  public String getMarkup() {
-    return currentNode == this ? "marked" : null;
-  }
-*/
-
   public void evaluateTreePath() {
     treePath = new TreePath(this);
   }

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java?rev=1609121&r1=1609120&r2=1609121&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java Wed Jul  9 12:07:29 2014
@@ -27,6 +27,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.annotation.PostConstruct;
+import javax.enterprise.event.Observes;
 import javax.faces.context.FacesContext;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -94,7 +95,7 @@ public class NavigationState implements 
     }
   }
 
-  public String gotoNode(final NavigationNode node) {
+  public String gotoNode(@Observes final NavigationNode node) {
     if (node == null) {
       return gotoFirst();
     } else {

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java?rev=1609121&r1=1609120&r2=1609121&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java Wed Jul  9 12:07:29 2014
@@ -23,6 +23,7 @@ import org.apache.myfaces.tobago.example
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Event;
 import javax.faces.context.ExternalContext;
@@ -50,23 +51,28 @@ public class NavigationTree implements S
 
   private static final Logger LOG = LoggerFactory.getLogger(NavigationTree.class);
 
-  private NavigationNode tree;
+  private NavigationNode root;
 
   @Inject
-  private Event<NavigationEvent> events;
+  private Event<NavigationNode> events;
+
+  /**
+   * todo: Seems not working with Java EE 6, needs Java EE 7?
+   */
+//  @Inject
+//  private ServletContext servletContext;
 
   public NavigationTree() {
-      final ServletContext servletContext
-          = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
-      final List<String> list = locateResourcesInWar(servletContext, "/content", new ArrayList<String>());
-      init(list);
+    LOG.info("<init>");
   }
 
-  protected NavigationTree(final List<String> list) {
-    init(list);
-  }
+  @PostConstruct
+  protected void postConstruct() {
+    // todo: refactor with Java EE 7
+    final ServletContext servletContext;
+    servletContext = ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext());
+    final List<String> list = locateResourcesInWar(servletContext, "/content", new ArrayList<String>());
 
-  protected void init(final List<String> list) {
     list.add("/content/root-dummy.xhtml"); // helps to build the tree, this is not an existing file
     final List<NavigationNode> nodes = new ArrayList<NavigationNode>();
     for (final String path : list) {
@@ -80,7 +86,7 @@ public class NavigationTree implements S
     Collections.sort(nodes);
 
     // after sorting the first node is the root node.
-    tree = nodes.get(0);
+    root = nodes.get(0);
 
     final Map<String, NavigationNode> map = new HashMap<String, NavigationNode>();
 //    map.put(tree.getBranch(), tree);
@@ -95,7 +101,7 @@ public class NavigationTree implements S
     }
   }
 
-  private static List<String> locateResourcesInWar(
+  protected List<String> locateResourcesInWar(
       final ServletContext servletContext, final String directory, final List<String> result) {
 
     final Set<String> resourcePaths = servletContext.getResourcePaths(directory);
@@ -130,7 +136,7 @@ public class NavigationTree implements S
   }
 
   public NavigationNode findByViewId(String viewId) {
-    final Enumeration enumeration = tree.depthFirstEnumeration();
+    final Enumeration enumeration = root.depthFirstEnumeration();
     while (enumeration.hasMoreElements()) {
       final NavigationNode node = ((NavigationNode) enumeration.nextElement());
       if (node.getOutcome() != null && viewId.contains(node.getOutcome())) {
@@ -141,11 +147,11 @@ public class NavigationTree implements S
   }
 
   public NavigationNode getTree() {
-    return tree;
+    return root;
   }
 
   public void gotoNode(final NavigationNode node) {
-    events.fire(new NavigationEvent(node));
+    events.fire(node);
   }
 
   public String viewSource() {

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/NavigationUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/NavigationUnitTest.java?rev=1609121&r1=1609120&r2=1609121&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/NavigationUnitTest.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/NavigationUnitTest.java Wed Jul  9 12:07:29 2014
@@ -23,25 +23,32 @@ import org.apache.myfaces.tobago.interna
 import org.junit.Assert;
 import org.junit.Test;
 
+import javax.servlet.ServletContext;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
 public class NavigationUnitTest extends AbstractTobagoTestBase {
 
+  private static final List<String> LIST = new ArrayList<String>(Arrays.asList(
+      "/content/00/test-1.xhtml",
+      "/content/00/07/test-2.xhtml",
+      "/content/01/test.xhtml",
+      "/content/00/00/test-4.xhtml",
+      "/content/bad.jsp",
+      "/content/00_00_bad.gif"
+  ));
+
   @Test
   public void testFileNames() {
-    final List<String> list = new ArrayList<String>(Arrays.asList(
-        "/content/00/test-1.xhtml",
-// todo        "/content/00/x-bad.xhtml", // x- means excluded
-        "/content/00/07/test-2.xhtml",
-        "/content/00/07/x-bad.xhtml", // x- means excluded
-        "/content/01/test.xhtml",
-        "/content/00/00/test-4.xhtml",
-        "/content/bad.jsp",
-        "/content/00_00_bad.gif"
-    ));
-    final NavigationTree navigation = new NavigationTree(list);
+    final NavigationTree navigation = new NavigationTree() {
+      @Override
+      protected List<String> locateResourcesInWar(
+          ServletContext servletContext, String directory, List<String> result) {
+        return LIST;
+      }
+    };
+    navigation.postConstruct();
     final NavigationNode root = navigation.getTree();
     Assert.assertEquals(2, root.getChildCount());
     final NavigationNode n00 = (NavigationNode) root.getChildAt(0);