From afc0dcaf25a4831f6ad7f8285f5ad161c6ec8659 Mon Sep 17 00:00:00 2001 From: fedejeanne Date: Fri, 21 Jul 2023 08:48:38 +0200 Subject: [PATCH] Postpone long-running operations to the activation of the "Tracing" tab. Don't start unnecessary operations that only concern the "Tracing" tab upon initialization of the PDE-Run configuration (in the dialog "Run configurations..."). Instead, only do them when the tab is first selected. This speeds up opening the dialog "Run configurations..." (and also switching to a PDE-Run configuration when the dialog is already opened). Show a progress indicator when doing some (possibly) long-running operations in the "Tracing" tab. Contributes to https://github.com/vi-eclipse/Eclipse-PDE/issues/1 --- .../pde/internal/ui/PDEUIMessages.java | 3 + .../internal/ui/launcher/TracingBlock.java | 95 ++++++++++++++++--- .../pde/internal/ui/pderesources.properties | 3 + .../eclipse/pde/ui/launcher/TracingTab.java | 11 ++- 4 files changed, 99 insertions(+), 13 deletions(-) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java index 40f3c7d6d9d..d5c5834611f 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java @@ -1093,6 +1093,9 @@ public class PDEUIMessages extends NLS { public static String TracingTab_AttributeLabel_TracingChecked; public static String TracingTab_AttributeLabel_TracingNone; + public static String TracingBlock_initializing_tracing_options; + public static String TracingBlock_initializing_tracing_template; + public static String TracingBlock_initializing_tracing_template_table; public static String TracingBlock_restore_default; public static String TracingBlock_restore_default_selected; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/TracingBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/TracingBlock.java index dee79437636..54c87fdbb03 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/TracingBlock.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/TracingBlock.java @@ -18,19 +18,24 @@ import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; +import java.lang.reflect.InvocationTargetException; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Properties; import java.util.StringTokenizer; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.IStructuredSelection; @@ -61,6 +66,59 @@ public class TracingBlock { + private class TracingCache { + private Properties fTracingTemplateCopy; + private Map fOptions; + private Properties fTracingOptions; + private String fTemplateTableId; + private Hashtable fTemplateTable; + + Properties getTracingTemplateCopy() { + if (fTracingTemplateCopy == null) { + runShowingProgress(PDEUIMessages.TracingBlock_initializing_tracing_template, () -> { + fTracingTemplateCopy = PDECore.getDefault().getTracingOptionsManager().getTracingTemplateCopy(); + }); + } + return fTracingTemplateCopy; + } + + Properties getTracingOptions(Map options) { + if (fOptions == null || !Objects.equals(fOptions, options)) { + fOptions = options; + runShowingProgress(PDEUIMessages.TracingBlock_initializing_tracing_options, () -> { + fTracingOptions = PDECore.getDefault().getTracingOptionsManager().getTracingOptions(fOptions); + }); + } + + return fTracingOptions; + } + + Hashtable getTemplateTable(String pluginId) { + if (fTemplateTableId == null || !Objects.equals(fTemplateTableId, pluginId)) { + fTemplateTableId = pluginId; + + String taskName = MessageFormat.format(PDEUIMessages.TracingBlock_initializing_tracing_template_table, + pluginId); + runShowingProgress(taskName, () -> { + fTemplateTable = PDECore.getDefault().getTracingOptionsManager().getTemplateTable(pluginId); + }); + } + + return fTemplateTable; + } + + private void runShowingProgress(String taskName, Runnable runnable) { + try { + fRunnableContext.run(true, false, progressMonitor -> { + progressMonitor.beginTask(taskName, IProgressMonitor.UNKNOWN); + runnable.run(); + }); + } catch (InvocationTargetException | InterruptedException e) { + PDEPlugin.logException(e); + } + } + } + private TracingTab fTab; private Button fTracingCheck; private CheckboxTableViewer fPluginViewer; @@ -73,6 +131,9 @@ public class TracingBlock { private Hashtable fPropertySources = new Hashtable<>(); private FormToolkit fToolkit; private ScrolledPageBook fPageBook; + private boolean fInitialized; + private final TracingCache fTracingCache = new TracingCache(); + private IRunnableContext fRunnableContext; /** * The last selected item in the list is stored in the dialog settings. @@ -206,8 +267,7 @@ public void widgetSelected(SelectionEvent e) { IPluginModelBase model = (IPluginModelBase) selec.getFirstElement(); String modelName = model.getBundleDescription().getSymbolicName(); if (modelName != null) { - Properties properties = PDECore.getDefault().getTracingOptionsManager() - .getTracingTemplateCopy(); + Properties properties = fTracingCache.getTracingTemplateCopy(); for (String key : properties.stringPropertyNames()) { if (key.startsWith(modelName + '/')) { fMasterOptions.remove(key); @@ -231,7 +291,7 @@ public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) { disposePropertySources(); fMasterOptions.clear(); - fMasterOptions.putAll(PDECore.getDefault().getTracingOptionsManager().getTracingTemplateCopy()); + fMasterOptions.putAll(fTracingCache.getTracingTemplateCopy()); Object elements[] = fPluginViewer.getCheckedElements(); for (int i = 0; i < elements.length; i++) { if (elements[i] instanceof IPluginModelBase) { @@ -276,17 +336,23 @@ protected int createPropertySheet(Composite parent) { return style == SWT.NULL ? 2 : 0; } - public void initializeFrom(ILaunchConfiguration config) { + private void initializeFromIfNecessary(ILaunchConfiguration config, IRunnableContext runnableContext) { + if (fInitialized) { + return; + } + fMasterOptions.clear(); disposePropertySources(); try { fTracingCheck.setSelection(config.getAttribute(IPDELauncherConstants.TRACING, false)); Map options = config.getAttribute(IPDELauncherConstants.TRACING_OPTIONS, (Map) null); - if (options == null) { - fMasterOptions.putAll(PDECore.getDefault().getTracingOptionsManager().getTracingTemplateCopy()); - } else { - fMasterOptions.putAll(PDECore.getDefault().getTracingOptionsManager().getTracingOptions(options)); - } + + final Properties properties = (options == null) // + ? fTracingCache.getTracingTemplateCopy() + : fTracingCache.getTracingOptions(options); + + fMasterOptions.putAll(properties); + masterCheckChanged(false); String checked = config.getAttribute(IPDELauncherConstants.TRACING_CHECKED, (String) null); if (checked == null) { @@ -321,6 +387,8 @@ public void initializeFrom(ILaunchConfiguration config) { } catch (CoreException e) { PDEPlugin.logException(e); } + + fInitialized = true; } public void performApply(ILaunchConfigurationWorkingCopy config) { @@ -364,12 +432,17 @@ public void performApply(ILaunchConfigurationWorkingCopy config) { } } + public void setRunnableContext(IRunnableContext context) { + fRunnableContext = context; + } + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { configuration.setAttribute(IPDELauncherConstants.TRACING, false); configuration.setAttribute(IPDELauncherConstants.TRACING_CHECKED, IPDELauncherConstants.TRACING_NONE); } - public void activated(ILaunchConfigurationWorkingCopy workingCopy) { + public void activated(ILaunchConfigurationWorkingCopy workingCopy, IRunnableContext runnableContext) { + initializeFromIfNecessary(workingCopy, runnableContext); fPageBook.getParent().getParent().layout(true); } @@ -459,7 +532,7 @@ private TracingPropertySource getPropertySource(IPluginModelBase model) { TracingPropertySource source = fPropertySources.get(model); if (source == null) { String id = model.getPluginBase().getId(); - Hashtable defaults = PDECore.getDefault().getTracingOptionsManager().getTemplateTable(id); + Hashtable defaults = fTracingCache.getTemplateTable(id); source = new TracingPropertySource(model, fMasterOptions, defaults, this); fPropertySources.put(model, source); source.setChanged(true); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties index b7fc95737c7..b17eaeb6f0e 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties @@ -599,6 +599,9 @@ TracingTab_AttributeLabel_TracingOptions=Tracing options TracingTab_AttributeLabel_TracingChecked=Tracing select all TracingTab_AttributeLabel_TracingNone=Tracing select none +TracingBlock_initializing_tracing_options=Initializing tracing options +TracingBlock_initializing_tracing_template=Initializing tracing template +TracingBlock_initializing_tracing_template_table=Initializing tracing template table for ''{0}'' TracingBlock_restore_default=Restore &All to Defaults TracingBlock_restore_default_selected=Restore &Selected to Defaults TracingLauncherTab_name = Trac&ing diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/TracingTab.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/TracingTab.java index 75aa4308a82..9b755ee2f77 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/TracingTab.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/TracingTab.java @@ -16,6 +16,7 @@ import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.pde.internal.ui.IHelpContextIds; import org.eclipse.pde.internal.ui.PDEPlugin; @@ -67,7 +68,7 @@ public void createControl(Composite parent) { @Override public void activated(ILaunchConfigurationWorkingCopy workingCopy) { - fTracingBlock.activated(workingCopy); + fTracingBlock.activated(workingCopy, getLaunchConfigurationDialog()); } @Override @@ -81,7 +82,13 @@ public void dispose() { @Override public void initializeFrom(ILaunchConfiguration config) { - fTracingBlock.initializeFrom(config); + // the heavy lifting occurs in #activated(...) + } + + @Override + public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) { + super.setLaunchConfigurationDialog(dialog); + fTracingBlock.setRunnableContext(dialog); } @Override