Add "check subtree" feature to TimeGraphFilterDialog
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 22 Mar 2013 15:16:04 +0000 (11:16 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 12 Apr 2013 15:50:23 +0000 (11:50 -0400)
Change-Id: Ib3d9a4c634d506c58524af704f903be685aaf3d1
Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Reviewed-on: https://git.eclipse.org/r/11390
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphFilterDialog.java

index 059a487926aa582af7c6c9451f700bcf9a7376f0..a859a8469b1712552b4a255ae5ab3a444519a9d0 100644 (file)
@@ -105,6 +105,8 @@ public class Messages extends NLS {
     public static String TmfTimeFilterDialog_UNCHECK_ALL;
     public static String TmfTimeFilterDialog_CHECK_SELECTED;
     public static String TmfTimeFilterDialog_UNCHECK_SELECTED;
+    public static String TmfTimeFilterDialog_CHECK_SUBTREE;
+    public static String TmfTimeFilterDialog_UNCHECK_SUBTREE;
 
     public static String TmfTimeTipHandler_DURATION;
     public static String TmfTimeTipHandler_TRACE_DATE;
index db97d10d7b9f4c762a5ddec6e22a4ab468214553..e2aac10af73fbdf6ed782d4866cb196e03ed2488 100644 (file)
@@ -88,6 +88,8 @@ TmfTimeFilterDialog_CHECK_ALL=Check all
 TmfTimeFilterDialog_UNCHECK_ALL=Uncheck all
 TmfTimeFilterDialog_CHECK_SELECTED=Check selected
 TmfTimeFilterDialog_UNCHECK_SELECTED=Uncheck selected
+TmfTimeFilterDialog_CHECK_SUBTREE=Check subtree
+TmfTimeFilterDialog_UNCHECK_SUBTREE=Uncheck subtree
 
 # org.eclipse.linuxtools.tmf.ui.viewers.timegraph.widgets
 TmfTimeTipHandler_DURATION=Duration
index c8956ed1800a9f464c1324b8ba6da3f06d814fd4..b4f3bb476ca1519e86d1f5ef3875c95a04369b8e 100644 (file)
@@ -61,6 +61,11 @@ import org.eclipse.ui.dialogs.SelectionStatusDialog;
  * @author François Rajotte
  */
 public class TimeGraphFilterDialog extends SelectionStatusDialog {
+    private final static int BUTTON_CHECK_SELECTED_ID = IDialogConstants.CLIENT_ID;
+    private final static int BUTTON_UNCHECK_SELECTED_ID = IDialogConstants.CLIENT_ID + 1;
+    private final static int BUTTON_CHECK_SUBTREE_ID = IDialogConstants.CLIENT_ID + 2;
+    private final static int BUTTON_UNCHECK_SUBTREE_ID = IDialogConstants.CLIENT_ID + 3;
+
 
     private CheckboxTreeViewer fViewer;
 
@@ -353,7 +358,6 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
     protected Composite createSelectionButtons(Composite composite) {
         Composite buttonComposite = new Composite(composite, SWT.RIGHT);
         GridLayout layout = new GridLayout();
-        layout.numColumns = 2;
         layout.marginWidth = 0;
         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
         buttonComposite.setLayout(layout);
@@ -364,62 +368,86 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
         buttonComposite.setLayoutData(data);
 
         /* Create the buttons in the good order to place them as we want */
+        Button checkSelectedButton = createButton(buttonComposite,
+                BUTTON_CHECK_SELECTED_ID, Messages.TmfTimeFilterDialog_CHECK_SELECTED,
+                false);
+        Button checkSubtreeButton = createButton(buttonComposite,
+                BUTTON_CHECK_SUBTREE_ID, Messages.TmfTimeFilterDialog_CHECK_SUBTREE,
+                false);
         Button checkAllButton = createButton(buttonComposite,
                 IDialogConstants.SELECT_ALL_ID, Messages.TmfTimeFilterDialog_CHECK_ALL,
                 false);
-        Button checkSelectedButton = createButton(buttonComposite,
-                IDialogConstants.CLIENT_ID, Messages.TmfTimeFilterDialog_CHECK_SELECTED,
+
+        Button uncheckSelectedButton = createButton(buttonComposite,
+                BUTTON_UNCHECK_SELECTED_ID, Messages.TmfTimeFilterDialog_UNCHECK_SELECTED,
+                false);
+        Button uncheckSubtreeButton = createButton(buttonComposite,
+                BUTTON_UNCHECK_SUBTREE_ID, Messages.TmfTimeFilterDialog_UNCHECK_SUBTREE,
                 false);
         Button uncheckAllButton = createButton(buttonComposite,
                 IDialogConstants.DESELECT_ALL_ID, Messages.TmfTimeFilterDialog_UNCHECK_ALL,
                 false);
-        Button uncheckSelectedButton = createButton(buttonComposite,
-                IDialogConstants.CLIENT_ID + 1, Messages.TmfTimeFilterDialog_UNCHECK_SELECTED,
-                false);
+
 
         /*
          * Apply the layout again after creating the buttons to override
          * createButton messing with the columns
          */
-        layout.numColumns = 2;
+        layout.numColumns = 3;
         buttonComposite.setLayout(layout);
 
         /* Add a listener to each button */
-        checkAllButton.addSelectionListener(new SelectionAdapter() {
+        checkSelectedButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                Object[] viewerElements = fContentProvider.getElements(fInput);
+                TreeSelection selection = (TreeSelection) fViewer.getSelection();
 
-                for (int i = 0; i < viewerElements.length; i++) {
-                    fViewer.setSubtreeChecked(viewerElements[i], true);
+                for (Object element : selection.toArray()) {
+                    checkElement(element);
                 }
 
                 updateOKStatus();
             }
         });
 
-        uncheckAllButton.addSelectionListener(new SelectionAdapter() {
+        checkSubtreeButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                fViewer.setCheckedElements(new Object[0]);
+                TreeSelection selection = (TreeSelection) fViewer.getSelection();
+
+                for (Object element : selection.toArray()) {
+                    checkElementAndSubtree(element);
+                }
+            }
+        });
+
+        checkAllButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                Object[] viewerElements = fContentProvider.getElements(fInput);
+
+                for (int i = 0; i < viewerElements.length; i++) {
+                    fViewer.setSubtreeChecked(viewerElements[i], true);
+                }
+
                 updateOKStatus();
             }
         });
 
-        checkSelectedButton.addSelectionListener(new SelectionAdapter() {
+        uncheckSelectedButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 TreeSelection selection = (TreeSelection) fViewer.getSelection();
 
                 for (Object element : selection.toArray()) {
-                    checkElement(element);
+                    uncheckElement(element);
                 }
 
                 updateOKStatus();
             }
         });
 
