c4ef24495c11090f70ec9ded6ca30d9cb88e84aa
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / parsers / CustomParserUtils.java
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;
23 import org.eclipse.jface.dialogs.MessageDialog;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.tracecompass.internal.tmf.ui.project.operations.TmfWorkspaceModifyOperation;
26 import org.eclipse.tracecompass.tmf.core.TmfProjectNature;
27 import org.eclipse.tracecompass.tmf.ui.editors.TmfTraceColumnManager;
28 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
29 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry;
30 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
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 }
75
76 /*
77 * Clear the column order for this trace type. Must be done after closing the editors.
78 */
79 TmfTraceColumnManager.clearColumnOrder(traceTypeId);
80 }
81 };
82 try {
83 PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
84 } catch (InterruptedException e) {
85 } catch (InvocationTargetException e) {
86 MessageDialog.openError(Display.getDefault().getActiveShell(), e.toString(), e.getTargetException().toString());
87 }
88 }
89 }
This page took 0.037546 seconds and 4 git commands to generate.