Author: julien(a)jboss.com
Date: 2008-07-01 10:25:37 -0400 (Tue, 01 Jul 2008)
New Revision: 11231
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/PresentationClientAgent.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPane.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ui/UIContextImpl.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/model/ui/UIContext.java
Log:
start to improve and decouple ajax object / gwt widget life cycle in order to be able to
perform update&refresh efficiently
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/PresentationClientAgent.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/PresentationClientAgent.java 2008-07-01
13:14:12 UTC (rev 11230)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/PresentationClientAgent.java 2008-07-01
14:25:37 UTC (rev 11231)
@@ -103,7 +103,7 @@
context.update(updates);
//
- context.getRoot().refresh();
+ context.getRoot().refresh(false);
//
bottom.add(context.getRoot().getWidget());
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java 2008-07-01
13:14:12 UTC (rev 11230)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java 2008-07-01
14:25:37 UTC (rev 11231)
@@ -22,10 +22,10 @@
******************************************************************************/
package org.jboss.portal.presentation.ajax.client.model;
-import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.Widget;
import java.util.Iterator;
import java.util.Map;
@@ -42,17 +42,31 @@
/** . */
private Panel layout;
- /** . */
- private Widget widget;
-
-// private boolean
-
public AjaxLayout(String id, Map properties)
{
super(id, properties);
+ }
+ protected final void doRefresh(Panel parent)
+ {
+ if (layout != null)
+ {
+ parent.remove(layout);
+
+ //
+ for (Iterator i = layout.iterator();i.hasNext();)
+ {
+ Widget child = (Widget)i.next();
+
+ //
+ layout.remove(child);
+ }
+
+ //
+ this.layout = null;
+ }
+
//
- Panel widget = createPanel(id, properties);
Panel layout;
//
@@ -80,39 +94,25 @@
}
//
- widget.add(layout);
-
- //
layout.setStyleName("pf-Layout");
//
- this.layout = layout;
- this.widget = widget;
- }
+ for (Iterator i = getChildren().iterator();i.hasNext();)
+ {
+ AjaxObject child = (AjaxObject)i.next();
- protected abstract Panel createPanel(String id, Map properties);
+ //
+ layout.add(child.getWidget());
+ }
- protected void doAddChild(AjaxObject child)
- {
- Widget childWidget = child.getWidget();
+ //
+ parent.add(layout);
//
- layout.add(childWidget);
+ this.layout = layout;
}
- public Widget getWidget()
+ protected void doAddChild(AjaxObject child)
{
- return widget;
}
-
- protected void doRefresh()
- {
- for (Iterator i = getChildren().iterator();i.hasNext();)
- {
- AjaxObject child = (AjaxObject)i.next();
-
- //
- child.refresh();
- }
- }
}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java 2008-07-01
13:14:12 UTC (rev 11230)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java 2008-07-01
14:25:37 UTC (rev 11231)
@@ -27,6 +27,7 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Collection;
+import java.util.Iterator;
import org.jboss.portal.presentation.ajax.client.model.update.ModelUpdate;
import org.jboss.portal.presentation.ajax.client.model.update.AddObject;
@@ -57,13 +58,74 @@
/** . */
private AjaxObject parent;
+ /** . */
+ private boolean stale;
+
protected AjaxObject(String id, Map properties)
{
this.id = id;
this.children = new HashMap();
this.properties = properties;
+ this.stale = true;
}
+ public final void createWidget()
+ {
+ for (Iterator i = children.values().iterator();i.hasNext();)
+ {
+ AjaxObject child = (AjaxObject)i.next();
+
+ //
+ child.createWidget();
+ }
+
+ //
+ doCreateWidget();
+ }
+
+ public final void destroyWidget()
+ {
+ doDestroyWidget();
+
+ //
+ for (Iterator i = children.values().iterator();i.hasNext();)
+ {
+ AjaxObject child = (AjaxObject)i.next();
+
+ //
+ child.destroyWidget();
+ }
+ }
+
+ public final void refresh(boolean force)
+ {
+ if (stale || force)
+ {
+ doRefresh(force);
+
+ //
+ stale = false;
+ }
+ }
+
+ private void addChild(AjaxObject child)
+ {
+ // Create relationship
+ children.put(child.getId(), child);
+ child.parent = this;
+
+ //
+ doAddChild(child);
+
+ //
+ stale = true;
+ }
+
+ public final boolean isStale()
+ {
+ return stale;
+ }
+
public final Object getPropertyValue(String propertyName)
{
return properties.get(propertyName);
@@ -89,25 +151,16 @@
return parent;
}
- private void addChild(AjaxObject child)
- {
- // Create relationship
- children.put(child.getId(), child);
- child.parent = this;
+ protected abstract void doCreateWidget();
- // Perform DOM wiring
- doAddChild(child);
- }
+ protected abstract void doRefresh(boolean force);
- public void refresh()
- {
- doRefresh();
- }
+ protected abstract void doDestroyWidget();
- protected abstract void doRefresh();
-
protected abstract void doAddChild(AjaxObject child);
+ protected abstract void doRemoveChild(AjaxObject child);
+
public abstract Widget getWidget();
public static class Context
@@ -178,6 +231,9 @@
// Wire to the context
objects.put(addObject.getObjectId(), object);
object.context = this;
+
+ // We create the widget
+ object.createWidget();
}
else if (update instanceof CreateChildren)
{
@@ -194,6 +250,9 @@
parent.addChild(child);
}
}
+
+ // We refresh the root
+ root.refresh(false);
}
}
}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java 2008-07-01
13:14:12 UTC (rev 11230)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java 2008-07-01
14:25:37 UTC (rev 11231)
@@ -22,11 +22,12 @@
******************************************************************************/
package org.jboss.portal.presentation.ajax.client.model;
-import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.Widget;
import java.util.Map;
+import java.util.Iterator;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -35,25 +36,57 @@
public class AjaxPage extends AjaxLayout
{
+ /** . */
+ private VerticalPanel widget;
+
public AjaxPage(String id, Map properties)
{
super(id, properties);
}
- protected Panel createPanel(String id, Map properties)
+ protected void doRefresh(boolean force)
{
+ for (Iterator i = getChildren().iterator();i.hasNext();)
+ {
+ AjaxObject child = (AjaxObject)i.next();
+
+ //
+ child.refresh(force);
+ }
+
+ //
+ doRefresh(widget);
+ }
+
+ public Widget getWidget()
+ {
+ return widget;
+ }
+
+ protected void doCreateWidget()
+ {
Label title = new Label();
- title.setText("Page " + id);
+ title.setText("Page " + getId());
title.setStyleName("pf-Title");
//
- VerticalPanel panel = new VerticalPanel();
- panel.setStyleName("pf-Pane");
+ VerticalPanel widget = new VerticalPanel();
+ widget.setStyleName("pf-Page");
//
- panel.add(title);
+ widget.add(title);
//
- return panel;
+ this.widget = widget;
}
+
+ protected void doDestroyWidget()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void doRemoveChild(AjaxObject child)
+ {
+ throw new UnsupportedOperationException();
+ }
}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPane.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPane.java 2008-07-01
13:14:12 UTC (rev 11230)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPane.java 2008-07-01
14:25:37 UTC (rev 11231)
@@ -22,10 +22,12 @@
******************************************************************************/
package org.jboss.portal.presentation.ajax.client.model;
-import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.Hyperlink;
import java.util.Map;
+import java.util.Iterator;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -33,17 +35,50 @@
*/
public class AjaxPane extends AjaxLayout
{
+
+ /** . */
+ private VerticalPanel widget;
+
public AjaxPane(String id, Map properties)
{
super(id, properties);
}
- protected Panel createPanel(String id, Map properties)
+ protected void doCreateWidget()
{
- VerticalPanel panel = new VerticalPanel();
- panel.setStyleName("pf-Pane");
+ VerticalPanel widget = new VerticalPanel();
+ widget.setStyleName("pf-Pane");
//
- return panel;
+ this.widget = widget;
}
+
+ protected void doRefresh(boolean force)
+ {
+ for (Iterator i = getChildren().iterator();i.hasNext();)
+ {
+ AjaxObject child = (AjaxObject)i.next();
+
+ //
+ child.refresh(force);
+ }
+
+ //
+ doRefresh(widget);
+ }
+
+ protected void doDestroyWidget()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void doRemoveChild(AjaxObject child)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Widget getWidget()
+ {
+ return widget;
+ }
}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java 2008-07-01
13:14:12 UTC (rev 11230)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java 2008-07-01
14:25:37 UTC (rev 11231)
@@ -66,9 +66,12 @@
public AjaxWindow(String id, Map properties)
{
super(id, properties);
+ }
+ protected void doCreateWidget()
+ {
//
- Label title = new Label("Window " + id);
+ Label title = new Label("Window " + getId());
HTML markup = new HTML();
VerticalPanel widget = new VerticalPanel();
widget.add(title);
@@ -149,8 +152,8 @@
Map form = new HashMap();
Tools.serialize(current, form);
windowAction = new OpaqueWindowAction(uri, form);
-
+
/*
var enctype = current.enctype
@@ -214,7 +217,7 @@
if (stale != null)
{
log.info("Going to refresh portlet window " +
staleObject);
- stale.refresh();
+ stale.refresh(true);
}
else
{
@@ -230,6 +233,16 @@
});
}
+ protected void doDestroyWidget()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void doRemoveChild(AjaxObject child)
+ {
+ throw new UnsupportedOperationException();
+ }
+
protected void doAddChild(AjaxObject child)
{
throw new UnsupportedOperationException();
@@ -240,7 +253,7 @@
return widget;
}
- protected void doRefresh()
+ protected void doRefresh(boolean force)
{
final PresentationClientRemoteAsync remote =
(PresentationClientRemoteAsync)GWT.create(PresentationClientRemote.class);
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ui/UIContextImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ui/UIContextImpl.java 2008-07-01
13:14:12 UTC (rev 11230)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ui/UIContextImpl.java 2008-07-01
14:25:37 UTC (rev 11231)
@@ -29,7 +29,7 @@
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class UIContextImpl extends UIPageImpl implements UIContext
+public class UIContextImpl extends UILayoutImpl implements UIContext
{
public UIContextImpl(
StructuralObject structuralObject,
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/model/ui/UIContext.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/model/ui/UIContext.java 2008-07-01
13:14:12 UTC (rev 11230)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/model/ui/UIContext.java 2008-07-01
14:25:37 UTC (rev 11231)
@@ -28,6 +28,6 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public interface UIContext extends UIPage
+public interface UIContext extends UILayout
{
}
\ No newline at end of file