Commit | Line | Data |
---|---|---|
ca2ff0c7 PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are made | |
5 | * 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 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.internal.tmf.ui.parsers; | |
14 | ||
15 | import java.lang.reflect.InvocationTargetException; | |
16 | ||
17 | import org.eclipse.core.resources.IProject; | |
18 | import org.eclipse.core.resources.ResourcesPlugin; | |
19 | import org.eclipse.core.runtime.CoreException; | |
20 | import org.eclipse.core.runtime.IProgressMonitor; | |
21 | import org.eclipse.core.runtime.OperationCanceledException; | |
22 | import org.eclipse.jdt.annotation.NonNull; | |
ca2ff0c7 | 23 | import org.eclipse.swt.widgets.Display; |
c365e27d | 24 | import org.eclipse.tracecompass.internal.tmf.ui.editors.TmfTableColumnUtils; |
ca2ff0c7 PT |
25 | import org.eclipse.tracecompass.tmf.core.TmfProjectNature; |
26 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; | |
27 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry; | |
28 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement; | |
8e25df71 | 29 | import org.eclipse.tracecompass.tmf.ui.project.model.TraceUtils; |
024a2c6b | 30 | import org.eclipse.tracecompass.tmf.ui.project.operations.TmfWorkspaceModifyOperation; |
ca2ff0c7 PT |
31 | import org.eclipse.ui.PlatformUI; |
32 | ||
33 | /** | |
34 | * Custom parser utility methods. | |
35 | * | |
36 | * @author Patrick Tasse | |
37 | * | |
38 | */ | |
39 | public class CustomParserUtils { | |
40 | ||
41 | /** | |
42 | * Perform required cleanup when a custom parser is modified or deleted. | |
43 | * | |
44 | * @param traceTypeId | |
45 | * the trace type id | |
46 | */ | |
47 | public static void cleanup(@NonNull final String traceTypeId) { | |
48 | ||
49 | /* | |
50 | * Close all editors and delete supplementary files of traces with this trace type. | |
51 | */ | |
52 | TmfWorkspaceModifyOperation operation = new TmfWorkspaceModifyOperation() { | |
53 | @Override | |
54 | public void execute(IProgressMonitor monitor) throws CoreException { | |
55 | for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { | |
56 | if (project.hasNature(TmfProjectNature.ID)) { | |
57 | TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true); | |
58 | for (final TmfTraceElement trace : projectElement.getTracesFolder().getTraces()) { | |
59 | if (monitor.isCanceled()) { | |
60 | throw new OperationCanceledException(); | |
61 | } | |
62 | if (traceTypeId.equals(trace.getTraceType())) { | |
63 | Display.getDefault().syncExec(new Runnable() { | |
64 | @Override | |
65 | public void run() { | |
66 | trace.closeEditors(); | |
67 | } | |
68 | }); | |
69 | trace.deleteSupplementaryResources(); | |
70 | trace.refreshSupplementaryFolder(); | |
71 | } | |
72 | } | |
73 | } | |
74 | } | |
14665360 PT |
75 | |
76 | /* | |
c365e27d | 77 | * Clear the column settings for this trace type. Must be done after closing the editors. |
14665360 | 78 | */ |
c365e27d MK |
79 | TmfTableColumnUtils.clearColumnOrder(traceTypeId); |
80 | TmfTableColumnUtils.clearColumnWidth(traceTypeId); | |
81 | TmfTableColumnUtils.clearColumnResizable(traceTypeId); | |
ca2ff0c7 PT |
82 | } |
83 | }; | |
84 | try { | |
85 | PlatformUI.getWorkbench().getProgressService().run(true, true, operation); | |
86 | } catch (InterruptedException e) { | |
87 | } catch (InvocationTargetException e) { | |
8e25df71 | 88 | TraceUtils.displayErrorMsg(e.toString(), e.getTargetException().toString()); |
ca2ff0c7 PT |
89 | } |
90 | } | |
91 | } |