wlu: wbe move up and down among greens
diff --git a/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/BSActivityItemProvider.java b/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/BSActivityItemProvider.java
index 54c4c9a..59d8024 100644
--- a/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/BSActivityItemProvider.java
+++ b/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/BSActivityItemProvider.java
@@ -586,20 +586,25 @@
 			return children;
 		}
 		
-		
-		System.out.println("LD> handleGlobalOrdering 1, this: " + this);
 		List childList = handleGlobalOrdering(activity, (List) children);
-		System.out.println("LD> handleGlobalOrdering 2, this: " + this);
-		System.out.println("");
+//		System.out.println("");
 		
 		return childList;
 	}
 
 	private List handleGlobalOrdering(Activity activity, List childList) {
 
-		System.out.println("LD> activity: " + activity);
-
 		WbePropUtil propUtil = WbePropUtil.getWbePropUtil();
+//		Set localSet = new HashSet(activity.getBreakdownElements());
+//		System.out.println("LD> orignail: ");
+//		for (int i = 0; i < childList.size(); i++) {
+//			Object item = TngUtil.unwrap(childList.get(i));
+//			System.out.println("LD> " + i + ": " + item);
+//			if (localSet.contains(item)) {
+//				System.out.println("LD> globalPrev: " + propUtil.getGlobalPresentedAfter((WorkBreakdownElement) item));
+//			}
+//			System.out.println("");
+//		}
 		
 		WorkBreakdownElement globalPresentedAfter = null;
 		LinkedChildList linkedChildList = null;
@@ -655,6 +660,16 @@
 				node = node.nextNode;
 			}
 		}
+	
+//		System.out.println("LD> result: ");
+//		for (int i = 0; i < childList.size(); i++) {
+//			Object item = TngUtil.unwrap(childList.get(i));
+//			System.out.println("LD> " + i + ": " + item);
+//			if (localSet.contains(item)) {
+//				System.out.println("LD> globalPrev: " + propUtil.getGlobalPresentedAfter((WorkBreakdownElement) item));
+//			}
+//			System.out.println("");
+//		}
 		
 		return childList;
 	}
