1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.parsers
;
15 import java
.lang
.reflect
.InvocationTargetException
;
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
;
23 import org
.eclipse
.swt
.widgets
.Display
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.operations
.TmfWorkspaceModifyOperation
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.TmfProjectNature
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfTraceColumnManager
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectElement
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectRegistry
;
29 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceElement
;
30 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TraceUtils
;
31 import org
.eclipse
.ui
.PlatformUI
;
34 * Custom parser utility methods.
36 * @author Patrick Tasse
39 public class CustomParserUtils
{
42 * Perform required cleanup when a custom parser is modified or deleted.
47 public static void cleanup(@NonNull final String traceTypeId
) {
50 * Close all editors and delete supplementary files of traces with this trace type.
52 TmfWorkspaceModifyOperation operation
= new TmfWorkspaceModifyOperation() {
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();
62 if (traceTypeId
.equals(trace
.getTraceType())) {
63 Display
.getDefault().syncExec(new Runnable() {
69 trace
.deleteSupplementaryResources();
70 trace
.refreshSupplementaryFolder();
77 * Clear the column order for this trace type. Must be done after closing the editors.
79 TmfTraceColumnManager
.clearColumnOrder(traceTypeId
);
83 PlatformUI
.getWorkbench().getProgressService().run(true, true, operation
);
84 } catch (InterruptedException e
) {
85 } catch (InvocationTargetException e
) {
86 TraceUtils
.displayErrorMsg(e
.toString(), e
.getTargetException().toString());