UndoRedo V1.2
by Matthew Ford
2005/06/27

au.com.forward.undoRedo
Interface IHaveDescription

All Known Implementing Classes:
BranchDefaultMutableTreeNode, UndoRedoEdit

public interface IHaveDescription

This interface indicates that the UndoableEdit has a long description that gives more information then the getPresentationName()


Method Summary
 void cancelGetDescription()
          Cancels getDescription(au.com.forward.undoRedo.IDisplayText, au.com.forward.undoRedo.UndoRedoTreeNode).
 void getDescription(IDisplayText textDisplay, UndoRedoTreeNode undoRedoTreeNode)
          Gets the Description of the UndoableEdit.
 

Method Detail

getDescription

void getDescription(IDisplayText textDisplay,
                    UndoRedoTreeNode undoRedoTreeNode)
Gets the Description of the UndoableEdit.
If getting the description will take some time, such as generating a diff for example. Then display a short message and start a thread to call back to the textDisplay.setText() when the description is ready.
If the selection has changed before textDisplay.setText() is called, then the text is discarded.
cancelGetDescription() is called when the selection changes and the text is no longer needed.

A possiable implementation is:-

      volatile Thread loadThread = null;
      volatile boolean interrupted = false;
      public void getDescription(IDisplayText textDisplay, boolean ) {
          interrupted = false;
          textDisplay.setText("Loading description...");
          final IDisplayText display = textDisplay;
          Thread loadThread = new Thread(new Runnable() {
              public void run() {
                  if (interrupted) {
                      // got interrupt befor we could start.
                      // add more tests like this one to stop the thread promptly on interrupt()
                      return;
                  }
                  try {
                      // create description here checking interrupted every so often
                      display.setText(description);
                  } catch (Throwable t) {
                      try {
                          display.setText("Error getting description.\n"+t.getMessage());
                      } catch(Throwable tt) {
                          // log this serious error somewhere...
                      }
                  }
              }
          });
          loadThread.start();
      }

      public void cancelGetDescription() {
          interrupted = true;
          if (loadThread != null) {
              loadThread.interrupt();
          }
      }


cancelGetDescription

void cancelGetDescription()
Cancels getDescription(au.com.forward.undoRedo.IDisplayText, au.com.forward.undoRedo.UndoRedoTreeNode).
This is called when the undo/redo tree selection changes to cancel the previous getDescription.


©2005, Forward Computing and Control Pty. Ltd
ACN 003 669 994   NSW Australia
All Rights Reserved.