Author: julien(a)jboss.com
Date: 2008-07-08 12:44:15 -0400 (Tue, 08 Jul 2008)
New Revision: 11353
Added:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/
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/Drag.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Draggable.java
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/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/AjaxWindow.java
Log:
start to implement drag and drop
Added:
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
(rev 0)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDContext.java 2008-07-08
16:44:15 UTC (rev 11353)
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.ajax.client.dnd;
+
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.Element;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface DnDContext
+{
+
+ Draggable findDraggableByHandle(Panel panel, Element element);
+
+}
Added:
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
(rev 0)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/DnDPanel.java 2008-07-08
16:44:15 UTC (rev 11353)
@@ -0,0 +1,169 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.ajax.client.dnd;
+
+import com.google.gwt.user.client.ui.SimplePanel;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.EventPreview;
+import org.jboss.portal.presentation.ajax.client.util.logging.Logger;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class DnDPanel extends SimplePanel implements EventPreview
+{
+
+ /** . */
+ private final Logger log = Logger.getLogger(DnDPanel.class);
+
+ /** . */
+ private Drag drag;
+
+ /** . */
+ private DnDContext context;
+
+ public DnDPanel(DnDContext context)
+ {
+ DOM.sinkEvents(getElement(), Event.MOUSEEVENTS);
+ DOM.addEventPreview(this);
+
+ this.context = context;
+ }
+
+ public boolean onEventPreview(Event event)
+ {
+ if (DOM.eventGetType(event) == Event.ONMOUSEDOWN)
+ {
+ Object draggable = context.findDraggableByHandle(this,
DOM.eventGetTarget(event));
+
+ //
+ if (draggable != null)
+ {
+ DOM.eventPreventDefault(event);
+ }
+ }
+
+ //
+ return true;
+ }
+
+ public void onBrowserEvent(Event event)
+ {
+ if (context != null)
+ {
+ Element element = DOM.eventGetTarget(event);
+
+ //
+ switch (DOM.eventGetType(event))
+ {
+ case Event.ONMOUSEDOWN:
+ {
+ Draggable draggable = context.findDraggableByHandle(this, element);
+
+ //
+ if (draggable != null)
+ {
+ Element containerElement = draggable.getContainer();
+ int left = DOM.getAbsoluteLeft(draggable.getContainer());
+ int top = DOM.getAbsoluteTop(draggable.getContainer());
+ int x = DOM.eventGetClientX(event);
+ int y = DOM.eventGetClientY(event);
+ int deltaX = x - left;
+ int deltaY = y - top;
+
+ //
+ log.debug("Starting drag element=(" + left + "," +
top + "), mouse=(" + x +
+ "," + y + "), delta=(" + deltaX + ","
+ deltaY + ") with draggable " + draggable);
+
+ //
+ DOM.setStyleAttribute(containerElement, "position",
"fixed");
+ DOM.setIntStyleAttribute(containerElement, "left", left);
+ DOM.setIntStyleAttribute(containerElement, "top", top);
+
+ //
+ drag = new Drag(
+ deltaX,
+ deltaY,
+ element,
+ draggable
+ );
+
+ //
+ // DOM.setCapture(element);
+ }
+
+ //
+ break;
+ }
+ case Event.ONMOUSEUP:
+ {
+ if (drag != null)
+ {
+ stopDrag();
+ }
+ break;
+ }
+ case Event.ONMOUSEMOVE:
+ {
+ if (drag != null)
+ {
+ int x = DOM.eventGetClientX(event);
+ int y = DOM.eventGetClientY(event);
+ int newX = x - drag.deltaX;
+ int newY = y - drag.deltaY;
+ DOM.setIntStyleAttribute(drag.draggable.getContainer(),
"left", newX);
+ DOM.setIntStyleAttribute(drag.draggable.getContainer(),
"top", newY);
+ log.debug("Dragging at position (" + newX + "," +
newY + ") with draggable " + drag.draggable);
+ }
+
+ //
+ break;
+ }
+ case Event.ONMOUSEOVER:
+ case Event.ONMOUSEOUT:
+ {
+ if (drag != null && element == getElement())
+ {
+ stopDrag();
+ }
+ break;
+ }
+ }
+
+
+ }
+ }
+
+ private void stopDrag()
+ {
+ log.debug("Stopping drag with draggable " + drag.draggable);
+ // DOM.releaseCapture(drag.element);
+ Element containerElement = drag.draggable.getContainer();
+ DOM.setStyleAttribute(containerElement, "position", null);
+ drag = null;
+ }
+
+}
Added:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Drag.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Drag.java
(rev 0)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Drag.java 2008-07-08
16:44:15 UTC (rev 11353)
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.ajax.client.dnd;
+
+import com.google.gwt.user.client.Element;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+class Drag
+{
+
+ /** . */
+ final int deltaX;
+
+ /** . */
+ final int deltaY;
+
+ /** . */
+ final Element element;
+
+ /** . */
+ final Draggable draggable;
+
+ Drag(int deltaX, int deltaY, Element element, Draggable draggable)
+ {
+ this.deltaX = deltaX;
+ this.deltaY = deltaY;
+ this.element = element;
+ this.draggable = draggable;
+ }
+}
Added:
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
(rev 0)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/dnd/Draggable.java 2008-07-08
16:44:15 UTC (rev 11353)
@@ -0,0 +1,41 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.ajax.client.dnd;
+
+import com.google.gwt.user.client.Element;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface Draggable
+{
+
+ /**
+ * Returns the element container that will be used for moving.
+ *
+ * @return the element container
+ */
+ Element getContainer();
+
+}
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-08
15:06:11 UTC (rev 11352)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxLayout.java 2008-07-08
16:44:15 UTC (rev 11353)
@@ -26,11 +26,13 @@
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 java.util.Iterator;
import java.util.Map;
import org.jboss.portal.presentation.ajax.client.Constants;
+import org.jboss.portal.presentation.ajax.client.dnd.Draggable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -112,6 +114,11 @@
this.layout = layout;
}
+ protected Draggable doFindDraggable(Element element)
+ {
+ return null;
+ }
+
protected void doAddChild(AjaxObject child)
{
}
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-08
15:06:11 UTC (rev 11352)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxObject.java 2008-07-08
16:44:15 UTC (rev 11353)
@@ -23,6 +23,7 @@
package org.jboss.portal.presentation.ajax.client.model;
import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.Element;
import java.util.Map;
import java.util.HashMap;
@@ -39,6 +40,7 @@
import org.jboss.portal.presentation.ajax.client.model.update.RemoveObject;
import org.jboss.portal.presentation.ajax.client.util.logging.Logger;
import org.jboss.portal.presentation.ajax.client.AgentContext;
+import org.jboss.portal.presentation.ajax.client.dnd.Draggable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -127,6 +129,23 @@
}
}
+ public final Draggable findDraggabble(Element element)
+ {
+ Draggable draggable = doFindDraggable(element);
+
+ //
+ for (Iterator i = getChildren().iterator();i.hasNext() && draggable ==
null;)
+ {
+ AjaxObject child = (AjaxObject)i.next();
+
+ //
+ draggable = child.findDraggabble(element);
+ }
+
+ //
+ return draggable;
+ }
+
public final void refresh(boolean force)
{
context.log.debug("Requesting for" + (force ? " forced " :
" ") + "refresh of object " + id);
@@ -200,9 +219,11 @@
protected abstract void doRemoveChild(AjaxObject child);
+ protected abstract Draggable doFindDraggable(Element element);
+
public abstract Widget getWidget();
- public static class Context
+ public final static class Context
{
/** . */
@@ -238,6 +259,11 @@
return root;
}
+ Logger getLog()
+ {
+ return log;
+ }
+
public void update(ModelUpdate[] updates)
{
for (int i = 0; i < updates.length;i++)
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-08
15:06:11 UTC (rev 11352)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxPage.java 2008-07-08
16:44:15 UTC (rev 11353)
@@ -25,9 +25,15 @@
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 com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.Element;
import java.util.Map;
+import org.jboss.portal.presentation.ajax.client.dnd.DnDPanel;
+import org.jboss.portal.presentation.ajax.client.dnd.DnDContext;
+import org.jboss.portal.presentation.ajax.client.dnd.Draggable;
+
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
@@ -38,6 +44,9 @@
/** . */
private VerticalPanel widget;
+ /** . */
+ private DnDPanel dndPanel;
+
public AjaxPage(String id, Map properties)
{
super(id, properties);
@@ -45,7 +54,7 @@
protected void doRefresh(boolean force)
{
- doRefresh(widget);
+ doRefresh(dndPanel);
}
public Widget getWidget()
@@ -58,10 +67,12 @@
Label title = new Label("Page " + getId());
MetaWidget meta = new MetaWidget(this);
VerticalPanel widget = new VerticalPanel();
+ DnDPanel dndPanel = new DnDPanel(dndContext);
//
meta.add(title);
widget.add(meta);
+ widget.add(dndPanel);
//
title.setStyleName("pf-Title");
@@ -69,10 +80,20 @@
//
this.widget = widget;
+ this.dndPanel = dndPanel;
}
protected void doDestroyWidget()
{
widget = null;
}
+
+ /** . */
+ private final DnDContext dndContext = new DnDContext()
+ {
+ public Draggable findDraggableByHandle(Panel panel, Element element)
+ {
+ return findDraggabble(element);
+ }
+ };
}
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-08
15:06:11 UTC (rev 11352)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java 2008-07-08
16:44:15 UTC (rev 11353)
@@ -36,6 +36,7 @@
import com.google.gwt.core.client.GWT;
import org.jboss.portal.presentation.ajax.client.PresentationClientRemoteAsync;
import org.jboss.portal.presentation.ajax.client.PresentationClientRemote;
+import org.jboss.portal.presentation.ajax.client.dnd.Draggable;
import org.jboss.portal.presentation.ajax.client.protocol.OpaqueWindowAction;
import org.jboss.portal.presentation.ajax.client.protocol.DestroyObjectAction;
import org.jboss.portal.presentation.ajax.client.util.Tools;
@@ -66,11 +67,35 @@
/** . */
private HTML markup;
+ /** . */
+ private Draggable draggable;
+
public AjaxWindow(String id, Map properties)
{
super(id, properties);
+
+ //
+ draggable = new Draggable()
+ {
+ public Element getContainer()
+ {
+ return widget.getElement();
+ }
+ };
}
+ protected Draggable doFindDraggable(Element element)
+ {
+ if (title.getElement() == element)
+ {
+ return draggable;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
protected void doCreateWidget()
{
//
@@ -84,11 +109,12 @@
getContext().getAgentContext().process(new DestroyObjectAction(getId()));
}
});
- MetaWidget meta = new MetaWidget(this);
+// MetaWidget meta = new MetaWidget(this);
//
- meta.add(title);
- widget.add(meta);
+// meta.add(title);
+// widget.add(meta);
+ widget.add(title);
widget.add(close);
widget.add(markup);