[488507] Duplicate entries in New Runtime Wizard for Installed server
adapters - fix pom version and drop ui and core piece

Change-Id: I3605d9d57eefc43708a329b51904bbf817e3fd43
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerCore.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerCore.java
index 635a5db..3bf436f 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerCore.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerCore.java
@@ -314,8 +314,8 @@
 	private static List<RuntimeTypeWithServerProxy> createProxyRuntimeTypes(IProgressMonitor monitor){
 		List<ServerProxy> serverProxyList = Discovery.getExtensionsWithServer(monitor);
 		List<RuntimeTypeWithServerProxy> serverTypeProxyList = new ArrayList<RuntimeTypeWithServerProxy>();
-		for (Iterator iterator = serverProxyList.iterator(); iterator.hasNext();) {
-			ServerProxy serverProxy = (ServerProxy) iterator.next();
+		for (int i=0; i< serverProxyList.size(); i++) {
+			ServerProxy serverProxy = serverProxyList.get(i);
 			serverTypeProxyList.add(new RuntimeTypeWithServerProxy(serverProxy.getRuntimeType(), new ServerTypeProxy(serverProxy)));
 		}
 		return serverTypeProxyList;
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/RuntimeTypeProxy.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/RuntimeTypeProxy.java
index d659d90..1e36ee5 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/RuntimeTypeProxy.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/RuntimeTypeProxy.java
@@ -1,5 +1,5 @@
 /*******************************************************************************

- * Copyright (c) 2015 IBM Corporation and others.

+ * Copyright (c) 2015, 2016 IBM Corporation and others.

  * 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

@@ -24,13 +24,15 @@
 	private String name;

 	private String vendor;

 	private String description;

+	private String proxyRuntimeId;

 

-	public RuntimeTypeProxy(String id, String name, String description, String vendor) {

+	public RuntimeTypeProxy(String id, String name, String description, String vendor, String proxyRuntimeId) {

 		super();

 		this.runtimTypeId = id;

 		this.name = name;

 		this.description = description;

 		this.vendor = vendor;

+		this.proxyRuntimeId = proxyRuntimeId;

 	}

 	public RuntimeTypeProxy(RuntimeProxy runtimeProxy) {

 		super();

@@ -38,6 +40,7 @@
 		this.name = runtimeProxy.getName();

 		this.description = runtimeProxy.getDescription();

 		this.vendor = runtimeProxy.getVendor();

+		this.proxyRuntimeId = runtimeProxy.getProxyRuntimeId();

 	}

 

 	/**

@@ -89,6 +92,10 @@
 		return null;

 	}

 

+	public String getProxyRuntimeId() {

+		return proxyRuntimeId;

+	}

+	

 	public String toString() {

 		return "RuntimeType[" + getId() + ", " + getName() + "]";

 	}

diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/RuntimeTypeWithServerProxy.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/RuntimeTypeWithServerProxy.java
index 3f2a87a..6bfbc7c 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/RuntimeTypeWithServerProxy.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/RuntimeTypeWithServerProxy.java
@@ -25,13 +25,15 @@
 	private String vendor;

 	private String description;

 	private ServerTypeProxy serverTypeProxy;

+	private String proxyRuntimeId;

 

-	public RuntimeTypeWithServerProxy(String id, String name, String description, String vendor) {

+	public RuntimeTypeWithServerProxy(String id, String name, String description, String vendor, String proxyRuntimeId) {

 		super();

 		this.runtimTypeId = id;

 		this.name = name;

 		this.description = description;

 		this.vendor = vendor;

+		this.proxyRuntimeId = proxyRuntimeId;

 	}

 	public RuntimeTypeWithServerProxy(RuntimeProxy runtimeProxy, ServerTypeProxy server) {

 		super();

@@ -40,6 +42,7 @@
 		this.description = runtimeProxy.getDescription();

 		this.vendor = runtimeProxy.getVendor();

 		this.serverTypeProxy = server;

+		this.proxyRuntimeId = runtimeProxy.getProxyRuntimeId();

 	}

 

 	/**

@@ -98,4 +101,8 @@
 		return serverTypeProxy;

 	}

 	

+	public String getProxyRuntimeId() {

+		return proxyRuntimeId;

+	}

+	

 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/ServerUIUtil.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/ServerUIUtil.java
index 3871dd2..2d378c1 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/ServerUIUtil.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/ServerUIUtil.java
@@ -117,6 +117,8 @@
 			}
 		}
 		if (!userInitiated){
+			if (!ServerUIPlugin.getPreferences().getExtAdapter())
+				return null;
 			int cacheFrequency = ServerUIPlugin.getPreferences().getCacheFrequency();
 			if (cacheFrequency == 0 /*Manual*/){
 				// User will explicitly refresh
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/ServerPreferencePage.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/ServerPreferencePage.java
index 34c5ab4..88c7917 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/ServerPreferencePage.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/ServerPreferencePage.java
@@ -115,7 +115,8 @@
 		refreshNow.setLayoutData(data);
 		String refreshButtonText = ServerUIUtil.refreshButtonText;
 		ServerUIUtil.setListener(new UpdateJobChangeListener());
-		if (refreshButtonText.equals(Messages.cacheUpdate_refreshNow))
+		 // Manual refresh is allowed if Downloadable adapters are shown in server/runtime wizard and refresh not active
+		if (refreshButtonText.equals(Messages.cacheUpdate_refreshNow) && ServerUIPlugin.getPreferences().getExtAdapter())
 			refreshNow.setEnabled(true);
 		else
 			refreshNow.setEnabled(false);
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/viewers/RuntimeTypeTreeContentProvider.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/viewers/RuntimeTypeTreeContentProvider.java
index 6185cd8..c243dc4 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/viewers/RuntimeTypeTreeContentProvider.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/viewers/RuntimeTypeTreeContentProvider.java
@@ -12,6 +12,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -21,6 +22,8 @@
 import org.eclipse.wst.server.core.ServerCore;
 import org.eclipse.wst.server.core.ServerUtil;
 import org.eclipse.wst.server.core.internal.RuntimeType;
+import org.eclipse.wst.server.core.internal.RuntimeTypeWithServerProxy;
+import org.eclipse.wst.server.ui.internal.Trace;
 /**
  * Runtime type content provider.
  */
@@ -29,6 +32,7 @@
 	protected String type;
 	protected String version;
 	protected String runtimeTypeId;
+	List<IRuntimeType> runtimeInstalledList;
 
 	/**
 	 * RuntimeTypeContentProvider constructor.
@@ -52,6 +56,7 @@
 
 	public void fillTree() {
 		clean();
+		runtimeInstalledList = new ArrayList<IRuntimeType>();
 		List<TreeElement> list = new ArrayList<TreeElement>();
 		IRuntimeType[] runtimeTypes = ServerUtil.getRuntimeTypes(type, version, runtimeTypeId);
 		if (runtimeTypes != null) {
@@ -71,6 +76,7 @@
 					TreeElement ele = getOrCreate(list, runtimeType.getVendor());
 					ele.contents.add(runtimeType);
 					elementToParentMap.put(runtimeType, ele);
+					runtimeInstalledList.add(runtimeType);
 				}
 			}
 		}
@@ -94,8 +100,20 @@
 				}
 				
 				TreeElement ele = getOrCreate(list, runtimeType.getVendor());
-				ele.contents.add(runtimeType);
-				elementToParentMap.put(runtimeType, ele);
+				if (compareRuntimes(ele.contents, (RuntimeTypeWithServerProxy)runtimeType) )
+					continue;
+				if (!compareRuntimes(runtimeInstalledList, (RuntimeTypeWithServerProxy)runtimeType)){
+					// Sometime vendor name is different so need to search the entire list
+					ele.contents.add(runtimeType);
+					elementToParentMap.put(runtimeType, ele);
+				}
+				else {
+					// Remove the empty node
+					if (ele.contents.isEmpty()) {
+						list.remove(ele);
+						elementToParentMap.remove(ele);
+					}
+				}
 			}
 		}
 		if (list.size() >0) {
@@ -111,4 +129,18 @@
 			});
 		}
 	}
+	
+	private boolean compareRuntimes(List runtimeList, RuntimeTypeWithServerProxy runtimeType) {
+		for (Iterator iterator = runtimeList.iterator(); iterator.hasNext();) {
+			IRuntimeType existingRuntime = (IRuntimeType) iterator.next();
+			if (existingRuntime.getId().equals(runtimeType.getProxyRuntimeId())) {
+				if (Trace.INFO) {
+					Trace.trace(Trace.STRING_INFO, "already installed: " + runtimeType.getProxyRuntimeId(), null);
+				}
+				return true;
+			}
+
+		}
+		return false;
+	}
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/viewers/ServerTypeTreeContentProvider.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/viewers/ServerTypeTreeContentProvider.java
index 04664f0..569b641 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/viewers/ServerTypeTreeContentProvider.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/viewers/ServerTypeTreeContentProvider.java
@@ -32,6 +32,7 @@
 	protected IModuleType moduleType;
 	protected String serverTypeId;
 	protected boolean includeIncompatibleVersions;
+	List<IServerType> serverInstalledList;
 
 	/**
 	 * ServerTypeTreeContentProvider constructor.
@@ -51,7 +52,7 @@
 	
 	public void fillTree() {
 		clean();
-
+		serverInstalledList = new ArrayList<IServerType>();
 		List<TreeElement> list = new ArrayList<TreeElement>();
 		IServerType[] serverTypes = ServerCore.getServerTypes();
 		if (serverTypes != null) {
@@ -64,6 +65,7 @@
 						TreeElement ele = getOrCreate(list, runtimeType.getVendor());
 						ele.contents.add(serverType);
 						elementToParentMap.put(serverType, ele);
+						serverInstalledList.add(serverType);
 					} catch (Exception e) {
 						if (Trace.WARNING) {
 							Trace.trace(Trace.STRING_WARNING, "Error in server configuration content provider", e);
@@ -151,9 +153,18 @@
 					try {
 						IRuntimeType runtimeType = serverType.getRuntimeType();
 						TreeElement ele = getOrCreate(list, runtimeType.getVendor());
-						if (!compareServers(ele.contents, (ServerTypeProxy)serverType)){
-							ele.contents.add(serverType);
-							elementToParentMap.put(serverType, ele);
+						if (compareServers(ele.contents, (ServerTypeProxy)serverType))
+							continue;
+						if ( !compareServers(serverInstalledList, (ServerTypeProxy)serverType)){ 
+							// Sometime vendor name is different so need to search the entire list
+								ele.contents.add(serverType);
+								elementToParentMap.put(serverType, ele);
+						}
+						else {
+							if (ele.contents.isEmpty()) {
+								list.remove(ele);
+								elementToParentMap.remove(ele);
+							}
 						}
 					} catch (Exception e) {
 						if (Trace.WARNING) {