/** The trace to filters hash map */
private final Map<ITmfTrace, @NonNull ViewerFilter[]> fFiltersMap = new HashMap<>();
+ /** The trace to view context hash map */
+ private final Map<ITmfTrace, ViewContext> fViewContext = new HashMap<>();
+
/** The trace to marker event sources hash map */
private final Map<ITmfTrace, List<IMarkerEventSource>> fMarkerEventSourcesMap = new HashMap<>();
private Comparator<ITimeGraphEntry>[] fColumnComparators;
- /** The sort direction */
- private int fDirection = SWT.DOWN;
-
/** The tree label provider, or null if combo is not used */
private TreeLabelProvider fLabelProvider = null;
/** The default column index for sorting */
private int fInitialSortColumn = 0;
+ /** The default column index for sorting */
+ private int fCurrentSortColumn = 0;
+
+ /** The current sort direction */
+ private int fSortDirection = SWT.DOWN;
+
/** Flag to indicate to reveal selection */
private volatile boolean fIsRevealSelection = false;
TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo();
int getAvailableWidth(int requestedOffset);
+
+ ITimeGraphEntry getSelection();
+
+ void setSelection(ITimeGraphEntry selection);
}
private class TimeGraphViewerWrapper implements ITimeGraphWrapper {
public int getAvailableWidth(int requestedOffset) {
return viewer.getAvailableWidth(requestedOffset);
}
+
+ @Override
+ public ITimeGraphEntry getSelection() {
+ return viewer.getSelection();
+ }
+
+ @Override
+ public void setSelection(ITimeGraphEntry selection) {
+ viewer.setSelection(selection);
+ }
}
private class TimeGraphComboWrapper implements ITimeGraphWrapper {
public int getAvailableWidth(int requestedOffset) {
return combo.getAvailableWidth(requestedOffset);
}
+
+ @Override
+ public ITimeGraphEntry getSelection() {
+ return combo.getTimeGraphViewer().getSelection();
+ }
+
+ @Override
+ public void setSelection(ITimeGraphEntry selection) {
+ combo.setSelection(selection);
+ }
}
/**
fEntryListMap.remove(signal.getTrace());
}
fFiltersMap.remove(signal.getTrace());
+ fViewContext.remove(signal.getTrace());
if (signal.getTrace() == fTrace) {
fTrace = null;
fEditorFile = null;
if (fTrace != null) {
/* save the filters of the previous trace */
fFiltersMap.put(fTrace, fTimeGraphWrapper.getFilters());
+ fViewContext.put(fTrace, new ViewContext(fCurrentSortColumn, fSortDirection, fTimeGraphWrapper.getSelection()));
}
fTrace = trace;
+ restoreViewContext();
fEditorFile = TmfTraceManager.getInstance().getTraceEditorFile(trace);
synchronized (fEntryListMap) {
fEntryList = fEntryListMap.get(fTrace);
}
boolean inputChanged = fEntryList != fTimeGraphWrapper.getInput();
if (inputChanged) {
- fTimeGraphWrapper.setInput(fEntryList);
- /* restore the previously saved filters, if any */
- fTimeGraphWrapper.setFilters(fFiltersMap.get(fTrace));
- fTimeGraphWrapper.getTimeGraphViewer().setLinks(null);
- fTimeGraphWrapper.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile));
- fTimeGraphWrapper.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
- fTimeGraphWrapper.getTimeGraphViewer().setMarkers(null);
- resetColumnSorting();
+ TimeGraphCombo combo = getTimeGraphCombo();
+ try {
+ // Set redraw to false to only draw once
+ if (combo != null) {
+ combo.getTreeViewer().getTree().setRedraw(false);
+ }
+ getTimeGraphViewer().getTimeGraphControl().setRedraw(false);
+ fTimeGraphWrapper.setInput(fEntryList);
+ /* restore the previously saved filters, if any */
+ fTimeGraphWrapper.setFilters(fFiltersMap.get(fTrace));
+ fTimeGraphWrapper.getTimeGraphViewer().setLinks(null);
+ fTimeGraphWrapper.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile));
+ fTimeGraphWrapper.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
+ fTimeGraphWrapper.getTimeGraphViewer().setMarkers(null);
+ applyViewContext();
+ } finally {
+ if (combo != null) {
+ combo.getTreeViewer().getTree().setRedraw(true);
+ }
+ getTimeGraphViewer().getTimeGraphControl().setRedraw(true);
+ }
} else {
fTimeGraphWrapper.refresh();
}
}
// reveal selection
- if (fIsRevealSelection && fTimeGraphWrapper instanceof TimeGraphComboWrapper) {
+ if (fIsRevealSelection) {
fIsRevealSelection = false;
- ITimeGraphEntry entry1 = fTimeGraphWrapper.getTimeGraphViewer().getSelection();
- fTimeGraphWrapper.getTimeGraphViewer().setSelection(entry1);
+ ITimeGraphEntry entry1 = fTimeGraphWrapper.getSelection();
+ fTimeGraphWrapper.setSelection(entry1);
}
if (!zoomThread) {
private void createColumnSelectionListener(TreeViewer treeViewer) {
for (int i = 0; i < fColumnComparators.length; i++) {
- final Comparator<ITimeGraphEntry> comp = fColumnComparators[i];
+ final int index = i;
+ final Comparator<ITimeGraphEntry> comp = fColumnComparators[index];
final Tree tree = treeViewer.getTree();
final TreeColumn column = tree.getColumn(i);
@Override
public void widgetSelected(SelectionEvent e) {
TreeColumn prevSortcolumn = tree.getSortColumn();
+ int direction = tree.getSortDirection();
if (prevSortcolumn == column) {
- fDirection = (fDirection == SWT.DOWN) ? SWT.UP : SWT.DOWN;
+ direction = (direction == SWT.DOWN) ? SWT.UP : SWT.DOWN;
} else {
- fDirection = SWT.DOWN;
+ direction = SWT.DOWN;
}
tree.setSortColumn(column);
- tree.setSortDirection(fDirection);
+ tree.setSortDirection(direction);
+ fSortDirection = direction;
+ fCurrentSortColumn = index;
Comparator<ITimeGraphEntry> comparator = comp;
+
if (comparator instanceof ITimeGraphEntryComparator) {
- ((ITimeGraphEntryComparator) comparator).setDirection(fDirection);
+ ((ITimeGraphEntryComparator) comparator).setDirection(direction);
}
- if (fDirection != SWT.DOWN) {
+ if (direction != SWT.DOWN) {
comparator = checkNotNull(Collections.reverseOrder(comparator));
}
setEntryComparator(comparator);
}
}
- private void resetColumnSorting() {
- if ((fTimeGraphWrapper instanceof TimeGraphComboWrapper) && (fColumnComparators != null)) {
- TreeViewer treeViewer = ((TimeGraphComboWrapper) fTimeGraphWrapper).getTreeViewer();
- fDirection = SWT.DOWN;
- if ((fInitialSortColumn < fColumnComparators.length) && (fColumnComparators[fInitialSortColumn] != null)) {
- setEntryComparator(fColumnComparators[fInitialSortColumn]);
+ private void restoreViewContext() {
+ TimeGraphCombo combo = getTimeGraphCombo();
+ ViewContext viewContext = fViewContext.get(fTrace);
+ if (combo != null) {
+ if (fColumnComparators != null) {
+ // restore sort settings
+ fSortDirection = SWT.DOWN;
+ fCurrentSortColumn = fInitialSortColumn;
+ if (viewContext != null) {
+ fSortDirection = viewContext.getSortDirection();
+ fCurrentSortColumn = viewContext.getSortColumn();
+ }
+ if ((fCurrentSortColumn < fColumnComparators.length) && (fColumnComparators[fCurrentSortColumn] != null)) {
+ Comparator<ITimeGraphEntry> comparator = fColumnComparators[fCurrentSortColumn];
+ if (comparator instanceof ITimeGraphEntryComparator) {
+ ((ITimeGraphEntryComparator) comparator).setDirection(fSortDirection);
+ }
+ if (fSortDirection != SWT.DOWN) {
+ comparator = checkNotNull(Collections.reverseOrder(comparator));
+ }
+ setEntryComparator(comparator);
+ }
}
+ }
+ }
+
+ private void applyViewContext() {
+ TimeGraphCombo combo = getTimeGraphCombo();
+ ViewContext viewContext = fViewContext.get(fTrace);
+ if (combo != null) {
+ TreeViewer treeViewer = combo.getTreeViewer();
final Tree tree = treeViewer.getTree();
- final TreeColumn column = tree.getColumn(fInitialSortColumn);
- tree.setSortDirection(fDirection);
+ final TreeColumn column = tree.getColumn(fCurrentSortColumn);
+ tree.setSortDirection(fSortDirection);
tree.setSortColumn(column);
+ combo.getTreeViewer().getControl().setFocus();
+ }
+ // restore and reveal selection
+ if ((viewContext != null) && (viewContext.getSelection() != null)) {
+ fTimeGraphWrapper.setSelection(viewContext.getSelection());
+ }
+ fViewContext.remove(fTrace);
+ }
+
+ private static class ViewContext {
+ private int fSortColumnIndex;
+ private int fSortDirection;
+ private @Nullable ITimeGraphEntry fSelection;
+
+ ViewContext(int sortColunm, int sortDirection, ITimeGraphEntry selection) {
+ fSortColumnIndex = sortColunm;
+ fSortDirection = sortDirection;
+ fSelection = selection;
+ }
+ /**
+ * @return the sortColumn
+ */
+ public int getSortColumn() {
+ return fSortColumnIndex;
+ }
+ /**
+ * @return the sortDirection
+ */
+ public int getSortDirection() {
+ return fSortDirection;
+ }
+ /**
+ * @return the selection
+ */
+ public ITimeGraphEntry getSelection() {
+ return fSelection;
}
}
}