[Bug 393354] JAX-WS Web Services node contents shows 'Loading...'
Update all CommonViewers instead of looking for ProjectExplorer only
diff --git a/bundles/org.eclipse.jst.ws.jaxws.dom.integration/.gitignore b/bundles/org.eclipse.jst.ws.jaxws.dom.integration/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/bundles/org.eclipse.jst.ws.jaxws.dom.integration/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/internal/util/CommonNavigatorFinder.java b/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/internal/util/CommonNavigatorFinder.java
new file mode 100755
index 0000000..efcb60b
--- /dev/null
+++ b/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/internal/util/CommonNavigatorFinder.java
@@ -0,0 +1,63 @@
+/*******************************************************************************

+ * Copyright (c) 2009 by SAP AG, Walldorf. 

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *     SAP AG - initial API and implementation

+ *******************************************************************************/

+package org.eclipse.jst.ws.jaxws.dom.integration.internal.util;

+

+import java.util.Collection;

+import java.util.LinkedList;

+

+import org.eclipse.ui.IViewPart;

+import org.eclipse.ui.IViewReference;

+import org.eclipse.ui.IWorkbenchWindow;

+import org.eclipse.ui.PlatformUI;

+import org.eclipse.ui.navigator.CommonNavigator;

+

+/**

+ * Finder for {@link CommonNavigator} views currently opened. This class must be used from the UI thread

+ * 

+ * @author Georgi Vachkov

+ */

+public class CommonNavigatorFinder

+{

+	private final IWorkbenchWindow wbWindow;

+

+	public CommonNavigatorFinder(final IWorkbenchWindow wbWindow)

+	{

+		this.wbWindow = wbWindow;

+	}

+

+	public CommonNavigatorFinder()

+	{

+		this(PlatformUI.getWorkbench().getActiveWorkbenchWindow());

+	}

+

+	/**

+	 * @return collection of {@link CommonNavigator} views currently opened, or empty collection if none

+	 */

+	public Collection<CommonNavigator> findCommonNavigators()

+	{

+		final Collection<CommonNavigator> result = new LinkedList<CommonNavigator>();

+

+		if (wbWindow == null || wbWindow.getActivePage() == null)

+		{

+			return result;

+		}

+

+		for (IViewReference viewRef : wbWindow.getActivePage().getViewReferences())

+		{

+			final IViewPart viewPart = viewRef.getView(false);

+			if (viewPart instanceof CommonNavigator)

+			{

+				result.add((CommonNavigator) viewPart);

+			}

+		}

+		return result;

+	}

+}

diff --git a/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/internal/util/ProjectExplorerUtil.java b/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/internal/util/ProjectExplorerUtil.java
deleted file mode 100755
index 82f68fd..0000000
--- a/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/internal/util/ProjectExplorerUtil.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************

- * Copyright (c) 2009 by SAP AG, Walldorf. 

- * All rights reserved. This program and the accompanying materials

- * are made available under the terms of the Eclipse Public License v1.0

- * which accompanies this distribution, and is available at

- * http://www.eclipse.org/legal/epl-v10.html

- *

- * Contributors:

- *     SAP AG - initial API and implementation

- *******************************************************************************/

-package org.eclipse.jst.ws.jaxws.dom.integration.internal.util;

-

-import org.eclipse.ui.IViewPart;

-import org.eclipse.ui.IWorkbenchWindow;

-import org.eclipse.ui.PlatformUI;

-

-/**

- * Utility class that holds methods to manipulate ProjectExplorer 

- * 

- * @author Georgi Vachkov

- */

-public class ProjectExplorerUtil 

-{

-	public static final ProjectExplorerUtil INSTANCE = new ProjectExplorerUtil();

-	

-	/**

-	 * This method should be called only from UI thread otherwise <code>null</code> will be returned

-	 * 

-	 * @return the project explorer {@link IViewPart} in case it is available otherwise <code>null</code>

-	 */

-	public IViewPart findProjectExplorer()

-	{

-		final IWorkbenchWindow workbenchWin = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

-		if (workbenchWin==null || workbenchWin.getActivePage()==null) {

-			return null;

-		}

-		

-		return workbenchWin.getActivePage().findView("org.eclipse.ui.navigator.ProjectExplorer"); //$NON-NLS-1$

-	}

-}

diff --git a/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/navigator/DOMAdapterFactoryContentProvider.java b/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/navigator/DOMAdapterFactoryContentProvider.java
index b482f67..03778f7 100755
--- a/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/navigator/DOMAdapterFactoryContentProvider.java
+++ b/bundles/org.eclipse.jst.ws.jaxws.dom.integration/src/org/eclipse/jst/ws/jaxws/dom/integration/navigator/DOMAdapterFactoryContentProvider.java
@@ -20,8 +20,8 @@
 import org.eclipse.emf.common.notify.AdapterFactory;
 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
 import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
