From 8906e53cb9e1a07afbccbe95df8658526a4ca56a Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 14 Mar 2013 14:53:05 -0400 Subject: [PATCH] Add multiple selection in the time graph filter dialog MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * 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 Signed-off-by: François Rajotte Reviewed-on: https://git.eclipse.org/r/11170 Reviewed-by: Alexandre Montplaisir Tested-by: Alexandre Montplaisir Tested-by: Hudson CI IP-Clean: Alexandre Montplaisir Reviewed-by: Matthew Khouzam IP-Clean: Matthew Khouzam Tested-by: Matthew Khouzam --- .../linuxtools/internal/tmf/ui/Messages.java | 6 +- .../internal/tmf/ui/messages.properties | 6 +- .../dialogs/TimeGraphFilterDialog.java | 145 ++++++++++-------- 3 files changed, 92 insertions(+), 65 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java index 8251105645..059a487926 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java @@ -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; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties index c85d0a04f5..db97d10d7b 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties @@ -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 diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphFilterDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphFilterDialog.java index c8d50e205c..c8956ed180 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphFilterDialog.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphFilterDialog.java @@ -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(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()); - } - } } } -- 2.34.1