Changeset 6096
- Timestamp:
- 2003-12-02T17:26:37+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/SynchronizedTreeModelTools.java
r5581 r6096 37 37 public class SynchronizedTreeModelTools { 38 38 /** Adds an insertNodeInto model update onto the AWT Event queue. This gets around the lack of synchronization illustrated above. */ 39 static final public Runnable insertNodeInto(final DefaultTreeModel model, final MutableTreeNode parent, final MutableTreeNode target_node) { 39 static final public Runnable insertNodeInto(DefaultTreeModel model, MutableTreeNode parent, MutableTreeNode target_node) { 40 return insertNodeInto(model, parent, target_node, true); 41 } 42 43 static final public Runnable insertNodeInto(final DefaultTreeModel model, final MutableTreeNode parent, final MutableTreeNode target_node, boolean wait_allowed) { 40 44 final Runnable doInsertNodeInto = new Runnable() { 41 45 public void run() { 46 ///ystem.err.print("Running task... "); 42 47 int index = -1; 43 48 int pos = 0; … … 70 75 } 71 76 }; 77 ///ystem.err.print("Queuing Task... "); 72 78 try { 73 //SwingUtilities.invokeLater(doInsertNodeInto); 74 SwingUtilities.invokeAndWait(doInsertNodeInto); 79 if(wait_allowed && !SwingUtilities.isEventDispatchThread()) { 80 ///ystem.err.print("In another thread - invoke and wait... "); 81 SwingUtilities.invokeAndWait(doInsertNodeInto); 82 } 83 else { 84 ///ystem.err.print("In Event Thread or wait not allowed - invoke later... "); 85 SwingUtilities.invokeLater(doInsertNodeInto); 86 } 75 87 } 76 88 catch (Exception e) { 77 89 e.printStackTrace(); 78 90 } 79 // If (and only if) we've thrown an error because we tried to invoke the runnable task and wait, when we are in the AWTEvent thread already, then try agin but with an invoke later. 80 catch (java.lang.Error error) { 81 if(error.toString().equals("java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread")) { 82 SwingUtilities.invokeLater(doInsertNodeInto); 83 } 84 } 91 ///ystem.err.print("Added Task... "); 85 92 return doInsertNodeInto; 86 93 }
Note:
See TracChangeset
for help on using the changeset viewer.