diff --git a/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/command/MoveDownCommand.java b/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/command/MoveDownCommand.java
index 976ffa2..08aa3ea 100644
--- a/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/command/MoveDownCommand.java
+++ b/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/command/MoveDownCommand.java
@@ -68,6 +68,14 @@
 	 * @see org.eclipse.emf.common.command.Command#execute()
 	 */
 	public void execute() {
+		if (elementObj instanceof WorkBreakdownElement) {
+			boolean completelyDone = MoveUpCommand.handleWbeGlobalMove(activity,
+					(WorkBreakdownElement) elementObj, false);
+			if (completelyDone) {
+				return;
+			}
+		}
+		
 		List allElements = activity.getBreakdownElements();
 
 		for (int i = 0; i < allElements.size(); i++) {
@@ -114,10 +122,7 @@
 		}
 		((EList) activity.getBreakdownElements()).move(transferLocation,
 				elementLocation);
-		
-		if (elementObj instanceof WorkBreakdownElement) {
-			MoveUpCommand.handleWbeGlobalMove(activity, (WorkBreakdownElement) elementObj, false);
-		}	
+	
 	}
 
 	public void undo() {
diff --git a/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/command/MoveUpCommand.java b/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/command/MoveUpCommand.java
index f36631a..d28b272 100644
--- a/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/command/MoveUpCommand.java
+++ b/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/process/command/MoveUpCommand.java
@@ -74,6 +74,14 @@
 	 * @see org.eclipse.emf.common.command.Command#execute()
 	 */
 	public void execute() {
+		if (elementObj instanceof WorkBreakdownElement) {
+			boolean completelyDone = handleWbeGlobalMove(activity,
+					(WorkBreakdownElement) elementObj, true);
+			if (completelyDone) {
+				return;
+			}
+		}	
+		
 		List allElements = activity.getBreakdownElements();
 
 		for (int i = 0; i < allElements.size(); i++) {
@@ -115,13 +123,19 @@
 		}
 		((EList) activity.getBreakdownElements()).move(transferLocation,
 				elementLocation);
-		
-		if (elementObj instanceof WorkBreakdownElement) {
-			handleWbeGlobalMove(activity, (WorkBreakdownElement) elementObj, true);
-		}		
+			
 	}
 
-	public static void handleWbeGlobalMove(Activity act, WorkBreakdownElement wbe, boolean up) {
+	//return true if move is completely done - no need to do local move
+	//return false if move is partially done - still need to do local move
+	public static boolean handleWbeGlobalMove(Activity act, WorkBreakdownElement wbe, boolean up) {
+		System.out.println("LD> handleWbeGlobalMove: begin");
+		boolean b = handleWbeGlobalMove_(act, wbe, up);
+		System.out.println("LD> handleWbeGlobalMove: end = " + b);
+		
+		return b;
+	}
+	public static boolean handleWbeGlobalMove_(Activity act, WorkBreakdownElement wbe, boolean up) {
 		AdapterFactory aFactory = TngAdapterFactory.INSTANCE
 				.getWBS_ComposedAdapterFactory();
 		ItemProviderAdapter adapter = (ItemProviderAdapter) aFactory.adapt(
@@ -129,42 +143,91 @@
 		
 		Collection<?> children = adapter.getChildren(act);
 		if (! (children instanceof List)) {
-			return;
+			return false;
 		}
 		
-		List<?> childList = (List<?>) children;
 		
+		boolean completelyDone = false;
+		List<?> childList = (List<?>) children;
+		Set<BreakdownElement> localSet = new HashSet<BreakdownElement>(act
+				.getBreakdownElements());
+		
+		WbePropUtil propUtil = WbePropUtil.getWbePropUtil();		
 		WorkBreakdownElement globalPresentedAfter = act;
 		for (int i = 0; i < childList.size(); i++) {
 			Object child = childList.get(i);
 			if (child == wbe) {
-				Object prev = null;
+				Object newPrev = null;
 				if (up) {
-					if (i - 2 >= 0) {
-						prev = TngUtil.unwrap(childList.get(i - 2));			
+					if (i == 0) {
+						break;
 					}
+
+					newPrev = i == 1 ? act : TngUtil.unwrap(childList.get(i - 2));
+					Object prevItem = childList.get(i - 1);		
+					Object nextItem = i + 1 < childList.size() ? childList
+							.get(i + 1) : null;
+					if (localSet.contains(prevItem)) {
+						propUtil.setGlobalPresentedAfter(
+								(WorkBreakdownElement) prevItem, wbe);
+					} else {
+						completelyDone = true;
+					}
+					if (nextItem != null && localSet.contains(nextItem)) {
+						WorkBreakdownElement nextWbe = (WorkBreakdownElement) nextItem;
+						prevItem = TngUtil.unwrap(prevItem);
+						if (prevItem instanceof WorkBreakdownElement) {
+							propUtil.setGlobalPresentedAfter(nextWbe,
+									(WorkBreakdownElement) prevItem);
+						} else {
+							propUtil.setGlobalPresentedAfter(nextWbe, null);
+						}
+					}
+				
 				} else {
-					if (i + 1 < childList.size()) {
-						prev = TngUtil.unwrap(childList.get(i + 1));	
+					if (i == childList.size() - 1) {
+						break;
 					}
+					
+					Object prevItem = i - 1 >= 0 ? childList.get(i - 1) : act;
+					newPrev = childList.get(i + 1);
+					if (localSet.contains(newPrev)) {
+						prevItem = TngUtil.unwrap(prevItem);
+						if (prevItem instanceof WorkBreakdownElement) {
+							propUtil.setGlobalPresentedAfter(
+									(WorkBreakdownElement) newPrev,
+									(WorkBreakdownElement) prevItem);
+						} else {
+							propUtil.setGlobalPresentedAfter(
+									(WorkBreakdownElement) newPrev, null);
+						}
+					} else {
+						completelyDone = true;
+						newPrev = TngUtil.unwrap(newPrev);
+					}
+					
+					Object newNextItem = i + 2 < childList.size() ? childList
+							.get(i + 2) : null;
+					if (newNextItem instanceof WorkBreakdownElement) {
+						propUtil.setGlobalPresentedAfter((WorkBreakdownElement) newNextItem, wbe);
+					}
+
 				}
 				
-				if (prev instanceof WorkBreakdownElement) {
-					globalPresentedAfter = (WorkBreakdownElement) prev;
+				if (newPrev instanceof WorkBreakdownElement) {
+					globalPresentedAfter = (WorkBreakdownElement) newPrev;
 				}
 				
 				break;
 			}
-		}
-		
-		Set<BreakdownElement> locals = new HashSet<BreakdownElement>(act.getBreakdownElements());
-		
-		if (locals.contains(globalPresentedAfter)) {
-			return;
-		}
-		
-		WbePropUtil propUtil = WbePropUtil.getWbePropUtil();		
+		}	
 		propUtil.setGlobalPresentedAfter(wbe, globalPresentedAfter);
+
+		if (! act.getBreakdownElements().isEmpty()) {
+			((EList) act.getBreakdownElements()).move(0, 0);	//hmm ... cause notifying UI refresh
+		}
+		
+		return completelyDone;
 	}
 
 	public void undo() {
diff --git a/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/util/WbePropUtil.java b/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/util/WbePropUtil.java
index 08ab559..63947a9 100644
--- a/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/util/WbePropUtil.java
+++ b/1.5/plugins/org.eclipse.epf.library.edit/src/org/eclipse/epf/library/edit/util/WbePropUtil.java
@@ -34,8 +34,9 @@
 
 	public void setGlobalPresentedAfter(WorkBreakdownElement wbe,
 			WorkBreakdownElement globalPresentedAfter) {
-		setStringValue(wbe, WBE_GlobalPresentedAfter, globalPresentedAfter
-				.getGuid());
+		setStringValue(wbe, WBE_GlobalPresentedAfter,
+				globalPresentedAfter == null ? null : globalPresentedAfter
+						.getGuid());
 	}
 	
 }