try {
tree.setRedraw(false);
fTreeViewer.refresh();
- fTreeViewer.expandToLevel(fTreeViewer.getAutoExpandLevel());
} finally {
tree.setRedraw(true);
}
}
/**
- * 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.
+ * Sets the auto-expand level to be used for new entries discovered when
+ * calling {@link #setInput(Object)} or {@link #refresh()}. 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
private List<TreeItem> getVisibleExpandedItems(Tree tree, boolean refresh) {
if (fVisibleExpandedItems == null || refresh) {
- ArrayList<TreeItem> items = new ArrayList<>();
- for (TreeItem item : tree.getItems()) {
- if (item.getData() == FILLER) {
- break;
- }
- items.add(item);
- if (item.getExpanded()) {
- addVisibleExpandedItems(items, item);
- }
- }
- fVisibleExpandedItems = items;
+ List<TreeItem> visibleExpandedItems = new ArrayList<>();
+ addVisibleExpandedItems(visibleExpandedItems, tree.getItems());
+ fVisibleExpandedItems = visibleExpandedItems;
}
return fVisibleExpandedItems;
}
- private void addVisibleExpandedItems(List<TreeItem> items, TreeItem treeItem) {
- for (TreeItem item : treeItem.getItems()) {
- items.add(item);
- if (item.getExpanded()) {
- addVisibleExpandedItems(items, item);
+ private void addVisibleExpandedItems(List<TreeItem> visibleExpandedItems, TreeItem[] items) {
+ for (TreeItem item : items) {
+ Object data = item.getData();
+ if (data == FILLER) {
+ break;
+ }
+ visibleExpandedItems.add(item);
+ boolean expandedState = fTimeGraphViewer.getExpandedState((ITimeGraphEntry) data);
+ if (item.getExpanded() != expandedState) {
+ /* synchronize the expanded state of both viewers */
+ fTreeViewer.setExpandedState(data, expandedState);
+ }
+ if (expandedState) {
+ addVisibleExpandedItems(visibleExpandedItems, item.getItems());
}
}
}
}
/**
- * 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.
+ * Sets the auto-expand level to be used for new entries discovered when
+ * calling {@link #setInput(Object)} or {@link #refresh()}. 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
return fTimeGraphCtrl.getAutoExpandLevel();
}
+ /**
+ * Get the expanded state of an entry.
+ *
+ * @param entry
+ * The entry
+ * @return true if the entry is expanded, false if collapsed
+ * @since 2.0
+ */
+ public boolean getExpandedState(ITimeGraphEntry entry) {
+ return fTimeGraphCtrl.getExpandedState(entry);
+ }
+
/**
* Set the expanded state of an entry
*
}
/**
- * Expands all nodes of the viewer's tree, starting with the root.
+ * Expands all entries of the viewer's tree, starting with the root.
*/
public void expandAll() {
fTimeGraphCtrl.expandAll();
}
/**
- * Get the number of sub-elements when expanded
+ * Get the number of expanded (visible) time graph entries. This includes
+ * leafs and does not include filtered-out entries.
*
- * @return The element count
+ * @return The number of expanded (visible) time graph entries
*/
public int getExpandedElementCount() {
return fTimeGraphCtrl.getExpandedElementCount();
}
/**
- * Get the sub-elements
+ * Get the expanded (visible) time graph entries. This includes leafs and
+ * does not include filtered-out entries.
*
- * @return The array of entries that are below this one
+ * @return The array of expanded (visible) time graph entries
*/
public ITimeGraphEntry[] getExpandedElements() {
return fTimeGraphCtrl.getExpandedElements();
}
/**
- * 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
+ * Sets the auto-expand level to be used for new entries discovered when
+ * calling {@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
return fAutoExpandLevel;
}
+ /**
+ * Get the expanded state of a given entry.
+ *
+ * @param entry
+ * The entry
+ * @return true if the entry is expanded, false if collapsed
+ * @since 2.0
+ */
+ public boolean getExpandedState(ITimeGraphEntry entry) {
+ Item item = fItemData.fItemMap.get(entry);
+ return (item != null ? item.fExpanded : false);
+ }
+
/**
* Set the expanded state of a given entry
*
}
/**
- * Get the number of expanded items
+ * Get the number of expanded (visible) items
*
- * @return The count of expanded items
+ * @return The count of expanded (visible) items
*/
public int getExpandedElementCount() {
return fItemData.fExpandedItems.length;
}
/**
- * Get an array of all expanded elements
+ * Get an array of all expanded (visible) elements
*
- * @return The expanded elements
+ * @return The expanded (visible) elements
*/
public ITimeGraphEntry[] getExpandedElements() {
ArrayList<ITimeGraphEntry> elements = new ArrayList<>();
}
private class ItemData {
- private final Map<ITimeGraphEntry, Item> fItemMap = new LinkedHashMap<>();
+ private Map<ITimeGraphEntry, Item> fItemMap = new LinkedHashMap<>();
private Item[] fExpandedItems = new Item[0];
private Item[] fItems = new Item[0];
private ITimeGraphEntry fRootEntries[] = new ITimeGraphEntry[0];
}
public void refreshData() {
- fItemMap.clear();
fFilteredOut.clear();
ITimeGraphEntry selection = getSelectedTrace();
+ Map<ITimeGraphEntry, Item> itemMap = new LinkedHashMap<>();
for (int i = 0; i < fRootEntries.length; i++) {
ITimeGraphEntry entry = fRootEntries[i];
- refreshData(fItemMap, null, 0, entry);
+ refreshData(itemMap, null, 0, entry);
}
+ fItemMap = itemMap;
fItems = fItemMap.values().toArray(new Item[0]);
updateExpandedItems();
if (selection != null) {
}
itemMap.put(entry, item);
if (entry.hasChildren()) {
- item.fExpanded = fAutoExpandLevel == ALL_LEVELS || level < fAutoExpandLevel;
+ Item oldItem = fItemMap.get(entry);
+ if (oldItem != null && oldItem.fHasChildren && level == oldItem.fLevel && entry.getParent() == oldItem.fEntry.getParent()) {
+ /* existing items keep their old expanded state */
+ item.fExpanded = oldItem.fExpanded;
+ } else {
+ /* new items set the expanded state according to auto-expand level */
+ item.fExpanded = fAutoExpandLevel == ALL_LEVELS || level < fAutoExpandLevel;
+ }
item.fHasChildren = true;
for (ITimeGraphEntry child : entry.getChildren()) {
refreshData(itemMap, item, level + 1, child);