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

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.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:
74
74
 
75
75
        // Check if we are closing down
76
76
        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
77
 
        if (window == null)
 
77
        if (window == null) {
78
78
            return false;
 
79
        }
79
80
 
80
81
        // Get the selection
81
82
        final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
82
83
        final IWorkbenchPart part = page.getActivePart();
83
84
        final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
84
 
        if (selectionProvider == null)
 
85
        if (selectionProvider == null) {
85
86
            return false;
 
87
        }
86
88
        final ISelection selection = selectionProvider.getSelection();
87
89
 
88
90
        // Make sure there is only one selection and that it is a trace
91
93
            final TreeSelection sel = (TreeSelection) selection;
92
94
            // There should be only one item selected as per the plugin.xml
93
95
            final Object element = sel.getFirstElement();
94
 
            if (element instanceof TmfTraceElement)
 
96
            if (element instanceof TmfTraceElement) {
95
97
                fTrace = (TmfTraceElement) element;
 
98
            }
96
99
        }
97
100
 
98
101
        // We only enable opening from the Traces folder for now
109
112
 
110
113
        // Check if we are closing down
111
114
        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
112
 
        if (window == null)
 
115
        if (window == null) {
113
116
            return null;
 
117
        }
114
118
 
115
119
        // Check that the trace is valid
116
 
        if (fTrace == null)
 
120
        if (fTrace == null) {
117
121
            return null;
 
122
        }
118
123
 
119
124
        // If trace is under an experiment, use the original trace from the traces folder
120
125
        fTrace = fTrace.getElementUnderTraceFolder();
139
144
 
140
145
        final IResource resource = fTrace.getResource();
141
146
        IFile file = null;
142
 
        if (resource instanceof IFile)
 
147
        if (resource instanceof IFile) {
143
148
            file = (IFile) resource;
144
 
        else if (resource instanceof IFolder)
 
149
        } else if (resource instanceof IFolder) {
145
150
            try {
146
151
                final IFile bookmarksFile = fTrace.getProject().getTracesFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
147
152
                if (!bookmarksFile.exists()) {
152
157
 
153
158
                final IFolder folder = (IFolder) resource;
154
159
                file = folder.getFile(fTrace.getName() + '_');
155
 
                if (!file.exists())
 
160
                if (!file.exists()) {
156
161
                    file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
 
162
                }
157
163
                file.setHidden(true);
158
 
                if (usesEditor)
 
164
                if (usesEditor) {
159
165
                    file.setPersistentProperty(TmfCommonConstants.TRACETYPE, fTrace.getTraceType());
160
 
                else
 
166
                } else {
161
167
                    file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfTrace.class.getCanonicalName());
 
168
                }
162
169
            } catch (final CoreException e) {
163
170
                Activator.getDefault().logError("Error opening trace " + fTrace.getName(), e); //$NON-NLS-1$
164
171
            }
 
172
        }
165
173
 
166
 
        if (usesEditor)
 
174
        if (usesEditor) {
167
175
            try {
168
176
                final IEditorInput editorInput = new TmfEditorInput(file, trace);
169
177
                final IWorkbench wb = PlatformUI.getWorkbench();
175
183
                    activePage.activate(editor);
176
184
                } else {
177
185
                    activePage.openEditor(editorInput, editorId);
178
 
                    if (resource instanceof IFile)
 
186
                    if (resource instanceof IFile) {
179
187
                        IDE.setDefaultEditor((IFile) resource, editorId);
 
188
                    }
180
189
                }
181
190
            } catch (final PartInitException e) {
182
191
                Activator.getDefault().logError("Error opening trace " + fTrace.getName(), e); //$NON-NLS-1$
183
192
            }
184
 
        else {
 
193
        } else {
185
194
            // Create the experiment
186
195
            final ITmfTrace[] traces = new ITmfTrace[] { trace };
187
196
            final TmfExperiment experiment = new TmfExperiment(traceEvent.getClass(), fTrace.getName(), traces, trace.getCacheSize());
194
203
        return null;
195
204
    }
196
205
 
197
 
    private void displayErrorMsg(final String errorMsg) {
 
206
    private static void displayErrorMsg(final String errorMsg) {
198
207
        final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
199
208
        mb.setText(Messages.OpenTraceHandler_Title);
200
209
        mb.setMessage(errorMsg);