Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2014-05-15 13:57:39 -0400
committerPatrick Tasse2014-05-16 14:25:52 -0400
commit0b6ed6f904dd99d67eca519d560797eb6b9b7e9e (patch)
tree9f063b52e774715b69daabe78c3ae6c07b38bcb2
parentf3dbabad0ccdbf89fcdbabdb7a5cc4acd8f9cd8b (diff)
downloadorg.eclipse.linuxtools-0b6ed6f904dd99d67eca519d560797eb6b9b7e9e.tar.gz
org.eclipse.linuxtools-0b6ed6f904dd99d67eca519d560797eb6b9b7e9e.tar.xz
org.eclipse.linuxtools-0b6ed6f904dd99d67eca519d560797eb6b9b7e9e.zip
tmf: Support tree structure in SelectSupplementaryResourcesDialog
Change-Id: I62ccb5d80ace123621e2df4ddcd58dbf2fbf4d8e Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-on: https://git.eclipse.org/r/26736 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com> Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java126
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java4
2 files changed, 107 insertions, 23 deletions
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 501cc55a7d..e86d836071 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
@@ -14,20 +14,32 @@
package org.eclipse.linuxtools.internal.tmf.ui.project.dialogs;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map.Entry;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+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.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
@@ -41,17 +53,26 @@ import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
+import com.google.common.collect.Multimap;
+
/**
* SelectSupplementaryResourcesDialog
*/
public class SelectSupplementaryResourcesDialog extends Dialog {
// ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+ private static final Image EXPERIMENT_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/experiment.gif"); //$NON-NLS-1$
+ private static final Image TRACE_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/trace.gif"); //$NON-NLS-1$
+ private static final Image RESOURCE_IMAGE = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
+
+ // ------------------------------------------------------------------------
// Members
// ------------------------------------------------------------------------
private CheckboxTreeViewer fTreeViewer;
- private final IResource[] fAvailableResources;
- private IResource[] fReturndResources;
+ private final Multimap<TmfCommonProjectElement, IResource> fResourceMap;
+ private IResource[] fReturnedResources;
// ------------------------------------------------------------------------
// Constructor
@@ -62,12 +83,12 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
*
* @param shell
* Parent shell of this dialog
- * @param resources
- * Available resources
+ * @param resourceMap
+ * Map of element to supplementary resources
*/
- public SelectSupplementaryResourcesDialog(Shell shell, IResource[] resources) {
+ public SelectSupplementaryResourcesDialog(Shell shell, Multimap<TmfCommonProjectElement, IResource> resourceMap) {
super(shell);
- fAvailableResources = Arrays.copyOf(resources, resources.length);
+ fResourceMap = resourceMap;
setShellStyle(SWT.RESIZE | getShellStyle());
}
@@ -76,10 +97,10 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
// ------------------------------------------------------------------------
/**
- * @return A copy of the resources
+ * @return A copy of the selected resources
*/
public IResource[] getResources() {
- return Arrays.copyOf(fReturndResources, fReturndResources.length);
+ return Arrays.copyOf(fReturnedResources, fReturnedResources.length);
}
// ------------------------------------------------------------------------
@@ -120,17 +141,20 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
@Override
public boolean hasChildren(Object element) {
- return false;
+ return element instanceof TmfCommonProjectElement;
}
@Override
public Object getParent(Object element) {
+ if (element instanceof IResource) {
+ getParentElement((IResource) element);
+ }
return null;
}
@Override
public Object[] getElements(Object inputElement) {
- if (inputElement instanceof IResource[]) {
+ if (inputElement instanceof Object[]) {
return (Object[]) inputElement;
}
return null;
@@ -138,6 +162,9 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
@Override
public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof TmfCommonProjectElement) {
+ return fResourceMap.get((TmfCommonProjectElement) parentElement).toArray();
+ }
return null;
}
});
@@ -147,19 +174,64 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
public String getText(Object element) {
if (element instanceof IResource) {
IResource resource = (IResource) element;
- // remove .tracing/ segment
- return resource.getProjectRelativePath().removeFirstSegments(1).toString();
+ TmfCommonProjectElement projectElement = getParentElement(resource);
+ // remove .tracing/<supplementary folder> segments
+ IPath suppFolderPath = projectElement.getTraceSupplementaryFolder(projectElement.getElementPath()).getFullPath();
+ return resource.getFullPath().removeFirstSegments(suppFolderPath.segmentCount()).toString();
+ } else if (element instanceof TmfCommonProjectElement) {
+ TmfCommonProjectElement projectElement = (TmfCommonProjectElement) element;
+ return projectElement.getElementPath();
}
return super.getText(element);
}
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof IResource) {
+ return RESOURCE_IMAGE;
+ } else if (element instanceof TmfTraceElement) {
+ return TRACE_IMAGE;
+ } else if (element instanceof TmfExperimentElement) {
+ return EXPERIMENT_IMAGE;
+ }
+ return null;
+ }
+
});
- fTreeViewer.setInput(fAvailableResources);
+ fTreeViewer.setInput(fResourceMap.keySet().toArray());
+ fTreeViewer.expandAll();
setAllChecked(true);
- fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ fTreeViewer.addCheckStateListener(new ICheckStateListener() {
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if (event.getElement() instanceof TmfCommonProjectElement) {
+ fTreeViewer.setSubtreeChecked(event.getElement(), event.getChecked());
+ fTreeViewer.setGrayed(event.getElement(), false);
+ } else if (event.getElement() instanceof IResource) {
+ TmfCommonProjectElement projectElement = getParentElement((IResource) event.getElement());
+ int checkedCount = 0;
+ Collection<IResource> resources = fResourceMap.get(projectElement);
+ for (IResource resource : resources) {
+ if (fTreeViewer.getChecked(resource)) {
+ checkedCount++;
+ }
+ }
+ if (checkedCount == resources.size()) {
+ fTreeViewer.setChecked(projectElement, true);
+ fTreeViewer.setGrayed(projectElement, false);
+ } else if (checkedCount > 0) {
+ fTreeViewer.setGrayChecked(projectElement, true);
+ } else {
+ fTreeViewer.setGrayChecked(projectElement, false);
+ }
+ }
+ }
+ });
+ fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateOKButtonEnablement();
@@ -202,9 +274,19 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
return composite;
}
+ private TmfCommonProjectElement getParentElement(IResource resource) {
+ for (Entry<TmfCommonProjectElement, IResource> entry : fResourceMap.entries()) {
+ if (entry.getValue().equals(resource)) {
+ return entry.getKey();
+ }
+ }
+ return null;
+ }
+
private void setAllChecked(boolean state) {
- for (Object element : fAvailableResources) {
- fTreeViewer.setChecked(element, state);
+ for (Object element : fResourceMap.keySet()) {
+ fTreeViewer.setSubtreeChecked(element, state);
+ fTreeViewer.setGrayed(element, false);
}
}
@@ -228,12 +310,14 @@ public class SelectSupplementaryResourcesDialog extends Dialog {
@Override
protected void okPressed() {
- Object[] checked = fTreeViewer.getCheckedElements();
-
- fReturndResources = new IResource[checked.length];
- for (int i = 0; i < checked.length; i++) {
- fReturndResources[i] = (IResource) checked[i];
+ Object[] checkedElements = fTreeViewer.getCheckedElements();
+ List<IResource> checkedResources = new ArrayList<>(checkedElements.length);
+ for (Object checked : checkedElements) {
+ if (checked instanceof IResource) {
+ checkedResources.add((IResource) checked);
+ }
}
+ fReturnedResources = checkedResources.toArray(new IResource[0]);
super.okPressed();
}
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 5f526ea299..92436528d5 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
@@ -112,8 +112,8 @@ public class DeleteTraceSupplementaryFilesHandler extends AbstractHandler {
}
}
- SelectSupplementaryResourcesDialog dialog = new SelectSupplementaryResourcesDialog(window.getShell(),
- resourceMap.values().toArray(new IResource[0]));
+ SelectSupplementaryResourcesDialog dialog =
+ new SelectSupplementaryResourcesDialog(window.getShell(), resourceMap);
if (dialog.open() != Window.OK) {
return null;
}

Back to the top