Bug 544838 - Improve PluginBlock UI update and generalize config field

Change-Id: If4928937ba274a09ceff21b40b6454614a6c2152
Signed-off-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Reviewed-on: https://git.eclipse.org/r/c/pde/eclipse.pde.ui/+/192328
Tested-by: PDE Bot <pde-bot@eclipse.org>
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/AbstractPluginBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/AbstractPluginBlock.java
index 4d29880..e79d6cf 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/AbstractPluginBlock.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/AbstractPluginBlock.java
@@ -89,6 +89,11 @@
 	private Button fDefaultsButton;
 	private Button fFilterButton;
 
+	/**
+	 * The configuration this block is currently displaying or <code>null</code>
+	 * if none set.
+	 */
+	protected ILaunchConfiguration fLaunchConfig;
 	private Listener fListener = new Listener();
 
 	private Label fCounter;
@@ -322,7 +327,6 @@
 			fAddWorkspaceButton = createButton(parent, span, indent, NLS.bind(PDEUIMessages.AdvancedLauncherTab_addNew, fTab.getName().toLowerCase(Locale.ENGLISH)));
 		}
 
-
 		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
 		gd.horizontalSpan = span;
 		Label label = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
@@ -772,12 +776,11 @@
 	 * @throws CoreException
 	 */
 	public void initializeFrom(ILaunchConfiguration config, boolean enableTable) throws CoreException {
+		fLaunchConfig = config;
+		initializeButtonsFrom(config);
 		levelColumnCache = new HashMap<>();
 		autoColumnCache = new HashMap<>();
 		fPluginFilteredTree.getPatternFilter().setPattern(null);
-		fIncludeOptionalButton.setSelection(config.getAttribute(IPDELauncherConstants.INCLUDE_OPTIONAL, true));
-		fAddWorkspaceButton.setSelection(config.getAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true));
-		fAutoValidate.setSelection(config.getAttribute(IPDELauncherConstants.AUTOMATIC_VALIDATE, true));
 		if (!enableTable) {
 			fPluginTreeViewer.setInput(null);
 		} else if (fPluginTreeViewer.getInput() == null) {
@@ -785,6 +788,12 @@
 			fPluginTreeViewer.setInput(PDEPlugin.getDefault());
 			fPluginTreeViewer.reveal(fWorkspacePlugins);
 		}
+	}
+
+	protected void initializeButtonsFrom(ILaunchConfiguration config) throws CoreException {
+		fIncludeOptionalButton.setSelection(config.getAttribute(IPDELauncherConstants.INCLUDE_OPTIONAL, true));
+		fAddWorkspaceButton.setSelection(config.getAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true));
+		fAutoValidate.setSelection(config.getAttribute(IPDELauncherConstants.AUTOMATIC_VALIDATE, true));
 		fFilterButton.setSelection(config.getAttribute(IPDELauncherConstants.SHOW_SELECTED_ONLY, false));
 	}
 
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiBundleBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiBundleBlock.java
index b91f27b..7014274 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiBundleBlock.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiBundleBlock.java
@@ -27,8 +27,6 @@
 
 public class OSGiBundleBlock extends AbstractPluginBlock {
 
-	private ILaunchConfiguration fLaunchConfiguration;
-
 	public OSGiBundleBlock(BundlesTab tab) {
 		super(tab);
 	}
@@ -69,7 +67,6 @@
 	public void initializeFrom(ILaunchConfiguration configuration) throws CoreException {
 		super.initializeFrom(configuration, true);
 		initializePluginsState(configuration);
-		fLaunchConfiguration = configuration;
 	}
 
 	// TODO deal with the discrepency between save/init states of the two blocks
@@ -81,8 +78,8 @@
 
 	@Override
 	protected LaunchValidationOperation createValidationOperation() throws CoreException {
-		Set<IPluginModelBase> models = BundleLauncherHelper.getMergedBundleMap(fLaunchConfiguration, true).keySet();
-		return new LaunchValidationOperation(fLaunchConfiguration, models);
+		Set<IPluginModelBase> models = BundleLauncherHelper.getMergedBundleMap(fLaunchConfig, true).keySet();
+		return new LaunchValidationOperation(fLaunchConfig, models);
 	}
 
 }
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/PluginBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/PluginBlock.java
index cf27c76..82e920c 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/PluginBlock.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/PluginBlock.java
@@ -31,10 +31,6 @@
 public class PluginBlock extends AbstractPluginBlock {
 
 	/**
-	 * The configuration this block is currently displaying or <code>null</code> if none set
-	 */
-	protected ILaunchConfiguration fLaunchConfig;
-	/**
 	 * Whether the controls have been initialized for fLaunchConfig
 	 */
 	protected boolean fIsEnabled = false;
@@ -51,13 +47,12 @@
 
 	@Override
 	public void initializeFrom(ILaunchConfiguration config, boolean enableTable) throws CoreException {
-
+		super.initializeButtonsFrom(config);
 		if (fLaunchConfig != null && fLaunchConfig.equals(config) && fIsEnabled == enableTable) {
 			// Do nothing
 			return;
 		}
 
-		fLaunchConfig = config;
 		fIsEnabled = enableTable;
 
 		super.initializeFrom(config, enableTable);