Bug 530711 - [9] Add JavaJRETab constructor with param to activate check
for classpath dependencies change

Change-Id: I4013e92a279cfaa7a06cdd7e1bcd485fa4d52ea3
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaJRETab.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaJRETab.java
index ce8675a..fbb36a9 100644
--- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaJRETab.java
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaJRETab.java
@@ -97,6 +97,8 @@
 		}
 	};
 
+	private boolean fCheckForClasspathDependenciesChange;
+
 	/**
 	 * Constructor
 	 */
@@ -105,6 +107,21 @@
 		setHelpContextId(IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_JRE_TAB);
 	}
 
+	/**
+	 * Constructor
+	 *
+	 * @param checkForClasspathDependenciesChange
+	 *            if this is true, and the user changes between a non-modular jvm and a modular jvm, the user will be asked to apply changes before
+	 *            the tab is exited and the tabs will be refreshed.
+	 *
+	 * @since 3.9
+	 */
+	public JavaJRETab(boolean checkForClasspathDependenciesChange) {
+		this();
+		this.fCheckForClasspathDependenciesChange = checkForClasspathDependenciesChange;
+	}
+
+
 	/* (non-Javadoc)
 	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#dispose()
 	 */
@@ -645,20 +662,12 @@
 	 */
 	@Override
 	public boolean OkToLeaveTab() {
-		ILaunchConfiguration launchConfiguration = getLaunchConfiguration();
-		try {
-			String id = launchConfiguration.getType().getIdentifier();
-			// Add "org.eclipse.jdt.launching.javaApplet" after support for java 9 is added in javaapplet
-			if (id.equals("org.eclipse.jdt.launching.localJavaApplication")) { //$NON-NLS-1$
-				boolean newJREModular = JavaRuntime.isModularConfiguration(getLaunchConfiguration());
-				if (fCurrentJREModular != newJREModular) {
-					return handleClasspathDependenciesChange(newJREModular);
-				}
+		if (fCheckForClasspathDependenciesChange) {
+			boolean newJREModular = JavaRuntime.isModularConfiguration(getLaunchConfiguration());
+			if (fCurrentJREModular != newJREModular) {
+				return handleClasspathDependenciesChange(newJREModular);
 			}
 		}
-		catch (CoreException e) {
-			e.printStackTrace();
-		}
 
 		return true;
 	}
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LocalJavaApplicationTabGroup.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LocalJavaApplicationTabGroup.java
index 0ade0dd..d39c021 100644
--- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LocalJavaApplicationTabGroup.java
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LocalJavaApplicationTabGroup.java
@@ -13,10 +13,9 @@
 
 
 import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer;
-import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
 import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
 import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.DebugUITools;
 import org.eclipse.debug.ui.EnvironmentTab;
 import org.eclipse.debug.ui.ILaunchConfigurationDialog;
 import org.eclipse.debug.ui.ILaunchConfigurationTab;
@@ -38,27 +37,13 @@
 	 */
 	@Override
 	public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
-		JavaClasspathTab tab = null;
-		if (dialog instanceof LaunchConfigurationsDialog) {
-			LaunchConfigurationTabGroupViewer tabViewer = ((LaunchConfigurationsDialog) dialog).getTabViewer();
-			if (tabViewer != null) {
-				Object input = tabViewer.getInput();
-				if (input instanceof ILaunchConfiguration) {
-					ILaunchConfiguration configuration = (ILaunchConfiguration) input;
-					if (JavaRuntime.isModularConfiguration(configuration)) {
-						tab = new JavaDependenciesTab();
-					}
-				}
-			}
-		}
-		if (tab == null) {
-			tab = new JavaClasspathTab();
-		}
+		ILaunchConfiguration configuration = DebugUITools.getLaunchConfiguration(dialog);
+		boolean isModularConfiguration = configuration != null && JavaRuntime.isModularConfiguration(configuration);
 		ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
 			new JavaMainTab(),
 			new JavaArgumentsTab(),
-			new JavaJRETab(),
-				tab,
+			new JavaJRETab(true), 
+			isModularConfiguration ? new JavaDependenciesTab() : new JavaClasspathTab(),
 			new SourceLookupTab(),
 			new EnvironmentTab(),
 			new CommonTab(),