Add multiple selection in the time graph filter dialog
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 14 Mar 2013 18:53:05 +0000 (14:53 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 18 Mar 2013 19:46:40 +0000 (15:46 -0400)
* Add "(un)check selected" buttons
* Change "(de)select all" to "(un)check all"
* Remove container mode option

Change-Id: Id002dc2f93589f2e8c209c87598476ba3f4006c0
Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Signed-off-by: François Rajotte <francois.rajotte@polymtl.ca>
Reviewed-on: https://git.eclipse.org/r/11170
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
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 82511056453baea7f08ad608e2adfae376976a09..059a487926aa582af7c6c9451f700bcf9a7376f0 100644 (file)
@@ -101,8 +101,10 @@ public class Messages extends NLS {
     public static String TmfTimeLegend_StateTypeName;
     public static String TmfTimeFilterDialog_WINDOW_TITLE;
     public static String TmfTimeFilterDialog_MESSAGE;
-    public static String TmfTimeFilterDialog_SELECT_ALL;
-    public static String TmfTimeFilterDialog_DESELECT_ALL;
+    public static String TmfTimeFilterDialog_CHECK_ALL;
+    public static String TmfTimeFilterDialog_UNCHECK_ALL;
+    public static String TmfTimeFilterDialog_CHECK_SELECTED;
+    public static String TmfTimeFilterDialog_UNCHECK_SELECTED;
 
     public static String TmfTimeTipHandler_DURATION;
     public static String TmfTimeTipHandler_TRACE_DATE;
index c85d0a04f5d9f9c11af0e0ee03ef2cd5e92b83e4..db97d10d7b9f4c762a5ddec6e22a4ab468214553 100644 (file)
@@ -84,8 +84,10 @@ TmfTimeLegend_WINDOW_TITLE=Trace Visualizer's Legend
 TmfTimeLegend_StateTypeName=States
 TmfTimeFilterDialog_WINDOW_TITLE=Filter
 TmfTimeFilterDialog_MESSAGE=Check the entries to show
-TmfTimeFilterDialog_SELECT_ALL=Select all
-TmfTimeFilterDialog_DESELECT_ALL=Deselect all
+TmfTimeFilterDialog_CHECK_ALL=Check all
+TmfTimeFilterDialog_UNCHECK_ALL=Uncheck all
+TmfTimeFilterDialog_CHECK_SELECTED=Check selected
+TmfTimeFilterDialog_UNCHECK_SELECTED=Uncheck selected
 
 # org.eclipse.linuxtools.tmf.ui.viewers.timegraph.widgets
 TmfTimeTipHandler_DURATION=Duration
index c8d50e205c30e53b9bcd2515c0469bf9589a8e6d..c8956ed1800a9f464c1324b8ba6da3f06d814fd4 100644 (file)
@@ -29,6 +29,7 @@ import org.eclipse.jface.viewers.CheckboxTreeViewer;
 import org.eclipse.jface.viewers.IBaseLabelProvider;
 import org.eclipse.jface.viewers.ICheckStateListener;
 import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.linuxtools.internal.tmf.ui.Messages;
@@ -37,7 +38,6 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.BusyIndicator;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
@@ -48,7 +48,6 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Tree;
 import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
 import org.eclipse.ui.dialogs.ISelectionStatusValidator;
 import org.eclipse.ui.dialogs.SelectionStatusDialog;
 
@@ -90,8 +89,6 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
 
     private int fHeight = 18;
 
-    private boolean fContainerMode;
-
     private Object[] fExpandedElements;
 
     /**
@@ -105,21 +102,9 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
         setResult(new ArrayList<Object>(0));
         setStatusLineAboveButtons(true);
         setHelpAvailable(false);
-        fContainerMode = false;
         fExpandedElements = null;
     }
 
-    /**
-     * If set, the checked /gray state of containers (inner nodes) is derived
-     * from the checked state of its leaf nodes.
-     *
-     * @param containerMode
-     *            The containerMode to set
-     */
-    public void setContainerMode(boolean containerMode) {
-        fContainerMode = containerMode;
-    }
-
     /**
      * Sets the initial selection. Convenience method.
      *
@@ -315,11 +300,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
      * @return the tree viewer
      */
     protected CheckboxTreeViewer createTreeViewer(Composite parent) {
-        if (fContainerMode) {
-            fViewer = new ContainerCheckedTreeViewer(parent, SWT.BORDER);
-        } else {
-            fViewer = new CheckboxTreeViewer(parent, SWT.BORDER);
-        }
+        fViewer = new CheckboxTreeViewer(parent, SWT.BORDER | SWT.MULTI);
 
         Tree tree = fViewer.getTree();
         tree.setHeaderVisible(true);
@@ -372,7 +353,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
     protected Composite createSelectionButtons(Composite composite) {
         Composite buttonComposite = new Composite(composite, SWT.RIGHT);
         GridLayout layout = new GridLayout();
-        layout.numColumns = 0;
+        layout.numColumns = 2;
         layout.marginWidth = 0;
         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
         buttonComposite.setLayout(layout);
@@ -381,38 +362,97 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
                 | GridData.GRAB_HORIZONTAL);
         data.grabExcessHorizontalSpace = true;
         buttonComposite.setLayoutData(data);
-        Button selectButton = createButton(buttonComposite,
-                IDialogConstants.SELECT_ALL_ID, Messages.TmfTimeFilterDialog_SELECT_ALL,
+
+        /* Create the buttons in the good order to place them as we want */
+        Button checkAllButton = createButton(buttonComposite,
+                IDialogConstants.SELECT_ALL_ID, Messages.TmfTimeFilterDialog_CHECK_ALL,
+                false);
+        Button checkSelectedButton = createButton(buttonComposite,
+                IDialogConstants.CLIENT_ID, Messages.TmfTimeFilterDialog_CHECK_SELECTED,
+                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);
-        SelectionListener listener = new SelectionAdapter() {
+
+        /*
+         * Apply the layout again after creating the buttons to override
+         * createButton messing with the columns
+         */
+        layout.numColumns = 2;
+        buttonComposite.setLayout(layout);
+
+        /* Add a listener to each button */
+        checkAllButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 Object[] viewerElements = fContentProvider.getElements(fInput);
-                if (fContainerMode) {
-                    fViewer.setCheckedElements(viewerElements);
-                } else {
-                    for (int i = 0; i < viewerElements.length; i++) {
-                        fViewer.setSubtreeChecked(viewerElements[i], true);
-                    }
+
+                for (int i = 0; i < viewerElements.length; i++) {
+                    fViewer.setSubtreeChecked(viewerElements[i], true);
                 }
+
                 updateOKStatus();
             }
-        };
-        selectButton.addSelectionListener(listener);
-        Button deselectButton = createButton(buttonComposite,
-                IDialogConstants.DESELECT_ALL_ID, Messages.TmfTimeFilterDialog_DESELECT_ALL,
-                false);
-        listener = new SelectionAdapter() {
+        });
+
+        uncheckAllButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 fViewer.setCheckedElements(new Object[0]);
                 updateOKStatus();
             }
-        };
-        deselectButton.addSelectionListener(listener);
+        });
+
+        checkSelectedButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                TreeSelection selection = (TreeSelection) fViewer.getSelection();
+
+                for (Object element : selection.toArray()) {
+                    checkElement(element);
+                }
+
+                updateOKStatus();
+            }
+        });
+
+        uncheckSelectedButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                TreeSelection selection = (TreeSelection) fViewer.getSelection();
+
+                for (Object element : selection.toArray()) {
+                    uncheckElement(element);
+                }
+
+                updateOKStatus();
+            }
+        });
+
         return buttonComposite;
     }
 
