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>
public static String TmfTimeFilterDialog_UNCHECK_ALL;
public static String TmfTimeFilterDialog_CHECK_SELECTED;
public static String TmfTimeFilterDialog_UNCHECK_SELECTED;
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;
public static String TmfTimeTipHandler_DURATION;
public static String TmfTimeTipHandler_TRACE_DATE;
TmfTimeFilterDialog_UNCHECK_ALL=Uncheck all
TmfTimeFilterDialog_CHECK_SELECTED=Check selected
TmfTimeFilterDialog_UNCHECK_SELECTED=Uncheck selected
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
# org.eclipse.linuxtools.tmf.ui.viewers.timegraph.widgets
TmfTimeTipHandler_DURATION=Duration
* @author François Rajotte
*/
public class TimeGraphFilterDialog extends 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;
private CheckboxTreeViewer fViewer;
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite = new Composite(composite, SWT.RIGHT);
GridLayout layout = new GridLayout();
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite = new Composite(composite, SWT.RIGHT);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
buttonComposite.setLayout(layout);
layout.marginWidth = 0;
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
buttonComposite.setLayout(layout);
buttonComposite.setLayoutData(data);
/* Create the buttons in the good order to place them as we want */
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 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);
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
*/
/*
* Apply the layout again after creating the buttons to override
* createButton messing with the columns
*/
buttonComposite.setLayout(layout);
/* Add a listener to each button */
buttonComposite.setLayout(layout);
/* Add a listener to each button */
- checkAllButton.addSelectionListener(new SelectionAdapter() {
+ checkSelectedButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@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();
}
});
}
updateOKStatus();
}
});
- uncheckAllButton.addSelectionListener(new SelectionAdapter() {
+ checkSubtreeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@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);
+ }
+
- checkSelectedButton.addSelectionListener(new SelectionAdapter() {
+ uncheckSelectedButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TreeSelection selection = (TreeSelection) fViewer.getSelection();
for (Object element : selection.toArray()) {
@Override
public void widgetSelected(SelectionEvent e) {
TreeSelection selection = (TreeSelection) fViewer.getSelection();
for (Object element : selection.toArray()) {
+ uncheckElement(element);
}
updateOKStatus();
}
});
}
updateOKStatus();
}
});
- uncheckSelectedButton.addSelectionListener(new SelectionAdapter() {
+ uncheckSubtreeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TreeSelection selection = (TreeSelection) fViewer.getSelection();
@Override
public void widgetSelected(SelectionEvent e) {
TreeSelection selection = (TreeSelection) fViewer.getSelection();
+ uncheckAllButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fViewer.setCheckedElements(new Object[0]);
+ updateOKStatus();
+ }
+ });
+
return buttonComposite;
}
return buttonComposite;
}
+ /**
+ * Check an element and all its parents.
+ *
+ * @param element
+ * The element to check.
+ */
private void checkElement(Object element) {
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);
}
}
uncheckElement(child);
}
}