+import org.eclipse.jst.ws.jaxws.dom.integration.internal.util.CommonNavigatorFinder;
 import org.eclipse.jst.ws.jaxws.dom.integration.internal.util.LoadingWsProjectNodesCollector;
-import org.eclipse.jst.ws.jaxws.dom.integration.internal.util.ProjectExplorerUtil;
 import org.eclipse.jst.ws.jaxws.dom.integration.navigator.ILoadingWsProject.ILoadingDummy;
 import org.eclipse.jst.ws.jaxws.dom.runtime.api.IDOM;
 import org.eclipse.jst.ws.jaxws.dom.runtime.api.IServiceEndpointInterface;
@@ -41,7 +41,6 @@
 import org.eclipse.jst.ws.jaxws.utils.logging.Logger;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.navigator.CommonNavigator;
 import org.eclipse.ui.navigator.CommonViewer;
 
@@ -322,15 +321,14 @@
 	
 	private abstract class ExchangeLoadingWsProjectRunnable implements Runnable
 	{
-		public void run() 
+		public void run()
 		{
-			final IViewPart viewPart = ProjectExplorerUtil.INSTANCE.findProjectExplorer();
-			if (viewPart instanceof CommonNavigator) 
+			for (CommonNavigator navigator : new CommonNavigatorFinder().findCommonNavigators())
 			{
-				final CommonViewer commonViewer = ((CommonNavigator)viewPart).getCommonViewer();
-				for(TreeItem treeItem : new LoadingWsProjectNodesCollector().getLoadingWsProjects(commonViewer.getTree().getItems()))
+				final CommonViewer commonViewer = navigator.getCommonViewer();
+				for (TreeItem treeItem : new LoadingWsProjectNodesCollector().getLoadingWsProjects(commonViewer.getTree().getItems()))
 				{
-					final IProject relevantProject = ((ILoadingWsProject)treeItem.getData()).getProject();					
+					final IProject relevantProject = ((ILoadingWsProject) treeItem.getData()).getProject();
 					updateTreeItemData(treeItem, commonViewer, relevantProject);
 					commonViewer.refresh(relevantProject);
 				}
diff --git a/bundles/org.eclipse.jst.ws.jaxws.dom.runtime/.gitignore b/bundles/org.eclipse.jst.ws.jaxws.dom.runtime/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/bundles/org.eclipse.jst.ws.jaxws.dom.runtime/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/bundles/org.eclipse.jst.ws.jaxws.dom.ui/.gitignore b/bundles/org.eclipse.jst.ws.jaxws.dom.ui/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/bundles/org.eclipse.jst.ws.jaxws.dom.ui/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/bundles/org.eclipse.jst.ws.jaxws.utils/.gitignore b/bundles/org.eclipse.jst.ws.jaxws.utils/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/bundles/org.eclipse.jst.ws.jaxws.utils/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/.gitignore b/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/src/org/eclipse/jst/ws/jaxws/dom/integration/tests/dom/AllTestsSuite.java b/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/src/org/eclipse/jst/ws/jaxws/dom/integration/tests/dom/AllTestsSuite.java
index b9af6d9..9af1d50 100755
--- a/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/src/org/eclipse/jst/ws/jaxws/dom/integration/tests/dom/AllTestsSuite.java
+++ b/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/src/org/eclipse/jst/ws/jaxws/dom/integration/tests/dom/AllTestsSuite.java
@@ -17,6 +17,7 @@
 import org.eclipse.jst.ws.jaxws.dom.integration.tests.navigator.DOMAdapterFactoryLabelProviderTest;
 import org.eclipse.jst.ws.jaxws.dom.integration.tests.navigator.DOMPropertyViewAdapterFactoryTest;
 import org.eclipse.jst.ws.jaxws.dom.integration.tests.navigator.WebServiceDecoratorTest;
+import org.eclipse.jst.ws.jaxws.dom.integration.tests.util.CommonNavigatorFinderTest;
 import org.eclipse.jst.ws.jaxws.dom.integration.tests.util.LoadingWsProjectNodesCollectorTest;
 
 public class AllTestsSuite
@@ -30,6 +31,7 @@
 		suite.addTestSuite(DOMPropertyViewAdapterFactoryTest.class);
 		suite.addTestSuite(WebServiceDecoratorTest.class);
 		suite.addTestSuite(LoadingWsProjectNodesCollectorTest.class);
+		suite.addTestSuite(CommonNavigatorFinderTest.class);
 		
 		return suite;
 	}
diff --git a/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/src/org/eclipse/jst/ws/jaxws/dom/integration/tests/util/CommonNavigatorFinderTest.java b/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/src/org/eclipse/jst/ws/jaxws/dom/integration/tests/util/CommonNavigatorFinderTest.java
new file mode 100644
index 0000000..9b9b16f
--- /dev/null
+++ b/tests/org.eclipse.jst.ws.jaxws.dom.integration.tests/src/org/eclipse/jst/ws/jaxws/dom/integration/tests/util/CommonNavigatorFinderTest.java
@@ -0,0 +1,84 @@
+/*******************************************************************************

+ * Copyright (c) 2013 by SAP AG, Walldorf. 

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ *

+ * Contributors:

+ *     SAP AG - initial API and implementation

+ *******************************************************************************/

+package org.eclipse.jst.ws.jaxws.dom.integration.tests.util;

+

+import java.util.Collection;

+

+import org.eclipse.jst.ws.jaxws.dom.integration.internal.util.CommonNavigatorFinder;

+import org.eclipse.jst.ws.jaxws.testutils.jmock.Mock;

+import org.eclipse.jst.ws.jaxws.testutils.jmock.MockObjectTestCase;

+import org.eclipse.ui.IViewPart;

+import org.eclipse.ui.IViewReference;

+import org.eclipse.ui.IWorkbenchPage;

+import org.eclipse.ui.IWorkbenchWindow;

+import org.eclipse.ui.navigator.CommonNavigator;

+

+public class CommonNavigatorFinderTest extends MockObjectTestCase

+{

+	private CommonNavigatorFinder finder;

+	private Mock<IWorkbenchWindow> wbWindow;

+	private Mock<IWorkbenchPage> wbPage;

+

+	@Override

+	protected void setUp() throws Exception

+	{

+		super.setUp();

+		wbPage = mock(IWorkbenchPage.class);

+		wbWindow = mock(IWorkbenchWindow.class);

+		wbWindow.stubs().method("getActivePage").will(returnValue(wbPage.proxy()));

+		finder = new CommonNavigatorFinder(wbWindow.proxy());

+	}

+

+	public void testWbWindowIsNull()

+	{

+		finder = new CommonNavigatorFinder(null);

+		assertTrue("Empty collection expected", finder.findCommonNavigators().isEmpty());

+	}

+

+	public void testNoCommonNavigatorsOpened()

+	{

+		wbPage.stubs().method("getViewReferences").will(returnValue(new IViewReference[] {}));

+		assertTrue("Empty collection expected", finder.findCommonNavigators().isEmpty());

+	}

+

+	public void testCommonNavigatorNotYetInstantiated()

+	{

+		final IViewReference viewRef = mockViewReference(null);

+		wbPage.stubs().method("getViewReferences").will(returnValue(new IViewReference[] { viewRef }));

+		assertTrue("Empty collection expected", finder.findCommonNavigators().isEmpty());

+	}

+

+	public void testNonCommonNavigatorViewNotFound()

+	{

+		final Mock<IViewPart> viewPart = mock(IViewPart.class);

+		final IViewReference viewRef = mockViewReference(viewPart.proxy());

+		wbPage.stubs().method("getViewReferences").will(returnValue(new IViewReference[] { viewRef }));

+		assertTrue("Empty collection expected", finder.findCommonNavigators().isEmpty());

+	}

+

+	public void testCommonNavigatorOpened()

+	{

+		final CommonNavigator navigatorMock = new CommonNavigator();

+		final IViewReference viewRef = mockViewReference(navigatorMock);

+		wbPage.stubs().method("getViewReferences").will(returnValue(new IViewReference[] { viewRef }));

+		final Collection<CommonNavigator> foundNavigators = finder.findCommonNavigators();

+		assertEquals("One navigator expected", 1, foundNavigators.size());

+		assertSame("Unexpected navigator", navigatorMock, foundNavigators.iterator().next());

+	}

+

+	private IViewReference mockViewReference(final IViewPart viewPart)

+	{

+		final Mock<IViewReference> viewRefMock = mock(IViewReference.class);

+		viewRefMock.stubs().method("getView").will(returnValue(viewPart));

+		return viewRefMock.proxy();

+	}

+

+}

diff --git a/tests/org.eclipse.jst.ws.jaxws.dom.runtime.tests/.gitignore b/tests/org.eclipse.jst.ws.jaxws.dom.runtime.tests/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/tests/org.eclipse.jst.ws.jaxws.dom.runtime.tests/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/tests/org.eclipse.jst.ws.jaxws.dom.ui.tests/.gitignore b/tests/org.eclipse.jst.ws.jaxws.dom.ui.tests/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/tests/org.eclipse.jst.ws.jaxws.dom.ui.tests/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/tests/org.eclipse.jst.ws.jaxws.testutils/.gitignore b/tests/org.eclipse.jst.ws.jaxws.testutils/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/tests/org.eclipse.jst.ws.jaxws.testutils/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/tests/org.eclipse.jst.ws.jaxws.utils.tests/.gitignore b/tests/org.eclipse.jst.ws.jaxws.utils.tests/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/tests/org.eclipse.jst.ws.jaxws.utils.tests/.gitignore
@@ -0,0 +1 @@
+/bin