From: Patrick Tasse Date: Fri, 13 Mar 2015 19:38:06 +0000 (-0400) Subject: tmf: Perform cleanup when custom parser is modified or deleted X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=ca2ff0c7be81297a21fc5c79f2fce71aac5ce98c;p=deliverable%2Ftracecompass.git tmf: Perform cleanup when custom parser is modified or deleted All traces in all projects which have the modified or deleted custom parser's trace type should be closed and have their supplementary files deleted. Change-Id: I872cefb7e0aa9e3d9e6370766bb6319cb256d503 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/43825 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- diff --git a/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF index 93b4faf4c3..fe979eee57 100644 --- a/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF @@ -25,6 +25,7 @@ Export-Package: org.eclipse.tracecompass.internal.tmf.ui;x-friends:="org.eclipse org.eclipse.tracecompass.internal.tmf.ui.dialogs;x-internal:=true, org.eclipse.tracecompass.internal.tmf.ui.editors;x-internal:=true, org.eclipse.tracecompass.internal.tmf.ui.editors.handlers;x-internal:=true, + org.eclipse.tracecompass.internal.tmf.ui.parsers;x-internal:=true, org.eclipse.tracecompass.internal.tmf.ui.parsers.wizards;x-friends:="org.eclipse.tracecompass.tmf.ui.tests", org.eclipse.tracecompass.internal.tmf.ui.preferences;x-internal:=true, org.eclipse.tracecompass.internal.tmf.ui.project.dialogs;x-internal:=true, diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/ManageCustomParsersDialog.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/ManageCustomParsersDialog.java index 29472e6e5d..a69b77ff82 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/ManageCustomParsersDialog.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/ManageCustomParsersDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -34,10 +34,13 @@ import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Shell; import org.eclipse.tracecompass.internal.tmf.ui.Activator; import org.eclipse.tracecompass.internal.tmf.ui.Messages; +import org.eclipse.tracecompass.internal.tmf.ui.parsers.CustomParserUtils; import org.eclipse.tracecompass.internal.tmf.ui.parsers.wizards.CustomTxtParserWizard; import org.eclipse.tracecompass.internal.tmf.ui.parsers.wizards.CustomXmlParserWizard; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition; import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper; @@ -219,8 +222,10 @@ public class ManageCustomParsersDialog extends Dialog { String name = selection.substring(selection.indexOf(SEP) + SEP_LEN); if (txtButton.getSelection()) { CustomTxtTraceDefinition.delete(category, name); + CustomParserUtils.cleanup(CustomTxtTrace.buildTraceTypeId(category, name)); } else if (xmlButton.getSelection()) { CustomXmlTraceDefinition.delete(category, name); + CustomParserUtils.cleanup(CustomXmlTrace.buildTraceTypeId(category, name)); } fillParserList(); } diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/CustomParserUtils.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/CustomParserUtils.java new file mode 100644 index 0000000000..43d97fc841 --- /dev/null +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/CustomParserUtils.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2015 Ericsson + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.tracecompass.internal.tmf.ui.parsers; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.tracecompass.internal.tmf.ui.project.operations.TmfWorkspaceModifyOperation; +import org.eclipse.tracecompass.tmf.core.TmfProjectNature; +import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; +import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry; +import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.ui.PlatformUI; + +/** + * Custom parser utility methods. + * + * @author Patrick Tasse + * + */ +public class CustomParserUtils { + + /** + * Perform required cleanup when a custom parser is modified or deleted. + * + * @param traceTypeId + * the trace type id + */ + public static void cleanup(@NonNull final String traceTypeId) { + + /* + * Close all editors and delete supplementary files of traces with this trace type. + */ + TmfWorkspaceModifyOperation operation = new TmfWorkspaceModifyOperation() { + @Override + public void execute(IProgressMonitor monitor) throws CoreException { + for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { + if (project.hasNature(TmfProjectNature.ID)) { + TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true); + for (final TmfTraceElement trace : projectElement.getTracesFolder().getTraces()) { + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + if (traceTypeId.equals(trace.getTraceType())) { + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + trace.closeEditors(); + } + }); + trace.deleteSupplementaryResources(); + trace.refreshSupplementaryFolder(); + } + } + } + } + } + }; + try { + PlatformUI.getWorkbench().getProgressService().run(true, true, operation); + } catch (InterruptedException e) { + } catch (InvocationTargetException e) { + MessageDialog.openError(Display.getDefault().getActiveShell(), e.toString(), e.getTargetException().toString()); + } + } +} diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserWizard.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserWizard.java index 8affbab32f..67900612cd 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserWizard.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserWizard.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -15,6 +15,8 @@ package org.eclipse.tracecompass.internal.tmf.ui.parsers.wizards; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; +import org.eclipse.tracecompass.internal.tmf.ui.parsers.CustomParserUtils; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; @@ -58,9 +60,11 @@ public class CustomTxtParserWizard extends Wizard implements INewWizard { @Override public boolean performFinish() { CustomTxtTraceDefinition def = outputPage.getDefinition(); - if (definition != null && (!initialCategoryName.equals(def.categoryName) || - !initialDefinitionName.equals(def.definitionName))) { - CustomTxtTraceDefinition.delete(initialCategoryName, initialDefinitionName); + if (definition != null) { + if (!initialCategoryName.equals(def.categoryName) || !initialDefinitionName.equals(def.definitionName)) { + CustomTxtTraceDefinition.delete(initialCategoryName, initialDefinitionName); + } + CustomParserUtils.cleanup(CustomTxtTrace.buildTraceTypeId(initialCategoryName, initialDefinitionName)); } def.save(); return true; diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserWizard.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserWizard.java index 8edbc95396..32dde00c6c 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserWizard.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserWizard.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -15,6 +15,8 @@ package org.eclipse.tracecompass.internal.tmf.ui.parsers.wizards; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; +import org.eclipse.tracecompass.internal.tmf.ui.parsers.CustomParserUtils; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; @@ -58,9 +60,11 @@ public class CustomXmlParserWizard extends Wizard implements INewWizard { @Override public boolean performFinish() { CustomXmlTraceDefinition def = outputPage.getDefinition(); - if (definition != null && (!initialCategoryName.equals(def.categoryName) || - !initialDefinitionName.equals(def.definitionName))) { - CustomXmlTraceDefinition.delete(initialCategoryName, initialDefinitionName); + if (definition != null) { + if (!initialCategoryName.equals(def.categoryName) || !initialDefinitionName.equals(def.definitionName)) { + CustomXmlTraceDefinition.delete(initialCategoryName, initialDefinitionName); + } + CustomParserUtils.cleanup(CustomXmlTrace.buildTraceTypeId(initialCategoryName, initialDefinitionName)); } def.save(); return true;