tmf: Support auto-expand level in time graph widgets
authorPatrick Tasse <patrick.tasse@gmail.com>
Fri, 20 Jun 2014 15:39:40 +0000 (11:39 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Tue, 8 Jul 2014 15:45:26 +0000 (11:45 -0400)
Change-Id: Ide5bf142c251349eaf0c757da3390f6151934695
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/28822
Tested-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java

index b99936dbb2f2fee59bda86902baeac9cd2934d55..ecffa3e8db615544d2ff2472f5c14a297074c7e2 100644 (file)
@@ -79,6 +79,10 @@ public class TimeGraphCombo extends Composite {
     // Constants
     // ------------------------------------------------------------------------
 
+    /** Constant indicating that all levels of the time graph should be expanded
+     * @since 3.1 */
+    public static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
+
     private static final Object FILLER = new Object();
 
     private static final String ITEM_HEIGHT = "$height$"; //$NON-NLS-1$
@@ -936,6 +940,41 @@ public class TimeGraphCombo extends Composite {
         alignTreeItems(false);
     }
 
+    /**
+     * Sets the auto-expand level to be used when the input of the viewer is set
+     * using {@link #setInput(Object)}. The value 0 means that there is no
+     * auto-expand; 1 means that top-level elements are expanded, but not their
+     * children; 2 means that top-level elements are expanded, and their
+     * children, but not grand-children; and so on.
+     * <p>
+     * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
+     * </p>
+     * @param level
+     *            non-negative level, or <code>ALL_LEVELS</code> to expand all
+     *            levels of the tree
+     * @since 3.1
+     */
+    public void setAutoExpandLevel(int level) {
+        fTimeGraphViewer.setAutoExpandLevel(level);
+        if (level <= 0) {
+            fTreeViewer.setAutoExpandLevel(level);
+        } else {
+            fTreeViewer.setAutoExpandLevel(level + 1);
+        }
+    }
+
+    /**
+     * Returns the auto-expand level.
+     *
+     * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
+     *         the tree are expanded automatically
+     * @see #setAutoExpandLevel
+     * @since 3.1
+     */
+    public int getAutoExpandLevel() {
+        return fTimeGraphViewer.getAutoExpandLevel();
+    }
+
     /**
      * Set the expanded state of an entry
      *
index 88b91a754f8dee9f1151f0c89958fab4262cee03..85f3c78ee3f03695d8c36676cf798f0f16cf75ec 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
@@ -66,6 +67,10 @@ import org.eclipse.swt.widgets.Slider;
  */
 public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
 
+    /** Constant indicating that all levels of the time graph should be expanded
+     * @since 3.1 */
+    public static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
+
     private static final int DEFAULT_NAME_WIDTH = 200;
     private static final int MIN_NAME_WIDTH = 6;
     private static final int MAX_NAME_WIDTH = 1000;
@@ -1272,6 +1277,36 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         return fTimeGraphCtrl.getTopIndex();
     }
 
+    /**
+     * Sets the auto-expand level to be used when the input of the viewer is set
+     * using {@link #setInput(Object)}. The value 0 means that there is no
+     * auto-expand; 1 means that top-level elements are expanded, but not their
+     * children; 2 means that top-level elements are expanded, and their
+     * children, but not grand-children; and so on.
+     * <p>
+     * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
+     * </p>
+     * @param level
+     *            non-negative level, or <code>ALL_LEVELS</code> to expand all
+     *            levels of the tree
+     * @since 3.1
+     */
+    public void setAutoExpandLevel(int level) {
+        fTimeGraphCtrl.setAutoExpandLevel(level);
+    }
+
+    /**
+     * Returns the auto-expand level.
+     *
+     * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
+     *         the tree are expanded automatically
+     * @see #setAutoExpandLevel
+     * @since 3.1
+     */
+    public int getAutoExpandLevel() {
+        return fTimeGraphCtrl.getAutoExpandLevel();
+    }
+
     /**
      * Set the expanded state of an entry
      *
index e38fd420e4d695094e370224388385275e73b9a5..a2bf16d7461fe932d639d10619be01d14e46529d 100644 (file)
@@ -29,6 +29,7 @@ import java.util.Map;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
@@ -92,6 +93,10 @@ public class TimeGraphControl extends TimeGraphBaseControl
     /** Max scrollbar size */
     public static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;
 
+    /** Constant indicating that all levels of the time graph should be expanded
+     * @since 3.1 */
+    public static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
+
     private static final int DRAG_NONE = 0;
     private static final int DRAG_TRACE_ITEM = 1;
     private static final int DRAG_SPLIT_LINE = 2;
@@ -145,6 +150,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
     private final List<ViewerFilter> fFilters = new ArrayList<>();
     private MenuDetectEvent fPendingMenuDetectEvent = null;
     private boolean fHideArrows = false;
+    private int fAutoExpandLevel = ALL_LEVELS;
 
     private int fBorderWidth = 0;
     private int fHeaderHeight = 0;
@@ -481,6 +487,37 @@ public class TimeGraphControl extends TimeGraphBaseControl
         redraw();
     }
 
+    /**
+     * Sets the auto-expand level to be used when the entries are refreshed
+     * using {@link #refreshData()} or {@link #refreshData(ITimeGraphEntry[])}.
+     * The value 0 means that there is no auto-expand; 1 means that top-level
+     * entries are expanded, but not their children; 2 means that top-level
+     * entries are expanded, and their children, but not grand-children; and so
+     * on.
+     * <p>
+     * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
+     * </p>
+     * @param level
+     *            non-negative level, or <code>ALL_LEVELS</code> to expand all
+     *            levels of the tree
+     * @since 3.1
+     */
+    public void setAutoExpandLevel(int level) {
+        fAutoExpandLevel = level;
+    }
+
+    /**
+     * Returns the auto-expand level.
+     *
+     * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
+     *         the tree are expanded automatically
+     * @see #setAutoExpandLevel
+     * @since 3.1
+     */
+    public int getAutoExpandLevel() {
+        return fAutoExpandLevel;
+    }
+
     /**
      * Set the expanded state of a given entry
      *
@@ -2468,7 +2505,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
             }
             itemMap.put(entry, item);
             if (entry.hasChildren()) {
-                item.fExpanded = true;
+                item.fExpanded = fAutoExpandLevel == ALL_LEVELS || level < fAutoExpandLevel;
                 item.fHasChildren = true;
                 for (ITimeGraphEntry child : entry.getChildren()) {
                     refreshData(itemMap, item, level + 1, child);
This page took 0.03011 seconds and 5 git commands to generate.