Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
0.8
-
None
-
None
Description
There are a large number of classes that use code very similar to this:
public void selectionChanged(IAction action, ISelection selection) {
// if (selection instanceof IStructuredSelection) {
Object first = ((IStructuredSelection) selection).getFirstElement();
IResource resource = (IResource) first;
if (resource != null) {
IProject newActiveProject = resource.getProject();
if (newActiveProject != activeProject) {
// TODO: only attempt to load config file if this is a Forrest
// project
activeProject = newActiveProject;
projectName = activeProject.getProject().getName();
xDocPath = (activeProject.getProject().getLocation().toString() + java.io.File.separator);
}
}
}
These calsses all keep track of the currently active project and loading a file that is to be worked with whenever the current selection changes.
This is a performance bottleneck in the system. We have the same code executing multiple times in different objects and we have multiple copies of the active project and, in some cases, multiple copies of the file that is referenced.
This code should be moved to some central class that tracks the acrive project for the whole plugin and provides a mechanism for accessing the various config files in use. This will result in only a single object executing the event hadling code and there being only one copy of the files to be edited.
public void selectionChanged(IAction action, ISelection selection) {
// if (selection instanceof IStructuredSelection) {
Object first = ((IStructuredSelection) selection).getFirstElement();
IResource resource = (IResource) first;
if (resource != null) {
IProject newActiveProject = resource.getProject();
if (newActiveProject != activeProject) {
// TODO: only attempt to load config file if this is a Forrest
// project
activeProject = newActiveProject;
projectName = activeProject.getProject().getName();
xDocPath = (activeProject.getProject().getLocation().toString() + java.io.File.separator);
}
}
}
These calsses all keep track of the currently active project and loading a file that is to be worked with whenever the current selection changes.
This is a performance bottleneck in the system. We have the same code executing multiple times in different objects and we have multiple copies of the active project and, in some cases, multiple copies of the file that is referenced.
This code should be moved to some central class that tracks the acrive project for the whole plugin and provides a mechanism for accessing the various config files in use. This will result in only a single object executing the event hadling code and there being only one copy of the files to be edited.