### Eclipse Workspace Patch 1.0
#P org.jboss.tools.vpe
Index: src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
--- src/org/jboss/tools/vpe/editor/VpeController.java	(revision 37932)
+++ src/org/jboss/tools/vpe/editor/VpeController.java	(working copy)
@@ -46,6 +46,10 @@
 import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.events.MenuEvent;
 import org.eclipse.swt.events.MenuListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseWheelListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Color;
@@ -56,6 +60,7 @@
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.ScrollBar;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IFileEditorInput;
@@ -150,17 +155,27 @@
 import org.jboss.tools.vpe.resref.core.RelativeFolderReferenceList;
 import org.jboss.tools.vpe.resref.core.TaglibReferenceList;
 import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
+import org.mozilla.interfaces.nsIBaseWindow;
 import org.mozilla.interfaces.nsIDOMDocument;
 import org.mozilla.interfaces.nsIDOMElement;
 import org.mozilla.interfaces.nsIDOMEvent;
+import org.mozilla.interfaces.nsIDOMEventListener;
+import org.mozilla.interfaces.nsIDOMEventTarget;
 import org.mozilla.interfaces.nsIDOMKeyEvent;
 import org.mozilla.interfaces.nsIDOMMouseEvent;
 import org.mozilla.interfaces.nsIDOMMutationEvent;
 import org.mozilla.interfaces.nsIDOMNSUIEvent;
 import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMWindow;
+import org.mozilla.interfaces.nsIDOMWindowInternal;
+import org.mozilla.interfaces.nsIDocShell;
+import org.mozilla.interfaces.nsIScrollable;
 import org.mozilla.interfaces.nsISelection;
 import org.mozilla.interfaces.nsISelectionDisplay;
 import org.mozilla.interfaces.nsISelectionListener;
+import org.mozilla.interfaces.nsISupports;
+import org.mozilla.interfaces.nsIWebBrowser;
+import org.mozilla.xpcom.XPCOMException;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -340,7 +355,75 @@
 		if (textWidget != null) {
 			textWidget.addSelectionListener(this);
 		}
-
+		/*
+		 * Add ScrollBar Listeners
+		 */
+		if ((visualEditor != null) && (sourceEditor != null)) {
+			ScrollBar sourceVB = textWidget.getVerticalBar();
+			if (sourceVB != null) {
+				if (visualEditor.getXulRunnerEditor() != null) {
+					nsIWebBrowser webBrowser = visualEditor.getXulRunnerEditor().getWebBrowser();
+					if (webBrowser != null) {
+						/*
+						 * Initialize source and visual bars
+						 */
+						final nsIDOMWindow domWindow = webBrowser.getContentDOMWindow();
+						final nsIDOMWindowInternal windowInternal = org.jboss.tools.vpe.xulrunner.util.XPCOM
+								.queryInterface(domWindow, nsIDOMWindowInternal.class);
+						/*
+						 * Adding source listener
+						 */
+						SelectionListener sourceScrollSelectionListener = new SelectionListener() {
+							@Override
+							public void widgetSelected(SelectionEvent e) {
+								ScrollBar sb = (ScrollBar)e.widget;						
+								int pageYOffsetSrc = sb.getSelection();
+								int scrollMaxYSrc = sb.getMaximum() - sb.getThumb();
+								float percentsSrc = ((float)pageYOffsetSrc/scrollMaxYSrc);
+								int scrollMaxYVisual = -1;
+								scrollMaxYVisual = windowInternal.getScrollMaxY();
+								if (scrollMaxYVisual != 0 && scrollMaxYVisual != -1) {
+									// there is a visual scroll bar
+									int posY = ((int) (scrollMaxYVisual*percentsSrc));
+									domWindow.scrollTo(windowInternal.getPageXOffset(),posY);
+								}
+							}
+							@Override
+							public void widgetDefaultSelected(SelectionEvent e) { }
+						}; 
+						sourceVB.addSelectionListener(sourceScrollSelectionListener);
+						/*
+						 * Adding visual listener
+						 */
+//				nsIDOMEventListener visualScrollListener = new nsIDOMEventListener() {
+//					public nsISupports queryInterface(String interfaceId) { 
+//						return interfaceId.equals(nsIDOMEventListener.NS_IDOMEVENTLISTENER_IID) ? this : null; 
+//					}
+//					public void handleEvent(nsIDOMEvent event) {
+//						nsIDOMWindowInternal windowInternal = org.jboss.tools.vpe.xulrunner.util.XPCOM
+//								.queryInterface(domWindow, nsIDOMWindowInternal.class); 
+//						int pageYOffsetVisual = windowInternal.getPageYOffset();
+//						int scrollMaxYVisual = windowInternal.getScrollMaxY();
+//						float percentsVisual = ((float)pageYOffsetVisual/scrollMaxYVisual);
+//						int scrollMaxYSrc = -1;
+//						scrollMaxYSrc = sourceVB.getMaximum();
+//						if (scrollMaxYSrc != 1 && scrollMaxYSrc != -1) {
+//							// there is a source scroll bar
+//							int posY = ((int) (scrollMaxYSrc*percentsVisual));
+//							sourceVB.setSelection(posY);
+//						}
+//					}
+//				};
+//				try {
+//					nsIDOMEventTarget domEventTarget = queryInterface(domWindow, nsIDOMEventTarget.class);
+//					domEventTarget.addEventListener("scroll", visualScrollListener, false);
+//				} catch (XPCOMException e) {
+//					VpePlugin.getDefault().logError(e);
+//				}
+					}
+				}
+			}
+		}
 		registerEventTargets();
 
 		if (optionsListener == null) {
@@ -958,8 +1041,8 @@
 		}
 		onRefresh();
 	}
-
 
+
 	public boolean isKeyBinding(Event keyboardEvent) {
 		boolean keyBindingPressed = false;
 		List<KeyStroke> possibleKeyStrokes = WorkbenchKeyboard
@@ -1064,6 +1147,7 @@
 		if (uiJob != null && uiJob.getState() != Job.NONE) {
 			return;
 		}
+
 		if (visualRefreshJob == null || visualRefreshJob.getState() == Job.NONE) {
 			visualRefreshJob = new UIJob(VpeUIMessages.VPE_VISUAL_REFRESH_JOB) {
 				@Override
@@ -1768,10 +1852,8 @@
 
 	public void setZoomEventManager(IZoomEventManager zoomEventManager) {
 		this.zoomEventManager = zoomEventManager;
-	}
+	}
 
-
-
 	public VpeDropWindow getDropWindow() {
 		return dropWindow;
 	}
