TMF: added support for process filter in the TimeGraphFilterDialog.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / dialogs / TimeGraphFilterDialog.java
index b2b1c8d3a8098a118ebf7a5e85e0bc3e8333ed39..76465cd0710690bcbcebb3c2353b8878100ee3bb 100644 (file)
@@ -14,6 +14,7 @@
  *          align the selection buttons to the right
  *      François Rajotte - Support for multiple columns + selection control
  *      Patrick Tasse - Fix Sonar warnings
+ *      Generoso Pagano - Add tree filter
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs;
@@ -50,12 +51,13 @@ import org.eclipse.swt.widgets.Tree;
 import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+import org.eclipse.ui.dialogs.PatternFilter;
 import org.eclipse.ui.dialogs.SelectionStatusDialog;
 
 /**
- * Filter dialog for the time graphs
- * This class is derived from the CheckedTreeSelectionDialog
- * It was necessary to develop this similar dialog to allow multiple columns
+ * Filter dialog for the time graphs This class is derived from the
+ * CheckedTreeSelectionDialog It was necessary to develop this similar dialog to
+ * allow multiple columns
  *
  * @version 1.0
  * @since 2.0
@@ -70,7 +72,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
     private static final int DEFAULT_WIDTH = 60;
     private static final int DEFAULT_HEIGHT = 18;
 
-    private CheckboxTreeViewer fViewer;
+    private FilteredCheckboxTree fTree;
 
     private IBaseLabelProvider fLabelProvider;
 
@@ -205,21 +207,24 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
     }
 
     /**
-     * @param contentProvider The content provider for the table
+     * @param contentProvider
+     *            The content provider for the table
      */
     public void setContentProvider(ITreeContentProvider contentProvider) {
         fContentProvider = contentProvider;
     }
 
     /**
-     * @param labelProvider The label provider for the table
+     * @param labelProvider
+     *            The label provider for the table
      */
     public void setLabelProvider(IBaseLabelProvider labelProvider) {
         fLabelProvider = labelProvider;
     }
 
     /**
-     * @param columnNames An array of column names to display
+     * @param columnNames
+     *            An array of column names to display
      */
     public void setColumnNames(String[] columnNames) {
         if (columnNames != null) {
@@ -236,7 +241,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
     protected void updateOKStatus() {
         if (!fIsEmpty) {
             if (fValidator != null) {
-                fCurrStatus = fValidator.validate(fViewer.getCheckedElements());
+                fCurrStatus = fValidator.validate(fTree.getCheckedElements());
                 updateStatus(fCurrStatus);
             } else if (!fCurrStatus.isOK()) {
                 fCurrStatus = new Status(IStatus.OK, PlatformUI.PLUGIN_ID,
@@ -265,7 +270,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
 
     @Override
     protected void computeResult() {
-        setResult(Arrays.asList(fViewer.getCheckedElements()));
+        setResult(Arrays.asList(fTree.getCheckedElements()));
     }
 
     @Override
@@ -274,10 +279,10 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
             @Override
             public void run() {
                 TimeGraphFilterDialog.super.create();
-                fViewer.setCheckedElements(getInitialElementSelections()
+                fTree.setCheckedElements(getInitialElementSelections()
                         .toArray());
                 if (fExpandedElements != null) {
-                    fViewer.setExpandedElements(fExpandedElements);
+                    fTree.getViewer().setExpandedElements(fExpandedElements);
                 }
                 updateOKStatus();
             }
@@ -312,9 +317,11 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
      * @return the tree viewer
      */
     protected CheckboxTreeViewer createTreeViewer(Composite parent) {
-        fViewer = new CheckboxTreeViewer(parent, SWT.BORDER | SWT.MULTI);
+        PatternFilter filter = new TreePatternFilter();
+        filter.setIncludeLeadingWildcard(true);
+        fTree = new FilteredCheckboxTree(parent, SWT.BORDER | SWT.MULTI, filter, true);
 
-        Tree tree = fViewer.getTree();
+        Tree tree = fTree.getViewer().getTree();
         tree.setHeaderVisible(true);
         for (String columnName : fColumnNames) {
             TreeColumn column = new TreeColumn(tree, SWT.LEFT);
@@ -322,28 +329,22 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
             column.pack();
         }
 
-        fViewer.setContentProvider(fContentProvider);
-        fViewer.setLabelProvider(fLabelProvider);
-        fViewer.addCheckStateListener(new CheckStateListener());
-        fViewer.addCheckStateListener(new ICheckStateListener() {
-            @Override
-            public void checkStateChanged(CheckStateChangedEvent event) {
-                updateOKStatus();
-            }
-        });
-        fViewer.setComparator(fComparator);
+        fTree.getViewer().setContentProvider(fContentProvider);
+        fTree.getViewer().setLabelProvider(fLabelProvider);
+        fTree.addCheckStateListener(new CheckStateListener());
+        fTree.getViewer().setComparator(fComparator);
         if (fFilters != null) {
             for (int i = 0; i != fFilters.size(); i++) {
-                fViewer.addFilter(fFilters.get(i));
+                fTree.getViewer().addFilter(fFilters.get(i));
             }
         }
-        fViewer.setInput(fInput);
+        fTree.getViewer().setInput(fInput);
 
-        //pack the columns again for a nice view...
+        // pack the columns again for a nice view...
         for (TreeColumn column : tree.getColumns()) {
             column.pack();
         }
-        return fViewer;
+        return (CheckboxTreeViewer) fTree.getViewer();
     }
 
     /**
@@ -352,7 +353,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
      * @return the tree viewer
      */
     protected CheckboxTreeViewer getTreeViewer() {
-        return fViewer;
+        return (CheckboxTreeViewer) fTree.getViewer();
     }
 
     /**
@@ -395,7 +396,6 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
                 IDialogConstants.DESELECT_ALL_ID, Messages.TmfTimeFilterDialog_UNCHECK_ALL,
                 false);
 
-
         /*
          * Apply the layout again after creating the buttons to override
          * createButton messing with the columns
@@ -407,7 +407,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
         checkSelectedButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                TreeSelection selection = (TreeSelection) fViewer.getSelection();
+                TreeSelection selection = (TreeSelection) fTree.getViewer().getSelection();
 
                 for (Object element : selection.toArray()) {
                     checkElement(element);
@@ -420,7 +420,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
         checkSubtreeButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                TreeSelection selection = (TreeSelection) fViewer.getSelection();
+                TreeSelection selection = (TreeSelection) fTree.getViewer().getSelection();
 
                 for (Object element : selection.toArray()) {
                     checkElementAndSubtree(element);
@@ -434,7 +434,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
                 Object[] viewerElements = fContentProvider.getElements(fInput);
 
                 for (int i = 0; i < viewerElements.length; i++) {
-                    fViewer.setSubtreeChecked(viewerElements[i], true);
+                    fTree.setSubtreeChecked(viewerElements[i], true);
                 }
 
                 updateOKStatus();
@@ -444,7 +444,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
         uncheckSelectedButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                TreeSelection selection = (TreeSelection) fViewer.getSelection();
+                TreeSelection selection = (TreeSelection) fTree.getViewer().getSelection();
 
                 for (Object element : selection.toArray()) {
                     uncheckElement(element);
@@ -457,7 +457,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
         uncheckSubtreeButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                TreeSelection selection = (TreeSelection) fViewer.getSelection();
+                TreeSelection selection = (TreeSelection) fTree.getViewer().getSelection();
 
                 for (Object element : selection.toArray()) {
                     uncheckElement(element);
@@ -470,7 +470,13 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
         uncheckAllButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                fViewer.setCheckedElements(new Object[0]);
+                Object[] viewerElements = fContentProvider.getElements(fInput);
+                for (Object element : viewerElements) {
+                    if (fTree.getViewer().testFindItem(element) != null) {
+                        // uncheck only visible roots and their children
+                        uncheckElement(element);
+                    }
+                }
                 updateOKStatus();
             }
         });
@@ -485,11 +491,11 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
      *            The element to check.
      */
     private void checkElement(Object element) {
-        fViewer.setChecked(element, true);
+        fTree.setChecked(element, true);
 
         Object parent = fContentProvider.getParent(element);
 
-        if (parent != null) {
+        if (parent != null && !fTree.getChecked(parent)) {
             checkElement(parent);
         }
     }
@@ -515,7 +521,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
      *            The element to uncheck.
      */
     private void uncheckElement(Object element) {
-        fViewer.setChecked(element, false);
+        fTree.setChecked(element, false);
 
         for (Object child : fContentProvider.getChildren(element)) {
             uncheckElement(child);
@@ -527,7 +533,7 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
         if (elements.length > 0 && fFilters != null) {
             for (int i = 0; i < fFilters.size(); i++) {
                 ViewerFilter curr = fFilters.get(i);
-                elements = curr.filter(fViewer, input, elements);
+                elements = curr.filter(fTree.getViewer(), input, elements);
             }
         }
         return elements.length == 0;
@@ -554,7 +560,10 @@ public class TimeGraphFilterDialog extends SelectionStatusDialog {
                 }
             } catch (ClassCastException e) {
                 return;
+            } finally {
+                updateOKStatus();
             }
         }
+
     }
-}
+}
\ No newline at end of file
This page took 0.030698 seconds and 5 git commands to generate.