Commit | Line | Data |
---|---|---|
99504bb8 | 1 | /******************************************************************************* |
58ffe079 | 2 | * Copyright (c) 2010, 2015 Ericsson, École Polytechnique de Montréal |
99504bb8 GB |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Bernd Hufmann - Added supplementary files handling (in class TmfTraceElement) | |
11 | * Geneviève Bastien - Copied supplementary files handling from TmfTracElement | |
16036bc2 GB |
12 | * Moved to this class code to copy a model element |
13 | * Renamed from TmfWithFolderElement to TmfCommonProjectElement | |
339d539c | 14 | * Patrick Tasse - Add support for folder elements |
99504bb8 GB |
15 | *******************************************************************************/ |
16 | ||
2bdf0193 | 17 | package org.eclipse.tracecompass.tmf.ui.project.model; |
99504bb8 | 18 | |
8f5221c2 GB |
19 | import java.io.ByteArrayInputStream; |
20 | import java.io.InputStream; | |
21 | import java.util.ArrayList; | |
22 | import java.util.HashMap; | |
23 | import java.util.List; | |
24 | import java.util.Map; | |
25 | ||
339d539c | 26 | import org.eclipse.core.resources.IContainer; |
8f5221c2 | 27 | import org.eclipse.core.resources.IFile; |
99504bb8 GB |
28 | import org.eclipse.core.resources.IFolder; |
29 | import org.eclipse.core.resources.IResource; | |
8f5221c2 | 30 | import org.eclipse.core.resources.ResourcesPlugin; |
99504bb8 | 31 | import org.eclipse.core.runtime.CoreException; |
beb19106 | 32 | import org.eclipse.core.runtime.IPath; |
99504bb8 | 33 | import org.eclipse.core.runtime.NullProgressMonitor; |
339d539c | 34 | import org.eclipse.core.runtime.Path; |
367e2932 | 35 | import org.eclipse.jdt.annotation.NonNull; |
8f5221c2 | 36 | import org.eclipse.osgi.util.NLS; |
2bdf0193 | 37 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
3d04a314 | 38 | import org.eclipse.tracecompass.internal.tmf.ui.editors.ITmfEventsEditorConstants; |
2bdf0193 AM |
39 | import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; |
40 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper; | |
41 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager; | |
42 | import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; | |
43 | import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper; | |
44 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; | |
45 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; | |
46 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; | |
47 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
2bdf0193 | 48 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; |
8f5221c2 GB |
49 | import org.eclipse.ui.IEditorReference; |
50 | import org.eclipse.ui.IWorkbench; | |
51 | import org.eclipse.ui.IWorkbenchPage; | |
52 | import org.eclipse.ui.IWorkbenchWindow; | |
53 | import org.eclipse.ui.PartInitException; | |
54 | import org.eclipse.ui.PlatformUI; | |
55 | import org.eclipse.ui.part.FileEditorInput; | |
99504bb8 | 56 | |
99504bb8 | 57 | /** |
16036bc2 GB |
58 | * Base class for tracing project elements: it implements the common behavior of |
59 | * all project elements: supplementary files, analysis, types, etc. | |
99504bb8 | 60 | * |
e73a4ba5 | 61 | * @author Geneviève Bastien |
99504bb8 | 62 | */ |
16036bc2 | 63 | public abstract class TmfCommonProjectElement extends TmfProjectModelElement { |
99504bb8 | 64 | |
8f5221c2 GB |
65 | // ------------------------------------------------------------------------ |
66 | // Attributes | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
69 | // This trace type ID as defined in plugin.xml | |
70 | private String fTraceTypeId = null; | |
71 | ||
72 | private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$ | |
73 | ||
99504bb8 GB |
74 | // ------------------------------------------------------------------------ |
75 | // Constructors | |
76 | // ------------------------------------------------------------------------ | |
77 | ||
99504bb8 | 78 | /** |
16036bc2 GB |
79 | * Constructor. Creates model element. |
80 | * | |
81 | * @param name | |
82 | * The name of the element | |
83 | * @param resource | |
84 | * The resource. | |
85 | * @param parent | |
86 | * The parent element | |
99504bb8 | 87 | */ |
16036bc2 | 88 | public TmfCommonProjectElement(String name, IResource resource, TmfProjectModelElement parent) { |
99504bb8 | 89 | super(name, resource, parent); |
8f5221c2 GB |
90 | refreshTraceType(); |
91 | TmfSignalManager.register(this); | |
92 | } | |
93 | ||
94 | // ------------------------------------------------------------------------ | |
95 | // TmfProjectModelElement | |
96 | // ------------------------------------------------------------------------ | |
97 | ||
b3e4798c AM |
98 | /** |
99 | * @since 2.0 | |
100 | */ | |
8f5221c2 | 101 | @Override |
b3e4798c | 102 | protected void refreshChildren() { |
8f5221c2 GB |
103 | |
104 | /* Refreshes the analysis under this trace */ | |
105 | Map<String, TmfAnalysisElement> childrenMap = new HashMap<>(); | |
106 | for (TmfAnalysisElement analysis : getAvailableAnalysis()) { | |
107 | childrenMap.put(analysis.getAnalysisId(), analysis); | |
108 | } | |
109 | ||
a4a116c3 | 110 | TraceTypeHelper helper = TmfTraceType.getTraceType(getTraceType()); |
8f5221c2 | 111 | |
367e2932 | 112 | Class<@NonNull ? extends ITmfTrace> traceClass = null; |
8f5221c2 | 113 | |
4b3b667b | 114 | if (helper != null) { |
8f5221c2 GB |
115 | traceClass = helper.getTraceClass(); |
116 | } | |
117 | ||
118 | /* Remove all analysis and return */ | |
119 | if (traceClass == null) { | |
120 | for (TmfAnalysisElement analysis : childrenMap.values()) { | |
121 | removeChild(analysis); | |
122 | } | |
123 | return; | |
124 | } | |
125 | ||
126 | /** Get the base path to put the resource to */ | |
b3e4798c | 127 | IPath path = getResource().getFullPath(); |
8f5221c2 GB |
128 | |
129 | /* Add all new analysis modules or refresh outputs of existing ones */ | |
130 | for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules(traceClass).values()) { | |
131 | ||
132 | /* If the analysis is not a child of the trace, create it */ | |
133 | TmfAnalysisElement analysis = childrenMap.remove(module.getId()); | |
134 | if (analysis == null) { | |
135 | /** | |
136 | * No need for the resource to exist, nothing will be done with | |
137 | * it | |
138 | */ | |
139 | IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path.append(module.getId())); | |
9897c39c | 140 | analysis = new TmfAnalysisElement(module.getName(), newresource, this, module); |
b3e4798c | 141 | addChild(analysis); |
8f5221c2 GB |
142 | } |
143 | analysis.refreshChildren(); | |
144 | } | |
145 | ||
146 | /* Remove analysis that are not children of this trace anymore */ | |
147 | for (TmfAnalysisElement analysis : childrenMap.values()) { | |
148 | removeChild(analysis); | |
149 | } | |
150 | } | |
151 | ||
152 | // ------------------------------------------------------------------------ | |
153 | // Operations | |
154 | // ------------------------------------------------------------------------ | |
155 | ||
156 | /** | |
157 | * Returns the trace type ID. | |
158 | * | |
159 | * @return trace type ID. | |
160 | */ | |
161 | public String getTraceType() { | |
162 | return fTraceTypeId; | |
163 | } | |
164 | ||
165 | /** | |
4b3b667b PT |
166 | * Refreshes the trace type field by reading the trace type persistent |
167 | * property of the resource. | |
8f5221c2 GB |
168 | */ |
169 | public void refreshTraceType() { | |
170 | try { | |
4b3b667b | 171 | fTraceTypeId = TmfTraceType.getTraceTypeId(getResource()); |
8f5221c2 GB |
172 | } catch (CoreException e) { |
173 | Activator.getDefault().logError(NLS.bind(Messages.TmfCommonProjectElement_ErrorRefreshingProperty, getName()), e); | |
174 | } | |
99504bb8 GB |
175 | } |
176 | ||
8f5221c2 GB |
177 | /** |
178 | * Instantiate a <code>ITmfTrace</code> object based on the trace type and | |
179 | * the corresponding extension. | |
180 | * | |
181 | * @return the <code>ITmfTrace</code> or <code>null</code> for an error | |
182 | */ | |
183 | public abstract ITmfTrace instantiateTrace(); | |
184 | ||
99504bb8 | 185 | /** |
339d539c PT |
186 | * Return the supplementary folder path for this element. The returned path |
187 | * is relative to the project's supplementary folder. | |
99504bb8 | 188 | * |
339d539c | 189 | * @return The supplementary folder path for this element |
99504bb8 | 190 | */ |
339d539c PT |
191 | protected String getSupplementaryFolderPath() { |
192 | return getElementPath() + getSuffix(); | |
99504bb8 GB |
193 | } |
194 | ||
195 | /** | |
339d539c PT |
196 | * Return the element path relative to its common element (traces folder, |
197 | * experiments folder or experiment element). | |
e9e2c5ee | 198 | * |
339d539c PT |
199 | * @return The element path |
200 | */ | |
201 | public String getElementPath() { | |
202 | ITmfProjectModelElement parent = getParent(); | |
203 | while (!(parent instanceof TmfTracesFolder || parent instanceof TmfExperimentElement || parent instanceof TmfExperimentFolder)) { | |
204 | parent = parent.getParent(); | |
205 | } | |
b3e4798c | 206 | IPath path = getResource().getFullPath().makeRelativeTo(parent.getPath()); |
339d539c PT |
207 | return path.toString(); |
208 | } | |
209 | ||
210 | /** | |
211 | * @return The suffix for the supplementary folder | |
99504bb8 GB |
212 | */ |
213 | protected String getSuffix() { | |
214 | return ""; //$NON-NLS-1$ | |
215 | } | |
216 | ||
8f5221c2 GB |
217 | /** |
218 | * Returns a list of TmfTraceElements contained in project element. | |
219 | * | |
220 | * @return a list of TmfTraceElements, empty list if none | |
221 | */ | |
222 | public List<TmfTraceElement> getTraces() { | |
223 | return new ArrayList<>(); | |
224 | } | |
225 | ||
226 | /** | |
227 | * Get the instantiated trace associated with this element. | |
228 | * | |
229 | * @return The instantiated trace or null if trace is not (yet) available | |
230 | */ | |
231 | public ITmfTrace getTrace() { | |
232 | for (ITmfTrace trace : TmfTraceManager.getInstance().getOpenedTraces()) { | |
233 | if (trace.getResource().equals(getResource())) { | |
234 | return trace; | |
235 | } | |
236 | } | |
237 | return null; | |
238 | } | |
239 | ||
240 | /** | |
241 | * Returns the file resource used to store bookmarks after creating it if | |
242 | * necessary. If the trace resource is a file, it is returned directly. If | |
243 | * the trace resource is a folder, a linked file is returned. The file will | |
244 | * be created if it does not exist. | |
245 | * | |
246 | * @return the bookmarks file | |
247 | * @throws CoreException | |
248 | * if the bookmarks file cannot be created | |
249 | */ | |
250 | public abstract IFile createBookmarksFile() throws CoreException; | |
251 | ||
252 | /** | |
253 | * Actually returns the bookmark file or creates it in the project element's | |
254 | * folder | |
255 | * | |
256 | * @param bookmarksFolder | |
257 | * Folder where to put the bookmark file | |
58ffe079 MAL |
258 | * @param editorInputType |
259 | * The editor input type to set (trace or experiment) | |
8f5221c2 GB |
260 | * @return The bookmark file |
261 | * @throws CoreException | |
262 | * if the bookmarks file cannot be created | |
263 | */ | |
58ffe079 | 264 | protected IFile createBookmarksFile(IFolder bookmarksFolder, String editorInputType) throws CoreException { |
8f5221c2 GB |
265 | IFile file = getBookmarksFile(); |
266 | if (!file.exists()) { | |
267 | final IFile bookmarksFile = bookmarksFolder.getFile(BOOKMARKS_HIDDEN_FILE); | |
268 | if (!bookmarksFile.exists()) { | |
269 | final InputStream source = new ByteArrayInputStream(new byte[0]); | |
858a35cf | 270 | bookmarksFile.create(source, IResource.FORCE | IResource.HIDDEN, null); |
8f5221c2 | 271 | } |
858a35cf | 272 | file.createLink(bookmarksFile.getLocation(), IResource.REPLACE | IResource.HIDDEN, null); |
58ffe079 | 273 | file.setPersistentProperty(TmfCommonConstants.TRACETYPE, editorInputType); |
8f5221c2 GB |
274 | } |
275 | return file; | |
276 | } | |
277 | ||
278 | /** | |
279 | * Returns the optional editor ID from the trace type extension. | |
280 | * | |
281 | * @return the editor ID or <code>null</code> if not defined. | |
282 | */ | |
283 | public abstract String getEditorId(); | |
284 | ||
285 | /** | |
286 | * Returns the file resource used to store bookmarks. The file may not | |
287 | * exist. | |
288 | * | |
289 | * @return the bookmarks file | |
290 | */ | |
291 | public IFile getBookmarksFile() { | |
b3e4798c | 292 | final IFolder folder = (IFolder) getResource(); |
8f5221c2 GB |
293 | IFile file = folder.getFile(getName() + '_'); |
294 | return file; | |
295 | } | |
296 | ||
297 | /** | |
298 | * Close open editors associated with this experiment. | |
299 | */ | |
300 | public void closeEditors() { | |
301 | IFile file = getBookmarksFile(); | |
302 | FileEditorInput input = new FileEditorInput(file); | |
303 | IWorkbench wb = PlatformUI.getWorkbench(); | |
304 | for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) { | |
305 | for (IWorkbenchPage wbPage : wbWindow.getPages()) { | |
306 | for (IEditorReference editorReference : wbPage.getEditorReferences()) { | |
307 | try { | |
308 | if (editorReference.getEditorInput().equals(input)) { | |
309 | wbPage.closeEditor(editorReference.getEditor(false), false); | |
310 | } | |
311 | } catch (PartInitException e) { | |
312 | Activator.getDefault().logError(NLS.bind(Messages.TmfCommonProjectElement_ErrorClosingEditor, getName()), e); | |
313 | } | |
314 | } | |
315 | } | |
316 | } | |
317 | } | |
318 | ||
319 | /** | |
320 | * Get a friendly name for the type of element this common project element | |
321 | * is, to be displayed in UI messages. | |
322 | * | |
323 | * @return A string for the type of project element this object is, for | |
324 | * example "trace" or "experiment" | |
325 | */ | |
326 | public abstract String getTypeName(); | |
327 | ||
328 | /** | |
329 | * Copy this model element | |
330 | * | |
331 | * @param newName | |
332 | * The name of the new element | |
333 | * @param copySuppFiles | |
334 | * Whether to copy supplementary files or not | |
335 | * @return the new Resource object | |
336 | */ | |
337 | public IResource copy(final String newName, final boolean copySuppFiles) { | |
338 | ||
339 | final IPath newPath = getParent().getResource().getFullPath().addTrailingSeparator().append(newName); | |
340 | ||
341 | /* Copy supplementary files first, only if needed */ | |
342 | if (copySuppFiles) { | |
339d539c PT |
343 | String newElementPath = new Path(getElementPath()).removeLastSegments(1).append(newName).toString(); |
344 | copySupplementaryFolder(newElementPath); | |
8f5221c2 GB |
345 | } |
346 | /* Copy the trace */ | |
347 | try { | |
348 | getResource().copy(newPath, IResource.FORCE | IResource.SHALLOW, null); | |
e9e2c5ee | 349 | IResource trace = ((IFolder) getParent().getResource()).findMember(newName); |
8f5221c2 GB |
350 | |
351 | /* Delete any bookmarks file found in copied trace folder */ | |
e9e2c5ee MK |
352 | if (trace instanceof IFolder) { |
353 | IFolder folderTrace = (IFolder) trace; | |
354 | for (IResource member : folderTrace.members()) { | |
4b3b667b | 355 | String traceTypeId = TmfTraceType.getTraceTypeId(member); |
3d04a314 | 356 | if (ITmfEventsEditorConstants.TRACE_INPUT_TYPE_CONSTANTS.contains(traceTypeId)) { |
8f5221c2 | 357 | member.delete(true, null); |
3d04a314 | 358 | } else if (ITmfEventsEditorConstants.EXPERIMENT_INPUT_TYPE_CONSTANTS.contains(traceTypeId)) { |
8f5221c2 GB |
359 | member.delete(true, null); |
360 | } | |
361 | } | |
362 | } | |
e9e2c5ee | 363 | return trace; |
8f5221c2 GB |
364 | } catch (CoreException e) { |
365 | ||
366 | } | |
367 | return null; | |
368 | } | |
369 | ||
370 | /** | |
371 | * Get the list of analysis elements | |
372 | * | |
373 | * @return Array of analysis elements | |
374 | */ | |
375 | public List<TmfAnalysisElement> getAvailableAnalysis() { | |
376 | List<ITmfProjectModelElement> children = getChildren(); | |
377 | List<TmfAnalysisElement> analysis = new ArrayList<>(); | |
378 | for (ITmfProjectModelElement child : children) { | |
379 | if (child instanceof TmfAnalysisElement) { | |
380 | analysis.add((TmfAnalysisElement) child); | |
381 | } | |
382 | } | |
383 | return analysis; | |
384 | } | |
385 | ||
16036bc2 GB |
386 | // ------------------------------------------------------------------------ |
387 | // Supplementary files operations | |
388 | // ------------------------------------------------------------------------ | |
389 | ||
99504bb8 GB |
390 | /** |
391 | * Deletes this element specific supplementary folder. | |
392 | */ | |
393 | public void deleteSupplementaryFolder() { | |
339d539c PT |
394 | IFolder supplFolder = getTraceSupplementaryFolder(getSupplementaryFolderPath()); |
395 | try { | |
396 | deleteFolder(supplFolder); | |
397 | } catch (CoreException e) { | |
398 | Activator.getDefault().logError("Error deleting supplementary folder " + supplFolder, e); //$NON-NLS-1$ | |
399 | } | |
400 | } | |
401 | ||
402 | private static void deleteFolder(IFolder folder) throws CoreException { | |
403 | if (folder.exists()) { | |
404 | folder.delete(true, new NullProgressMonitor()); | |
405 | } | |
406 | IContainer parent = folder.getParent(); | |
407 | // delete empty folders up to the parent project | |
408 | if (parent instanceof IFolder && (!parent.exists() || parent.members().length == 0)) { | |
409 | deleteFolder((IFolder) parent); | |
99504bb8 GB |
410 | } |
411 | } | |
412 | ||
413 | /** | |
16036bc2 | 414 | * Renames the element specific supplementary folder according to the new |
339d539c | 415 | * element name or path. |
99504bb8 | 416 | * |
339d539c PT |
417 | * @param newElementPath |
418 | * The new element name or path | |
99504bb8 | 419 | */ |
339d539c PT |
420 | public void renameSupplementaryFolder(String newElementPath) { |
421 | IFolder oldSupplFolder = getTraceSupplementaryFolder(getSupplementaryFolderPath()); | |
99504bb8 GB |
422 | |
423 | // Rename supplementary folder | |
339d539c PT |
424 | try { |
425 | if (oldSupplFolder.exists()) { | |
426 | IFolder newSupplFolder = prepareTraceSupplementaryFolder(newElementPath + getSuffix(), false); | |
99504bb8 | 427 | oldSupplFolder.move(newSupplFolder.getFullPath(), true, new NullProgressMonitor()); |
99504bb8 | 428 | } |
339d539c PT |
429 | deleteFolder(oldSupplFolder); |
430 | } catch (CoreException e) { | |
431 | Activator.getDefault().logError("Error renaming supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$ | |
99504bb8 GB |
432 | } |
433 | } | |
434 | ||
435 | /** | |
339d539c PT |
436 | * Copies the element specific supplementary folder to the new element name |
437 | * or path. | |
99504bb8 | 438 | * |
339d539c PT |
439 | * @param newElementPath |
440 | * The new element name or path | |
99504bb8 | 441 | */ |
339d539c PT |
442 | public void copySupplementaryFolder(String newElementPath) { |
443 | IFolder oldSupplFolder = getTraceSupplementaryFolder(getSupplementaryFolderPath()); | |
99504bb8 GB |
444 | |
445 | // copy supplementary folder | |
446 | if (oldSupplFolder.exists()) { | |
447 | try { | |
339d539c | 448 | IFolder newSupplFolder = prepareTraceSupplementaryFolder(newElementPath + getSuffix(), false); |
99504bb8 GB |
449 | oldSupplFolder.copy(newSupplFolder.getFullPath(), true, new NullProgressMonitor()); |
450 | } catch (CoreException e) { | |
451 | Activator.getDefault().logError("Error renaming supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$ | |
452 | } | |
453 | } | |
454 | } | |
455 | ||
456 | /** | |
457 | * Copies the element specific supplementary folder a new folder. | |
458 | * | |
16036bc2 GB |
459 | * @param destination |
460 | * The destination folder to copy to. | |
99504bb8 GB |
461 | */ |
462 | public void copySupplementaryFolder(IFolder destination) { | |
339d539c | 463 | IFolder oldSupplFolder = getTraceSupplementaryFolder(getSupplementaryFolderPath()); |
99504bb8 GB |
464 | |
465 | // copy supplementary folder | |
466 | if (oldSupplFolder.exists()) { | |
467 | try { | |
c2f1c5b6 | 468 | TraceUtils.createFolder((IFolder) destination.getParent(), new NullProgressMonitor()); |
99504bb8 GB |
469 | oldSupplFolder.copy(destination.getFullPath(), true, new NullProgressMonitor()); |
470 | } catch (CoreException e) { | |
471 | Activator.getDefault().logError("Error copying supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$ | |
472 | } | |
473 | } | |
474 | } | |
475 | ||
99504bb8 | 476 | /** |
16036bc2 GB |
477 | * Refreshes the element specific supplementary folder information. It |
478 | * creates the folder if not exists. It sets the persistence property of the | |
479 | * trace resource | |
99504bb8 GB |
480 | */ |
481 | public void refreshSupplementaryFolder() { | |
6b44794a MK |
482 | IFolder supplFolder = createSupplementaryFolder(); |
483 | try { | |
484 | supplFolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); | |
485 | } catch (CoreException e) { | |
486 | Activator.getDefault().logError("Error refreshing supplementary folder " + supplFolder, e); //$NON-NLS-1$ | |
487 | } | |
99504bb8 GB |
488 | } |
489 | ||
490 | /** | |
491 | * Checks if supplementary resource exist or not. | |
492 | * | |
16036bc2 GB |
493 | * @return <code>true</code> if one or more files are under the element |
494 | * supplementary folder | |
99504bb8 GB |
495 | */ |
496 | public boolean hasSupplementaryResources() { | |
497 | IResource[] resources = getSupplementaryResources(); | |
498 | return (resources.length > 0); | |
499 | } | |
500 | ||
501 | /** | |
502 | * Returns the supplementary resources under the trace supplementary folder. | |
503 | * | |
504 | * @return array of resources under the trace supplementary folder. | |
505 | */ | |
506 | public IResource[] getSupplementaryResources() { | |
339d539c | 507 | IFolder supplFolder = getTraceSupplementaryFolder(getSupplementaryFolderPath()); |
99504bb8 GB |
508 | if (supplFolder.exists()) { |
509 | try { | |
510 | return supplFolder.members(); | |
511 | } catch (CoreException e) { | |
512 | Activator.getDefault().logError("Error deleting supplementary folder " + supplFolder, e); //$NON-NLS-1$ | |
513 | } | |
514 | } | |
515 | return new IResource[0]; | |
516 | } | |
517 | ||
518 | /** | |
519 | * Deletes the given resources. | |
520 | * | |
16036bc2 GB |
521 | * @param resources |
522 | * array of resources to delete. | |
99504bb8 GB |
523 | */ |
524 | public void deleteSupplementaryResources(IResource[] resources) { | |
525 | ||
526 | for (int i = 0; i < resources.length; i++) { | |
527 | try { | |
528 | resources[i].delete(true, new NullProgressMonitor()); | |
529 | } catch (CoreException e) { | |
530 | Activator.getDefault().logError("Error deleting supplementary resource " + resources[i], e); //$NON-NLS-1$ | |
531 | } | |
532 | } | |
533 | } | |
534 | ||
4726e963 BH |
535 | /** |
536 | * Deletes all supplementary resources in the supplementary directory | |
537 | */ | |
538 | public void deleteSupplementaryResources() { | |
539 | deleteSupplementaryResources(getSupplementaryResources()); | |
540 | } | |
541 | ||
6b44794a | 542 | private IFolder createSupplementaryFolder() { |
339d539c | 543 | IFolder supplFolder = prepareTraceSupplementaryFolder(getSupplementaryFolderPath(), true); |
99504bb8 GB |
544 | |
545 | try { | |
b3e4798c | 546 | getResource().setPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, supplFolder.getLocation().toOSString()); |
99504bb8 GB |
547 | } catch (CoreException e) { |
548 | Activator.getDefault().logError("Error setting persistant property " + TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, e); //$NON-NLS-1$ | |
549 | } | |
6b44794a | 550 | return supplFolder; |
99504bb8 GB |
551 | } |
552 | ||
8f5221c2 GB |
553 | // ------------------------------------------------------- |
554 | // Signal handlers | |
555 | // ------------------------------------------------------- | |
16036bc2 | 556 | |
beb19106 | 557 | /** |
8f5221c2 | 558 | * Handler for the Trace Opened signal |
beb19106 | 559 | * |
8f5221c2 GB |
560 | * @param signal |
561 | * The incoming signal | |
beb19106 | 562 | */ |
8f5221c2 GB |
563 | @TmfSignalHandler |
564 | public void traceOpened(TmfTraceOpenedSignal signal) { | |
565 | IResource resource = signal.getTrace().getResource(); | |
566 | if ((resource == null) || !resource.equals(getResource())) { | |
567 | return; | |
beb19106 | 568 | } |
beb19106 | 569 | |
8f5221c2 | 570 | getParent().refresh(); |
beb19106 GB |
571 | } |
572 | ||
99504bb8 | 573 | } |