Author: julien(a)jboss.com
Date: 2008-07-09 17:30:21 -0400 (Wed, 09 Jul 2008)
New Revision: 11388
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDContext.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDPanel.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Draggable.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Droppable.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/portal/src/main/java/org/jboss/portal/presentation/portal/PresentationServerImpl.java
Log:
improved DnD
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDContext.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDContext.java 2008-07-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDContext.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -22,8 +22,7 @@
******************************************************************************/
package org.jboss.portal.presentation.ajax.client.dnd;
-import com.google.gwt.user.client.ui.Panel;
-import com.google.gwt.user.client.Element;
+import java.util.Iterator;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -32,11 +31,9 @@
public interface DnDContext
{
-
+ Iterator getDraggables(int x, int y);
- Draggable findDraggable(int x, int y);
+ Iterator findDroppable(int x, int y);
- Droppable findDroppable(int x, int y);
-
}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDPanel.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDPanel.java 2008-07-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDPanel.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -30,6 +30,9 @@
import com.google.gwt.user.client.Window;
import org.jboss.portal.presentation.ajax.client.util.logging.Logger;
+import java.util.List;
+import java.util.Iterator;
+
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
@@ -63,7 +66,7 @@
{
int x = DOM.eventGetClientX(event);
int y = DOM.eventGetClientY(event);
- Draggable draggable = context.findDraggable(x + Window.getScrollLeft(), y +
Window.getScrollTop());
+ Draggable draggable = findDraggable(x + Window.getScrollLeft(), y +
Window.getScrollTop());
//
if (draggable != null)
@@ -76,6 +79,39 @@
return true;
}
+ private Draggable findDraggable(int x, int y)
+ {
+ Iterator draggables = context.getDraggables(x, y);
+ if (draggables.hasNext())
+ {
+ return (Draggable)draggables.next();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private Droppable findDroppable(int x, int y)
+ {
+ Iterator droppables = context.findDroppable(x, y);
+
+ //
+ while (droppables.hasNext())
+ {
+ Droppable droppable = (Droppable)droppables.next();
+
+ //
+ if (!droppable.getId().equals(drag.draggable.getId()))
+ {
+ return droppable;
+ }
+ }
+
+ //
+ return null;
+ }
+
public void onBrowserEvent(Event event)
{
if (context != null)
@@ -89,7 +125,7 @@
{
int x = DOM.eventGetClientX(event);
int y = DOM.eventGetClientY(event);
- Draggable draggable = context.findDraggable(x + Window.getScrollLeft(), y
+ Window.getScrollTop());
+ Draggable draggable = findDraggable(x + Window.getScrollLeft(), y +
Window.getScrollTop());
//
if (draggable != null)
@@ -173,7 +209,7 @@
private void updateDroppable(int x, int y)
{
- Droppable newDroppable = context.findDroppable(x, y);
+ Droppable newDroppable = findDroppable(x, y);
//
if (newDroppable != null)
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Draggable.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Draggable.java 2008-07-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Draggable.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -31,6 +31,8 @@
public interface Draggable
{
+ String getId();
+
/**
* Returns the element container that will be used for moving.
*
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Droppable.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Droppable.java 2008-07-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Droppable.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -29,6 +29,8 @@
public interface Droppable
{
+ String getId();
+
void enter(Draggable draggable);
void leave(Draggable draggable);
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-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -26,8 +26,6 @@
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 com.google.gwt.user.client.Element;
-import com.google.gwt.user.client.DOM;
import java.util.Iterator;
import java.util.Map;
@@ -119,6 +117,11 @@
private final Droppable droppable = new Droppable()
{
+ public String getId()
+ {
+ return AjaxLayout.this.getId();
+ }
+
public void enter(Draggable draggable)
{
layout.addStyleName("dnd-selected");
@@ -131,39 +134,39 @@
public boolean accept(Draggable draggable)
{
- if (draggable instanceof AjaxWindow.DraggableWindow)
+ AjaxObject dragged = null;
+
+ //
+ if (draggable instanceof AjaxWindow.DraggableImpl)
{
- AjaxWindow.DraggableWindow draggableWindow =
(AjaxWindow.DraggableWindow)draggable;
- AjaxWindow window = draggableWindow.getWindow();
+ dragged = ((AjaxWindow.DraggableImpl)draggable).getWindow();
+ }
+ else if (draggable instanceof AjaxPane.DraggableImpl)
+ {
+ dragged = ((AjaxPane.DraggableImpl)draggable).getPane();
+ }
+ //
+ if (dragged != null && !getChildren().contains(dragged))
+ {
+ AjaxObject parent = dragged.getParent();
+
//
- if (!getChildren().contains(window))
- {
- AjaxObject parent = window.getParent();
+ log.info("Moving window " + dragged.getId() + " from parent
" + parent.getId() + " to layout " + getId());
- //
- log.info("Moving window " + window.getId() + " from parent
" + parent.getId() + " to layout " + getId());
+ //
+ MoveObjectAction action = new MoveObjectAction(dragged.getId(), getId());
- //
- MoveObjectAction action = new MoveObjectAction(window.getId(), getId());
+ //
+ getContext().getAgentContext().process(action);
- //
- getContext().getAgentContext().process(action);
-
-// //
-// parent.removeChild(window);
-//
-// //
-// addChild(window);
-
- //
- return true;
- }
- else
- {
- log.info("Do not contain child " + window.getId());
- }
+ //
+ return true;
}
+ else
+ {
+ log.info("Do not contain child " + dragged.getId());
+ }
//
return false;
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-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import org.jboss.portal.presentation.ajax.client.model.update.ModelUpdate;
import org.jboss.portal.presentation.ajax.client.model.update.AddObject;
@@ -133,41 +134,44 @@
}
}
- public final Draggable findDraggabble(int x, int y)
+ public final void findDraggabble(List draggables, int x, int y)
{
- Draggable draggable = doFindDraggable(x, y);
-
- //
- for (Iterator i = getChildren().iterator();i.hasNext() && draggable ==
null;)
+ for (Iterator i = getChildren().iterator();i.hasNext();)
{
AjaxObject child = (AjaxObject)i.next();
//
- draggable = child.findDraggabble(x, y);
+ child.findDraggabble(draggables, x, y);
}
-
+
//
- return draggable;
+ Draggable draggable = doFindDraggable(x, y);
+
+ //
+ if (draggable != null)
+ {
+ draggables.add(draggable);
+ }
}
- public final Droppable findDroppable(int x, int y)
+ public final void findDroppable(List droppables, int x, int y)
{
for (Iterator i = getChildren().iterator();i.hasNext();)
{
AjaxObject child = (AjaxObject)i.next();
//
- Droppable droppable = child.findDroppable(x, y);
-
- //
- if (droppable != null)
- {
- return droppable;
- }
+ child.findDroppable(droppables, x, y);
}
//
- return doFindDroppable(x, y);
+ Droppable droppable = doFindDroppable(x, y);
+
+ //
+ if (droppable != null)
+ {
+ droppables.add(droppable);
+ }
}
public final void refresh(boolean force)
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-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -27,6 +27,9 @@
import com.google.gwt.user.client.ui.Widget;
import java.util.Map;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
import org.jboss.portal.presentation.ajax.client.dnd.DnDPanel;
import org.jboss.portal.presentation.ajax.client.dnd.DnDContext;
@@ -95,14 +98,19 @@
/** . */
private final DnDContext dndContext = new DnDContext()
{
- public Draggable findDraggable(int x, int y)
+
+ public Iterator getDraggables(int x, int y)
{
- return findDraggabble(x, y);
+ List draggables = new ArrayList();
+ AjaxPage.this.findDraggabble(draggables, x, y);
+ return draggables.iterator();
}
- public Droppable findDroppable(int x, int y)
+ public Iterator findDroppable(int x, int y)
{
- return AjaxPage.this.findDroppable(x, y);
+ List droppables = new ArrayList();
+ AjaxPage.this.findDroppable(droppables, x, y);
+ return droppables.iterator();
}
};
}
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-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPane.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -38,12 +38,27 @@
public class AjaxPane extends AjaxLayout
{
- /** . */
- private VerticalPanel widget;
+ class DraggableImpl implements Draggable
+ {
- /** . */
- private Draggable draggable = new Draggable()
- {
+ /** . */
+ private final AjaxPane pane;
+
+ DraggableImpl(AjaxPane pane)
+ {
+ this.pane = pane;
+ }
+
+ public AjaxPane getPane()
+ {
+ return pane;
+ }
+
+ public String getId()
+ {
+ return AjaxPane.this.getId();
+ }
+
public Element getContainer()
{
return widget.getElement();
@@ -74,11 +89,20 @@
public void rejected(Droppable droppable)
{
}
- };
+ }
+ /** . */
+ private VerticalPanel widget;
+
+ /** . */
+ private Draggable draggable;
+
public AjaxPane(String id, Map properties)
{
super(id, properties);
+
+ //
+ this.draggable = new DraggableImpl(this);
}
protected void doCreateWidget()
@@ -92,19 +116,18 @@
protected Draggable doFindDraggable(int x, int y)
{
-// int left = widget.getAbsoluteLeft();
-// int right = left + widget.getOffsetWidth();
-// int top = widget.getAbsoluteTop();
-// int bottom = top + widget.getOffsetHeight();
-// if (x >= left && x <= right && y >= top && y
<= bottom)
-// {
-// return draggable;
-// }
-// else
-// {
-// return null;
-// }
- return null;
+ int left = widget.getAbsoluteLeft();
+ int right = left + widget.getOffsetWidth();
+ int top = widget.getAbsoluteTop();
+ int bottom = top + widget.getOffsetHeight();
+ if (x >= left && x <= right && y >= top && y <=
bottom)
+ {
+ return draggable;
+ }
+ else
+ {
+ return null;
+ }
}
protected void doRefresh(boolean force)
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-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -69,19 +69,24 @@
private HTML markup;
/** . */
- private DraggableWindow draggable;
+ private DraggableImpl draggable;
- static class DraggableWindow implements Draggable
+ static class DraggableImpl implements Draggable
{
/** . */
private final AjaxWindow window;
- DraggableWindow(AjaxWindow window)
+ DraggableImpl(AjaxWindow window)
{
this.window = window;
}
+ public String getId()
+ {
+ return window.getId();
+ }
+
public AjaxWindow getWindow()
{
return window;
@@ -124,7 +129,7 @@
super(id, properties);
//
- draggable = new DraggableWindow(this);
+ draggable = new DraggableImpl(this);
}
protected Draggable doFindDraggable(int x, int y)
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/PresentationServerImpl.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/PresentationServerImpl.java 2008-07-09
20:39:40 UTC (rev 11387)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/PresentationServerImpl.java 2008-07-09
21:30:21 UTC (rev 11388)
@@ -126,10 +126,10 @@
String targetId = objectAction.getTargetId();
//
- PortalNode targetNode = (PortalNode)structuralAdapter.getNode(targetId);
+ Object target = structuralAdapter.getNode(targetId);
//
- if (targetNode == null)
+ if (target == null)
{
return new PresentationResponse(new ErrorResponse(404));
}
@@ -141,19 +141,29 @@
}
else if (objectAction instanceof DestroyUIObjectAction)
{
- LayoutElement referent = layoutStore.findElementByRef(targetNode.getId());
+ if (target instanceof PortalNode)
+ {
+ PortalNode targetNode = (PortalNode)target;
- //
- if (referent != null)
+ //
+ LayoutElement referent =
layoutStore.findElementByRef(targetNode.getId());
+
+ //
+ if (referent != null)
+ {
+ layoutStore.destroyElement(referent.getId());
+ }
+
+ //
+ portalNodeManager.destroy(targetNode.getId());
+
+ //
+ return new PresentationResponse(new ShowUIObjectResponse(targetId));
+ }
+ else
{
- layoutStore.destroyElement(referent.getId());
+ throw new NotYetImplemented();
}
-
- //
- portalNodeManager.destroy(targetNode.getId());
-
- //
- return new PresentationResponse(new ShowUIObjectResponse(targetId));
}
else if (objectAction instanceof LinkActivation)
{
@@ -164,7 +174,7 @@
ContentAction contentAction = (ContentAction)objectAction;
//
- WindowNode window = (WindowNode)targetNode;
+ WindowNode window = (WindowNode)target;
//
Content content = window.getContent();
@@ -218,7 +228,15 @@
}
//
- LayoutElement sourceElt = layoutStore.findElementByRef(targetNode.getId());
+ LayoutElement sourceElt;
+ if (target instanceof PortalNode)
+ {
+ sourceElt = layoutStore.findElementByRef(((PortalNode)target).getId());
+ }
+ else
+ {
+ sourceElt = (LayoutElement)target;
+ }
//
if (sourceElt == null)
@@ -230,7 +248,7 @@
destinationElt.add(sourceElt);
//
- System.out.println("Should move " + targetNode + " to " +
destinationElt);
+ System.out.println("Should move " + sourceElt + " to " +
destinationElt);
//
return new PresentationResponse(new ShowUIObjectResponse("blah"));