Commits

Hendrik Ebbers committed a278e3d Merge

Merged in convenience (pull request #7)

add default shortcut for immediately getting a Node when starting a flow.

Comments (0)

Files changed (5)

datafx-flow/src/main/java/org/datafx/controller/flow/DefaultFlowContainer.java

 package org.datafx.controller.flow;
 
 import javafx.scene.layout.StackPane;
-
 import org.datafx.controller.context.ViewContext;
 
-public class DefaultFlowContainer implements FlowContainer {
+public class DefaultFlowContainer implements FlowContainer<StackPane> {
 
     private final StackPane pane;
 
         this(new StackPane());
     }
 
-    public StackPane getPane() {
+    @Override
+    public StackPane getView() {
         return pane;
     }
 
     @Override
-    public <T> void setView(ViewContext<T> context) {
+    public <U> void setViewContext(ViewContext<U> context) {
         pane.getChildren().clear();
         pane.getChildren().add(context.getRootNode());
     }

datafx-flow/src/main/java/org/datafx/controller/flow/Flow.java

 /**
- * Copyright (c) 2011, 2013, Jonathan Giles, Johan Vos, Hendrik Ebbers
+ * Copyright (c) 2011, 2014, Jonathan Giles, Johan Vos, Hendrik Ebbers
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  */
 package org.datafx.controller.flow;
 
+import java.util.HashMap;
+import java.util.Map;
+import javafx.scene.Node;
+import javafx.scene.layout.StackPane;
 import org.datafx.controller.ViewConfiguration;
 import org.datafx.controller.flow.action.*;
 import org.datafx.controller.flow.context.ViewFlowContext;
 
-import java.util.HashMap;
-import java.util.Map;
-
 /**
  * This class defines a flow. A flow is a map of different views that are linked. 
  * A flow can define actions for each view or global actions for the complete flow. 
             }
         }
     }
+    
+    /**
+     * Start the flow with a default handler and a default FlowContainer
+     * This will start the flow using a DefaultFlowContainer, which returns a
+     * StackPane.
+     * @return the <tt>Parent</tt> that will be used for rendering
+     * 
+     * @throws FlowException 
+     */
+    public StackPane start () throws FlowException {
+        return start (new DefaultFlowContainer());
+    }
+    
+    /**
+     * Start the flow with a default handler and a provided FlowContainer
+     * 
+     * @param <T>
+     * @param flowContainer the FlowContainer used to visualize this flow
+     * @return the <tt>Parent</tt> that will be used for rendering
+     * @throws FlowException 
+     */
+    public <T extends Node> T start (FlowContainer<T> flowContainer) throws FlowException {
+        createHandler().start(flowContainer);
+        return flowContainer.getView();
+    }
 }

datafx-flow/src/main/java/org/datafx/controller/flow/FlowContainer.java

 /**
- * Copyright (c) 2011, 2013, Jonathan Giles, Johan Vos, Hendrik Ebbers
- * All rights reserved.
+ * Copyright (c) 2011, 2013, Jonathan Giles, Johan Vos, Hendrik Ebbers All
+ * rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *     * Neither the name of DataFX, the website javafxdata.org, nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
+ * modification, are permitted provided that the following conditions are met: *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. * Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions and
+ * the following disclaimer in the documentation and/or other materials provided
+ * with the distribution. * Neither the name of DataFX, the website
+ * javafxdata.org, nor the names of its contributors may be used to endorse or
+ * promote products derived from this software without specific prior written
+ * permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  */
 package org.datafx.controller.flow;
 
+import javafx.scene.Node;
+import javafx.scene.Parent;
 import org.datafx.controller.context.ViewContext;
 
 /**
- *  A Flow needs a JavaFX <tt>Parent</tt> node in that the current view of the flow will be added as a child. This interface defines a general class that will be used internally to set the new View for a Flow. A implementation should add the <tt>Node</tt> of the view to the scene graph.
+ * A Flow needs a JavaFX <tt>Parent</tt> node in that the current view of the
+ * flow will be added as a child. This interface defines a general class that
+ * will be used internally to set the new View for a Flow. A implementation
+ * should add the <tt>Node</tt> of the view to the scene graph.
  *
  * @author Hendrik Ebbers
+ * @param <T> Controller type of the current view
  * @see DefaultFlowContainer
  */
-public interface FlowContainer {
+public interface FlowContainer<T extends Node> {
 
     /**
-     * The given view will be the new view of the flow. Implementations should add the he <tt>Node</tt> of the view to the scene graph and remove the old view.
+     * The given view will be the new view of the flow. Implementations should
+     * add the he <tt>Node</tt> of the view to the scene graph and remove the
+     * old view.
+     *
      * @param context Context of the current view
-     * @param <T> Controller type of the current view
      */
-    public <T> void setView(ViewContext<T> context);
+    public <U> void setViewContext(ViewContext<U> context);
+
+    /**
+     * Return the <tt>Parent</tt> node that is rendering the flow.
+     *
+     * @return the <tt>Parent</tt> node that is rendering the flow
+     */
+    public T getView();
+
 }

datafx-flow/src/main/java/org/datafx/controller/flow/FlowHandler.java

 
     public <U> ViewContext<U> setNewView(FlowView<U> newView)
             throws FlowException {
-        System.out.println("CV = "+currentView);
         if (currentView != null) {
             controllerHistory.add(0, currentView.getViewContext().getController().getClass());
         }
 
         currentView = newView;
         flowContext.setCurrentViewContext(currentView.getViewContext());
-        container.setView(currentView.getViewContext());
+        container.setViewContext(currentView.getViewContext());
         return newView.getViewContext();
     }
 

datafx-samples/src/main/java/org/datafx/samples/app/DataFXDemo.java

 
 import javafx.application.Application;
 import javafx.scene.Scene;
+import javafx.scene.layout.StackPane;
 import javafx.stage.Stage;
-import org.datafx.controller.flow.DefaultFlowContainer;
 import org.datafx.controller.flow.Flow;
 
 /**
                 // An action is added to the flow. The action is registered fot the MasterView and has the unique id "load". The action is implemented by the LoadPersonsTask class
                 withTaskAction(MasterViewController.class, "load", LoadPersonsTask.class);
 
-        // A Flow needs a special container that wrappes the flow
-        DefaultFlowContainer container = new DefaultFlowContainer();
 
         //This starts the Flow
-        flow.createHandler().start(container);
-        Scene scene = new Scene(container.getPane());
+        StackPane parent = flow.start();
+        Scene scene = new Scene(parent);
         stage.setScene(scene);
         stage.show();