Author: rahul
Date: Fri Dec 22 12:46:40 2006
New Revision: 489753
URL: http://svn.apache.org/viewvc?view=rev&rev=489753
Log:
Better handling of UA navigation buttons usage for shale-dialog-scxml. The
opaqueState is fairly lightweight (the current state ID, which is a String).
Unlike the basic impl, there are no strategies (since subdialogs are
transparent, and the 'none' strategy doesn't really add any value for this impl
-- its unreleased, so semantic incompatibilities don't matter).
SHALE-61
Modified:
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
Modified:
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java?view=diff&rev=489753&r1=489752&r2=489753
==============================================================================
---
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
(original)
+++
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
Fri Dec 22 12:46:40 2006
@@ -20,6 +20,8 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
@@ -172,8 +174,9 @@
/**
* <p>The current SCXML state ID for this dialog instance, maintained
- * to reinitialize the transient [EMAIL PROTECTED] SCXMLExecutor} driving
this
- * dialog instance.</p>
+ * to reorient the dialog in accordance with any client-side navigation
+ * between "view states" that may have happened since we last left off.
+ * Serves as the "opaqueState" for this implementation.</p>
*/
private String stateId = null;
@@ -229,7 +232,7 @@
/** [EMAIL PROTECTED] */
public Object getOpaqueState() {
- return null; // Do not do anything yet, just fulfill the API contract
+ return stateId;
}
@@ -237,7 +240,50 @@
/** [EMAIL PROTECTED] */
public void setOpaqueState(Object opaqueState) {
- ; // Do not do anything yet, just fulfill the API contract
+ String viewStateId = String.valueOf(opaqueState);
+ if (viewStateId == null) {
+ throw new IllegalArgumentException("Dialog instance '" + getId()
+ + "' for dialog name '" + getName()
+ + "': null opaqueState received");
+ }
+
+ // account for user agent navigation
+ if (viewStateId != stateId) {
+
+ if (log().isTraceEnabled()) {
+ log().trace("Dialog instance '" + getId() + "' of dialog name
'"
+ + getName() + "': user navigated to view for state '"
+ + viewStateId + "', setting dialog to this state instead"
+ + " of '" + stateId + "'");
+ }
+
+ Map targets = executor.getStateMachine().getTargets();
+ State serverState = (State) targets.get(stateId);
+ State clientState = (State) targets.get(viewStateId);
+ if (clientState == null) {
+ throw new IllegalArgumentException("Dialog instance '"
+ + getId() + "' for dialog name '" + getName()
+ + "': opaqueState is not a SCXML state ID for the "
+ + "current dialog state machine");
+ }
+
+ Set states = executor.getCurrentStatus().getStates();
+ if (states.size() != 1) {
+ throw new IllegalStateException("Dialog instance '"
+ + getId() + "' for dialog name '" + getName()
+ + "': Cannot have multiple leaf states active when the"
+ + " SCXML dialog is in a 'view' state");
+ }
+
+ // remove last known server-side state, set to correct
+ // client-side state and fire the appropriate DCL events
+ states.remove(serverState);
+ fireOnExit(serverState.getId());
+
+ fireOnEntry(clientState.getId());
+ states.add(clientState);
+
+ }
}