12
12
package org.eclipse.linuxtools.internal.systemtap.ui.ide.views;
14
14
import java.io.File;
16
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
17
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
17
import org.eclipse.core.filesystem.IFileInfo;
18
import org.eclipse.core.filesystem.IFileStore;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.jobs.Job;
23
import org.eclipse.core.runtime.Status;
18
24
import org.eclipse.jface.preference.IPreferenceStore;
25
import org.eclipse.jface.util.IPropertyChangeListener;
26
import org.eclipse.jface.util.PropertyChangeEvent;
19
27
import org.eclipse.jface.viewers.DoubleClickEvent;
20
28
import org.eclipse.jface.viewers.IDoubleClickListener;
21
29
import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin;
22
30
import org.eclipse.linuxtools.internal.systemtap.ui.ide.Localization;
23
31
import org.eclipse.linuxtools.internal.systemtap.ui.ide.actions.hidden.KernelSourceAction;
24
32
import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants;
33
import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.PathPreferencePage;
34
import org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy;
35
import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager;
25
36
import org.eclipse.linuxtools.systemtap.ui.logging.LogManager;
26
37
import org.eclipse.linuxtools.systemtap.ui.structures.KernelSourceTree;
27
import org.eclipse.swt.SWT;
38
import org.eclipse.linuxtools.systemtap.ui.structures.TreeNode;
28
39
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.DirectoryDialog;
30
import org.eclipse.ui.PlatformUI;
40
import org.eclipse.ui.progress.UIJob;
35
43
* The Kernel Source Browser module for the SystemTap GUI. This browser provides a list of kernel source
36
* files and allows the user to open those files in an editor in order to place probes in arbitary locations.
44
* files and allows the user to open those files in an editor in order to place probes in arbitrary locations.
37
45
* @author Henry Hughes
38
46
* @author Ryan Morse
41
@SuppressWarnings("deprecation")
42
49
public class KernelBrowserView extends BrowserView {
50
private class KernelRefreshJob extends Job {
51
private boolean remote;
52
private URI kernelLocationURI;
53
private IRemoteFileProxy proxy;
54
private String kernelSource;
56
public KernelRefreshJob(boolean remote, URI kernelLocationURI, IRemoteFileProxy proxy, String kernelSource) {
57
super(Localization.getString("KernelBrowserView.RefreshingKernelSource")); //$NON-NLS-1$
59
this.kernelLocationURI = kernelLocationURI;
61
this.kernelSource = kernelSource;
65
public IStatus run(IProgressMonitor monitor) {
66
IPreferenceStore p = IDEPlugin.getDefault().getPreferenceStore();
67
KernelSourceTree kst = new KernelSourceTree();
68
String excluded[] = p.getString(IDEPreferenceConstants.P_EXCLUDED_KERNEL_SOURCE).split(File.pathSeparator);
70
kst.buildKernelTree(kernelLocationURI, excluded, proxy, monitor);
72
kst.buildKernelTree(kernelSource, excluded);
73
if (monitor.isCanceled())
74
return Status.CANCEL_STATUS;
75
UpdateKernelBrowserJob job = new UpdateKernelBrowserJob(kst);
78
return Status.OK_STATUS;
82
private class UpdateKernelBrowserJob extends UIJob {
84
public UpdateKernelBrowserJob(KernelSourceTree kst) {
85
super(Localization.getString("KernelBrowserView.UpdateKernelBrowser")); //$NON-NLS-1$
90
public IStatus runInUIThread(IProgressMonitor monitor) {
91
monitor.beginTask(Localization.getString("KernelBrowserView.UpdateKernelBrowser"), 100); //$NON-NLS-1$
93
return Status.OK_STATUS;
94
viewer.setInput(kst.getTree());
97
return Status.OK_STATUS;
101
public static final String ID = "org.eclipse.linuxtools.internal.systemtap.ui.ide.views.KernelBrowserView"; //$NON-NLS-1$
102
private KernelSourceAction doubleClickAction;
103
private IDoubleClickListener dblClickListener;
43
105
public KernelBrowserView() {
45
LogManager.logInfo("Initializing", this);
107
LogManager.logInfo("Initializing", this); //$NON-NLS-1$
49
111
* Creates the UI on the given <code>Composite</code>
51
114
public void createPartControl(Composite parent) {
52
LogManager.logDebug("Start createPartControl: parent-" + parent, this);
115
LogManager.logDebug("Start createPartControl: parent-" + parent, this); //$NON-NLS-1$
53
116
super.createPartControl(parent);
57
LogManager.logDebug("End createPartControl", this);
120
LogManager.logDebug("End createPartControl", this); //$NON-NLS-1$
61
124
* Wires up all of the actions for this browser, such as double and right click handlers.
63
126
public void makeActions() {
64
LogManager.logDebug("Start makeActions:", this);
127
LogManager.logDebug("Start makeActions:", this); //$NON-NLS-1$
65
128
doubleClickAction = new KernelSourceAction(getSite().getWorkbenchWindow(), this);
66
129
dblClickListener = new IDoubleClickListener() {
67
130
public void doubleClick(DoubleClickEvent event) {
68
LogManager.logDebug("Start doubleClick: event-" + event, this);
131
LogManager.logDebug("Start doubleClick: event-" + event, this); //$NON-NLS-1$
69
132
doubleClickAction.run();
70
LogManager.logDebug("End doubleClick:", this);
133
LogManager.logDebug("End doubleClick:", this); //$NON-NLS-1$
73
136
viewer.addDoubleClickListener(dblClickListener);
74
IDEPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(propertyChangeListener);
75
LogManager.logDebug("End makeActions:", this);
137
IDEPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(propertyChangeListener);
138
LogManager.logDebug("End makeActions:", this); //$NON-NLS-1$
80
143
* a response to the user changing the preferences related to the kernel source location, requiring
81
144
* that the application update the kernel source information.
83
147
public void refresh() {
84
LogManager.logDebug("Start refresh:", this);
85
KernelSourceTree kst = new KernelSourceTree();
148
LogManager.logDebug("Start refresh:", this); //$NON-NLS-1$
87
150
IPreferenceStore p = IDEPlugin.getDefault().getPreferenceStore();
88
151
String kernelSource = p.getString(IDEPreferenceConstants.P_KERNEL_SOURCE);
89
152
if(null == kernelSource || kernelSource.length() < 1) {
90
LogManager.logInfo("Kernel Source Directory not found, querying", this);
92
DirectoryDialog dialog= new DirectoryDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OPEN);
93
dialog.setText(Localization.getString("KernelBrowserView.WhereKernelSource"));
94
kernelSource = dialog.open();
96
if(null == kernelSource)
98
p.setValue(IDEPreferenceConstants.P_KERNEL_SOURCE, kernelSource);
101
String[] excluded = p.getString(IDEPreferenceConstants.P_EXCLUDED_KERNEL_SOURCE).split(File.pathSeparator);
103
kst.buildKernelTree(kernelSource, excluded);
104
super.viewer.setInput(kst.getTree());
107
LogManager.logDebug("End refresh:", this);
153
showBrowserErrorMessage(Localization.getString("KernelBrowserView.NoKernelSourceFound")); //$NON-NLS-1$
157
String localOrRemote = p.getString(IDEPreferenceConstants.P_REMOTE_LOCAL_KERNEL_SOURCE);
158
URI kernelLocationURI = null;
159
IRemoteFileProxy proxy = null;
160
boolean remote = localOrRemote.equals(PathPreferencePage.REMOTE);
162
boolean error = false;
164
kernelLocationURI = IDEPlugin.getDefault().createRemoteUri(kernelSource);
165
if (kernelLocationURI == null)
168
proxy = RemoteProxyManager.getInstance().getFileProxy(kernelLocationURI);
169
if (!validateProxy(proxy, kernelSource))
172
} catch (CoreException e2) {
176
showBrowserErrorMessage(Localization.getString("KernelBrowserView.KernelSourceDirNotFound")); //$NON-NLS-1$
181
KernelRefreshJob refreshJob = new KernelRefreshJob(remote, kernelLocationURI, proxy, kernelSource);
182
refreshJob.setUser(true);
183
refreshJob.setPriority(Job.SHORT);
184
refreshJob.schedule();
185
LogManager.logDebug("End refresh:", this); //$NON-NLS-1$
188
private boolean validateProxy(IRemoteFileProxy proxy, String kernelSource) {
191
IFileStore fs = proxy.getResource(kernelSource);
194
IFileInfo info = fs.fetchInfo();
202
private void showBrowserErrorMessage(String message) {
203
TreeNode t = new TreeNode("", "", false); //$NON-NLS-1$ //$NON-NLS-2$
204
t.add(new TreeNode("", message, false)); //$NON-NLS-1$
111
209
* A <code>IPropertyChangeListener</code> that detects changes to the Kernel Source location
112
210
* and runs the <code>updateKernelSourceTree</code> method.
114
212
private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
115
213
public void propertyChange(PropertyChangeEvent event) {
116
LogManager.logDebug("Start propertyChange: event-" + event, this);
117
if(event.getProperty().equals(IDEPreferenceConstants.P_KERNEL_SOURCE)) {
214
LogManager.logDebug("Start propertyChange: event-" + event, this); //$NON-NLS-1$
215
if(event.getProperty().equals(IDEPreferenceConstants.P_KERNEL_SOURCE) ||
216
event.getProperty().equals(IDEPreferenceConstants.P_REMOTE_LOCAL_KERNEL_SOURCE) ||
217
event.getProperty().equals(IDEPreferenceConstants.P_EXCLUDED_KERNEL_SOURCE)) {
120
LogManager.logDebug("End propertyChange:", this);
220
LogManager.logDebug("End propertyChange:", this); //$NON-NLS-1$
124
225
public void dispose() {
125
LogManager.logInfo("Disposing", this);
226
LogManager.logInfo("Disposing", this); //$NON-NLS-1$
127
IDEPlugin.getDefault().getPluginPreferences().removePropertyChangeListener(propertyChangeListener);
228
IDEPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(propertyChangeListener);
128
229
if(null != viewer)
129
230
viewer.removeDoubleClickListener(dblClickListener);
130
231
dblClickListener = null;