Skip to content

Commit

Permalink
Postpone long-running operations to the activation of the "Tracing" tab.
Browse files Browse the repository at this point in the history
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 vi-eclipse/Eclipse-PDE#1
  • Loading branch information
fedejeanne committed Jul 25, 2023
1 parent 575c801 commit afc0dca
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +66,59 @@

public class TracingBlock {

private class TracingCache {
private Properties fTracingTemplateCopy;
private Map<String, String> fOptions;
private Properties fTracingOptions;
private String fTemplateTableId;
private Hashtable<String, String> fTemplateTable;

Properties getTracingTemplateCopy() {
if (fTracingTemplateCopy == null) {
runShowingProgress(PDEUIMessages.TracingBlock_initializing_tracing_template, () -> {
fTracingTemplateCopy = PDECore.getDefault().getTracingOptionsManager().getTracingTemplateCopy();
});
}
return fTracingTemplateCopy;
}

Properties getTracingOptions(Map<String, String> 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<String, String> 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;
Expand All @@ -73,6 +131,9 @@ public class TracingBlock {
private Hashtable<IPluginModelBase, TracingPropertySource> 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.
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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<String, String> options = config.getAttribute(IPDELauncherConstants.TRACING_OPTIONS, (Map<String, String>) 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) {
Expand Down Expand Up @@ -321,6 +387,8 @@ public void initializeFrom(ILaunchConfiguration config) {
} catch (CoreException e) {
PDEPlugin.logException(e);
}

fInitialized = true;
}

public void performApply(ILaunchConfigurationWorkingCopy config) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -459,7 +532,7 @@ private TracingPropertySource getPropertySource(IPluginModelBase model) {
TracingPropertySource source = fPropertySources.get(model);
if (source == null) {
String id = model.getPluginBase().getId();
Hashtable<String, String> defaults = PDECore.getDefault().getTracingOptionsManager().getTemplateTable(id);
Hashtable<String, String> defaults = fTracingCache.getTemplateTable(id);
source = new TracingPropertySource(model, fMasterOptions, defaults, this);
fPropertySources.put(model, source);
source.setChanged(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void createControl(Composite parent) {

@Override
public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
fTracingBlock.activated(workingCopy);
fTracingBlock.activated(workingCopy, getLaunchConfigurationDialog());
}

@Override
Expand All @@ -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
Expand Down

0 comments on commit afc0dca

Please sign in to comment.