-        uncheckSelectedButton.addSelectionListener(new SelectionAdapter() {
+        uncheckSubtreeButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 TreeSelection selection = (TreeSelection) fViewer.getSelection();
@@ -432,23 +460,57 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
             }
         });
 
+        uncheckAllButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                fViewer.setCheckedElements(new Object[0]);
+                updateOKStatus();
+            }
+        });
+
         return buttonComposite;
     }
 
+    /**
+     * Check an element and all its parents.
+     *
+     * @param element
+     *            The element to check.
+     */
     private void checkElement(Object element) {
-        Object e = element;
-        while (e != null) {
-            fViewer.setChecked(e, true);
-            e = fContentProvider.getParent(e);
+        fViewer.setChecked(element, true);
+
+        Object parent = fContentProvider.getParent(element);
+
+        if (parent != null) {
+            checkElement(parent);
         }
     }
 
-    private void uncheckElement(Object element) {
-        Object e = element;
+    /**
+     * Check an element, all its parents and all its children.
+     *
+     * @param element
+     *            The element to check.
+     */
+    private void checkElementAndSubtree(Object element) {
+        checkElement(element);
+
+        for (Object child : fContentProvider.getChildren(element)) {
+            checkElementAndSubtree(child);
+        }
+    }
 
-        fViewer.setChecked(e, false);
+    /**
+     * Uncheck an element and all its children.
+     *
+     * @param element
+     *            The element to uncheck.
+     */
+    private void uncheckElement(Object element) {
+        fViewer.setChecked(element, false);
 
-        for (Object child : fContentProvider.getChildren(e)) {
+        for (Object child : fContentProvider.getChildren(element)) {
             uncheckElement(child);
         }
     }
This page took 0.028533 seconds and 5 git commands to generate.