+    private void checkElement(Object element) {
+        Object e = element;
+        while (e != null) {
+            fViewer.setChecked(e, true);
+            e = fContentProvider.getParent(e);
+        }
+    }
+
+    private void uncheckElement(Object element) {
+        Object e = element;
+
+        fViewer.setChecked(e, false);
+
+        for (Object child : fContentProvider.getChildren(e)) {
+            uncheckElement(child);
+        }
+    }
+
     private boolean evaluateIfTreeEmpty(Object input) {
         Object[] elements = fContentProvider.getElements(input);
         if (elements.length > 0) {
@@ -434,37 +474,20 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
 
         CheckStateListener() {
         }
+
         @Override
         public void checkStateChanged(CheckStateChangedEvent event) {
             try {
                 ITimeGraphEntry entry = (ITimeGraphEntry) event.getElement();
                 boolean checked = event.getChecked();
-                if (!checked) {
-                    uncheckChildren(entry);
-                }
-                else
-                {
-                    checkParent(entry);
+                if (checked) {
+                    checkElement(entry);
+                } else {
+                    uncheckElement(entry);
                 }
             } catch (ClassCastException e) {
                 return;
             }
         }
-
-        private void uncheckChildren(ITimeGraphEntry entry) {
-
-            for (ITimeGraphEntry child : entry.getChildren()) {
-                getTreeViewer().setChecked(child, false);
-                uncheckChildren(child);
-            }
-        }
-
-        private void checkParent(ITimeGraphEntry entry) {
-
-            if (entry.getParent() != null) {
-                getTreeViewer().setChecked(entry.getParent(), true);
-                checkParent(entry.getParent());
-            }
-        }
     }
 }
This page took 0.038917 seconds and 5 git commands to generate.