Author: craigmcc
Date: Sun Sep 10 17:49:02 2006
New Revision: 442051
URL: http://svn.apache.org/viewvc?view=rev&rev=442051
Log:
Support the ability to associate a DialogContext instance with a parent
DialogContext instance that also belongs to the same user. This will enable
use cases such as a pop-up window that wants to be able to pull information
from, and push information to, the data object associated with the parent
main window. A mechanism to programmatically create DialogContext instances
with such a relationship is provided, but there needs to be machinery added
yet to Dialog2PhaseListener to leverage this.
Note that child dialogs are different from subdialogs, because they are
associated with separate windows or frames. Subdialogs all operate within
the context of a single view (i.e. a single window or frame).
Modified:
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContextManager.java
Modified:
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java?view=diff&rev=442051&r1=442050&r2=442051
==============================================================================
---
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
(original)
+++
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
Sun Sep 10 17:49:02 2006
@@ -59,13 +59,17 @@
* @param manager [EMAIL PROTECTED] DialogContextManager} instance that
owns us
* @param dialog Configured dialog definition we will be following
* @param id Dialog identifier assigned to this instance
+ * @param parentDialogId Dialog identifier of the parent DialogContext
+ * instance associated with this one (if any)
*/
- LegacyDialogContext(DialogContextManager manager, Dialog dialog, String
id) {
+ LegacyDialogContext(DialogContextManager manager, Dialog dialog,
+ String id, String parentDialogId) {
this.manager = manager;
this.dialog = dialog;
this.dialogName = dialog.getName();
this.id = id;
+ this.parentDialogId = parentDialogId;
start(dialog);
@@ -82,12 +86,6 @@
/**
- * <p>Generic data object containing state information for this
instance.</p>
- */
-// private Object data = null;
-
-
- /**
* <p>The [EMAIL PROTECTED] Dialog} that this instance is executing. This
value is
* transient and may need to be regenerated.</p>
*/
@@ -120,6 +118,14 @@
/**
+ * <p>Identifier of the parent [EMAIL PROTECTED] DialogContext} associated
with
+ * this [EMAIL PROTECTED] DialogContext}, if any. If there is no such
parent,
+ * this value is set to <code>null</code>.</p>
+ */
+ private String parentDialogId = null;
+
+
+ /**
* <p>The stack of currently stored Position instances. If there
* are no entries, we have completed the exit state and should deactivate
* ourselves.</p>
@@ -196,6 +202,24 @@
Position position = peek();
if (position != null) {
return position.getDialog().getName();
+ } else {
+ return null;
+ }
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public DialogContext getParent() {
+
+ if (this.parentDialogId != null) {
+ DialogContext parent = manager.get(this.parentDialogId);
+ if (parent == null) {
+ throw new IllegalStateException("Dialog instance '"
+ + parentDialogId + "' was associated with this
instance '"
+ + getId() + "' but is no longer available");
+ }
+ return parent;
} else {
return null;
}
Modified:
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java?view=diff&rev=442051&r1=442050&r2=442051
==============================================================================
---
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java
(original)
+++
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java
Sun Sep 10 17:49:02 2006
@@ -95,6 +95,14 @@
/** [EMAIL PROTECTED] */
public DialogContext create(FacesContext context, String name) {
+ return create(context, name, null);
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public DialogContext create(FacesContext context, String name,
DialogContext parent) {
+
// Look up the specified dialog configuration
Map dialogs = dialogs(context);
Dialog dialog = (Dialog) dialogs.get(name);
@@ -103,8 +111,19 @@
+ name + "' can be found");
}
+ // Validate the specified parent (if any)
+ String parentDialogId = null;
+ if (parent != null) {
+ parentDialogId = parent.getId();
+ if (parent != get(parentDialogId)) {
+ throw new IllegalStateException("The specified parent
DialogContext '"
+ + parentDialogId + "' is not managed by this
DialogContextManager");
+ }
+ }
+
// Configure a new LegacyDialogContext instance
- LegacyDialogContext instance = new LegacyDialogContext(this, dialog,
generateId());
+ LegacyDialogContext instance = new LegacyDialogContext(this, dialog,
generateId(),
+ parentDialogId);
instance.setData(new HashMap());
map.put(instance.getId(), instance);
context.getExternalContext().getRequestMap().put(Constants.CONTEXT_BEAN,
instance);
Modified:
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java?view=diff&rev=442051&r1=442050&r2=442051
==============================================================================
---
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java
(original)
+++
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java
Sun Sep 10 17:49:02 2006
@@ -151,6 +151,12 @@
}
+ /** [EMAIL PROTECTED] */
+ public DialogContext getParent() {
+ throw new UnsupportedOperationException(); // FIXME - implement this
+ }
+
+
// -------------------------------------------------------- DialogContext
Methods
Modified:
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java?view=diff&rev=442051&r1=442050&r2=442051
==============================================================================
---
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java
(original)
+++
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogManager.java
Sun Sep 10 17:49:02 2006
@@ -84,6 +84,12 @@
}
+ /** [EMAIL PROTECTED] */
+ public DialogContext create(FacesContext context, String name,
DialogContext parent) {
+ throw new UnsupportedOperationException(); // FIXME - implement this
+ }
+
+
/** @{inheritDoc} */
public DialogContext get(String id) {
return (DialogContext) map.get(id);
Modified:
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java?view=diff&rev=442051&r1=442050&r2=442051
==============================================================================
---
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java
(original)
+++
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java
Sun Sep 10 17:49:02 2006
@@ -73,6 +73,16 @@
public String getName();
+ /**
+ * <p>Return the parent [EMAIL PROTECTED] DialogContext} instance
associated with this
+ * child [EMAIL PROTECTED] DialogContext}, if any; otherwise, return
<code>null</code>.</p>
+ *
+ * @exception IllegalStateException if a parent [EMAIL PROTECTED]
DialogContext} initially
+ * associated with this [EMAIL PROTECTED] DialogContext} is no longer
available
+ */
+ public DialogContext getParent();
+
+
// --------------------------------------------------- DialogContext
Methods
Modified:
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContextManager.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContextManager.java?view=diff&rev=442051&r1=442050&r2=442051
==============================================================================
---
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContextManager.java
(original)
+++
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContextManager.java
Sun Sep 10 17:49:02 2006
@@ -36,18 +36,49 @@
* <code>id</code> property guaranteed to be unique among all active
* instances for the current user. It shall also have been stored as
* a request scope attribute under key
<code>Constants.INSTANCE_BEAN</code>.
- * For ease of development, the newly created [EMAIL PROTECTED]
DialogContext} SHOULD
- * have been assigned a <code>data<code> property of an empty
- * <code>java.util.Map</code> (unless a particular dialog implementation
- * prefers to provide some more implementation specific default).</p>
- *
+ * The new instance will not be associated with any parent instance.</p>
*
* @param context FacesContext for the current request
* @param name Logical name of the dialog to be executed
+ *
* @exception IllegalArgumentException if no dialog definition
* can be found for the specified logical name
*/
public DialogContext create(FacesContext context, String name);
+
+
+ /**
+ * <p>Start a new instance of the specified dialog configuration, returning
+ * the newly started instance. This instance will include an
+ * <code>id</code> property guaranteed to be unique among all active
+ * instances for the current user. It shall also have been stored as
+ * a request scope attribute under key
<code>Constants.INSTANCE_BEAN</code>.
+ * The new instance will be associated with the specified parent instance,
+ * which must be managed by this [EMAIL PROTECTED] DialogContextManager}
and therefore
+ * belong to the same user.</p>
+ *
+ * <p><strong>IMPLEMENTATION NOTE</strong> - Applications should generally
+ * not call this method directly, because it will be awkward to associate
+ * the newly created [EMAIL PROTECTED] DialogContext} instance with a
different view
+ * instance. Instead, this method is primarily intended to support the
+ * ability to automatically associate the [EMAIL PROTECTED] DialogContext}
for, say,
+ * a pop-up window with the [EMAIL PROTECTED] DialogContext} of the
corresponding
+ * main window. This facility is supported automatically by the phase
+ * listener that manages saving and restoring the association of a
+ * [EMAIL PROTECTED] DialogContext} and its corresponding JSF view.</p>
+ *
+ * @param context FacesContext for the current request
+ * @param name Logical name of the dialog to be executed
+ * @param parent Parent DialogContext with which the new instance
+ * will be assocated (if any)
+ *
+ * @exception IllegalArgumentException if no dialog definition
+ * can be found for the specified logical name
+ * @exception IllegalStateException if the specified <code>parent</code>
+ * instance is not managed by this [EMAIL PROTECTED] DialogContextManager}
+ */
+ public DialogContext create(FacesContext context, String name,
+ DialogContext parent);
/**