Exemple #1
0
 protected void setWasExpanded(int from, int to) {
   // from == -1: don't expand anything
   // to == -1: expand to end
   // from < to: expand [from, to) (not including to)
   if (from >= 0) {
     while (to < 0 || from < to) {
       if (from >= m_AllRecords.size()) {
         return;
       }
       // System.out.println(from + "+");
       FilterRecord r = m_AllRecords.get(from++);
       r.m_WasExpanded = true;
     }
   }
 }
Exemple #2
0
    public void regenerateDisplay() {
      // Turn off tree updates
      m_FoldingText.setRedraw(false);

      // Show a wait cursor -- this can take a while
      Cursor wait = new Cursor(m_FoldingText.getWindow().getDisplay(), SWT.CURSOR_WAIT);
      m_FoldingText.getWindow().getShell().setCursor(wait);

      // We want to set the selection roughly back to where it was
      // initially (so if we were scrolled to one point in a long trace
      // we stay roughly at the same place) and we want to keep the block
      // where the selection occured either collapsed or not
      // to match the original. All other blocks will be collapsed --
      // which is fast to generate (less UI) and means we don't
      // have to match them all together.
      int selectionPos = m_FoldingText.getTextWindow().getSelection().x;
      Block selectedBlock =
          m_FoldingText.m_FoldingDoc.findBlockByVisibleCharPos(selectionPos, true);

      // The line in the full list of records which is currently selected
      int selectionIndex = (selectedBlock != null ? selectedBlock.getRecordIndex() : -1);
      boolean selectionExpanded = (selectedBlock != null ? selectedBlock.isExpanded() : false);

      // reset m_WasExpanded
      for (FilterRecord r : m_AllRecords) r.m_WasExpanded = false;

      int expandedIndexStart = -1;
      for (Block b : m_FoldingText.m_FoldingDoc.m_TextBlocks) {
        if (b.isExpanded()) {
          if (expandedIndexStart < 0) expandedIndexStart = b.getRecordIndex();
        } else {
          setWasExpanded(expandedIndexStart, b.getRecordIndex());
          expandedIndexStart = -1;
        }
      }
      setWasExpanded(expandedIndexStart, -1);

      Block newSelection = null;

      // Clear the existing text window
      m_FoldingText.getTextWindow().setText("");

      // Clear all existing blocks
      m_FoldingText.m_FoldingDoc.clear();

      int size = m_AllRecords.size();
      for (int i = 0; i < size; i++) {
        FilterRecord record = m_AllRecords.get(i);

        if (show(record.getType())) {
          if (record.isSubText())
            m_FoldingText.appendSubTextInternal(record.getText(), record.m_WasExpanded, i);
          else m_FoldingText.appendTextInternal(record.getText(), record.m_WasExpanded, i);
        }

        // If we reach the point where the previous selection occured
        // record
        // this block as the new location of the selection. It'll be the
        // last block at this moment.
        if (selectionIndex == i) newSelection = m_FoldingText.m_FoldingDoc.m_LastBlock;
      }

      // If we know which block to set the selection to, do so now.
      if (newSelection != null) {
        // Expand or contract it to match the previous state
        // This is a heuristic process--the blocks may not match
        // depending on how the filter is changed.
        m_FoldingText.m_FoldingDoc.expandBlock(newSelection, selectionExpanded);

        // Get the start position of the block and set the selection to
        // that line. This ensures the
        // top of the new selection block is at least visible.
        int newSelectionPos = m_FoldingText.m_FoldingDoc.getBlockSelectionRange(newSelection).x;
        m_FoldingText.setSelection(newSelectionPos, newSelectionPos);

        // Let's go one better and scroll it to the top of the window
        // (actually 15 lines beneath the top so it's "topish" not right
        // at the top)
        int start = newSelection.getStart();
        start = Math.max(start - 15, 0);
        m_FoldingText.getTextWindow().setTopIndex(start);
      }

      // Draw the new tree
      m_FoldingText.setRedraw(true);

      // Set the cursor back to normal
      m_FoldingText.getWindow().getShell().setCursor(null);
      wait.dispose();
    }