Revision: 3915
Author: [email protected]
Date: Mon Aug 23 15:29:34 2010
Log: Refixed the bugs where dragging tables while receiving a remove table
event from the server would cause exceptions.
http://code.google.com/p/power-architect/source/detail?r=3915
Modified:
/trunk/src/main/java/ca/sqlpower/architect/enterprise/NetworkConflictResolver.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/DraggablePlayPenComponent.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/olap/OLAPPane.java
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/NetworkConflictResolver.java
Fri Aug 20 13:17:17 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/NetworkConflictResolver.java
Mon Aug 23 15:29:34 2010
@@ -436,20 +436,19 @@
private void decodeMessage(String jsonArray, int newRevision) {
try {
if (currentRevision < newRevision) {
- for (UpdateListener listener : updateListeners) {
+ List<UpdateListener> updateListenersCopy = new
ArrayList<UpdateListener>(updateListeners);
+ for (UpdateListener listener : updateListenersCopy) {
listener.preUpdatePerformed(NetworkConflictResolver.this);
}
// Now we can apply the update ...
jsonDecoder.decode(jsonArray);
currentRevision = newRevision;
- List<UpdateListener> listenersToRemove = new
ArrayList<UpdateListener>();
- for (UpdateListener listener : updateListeners) {
+ for (UpdateListener listener : updateListenersCopy) {
if (listener.updatePerformed(this)) {
- listenersToRemove.add(listener);
+ updateListeners.remove(listener);
}
}
- updateListeners.removeAll(listenersToRemove);
}
} catch (Exception e) {
throw new RuntimeException("Failed to decode the message from
the server.", e);
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/DraggablePlayPenComponent.java
Tue Aug 10 14:52:03 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/DraggablePlayPenComponent.java
Mon Aug 23 15:29:34 2010
@@ -20,7 +20,9 @@
package ca.sqlpower.architect.swingui;
import java.awt.Point;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import org.apache.log4j.Logger;
@@ -57,6 +59,7 @@
logger.debug("zoomed event point: " + pp.zoomPoint(new Point(p)));
//$NON-NLS-1$
pp.setDraggingContainerPanes(true);
startedDragging();
+ Map<DraggablePlayPenComponent, Point> ppcToHandleMap = new
HashMap<DraggablePlayPenComponent, Point>();
while (it.hasNext()) {
// create FloatingContainerPaneListener for each selected item
@@ -72,8 +75,10 @@
+ (otherContainer.getY() - clickedItem.getY()));
Point handle = pp.zoomPoint(new Point(p));
handle.translate((int)(clickedItem.getX() -
otherContainer.getX()), (int) (clickedItem.getY() - otherContainer.getY()));
- new FloatingContainerPaneListener(pp, ppc, handle);
- }
+
+ ppcToHandleMap.put(ppc, handle);
+ }
+ new FloatingContainerPaneListener(pp, ppcToHandleMap);
}
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Mon Aug
23 12:24:08 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Mon Aug
23 15:29:34 2010
@@ -61,12 +61,14 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
@@ -2466,12 +2468,6 @@
draggingContainerPanes = false;
selectionInProgress = false;
-
- for (PlayPenComponent ppc : contentPane.getChildren()) {
- if (ppc.isBeingDragged()) {
- ppc.doneDragging();
- }
- }
if (rubberBand != null && evt.getButton() ==
MouseEvent.BUTTON1) {
Rectangle dirtyRegion = rubberBand;
@@ -2597,9 +2593,8 @@
private Insets scrollUnits = new Insets(AUTO_SCROLL_INSET,
AUTO_SCROLL_INSET, AUTO_SCROLL_INSET, AUTO_SCROLL_INSET);
private PlayPen pp;
- private PlayPenComponent ppc;
- private Point handle;
- private Point p;
+ private Map<DraggablePlayPenComponent, Point> ppcToHandleMap = new
HashMap<DraggablePlayPenComponent, Point>();
+ private Map<DraggablePlayPenComponent, Point> ppcToPointMap = new
HashMap<DraggablePlayPenComponent, Point>();
/**
* Creates a new mouse event handler that tracks mouse motion and
moves
@@ -2623,21 +2618,24 @@
* table" type actions, and should be set to false for
* dragging existing objects.
*/
- public FloatingContainerPaneListener(PlayPen pp, PlayPenComponent ppc,
Point handle) {
+ public FloatingContainerPaneListener(PlayPen pp,
Map<DraggablePlayPenComponent, Point> ppcToHandleMap) {
this.pp = pp;
Point pointerLocation =
MouseInfo.getPointerInfo().getLocation();
SwingUtilities.convertPointFromScreen(pointerLocation,pp);
logger.debug("Adding floating container pane at:"+ pointerLocation);
//$NON-NLS-1$
- p = new Point(pointerLocation.x - handle.x, pointerLocation.y -
handle.y);
-
- this.ppc = ppc;
- this.handle = handle;
+
+ this.ppcToHandleMap = new HashMap<DraggablePlayPenComponent,
Point>(ppcToHandleMap);
+
+ for (Entry<DraggablePlayPenComponent, Point> entry :
ppcToHandleMap.entrySet()) {
+ DraggablePlayPenComponent ppc = entry.getKey();
+ Point handle = entry.getValue();
+ Point point = new Point(pointerLocation.x - handle.x,
pointerLocation.y - handle.y);
+
+ ppcToPointMap.put(ppc, point);
+ }
pp.addMouseMotionListener(this);
pp.addMouseListener(this); // the click that ends this
operation
-
- pp.getContentPane().begin("Dragging " + this);
- pp.startCompoundEdit("Dragging " + this);
pp.cursorManager.tableDragStarted();
}
@@ -2647,38 +2645,44 @@
}
public void mouseDragged(MouseEvent e) {
- pp.zoomPoint(e.getPoint());
- p.setLocation(e.getPoint().x - handle.x, e.getPoint().y
- handle.y);
- pp.setChildPosition(ppc, p);
- JViewport viewport =
(JViewport)SwingUtilities.getAncestorOfClass(JViewport.class, pp);
- if(viewport==null || pp.getSelectedItems().size() < 1)
- return;
-
- // Theoretically should re-validate after each scroll. But that
would
- // cause the selected component to fall off the border.
- pp.revalidate();
- Point viewPos = viewport.getViewPosition();
- Rectangle view = viewport.getViewRect();
- int viewHeight = viewport.getHeight();
- int viewWidth = viewport.getWidth();
-
- // performs scrolling
- Rectangle bounds = pp.zoomRect(ppc.getBounds());
- if ((p.y - viewPos.y) < scrollUnits.top && viewPos.y > 0) { //
scroll up
- view.y = bounds.y - scrollUnits.top;
- } if ((viewPos.y + viewHeight - p.y - bounds.height) <
scrollUnits.bottom) { // scroll down
- view.y = bounds.y + bounds.height - viewHeight +
scrollUnits.bottom;
- } if ((p.x - viewPos.x) < scrollUnits.left && viewPos.x > 0) { //
scroll left
- view.x = bounds.x - scrollUnits.left;
- } if ((viewPos.x + viewWidth - p.x - bounds.width) <
scrollUnits.right) { // scroll right
- view.x = bounds.x + bounds.width - viewWidth +
scrollUnits.right;
- }
- logger.debug(viewport.getViewPosition());
- pp.scrollRectToVisible(view);
- // Necessary to stop tables from flashing.
- if (ppc != null) {
- ppc.repaint();
- }
+ for (Entry<DraggablePlayPenComponent, Point> entry :
ppcToHandleMap.entrySet()) {
+ DraggablePlayPenComponent ppc = entry.getKey();
+ Point handle = entry.getValue();
+ Point p = ppcToPointMap.get(ppc);
+
+ pp.zoomPoint(e.getPoint());
+ p.setLocation(e.getPoint().x - handle.x, e.getPoint().y -
handle.y);
+ pp.setChildPosition(ppc, p);
+ JViewport viewport =
(JViewport)SwingUtilities.getAncestorOfClass(JViewport.class, pp);
+ if(viewport==null || pp.getSelectedItems().size() < 1)
+ return;
+
+ // Theoretically should re-validate after each scroll. But that
would
+ // cause the selected component to fall off the border.
+ pp.revalidate();
+ Point viewPos = viewport.getViewPosition();
+ Rectangle view = viewport.getViewRect();
+ int viewHeight = viewport.getHeight();
+ int viewWidth = viewport.getWidth();
+
+ // performs scrolling
+ Rectangle bounds = pp.zoomRect(ppc.getBounds());
+ if ((p.y - viewPos.y) < scrollUnits.top && viewPos.y > 0) { //
scroll up
+ view.y = bounds.y - scrollUnits.top;
+ } if ((viewPos.y + viewHeight - p.y - bounds.height) <
scrollUnits.bottom) { // scroll down
+ view.y = bounds.y + bounds.height - viewHeight +
scrollUnits.bottom;
+ } if ((p.x - viewPos.x) < scrollUnits.left && viewPos.x > 0) {
// scroll left
+ view.x = bounds.x - scrollUnits.left;
+ } if ((viewPos.x + viewWidth - p.x - bounds.width) <
scrollUnits.right) { // scroll right
+ view.x = bounds.x + bounds.width - viewWidth +
scrollUnits.right;
+ }
+ logger.debug(viewport.getViewPosition());
+ pp.scrollRectToVisible(view);
+ // Necessary to stop tables from flashing.
+ if (ppc != null) {
+ ppc.repaint();
+ }
+ }
}
/**
@@ -2691,8 +2695,11 @@
pp.normalize();
pp.revalidate();
- pp.endCompoundEdit("Done moving " + ppc);
- pp.getContentPane().commit("Done moving " + ppc);
+ for (DraggablePlayPenComponent ppc :
ppcToHandleMap.keySet()) {
+ if (ppc.isBeingDragged()) {
+ ppc.doneDragging();
+ }
+ }
}
protected void cleanup() {
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
Mon Aug 23 12:24:08 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
Mon Aug 23 15:29:34 2010
@@ -650,7 +650,6 @@
getPlayPen().getSession().getEnterpriseSession().getUpdater().addListener(updateWhileMovingListener);
}
getParent().begin("Dragging " + this);
- getPlayPen().startCompoundEdit("Dragging " + this);
} else {
throw new IllegalStateException("Component is already in the
middle of a drag");
}
@@ -669,7 +668,6 @@
if (isBeingDragged) {
isBeingDragged = false;
if (ok) {
- getPlayPen().endCompoundEdit("Done dragging " + this);
getParent().commit("Done dragging " + this);
} else {
// We need to cleanup all of the
FloatingContainerPaneListeners
@@ -678,12 +676,9 @@
for (MouseMotionListener l :
getPlayPen().getMouseMotionListeners()) {
if (l instanceof FloatingContainerPaneListener) {
((FloatingContainerPaneListener) l).cleanup();
- getPlayPen().endCompoundEdit("Update received
while dragging.");
- getParent().rollback("Update received while
dragging.");
}
}
- getPlayPen().endCompoundEdit("Update received while
dragging.");
getParent().rollback("Update received while dragging");
JOptionPane.showMessageDialog(getPlayPen(), "There was an
update while you were dragging");
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/olap/OLAPPane.java
Thu Apr 8 07:59:33 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/olap/OLAPPane.java
Mon Aug 23 15:29:34 2010
@@ -32,9 +32,11 @@
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.swing.JComponent;
@@ -45,17 +47,18 @@
import org.apache.log4j.Logger;
import ca.sqlpower.architect.layout.LayoutEdge;
+import ca.sqlpower.architect.olap.MondrianModel.Schema;
import ca.sqlpower.architect.olap.OLAPObject;
import ca.sqlpower.architect.olap.OLAPUtil;
-import ca.sqlpower.architect.olap.MondrianModel.Schema;
import ca.sqlpower.architect.swingui.ASUtils;
import ca.sqlpower.architect.swingui.ContainerPane;
+import ca.sqlpower.architect.swingui.DraggablePlayPenComponent;
import ca.sqlpower.architect.swingui.PlayPen;
+import ca.sqlpower.architect.swingui.PlayPen.FloatingContainerPaneListener;
+import ca.sqlpower.architect.swingui.PlayPen.MouseModeType;
import ca.sqlpower.architect.swingui.PlayPenComponent;
import ca.sqlpower.architect.swingui.PlayPenContentPane;
import ca.sqlpower.architect.swingui.PlayPenCoordinate;
-import ca.sqlpower.architect.swingui.PlayPen.FloatingContainerPaneListener;
-import ca.sqlpower.architect.swingui.PlayPen.MouseModeType;
import ca.sqlpower.architect.swingui.event.SelectionEvent;
import ca.sqlpower.architect.swingui.olap.DimensionPane.HierarchySection;
import ca.sqlpower.object.annotation.Accessor;
@@ -286,6 +289,7 @@
logger.debug("zoomed event point: " + pp.zoomPoint(new
Point(p))); //$NON-NLS-1$
pp.setDraggingContainerPanes(true);
startedDragging();
+ Map<DraggablePlayPenComponent, Point> ppcToHandleMap = new
HashMap<DraggablePlayPenComponent, Point>();
while (it.hasNext()) {
// create FloatingContainerPaneListener for each
selected item
@@ -301,8 +305,10 @@
+ (otherContainer.getY() -
clickedItem.getY()));
Point handle = pp.zoomPoint(new Point(p));
handle.translate((int)(clickedItem.getX() -
otherContainer.getX()), (int) (clickedItem.getY() - otherContainer.getY()));
- new FloatingContainerPaneListener(pp, cp, handle);
- }
+
+ ppcToHandleMap.put(cp, handle);
+ }
+ new FloatingContainerPaneListener(pp, ppcToHandleMap);
}
} else if (evt.getID() == MouseEvent.MOUSE_MOVED || evt.getID() ==
MouseEvent.MOUSE_DRAGGED) {
logger.debug("Mouse moved/dragged to " + evt.getPoint());