~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/views/KernelBrowserView.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
package org.eclipse.linuxtools.internal.systemtap.ui.ide.views;
13
13
 
14
14
import java.io.File;
 
15
import java.net.URI;
15
16
 
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;
31
 
 
32
 
 
 
40
import org.eclipse.ui.progress.UIJob;
33
41
 
34
42
/**
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
39
47
 */
40
48
 
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;
 
55
 
 
56
                public KernelRefreshJob(boolean remote, URI kernelLocationURI, IRemoteFileProxy proxy, String kernelSource) {
 
57
                        super(Localization.getString("KernelBrowserView.RefreshingKernelSource")); //$NON-NLS-1$
 
58
                        this.remote = remote;
 
59
                        this.kernelLocationURI = kernelLocationURI;
 
60
                        this.proxy = proxy;
 
61
                        this.kernelSource = kernelSource;
 
62
                }
 
63
 
 
64
                @Override
 
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);
 
69
                        if (remote)
 
70
                                kst.buildKernelTree(kernelLocationURI, excluded, proxy, monitor);
 
71
                        else
 
72
                                kst.buildKernelTree(kernelSource, excluded);
 
73
                        if (monitor.isCanceled())
 
74
                                return Status.CANCEL_STATUS;
 
75
                        UpdateKernelBrowserJob job = new UpdateKernelBrowserJob(kst);
 
76
                        job.schedule();
 
77
                        monitor.done();
 
78
                        return Status.OK_STATUS;
 
79
                }
 
80
        }
 
81
 
 
82
        private class UpdateKernelBrowserJob extends UIJob {
 
83
                KernelSourceTree kst;
 
84
                public UpdateKernelBrowserJob(KernelSourceTree kst) {
 
85
                        super(Localization.getString("KernelBrowserView.UpdateKernelBrowser")); //$NON-NLS-1$
 
86
                        this.kst = kst;
 
87
                }
 
88
 
 
89
                @Override
 
90
                public IStatus runInUIThread(IProgressMonitor monitor) {
 
91
                        monitor.beginTask(Localization.getString("KernelBrowserView.UpdateKernelBrowser"), 100); //$NON-NLS-1$
 
92
                        if (kst == null)
 
93
                                return Status.OK_STATUS;
 
94
                        viewer.setInput(kst.getTree());
 
95
                        kst.dispose();
 
96
                        monitor.done();
 
97
                        return Status.OK_STATUS;
 
98
                }
 
99
        }
 
100
 
 
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;
 
104
 
43
105
        public KernelBrowserView() {
44
106
                super();
45
 
                LogManager.logInfo("Initializing", this);
 
107
                LogManager.logInfo("Initializing", this); //$NON-NLS-1$
46
108
        }
47
 
        
 
109
 
48
110
        /**
49
111
         * Creates the UI on the given <code>Composite</code>
50
112
         */
 
113
        @Override
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);
54
117
 
55
118
                refresh();
56
119
                makeActions();
57
 
                LogManager.logDebug("End createPartControl", this);
 
120
                LogManager.logDebug("End createPartControl", this); //$NON-NLS-1$
58
121
        }
59
122
 
60
123
        /**
61
124
         * Wires up all of the actions for this browser, such as double and right click handlers.
62
125
         */
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$
71
134
                        }
72
135
                };
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$
76
139
        }
77
140
 
78
141
        /**
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.
82
145
         */
 
146
        @Override
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$
86
149
                
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);
91
 
                        
92
 
                        DirectoryDialog dialog= new DirectoryDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OPEN);
93
 
                        dialog.setText(Localization.getString("KernelBrowserView.WhereKernelSource"));
94
 
                        kernelSource = dialog.open();
95
 
 
96
 
                        if(null == kernelSource)
97
 
                                kernelSource = "";
98
 
                        p.setValue(IDEPreferenceConstants.P_KERNEL_SOURCE, kernelSource);
99
 
                }
100
 
                
101
 
                String[] excluded = p.getString(IDEPreferenceConstants.P_EXCLUDED_KERNEL_SOURCE).split(File.pathSeparator);
102
 
                
103
 
                kst.buildKernelTree(kernelSource, excluded);
104
 
                super.viewer.setInput(kst.getTree());
105
 
 
106
 
                kst.dispose();
107
 
                LogManager.logDebug("End refresh:", this);
 
153
                        showBrowserErrorMessage(Localization.getString("KernelBrowserView.NoKernelSourceFound")); //$NON-NLS-1$
 
154
                        return;
 
155
                }
 
156
 
 
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);
 
161
                if (remote) {
 
162
                        boolean error = false;
 
163
                        try {
 
164
                                kernelLocationURI = IDEPlugin.getDefault().createRemoteUri(kernelSource);
 
165
                                if (kernelLocationURI == null)
 
166
                                        error = true;
 
167
                                else {
 
168
                                        proxy = RemoteProxyManager.getInstance().getFileProxy(kernelLocationURI);
 
169
                                        if (!validateProxy(proxy, kernelSource))
 
170
                                                error = true;
 
171
                                }
 
172
                        } catch (CoreException e2) {
 
173
                                error = true;
 
174
                        }
 
175
                        if (error) {
 
176
                                showBrowserErrorMessage(Localization.getString("KernelBrowserView.KernelSourceDirNotFound")); //$NON-NLS-1$
 
177
                                return;
 
178
                        }
 
179
                }
 
180
 
 
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$
 
186
        }
 
187
 
 
188
        private boolean validateProxy(IRemoteFileProxy proxy, String kernelSource) {
 
189
                if (proxy == null)
 
190
                        return false;
 
191
                IFileStore fs = proxy.getResource(kernelSource);
 
192
                if (fs == null)
 
193
                        return false;
 
194
                IFileInfo info = fs.fetchInfo();
 
195
                if (info == null)
 
196
                        return false;
 
197
                if (!info.exists())
 
198
                        return false;
 
199
                return true;
108
200
        }
109
201
        
 
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$
 
205
                viewer.setInput(t);
 
206
        }
 
207
 
110
208
        /**
111
209
         * A <code>IPropertyChangeListener</code> that detects changes to the Kernel Source location
112
210
         * and runs the <code>updateKernelSourceTree</code> method.
113
211
         */
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)) {
118
218
                                refresh();
119
219
                        }
120
 
                        LogManager.logDebug("End propertyChange:", this);
 
220
                        LogManager.logDebug("End propertyChange:", this); //$NON-NLS-1$
121
221
                }
122
222
        };
123
223
        
 
224
        @Override
124
225
        public void dispose() {
125
 
                LogManager.logInfo("Disposing", this);
 
226
                LogManager.logInfo("Disposing", this); //$NON-NLS-1$
126
227
                super.dispose();
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;
132
233
                        doubleClickAction.dispose();
133
234
                doubleClickAction = null;
134
235
        }
135
 
        
136
 
        public static final String ID = "org.eclipse.linuxtools.internal.systemtap.ui.ide.views.KernelBrowserView";
137
 
        private KernelSourceAction doubleClickAction;
138
 
        private IDoubleClickListener dblClickListener;
139
236
}