Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2014-05-01 20:34:10 -0400
committerPatrick Tasse2014-05-15 09:31:03 -0400
commit26d69a466861f0a88366ed976d68226cf63ae7c7 (patch)
treef015c81af7ded5aaebd82b0ee16b2c12d92d1621
parent23ee7b0070c0b50450508bf16e4ff89f3c8d1a96 (diff)
downloadorg.eclipse.linuxtools-26d69a466861f0a88366ed976d68226cf63ae7c7.tar.gz
org.eclipse.linuxtools-26d69a466861f0a88366ed976d68226cf63ae7c7.tar.xz
org.eclipse.linuxtools-26d69a466861f0a88366ed976d68226cf63ae7c7.zip
tmf: Improve Delete Supplementary Files command
- Make all checkbox elements checked by default in the dialog - Allow multiple selection as long as at least one of the selected elements has supplementary files - Update trace handler to support both traces and experiments, and delete the experiment handler - Ensure supplementary files for a particular trace are only shown once in the list (e.g. same trace selected both under Traces folder and under experiment, or two experiments selected that contain the same trace) - Ensure only traces and experiments that have supplementary resources to delete have their editors closed, and that their project is refreshed only once. Change-Id: I91f823c67c15da699c815fdf9daf9cfec5082ec9 Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-on: https://git.eclipse.org/r/25858 Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF3
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml63
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java29
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentSupplementaryFilesHandler.java141
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java121
5 files changed, 117 insertions, 240 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
index cf7bbea22e..547ae55b6c 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
@@ -73,5 +73,6 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.l
org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model,
org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets,
org.eclipse.linuxtools.tmf.ui.widgets.virtualtable
-Import-Package: org.eclipse.emf.common.util,
+Import-Package: com.google.common.collect,
+ org.eclipse.emf.common.util,
org.eclipse.emf.ecore
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml b/lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml
index 9688e349b8..5500c4c725 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml
@@ -665,26 +665,25 @@
<with
variable="selection">
<and>
- <count
- value="1">
- </count>
<iterate
ifEmpty="false"
operator="and">
- <and>
- <or>
- <instanceof
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
- </instanceof>
- <instanceof
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
- </instanceof>
- </or>
- <test
- forcePluginActivation="true"
- property="org.eclipse.linuxtools.tmf.ui.hasSupplementaryFiles">
- </test>
- </and>
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </or>
+ </iterate>
+ <iterate
+ ifEmpty="false"
+ operator="or">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.linuxtools.tmf.ui.hasSupplementaryFiles">
+ </test>
</iterate>
</and>
</with>
@@ -1419,19 +1418,6 @@
<handler
class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteTraceSupplementaryFilesHandler"
commandId="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files">
- <activeWhen>
- <and>
- <count
- value="1">
- </count>
- <iterate
- operator="and">
- <instanceof
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
- </instanceof>
- </iterate>
- </and>
- </activeWhen>
</handler>
<handler
class="org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport.ExportTracePackageHandler"
@@ -1455,23 +1441,6 @@
</activeWhen>
</handler>
<handler
- class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteExperimentSupplementaryFilesHandler"
- commandId="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files">
- <activeWhen>
- <and>
- <count
- value="1">
- </count>
- <iterate
- operator="and">
- <instanceof
- value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
- </instanceof>
- </iterate>
- </and>
- </activeWhen>
- </handler>
- <handler
class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.NewExperimentHandler"
commandId="org.eclipse.linuxtools.tmf.ui.command.new_experiment">
<activeWhen>
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java
index 5a1673589b..501cc55a7d 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java
@@ -120,9 +120,6 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
@Override
public boolean hasChildren(Object element) {
- if (element instanceof IResource[]) {
- return true;
- }
return false;
}
@@ -133,14 +130,14 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
@Override
public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
+ if (inputElement instanceof IResource[]) {
+ return (Object[]) inputElement;
+ }
+ return null;
}
@Override
public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof IResource[]) {
- return (Object[]) parentElement;
- }
return null;
}
});
@@ -159,6 +156,8 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
fTreeViewer.setInput(fAvailableResources);
+ setAllChecked(true);
+
fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
@@ -181,10 +180,7 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
selectAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- Object[] items = fAvailableResources;
- for (Object treeItem : items) {
- fTreeViewer.setChecked(treeItem, true);
- }
+ setAllChecked(true);
updateOKButtonEnablement();
}
@@ -195,10 +191,7 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
deselectAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- Object[] items = fAvailableResources;
- for (Object treeItem : items) {
- fTreeViewer.setChecked(treeItem, false);
- }
+ setAllChecked(false);
updateOKButtonEnablement();
}
@@ -209,6 +202,12 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
return composite;
}
+ private void setAllChecked(boolean state) {
+ for (Object element : fAvailableResources) {
+ fTreeViewer.setChecked(element, state);
+ }
+ }
+
private void updateOKButtonEnablement() {
Object[] checked = fTreeViewer.getCheckedElements();
getButton(IDialogConstants.OK_ID).setEnabled(checked.length > 0);
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentSupplementaryFilesHandler.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentSupplementaryFilesHandler.java
deleted file mode 100644
index ce69d2c3c7..0000000000
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentSupplementaryFilesHandler.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2014 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:
- * Bernd Hufmann - Initial API and implementation
- * Patrick Tasse - Close editors to release resources
- * Marc-Andre Laperle - Fix NPE (Bug 416574)
- *******************************************************************************/
-
-package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;
-import org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.SelectSupplementaryResourcesDialog;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * Handler for Delete Supplementary Files command on experiment
- */
-public class DeleteExperimentSupplementaryFilesHandler extends AbstractHandler {
-
- // ------------------------------------------------------------------------
- // Execution
- // ------------------------------------------------------------------------
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
-
- // Check if we are closing down
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (window == null) {
- return null;
- }
-
- // Get the selection
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IWorkbenchPart part = page.getActivePart();
- if (part == null) {
- return Boolean.FALSE;
- }
- ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
- if (selectionProvider == null) {
- return Boolean.FALSE;
- }
-
- ISelection selection = selectionProvider.getSelection();
-
- // Make sure there is only selection and that it is an experiment
- if (selection instanceof TreeSelection) {
- TreeSelection sel = (TreeSelection) selection;
- // There should be only one item selected as per the plugin.xml
- Object element = sel.getFirstElement();
- List<IResource> resourcesList = new ArrayList<>();
-
- if (element instanceof TmfExperimentElement) {
-
- TmfExperimentElement experiment = (TmfExperimentElement) element;
-
- IResource[] resources = experiment.getSupplementaryResources();
- // List to know which resources belong to the experiment
- List<IResource> experimentResources = Arrays.asList(resources);
-
- resourcesList.addAll(experimentResources);
-
- // Map to know which trace to close for each resource
- HashMap<IResource, TmfTraceElement> traceMap = new HashMap<>();
-
- for (TmfTraceElement aTrace : experiment.getTraces()) {
-
- // If trace is under an experiment, use the original trace from the traces folder
- aTrace = aTrace.getElementUnderTraceFolder();
-
- // Add the trace supplementary resources for the dialog
- resources = aTrace.getSupplementaryResources();
- resourcesList.addAll(Arrays.asList(resources));
-
- for (IResource resource : resources) {
- traceMap.put(resource, aTrace);
- }
- }
-
- SelectSupplementaryResourcesDialog dialog = new SelectSupplementaryResourcesDialog(window.getShell(), resourcesList.toArray(new IResource[resourcesList.size()]));
-
- if (dialog.open() != Window.OK) {
- return null;
- }
-
- IResource[] resourcesToDelete = dialog.getResources();
-
- // Delete the selected resources
- for (IResource resource : resourcesToDelete) {
- if (experimentResources.contains(resource)) {
- experiment.closeEditors();
- } else {
- traceMap.get(resource).closeEditors();
- }
-
- try {
- resource.delete(true, new NullProgressMonitor());
- } catch (CoreException e) {
- Activator.getDefault().logError("Error deleting supplementary resource " + resource, e); //$NON-NLS-1$
- }
- }
-
- IResource resource = experiment.getProject().getResource();
- if (resource != null) {
- try {
- resource.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- Activator.getDefault().logError("Error refreshing resource " + resource, e); //$NON-NLS-1$
- }
- }
- }
- }
- return null;
- }
-}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java
index c54adaa8e4..5f526ea299 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java
@@ -13,22 +13,34 @@
package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.SelectSupplementaryResourcesDialog;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfCommonProjectElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import com.google.common.collect.Multimap;
+import com.google.common.collect.TreeMultimap;
/**
* Handler for Delete Supplementary Files command on trace
@@ -36,6 +48,24 @@ import org.eclipse.ui.PlatformUI;
public class DeleteTraceSupplementaryFilesHandler extends AbstractHandler {
// ------------------------------------------------------------------------
+ // Inner classes
+ // ------------------------------------------------------------------------
+
+ private class ElementComparator implements Comparator<TmfCommonProjectElement> {
+ @Override
+ public int compare(TmfCommonProjectElement e1, TmfCommonProjectElement e2) {
+ return e1.getPath().toString().compareTo(e2.getPath().toString());
+ }
+ }
+
+ private class ResourceComparator implements Comparator<IResource> {
+ @Override
+ public int compare(IResource r1, IResource r2) {
+ return r1.getFullPath().toString().compareTo(r2.getFullPath().toString());
+ }
+ }
+
+ // ------------------------------------------------------------------------
// Execution
// ------------------------------------------------------------------------
@@ -49,49 +79,68 @@ public class DeleteTraceSupplementaryFilesHandler extends AbstractHandler {
}
// Get the selection
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IWorkbenchPart part = page.getActivePart();
- if (part == null) {
- return Boolean.FALSE;
- }
- ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
- if (selectionProvider == null) {
- return Boolean.FALSE;
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (!(selection instanceof IStructuredSelection)) {
+ return null;
}
+ final Multimap<TmfCommonProjectElement, IResource> resourceMap =
+ TreeMultimap.create(new ElementComparator(), new ResourceComparator());
+ final Iterator<Object> iterator = ((IStructuredSelection) selection).iterator();
- ISelection selection = selectionProvider.getSelection();
-
- // Make sure there is only selection and that it is an experiment
- if (selection instanceof TreeSelection) {
- TreeSelection sel = (TreeSelection) selection;
- // There should be only one item selected as per the plugin.xml
- Object element = sel.getFirstElement();
+ while (iterator.hasNext()) {
+ Object element = iterator.next();
if (element instanceof TmfTraceElement) {
TmfTraceElement trace = (TmfTraceElement) element;
// If trace is under an experiment, use the original trace from the traces folder
trace = trace.getElementUnderTraceFolder();
+ for (IResource resource : trace.getSupplementaryResources()) {
+ resourceMap.put(trace, resource);
+ }
- // Delete the selected resources
- IResource[] resources = trace.getSupplementaryResources();
-
- SelectSupplementaryResourcesDialog dialog = new SelectSupplementaryResourcesDialog(window.getShell(), resources);
- if (dialog.open() != Window.OK) {
- return null;
+ } else if (element instanceof TmfExperimentElement) {
+ TmfExperimentElement experiment = (TmfExperimentElement) element;
+ for (IResource resource : experiment.getSupplementaryResources()) {
+ resourceMap.put(experiment, resource);
+ }
+ for (TmfTraceElement trace : experiment.getTraces()) {
+ // If trace is under an experiment, use the original trace from the traces folder
+ trace = trace.getElementUnderTraceFolder();
+ for (IResource resource : trace.getSupplementaryResources()) {
+ resourceMap.put(trace, resource);
+ }
}
+ }
+ }
+
+ SelectSupplementaryResourcesDialog dialog = new SelectSupplementaryResourcesDialog(window.getShell(),
+ resourceMap.values().toArray(new IResource[0]));
+ if (dialog.open() != Window.OK) {
+ return null;
+ }
- trace.closeEditors();
- trace.deleteSupplementaryResources(dialog.getResources());
+ Set<IProject> projectsToRefresh = new HashSet<>();
- // Refresh project
- IResource resource = trace.getProject().getResource();
+ // Delete the resources that were selected
+ List<IResource> allResourcesToDelete = Arrays.asList(dialog.getResources());
+ for (TmfCommonProjectElement element : resourceMap.keySet()) {
+ List<IResource> traceResourcesToDelete = new ArrayList<>(resourceMap.get(element));
+ traceResourcesToDelete.retainAll(allResourcesToDelete);
+ if (!traceResourcesToDelete.isEmpty()) {
+ // Delete the selected resources
+ element.closeEditors();
+ element.deleteSupplementaryResources(traceResourcesToDelete.toArray(new IResource[0]));
+ projectsToRefresh.add(element.getProject().getResource());
+ }
+ }
- if (resource != null) {
- try {
- resource.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- Activator.getDefault().logError("Error refreshing resource " + resource, e); //$NON-NLS-1$
- }
- }
+ // Refresh projects
+ Iterator<IProject> projectIterator = projectsToRefresh.iterator();
+ while (projectIterator.hasNext()) {
+ IProject project = projectIterator.next();
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error refreshing project " + project, e); //$NON-NLS-1$
}
}

Back to the top