View | Details | Raw Unified | Return to bug 315415 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/cdt/debug/internal/ui/views/executables/SourceFilesLabelProvider.java (-29 / +116 lines)
Lines 12-21 Link Here
12
package org.eclipse.cdt.debug.internal.ui.views.executables;
12
package org.eclipse.cdt.debug.internal.ui.views.executables;
13
13
14
import com.ibm.icu.text.DateFormat;
14
import com.ibm.icu.text.DateFormat;
15
16
import java.io.File;
15
import java.util.Date;
17
import java.util.Date;
18
import java.util.List;
16
19
17
import org.eclipse.cdt.core.model.ITranslationUnit;
20
import org.eclipse.cdt.core.model.ITranslationUnit;
18
import org.eclipse.cdt.debug.core.executables.Executable;
21
import org.eclipse.cdt.debug.core.executables.Executable;
22
import org.eclipse.cdt.debug.core.executables.ExecutablesManager;
23
import org.eclipse.cdt.debug.core.executables.IExecutablesChangeListener;
24
import org.eclipse.cdt.internal.core.util.LRUCache;
19
import org.eclipse.cdt.ui.CElementLabelProvider;
25
import org.eclipse.cdt.ui.CElementLabelProvider;
20
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.Path;
27
import org.eclipse.core.runtime.Path;
Lines 25-48 Link Here
25
import org.eclipse.jface.viewers.TreeColumnViewerLabelProvider;
31
import org.eclipse.jface.viewers.TreeColumnViewerLabelProvider;
26
import org.eclipse.jface.viewers.ViewerCell;
32
import org.eclipse.jface.viewers.ViewerCell;
27
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.events.DisposeEvent;
35
import org.eclipse.swt.events.DisposeListener;
28
import org.eclipse.swt.graphics.Font;
36
import org.eclipse.swt.graphics.Font;
29
import org.eclipse.swt.widgets.Display;
37
import org.eclipse.swt.widgets.Display;
30
38
31
public class SourceFilesLabelProvider extends TreeColumnViewerLabelProvider {
39
public class SourceFilesLabelProvider extends TreeColumnViewerLabelProvider implements IExecutablesChangeListener {
32
40
33
	private SourceFilesViewer viewer;
41
	private SourceFilesViewer viewer;
34
42
35
	private LocalResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());
43
	private LocalResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());
36
44
45
	/** Information from an ITranslationUnit for the various displayed columns */
46
	static class TranslationUnitInfo {
47
		long nextCheckTimestamp;
48
		boolean isFile;
49
		boolean exists;
50
		boolean originalExists;
51
		long fileLength;
52
		long lastModified;
53
		IPath location;
54
		IPath originalLocation;
55
	}
56
	
57
	/** Tradeoff expensiveness of checking filesystem against likelihood 
58
	 * that files will be added/removed/changed in the given time period */
59
	private static final long FILE_CHECK_DELTA = 30 * 1000;
60
	
61
	static LRUCache<Object, TranslationUnitInfo> translationUnitInfoCache = new LRUCache<Object, TranslationUnitInfo>(1024);
62
	
37
	public SourceFilesLabelProvider(SourceFilesViewer viewer) {
63
	public SourceFilesLabelProvider(SourceFilesViewer viewer) {
38
		super(new CElementLabelProvider());
64
		super(new CElementLabelProvider());
39
		this.viewer = viewer;
65
		this.viewer = viewer;
66
		
67
		// brute-force clear the cache when executables change
68
		ExecutablesManager.getExecutablesManager().addExecutablesChangeListener(this);
69
		viewer.getControl().addDisposeListener(new DisposeListener() {
70
			public void widgetDisposed(DisposeEvent e) {
71
				ExecutablesManager.getExecutablesManager().removeExecutablesChangeListener(SourceFilesLabelProvider.this);
72
			}
73
		});
40
	}
74
	}
41
75
42
	@Override
76
	@Override
