Bug 518866 - [9] User should have the ability to define module path and
classpath while launching

Change-Id: I5192082c2076f5a39dbb82e29dec3e747d237aa7
diff --git a/org.eclipse.debug.ui/.settings/.api_filters b/org.eclipse.debug.ui/.settings/.api_filters
index e7430a9..b6cbd92 100644
--- a/org.eclipse.debug.ui/.settings/.api_filters
+++ b/org.eclipse.debug.ui/.settings/.api_filters
@@ -55,6 +55,12 @@
                 <message_argument value="OkToLeaveTab()"/>
             </message_arguments>
         </filter>
+        <filter id="404000815">
+            <message_arguments>
+                <message_argument value="org.eclipse.debug.ui.ILaunchConfigurationTab"/>
+                <message_argument value="postApply()"/>
+            </message_arguments>
+        </filter>
     </resource>
     <resource path="ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java" type="org.eclipse.debug.ui.actions.AbstractLaunchHistoryAction">
         <filter comment="Known leaked internal types" id="576725006">
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java
index d287fec..2bb3442 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java
@@ -105,7 +105,7 @@
 	/**
 	 * The old configuration
 	 */
-	private boolean sameInput = false;
+	private boolean fRefreshTabs = false;
 
 	/**
 	 * This view's control, which contains a composite area of controls
@@ -324,6 +324,10 @@
 			@Override
 			public void widgetSelected(SelectionEvent evt) {
 				handleApplyPressed();
+				ILaunchConfigurationTab[] tabs = getTabs();
+				for (ILaunchConfigurationTab tab : tabs) {
+					tab.postApply();
+				}
 			}
 		});
         Dialog.applyDialogFont(parent);
@@ -392,16 +396,11 @@
 						public void handleEvent(Event newEvent) {
 							if (newEvent.detail == SWT.Selection) { //
 								display.removeListener(SWT.PostEvent, this);
-								if (sameInput) {
-									displayInstanceTabs(true);
+								if (fRefreshTabs) {
+									refreshTabs(true);
 									fTabFolder.setSelection(selectedIndex);
 									refreshStatus();
 								}
-								if (canChangeTab) {
-									handleTabSelected();
-									refresh();
-								}
-
 							}
 						}
 					});
@@ -411,8 +410,6 @@
 		}
 	}
 
-	private boolean canChangeTab = true;
-
 	private void handleTabChange(int newPageIndex) {
 		if (fCurrentTabIndex == newPageIndex) {
 			return;
@@ -422,13 +419,10 @@
 			if (fCurrentTabIndex != -1) {
 				ILaunchConfigurationTab tab = tabs[fCurrentTabIndex];
 				fTabFolder.setSelection(fCurrentTabIndex);
-				if (!tab.OkToLeaveTab()) {
-					canChangeTab = false;
-
-				}
-				else {
-					canChangeTab = true;
+				if (tab.OkToLeaveTab()) {
 					fTabFolder.setSelection(newPageIndex);
+					handleTabSelected();
+					refresh();
 				}
 			}
 		} else {
@@ -667,10 +661,47 @@
 			}
 			inputChanged(input);
 		} else {
-			// Input needs to be changed even if same for Tab initializations
-			inputChanged(input);
+			if (!input.equals(getConfiguration())) {
+				inputChanged(input);
+			}
 		}
 	}
+	/*
+	 * Refresh tabs for same input
+	 */
+
+	public void refreshTabs(boolean refresh) {
+		if (DebugUIPlugin.getStandardDisplay().getThread().equals(Thread.currentThread())) {
+			refreshTabs0(refresh);
+		} else {
+			DebugUIPlugin.getStandardDisplay().syncExec(new Runnable() {
+				@Override
+				public void run() {
+					refreshTabs0(refresh);
+				}
+			});
+		}
+	}
+
+	/**
+	 * The input has changed to the given object, possibly <code>null</code>.
+	 *
+	 * @param input the new input, possibly <code>null</code>
+	 */
+	protected void refreshTabs0(boolean refreshTabs) {
+		final boolean refresh = refreshTabs;
+		Runnable r = new Runnable() {
+			@Override
+			public void run() {
+				fViewform.setRedraw(false);
+				fRefreshTabs = !refresh;
+				displayInstanceTabs(refresh);
+				refreshStatus();
+				fViewform.setRedraw(true);
+			}
+		};
+		BusyIndicator.showWhile(getShell().getDisplay(), r);
+	}
 
 	/**
 	 * The input has changed to the given object, possibly <code>null</code>.
@@ -688,10 +719,7 @@
 						ILaunchConfiguration configuration = (ILaunchConfiguration)finput;
 						boolean refreshTabs = true;
 						if (fWorkingCopy != null && fWorkingCopy.getOriginal().equals(configuration.getWorkingCopy().getOriginal())) {
-							sameInput = true;
 							refreshTabs = false;
-						} else {
-							sameInput = false;
 						}
 						fOriginal = configuration;
 						fWorkingCopy = configuration.getWorkingCopy();
@@ -1452,13 +1480,6 @@
 				return null;
 			}
 		}
-		ILaunchConfigurationTab[] tabs = getTabs();
-		if (fCurrentTabIndex != -1) {
-			ILaunchConfigurationTab tab = tabs[fCurrentTabIndex];
-			if (!tab.OkToLeaveTab()) {
-				return null;
-			}
-		}
 		Exception exception = null;
 		final ILaunchConfiguration[] saved = new ILaunchConfiguration[1];
 		try {
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/ILaunchConfigurationTab.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/ILaunchConfigurationTab.java
index fb2ccc2..158530f 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/ILaunchConfigurationTab.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/ILaunchConfigurationTab.java
@@ -245,5 +245,13 @@
 	public default boolean OkToLeaveTab() {
 		return true;
 	}
+
+	/**
+	 * Perform the changes after apply.
+	 *
+	 * @since 3.12
+	 */
+	public default void postApply() {
+	}
 }