43
	public void update(ViewerCell cell) {
77
	public void update(ViewerCell cell) {
44
		super.update(cell);
78
		super.update(cell);
45
79
80
		TranslationUnitInfo tuInfo = null;
81
		if (cell.getElement() instanceof ITranslationUnit) {
82
			long now = System.currentTimeMillis();
83
			tuInfo = fetchTranslationUnitInfo(cell.getElement(), now);
84
		}
85
		
46
		int orgColumnIndex = cell.getColumnIndex();
86
		int orgColumnIndex = cell.getColumnIndex();
47
87
48
		if (orgColumnIndex == 0) {
88
		if (orgColumnIndex == 0) {
Lines 53-64 Link Here
53
			}
93
			}
54
		} else if (orgColumnIndex == 1) {
94
		} else if (orgColumnIndex == 1) {
55
			cell.setText(null);
95
			cell.setText(null);
56
			if (cell.getElement() instanceof ITranslationUnit) {
96
			if (tuInfo != null) {
57
				ITranslationUnit tu = (ITranslationUnit) cell.getElement();
97
				if (tuInfo.location != null) {
58
				IPath path = tu.getLocation();
98
					cell.setText(tuInfo.location.toOSString());
59
				if (path != null) {
99
					if (tuInfo.exists)
60
					cell.setText(path.toOSString());
61
					if (path.toFile().exists())
62
						cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
100
						cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
63
					else
101
					else
64
						cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
102
						cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
Lines 67-77 Link Here
67
			cell.setImage(null);
105
			cell.setImage(null);
68
		} else if (orgColumnIndex == 2) {
106
		} else if (orgColumnIndex == 2) {
69
			cell.setText(null);
107
			cell.setText(null);
70
			if (cell.getElement() instanceof ITranslationUnit) {
108
			if (tuInfo != null && tuInfo.originalLocation != null) {
71
				Executable executable = (Executable) viewer.getInput();
109
				cell.setText(tuInfo.originalLocation.toOSString());
72
				Path path = new Path(executable.getOriginalLocation((ITranslationUnit) cell.getElement()));
110
				if (tuInfo.originalExists)
73
				cell.setText(path.toOSString());
74
				if (path.toFile().exists())
75
					cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
111
					cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
76
				else
112
				else
77
					cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
113
					cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
Lines 79-112 Link Here
79
			cell.setImage(null);
115
			cell.setImage(null);
80
		} else if (orgColumnIndex == 3) {
116
		} else if (orgColumnIndex == 3) {
81
			cell.setText(null);
117
			cell.setText(null);
82
			if (cell.getElement() instanceof ITranslationUnit) {
118
			if (tuInfo != null) {
83
				ITranslationUnit tu = (ITranslationUnit) cell.getElement();
119
				if (tuInfo.exists) {
84
				IPath path = tu.getLocation();
120
					cell.setText(Long.toString(tuInfo.fileLength));
85
				if (path != null && path.toFile().exists()) {
86
					long fileLength = path.toFile().length();
87
					cell.setText(Long.toString(fileLength));
88
				}
121
				}
89
			}
122
			}
90
			cell.setImage(null);
123
			cell.setImage(null);
91
		} else if (orgColumnIndex == 4) {
124
		} else if (orgColumnIndex == 4) {
92
			cell.setText(null);
125
			cell.setText(null);
93
			if (cell.getElement() instanceof ITranslationUnit) {
126
			if (tuInfo != null) {
94
				ITranslationUnit tu = (ITranslationUnit) cell.getElement();
127
				if (tuInfo.exists) {
95
				IPath path = tu.getLocation();
128
					String dateTimeString = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(
96
				if (path != null && path.toFile().exists()) {
129
							new Date(tuInfo.lastModified));
97
					long modified = path.toFile().lastModified();
98
					String dateTimeString = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date(modified));
99
					cell.setText(dateTimeString);
130
					cell.setText(dateTimeString);
100
				}
131
				}
101
			}
132
			}
102
			cell.setImage(null);
133
			cell.setImage(null);
103
		} else if (orgColumnIndex == 5) {
134
		} else if (orgColumnIndex == 5) {
104
			cell.setText(null);
135
			cell.setText(null);
105
			if (cell.getElement() instanceof ITranslationUnit) {
136
			if (tuInfo != null) {
106
				ITranslationUnit tu = (ITranslationUnit) cell.getElement();
137
				if (tuInfo.location != null) {
107
				IPath path = tu.getLocation();
138
					String fileExtension = tuInfo.location.getFileExtension();
108
				if (path != null) {
109
					String fileExtension = path.getFileExtension();
110
					if (fileExtension != null)
139
					if (fileExtension != null)
111
						cell.setText(fileExtension.toLowerCase());
140
						cell.setText(fileExtension.toLowerCase());
112
				}
141
				}
Lines 115-118 Link Here
115
		}
144
		}
116
	}
145
	}
117
146
147
	private TranslationUnitInfo fetchTranslationUnitInfo(Object element, long now) {
148
		TranslationUnitInfo info;
149
		synchronized (translationUnitInfoCache) {
150
			info = (TranslationUnitInfo) translationUnitInfoCache.get(element);
151
		}
152
		if (info == null || info.nextCheckTimestamp <= now) {
153
			if (info == null)
154
				info = new TranslationUnitInfo();
155
			
156
			if (element instanceof ITranslationUnit) {
157
				ITranslationUnit tu = (ITranslationUnit) element;
158
				info.location = tu.getLocation();
159
				if (info.location != null) {
160
					File file = info.location.toFile();
161
					info.exists = file.exists();
162
					info.fileLength = file.length();
163
					info.lastModified = file.lastModified();
164
					
165
					Executable executable = (Executable) viewer.getInput();
166
					info.originalLocation = new Path(executable.getOriginalLocation(tu));
167
					info.originalExists = info.originalLocation.toFile().exists();
168
				} else {
169
					info.exists = false;
170
					info.fileLength = 0;
171
					info.lastModified = 0;
172
					info.originalExists = false;
173
					info.originalLocation = null;
174
				}
175
			}
176
			
177
			info.nextCheckTimestamp = System.currentTimeMillis() + FILE_CHECK_DELTA;
178
			
179
			synchronized (translationUnitInfoCache) {
180
				translationUnitInfoCache.put(element, info);
181
			}
182
		}
183
		return info;
184
	}
185
186
	/* (non-Javadoc)
187
	 * @see org.eclipse.cdt.debug.core.executables.IExecutablesChangeListener#executablesListChanged()
188
	 */
189
	public void executablesListChanged() {
190
		synchronized (translationUnitInfoCache) {
191
			translationUnitInfoCache.flush();
192
		}
193
	}
194
195
	/* (non-Javadoc)
196
	 * @see org.eclipse.cdt.debug.core.executables.IExecutablesChangeListener#executablesChanged(java.util.List)
197
	 */
198
	public void executablesChanged(List<Executable> executables) {
199
		synchronized (translationUnitInfoCache) {
200
			translationUnitInfoCache.flush();
201
		}
202
	}
203
118
}
204
}
205
	
(-)src/org/eclipse/cdt/debug/internal/ui/views/executables/SourceFilesViewer.java (-4 / +13 lines)
Lines 24-29 Link Here
24
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.core.runtime.Status;
26
import org.eclipse.core.runtime.Status;
27
import org.eclipse.core.runtime.jobs.Job;
27
import org.eclipse.debug.core.DebugPlugin;
28
import org.eclipse.debug.core.DebugPlugin;
28
import org.eclipse.debug.core.ILaunchConfiguration;
29
import org.eclipse.debug.core.ILaunchConfiguration;
29
import org.eclipse.debug.core.ILaunchConfigurationListener;
30
import org.eclipse.debug.core.ILaunchConfigurationListener;
Lines 38-49 Link Here
38
import org.eclipse.swt.events.DisposeEvent;
39
import org.eclipse.swt.events.DisposeEvent;
39
import org.eclipse.swt.events.DisposeListener;
40
import org.eclipse.swt.events.DisposeListener;
40
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Composite;
42
import org.eclipse.swt.widgets.Display;
41
import org.eclipse.swt.widgets.Tree;
43
import org.eclipse.swt.widgets.Tree;
42
import org.eclipse.swt.widgets.TreeColumn;
44
import org.eclipse.swt.widgets.TreeColumn;
43
import org.eclipse.ui.IEditorPart;
45
import org.eclipse.ui.IEditorPart;
44
import org.eclipse.ui.IWorkbenchPage;
46
import org.eclipse.ui.IWorkbenchPage;
45
import org.eclipse.ui.PartInitException;
47
import org.eclipse.ui.PartInitException;
46
import org.eclipse.ui.progress.UIJob;
47
48
48
/**
49
/**
49
 * Displays the list of source files for the executable selected in the
50
 * Displays the list of source files for the executable selected in the
Lines 90-95 Link Here
90
		sourceFilesTree.addDisposeListener(new DisposeListener() {
91
		sourceFilesTree.addDisposeListener(new DisposeListener() {
91
92
92
			public void widgetDisposed(DisposeEvent e) {
93
			public void widgetDisposed(DisposeEvent e) {
94
				DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(SourceFilesViewer.this);
95
				
93
				CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().removeParticipants(
96
				CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().removeParticipants(
94
						new ISourceLookupParticipant[] { SourceFilesViewer.this });
97
						new ISourceLookupParticipant[] { SourceFilesViewer.this });
95
			}
98
			}
Lines 213-226 Link Here
213
	}
216
	}
214
217
215
	private void refreshContent() {
218
	private void refreshContent() {
216
		UIJob refreshJob = new UIJob(Messages.SourceFilesViewer_RefreshSourceFiles) {
219
		Job refreshJob = new Job(Messages.SourceFilesViewer_RefreshSourceFiles) {
217
220
218
			@Override
221
			@Override
219
			public IStatus runInUIThread(IProgressMonitor monitor) {
222
			public IStatus run(IProgressMonitor monitor) {
220
				Object input = getInput();
223
				Object input = getInput();
221
				if (input != null && input instanceof Executable) {
224
				if (input != null && input instanceof Executable) {
222
					((Executable)input).setRemapSourceFiles(true);
225
					((Executable)input).setRemapSourceFiles(true);
223
					refresh(true);
226
					Display.getDefault().asyncExec(new Runnable() {
227
						public void run() {
228
							if (SourceFilesViewer.this.getControl().isDisposed())
229
								return;
230
							refresh(true);
231
						}
232
					});
224
				}
233
				}
225
				return Status.OK_STATUS;
234
				return Status.OK_STATUS;
226
			}
235
			}

Return to bug 315415