1 11 package org.eclipse.text.undo; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.Assert; 17 18 import org.eclipse.jface.text.IDocument; 19 20 37 public final class DocumentUndoManagerRegistry { 38 39 private static final class Record { 40 public Record(IDocument document) { 41 count= 0; 42 undoManager= new DocumentUndoManager(document); 43 } 44 private int count; 45 private IDocumentUndoManager undoManager; 46 } 47 48 private static Map fgFactory= new HashMap (); 49 50 private DocumentUndoManagerRegistry() { 51 } 53 54 55 64 public static synchronized void connect(IDocument document) { 65 Assert.isNotNull(document); 66 Record record= (Record)fgFactory.get(document); 67 if (record == null) { 68 record= new Record(document); 69 fgFactory.put(document, record); 70 } 71 record.count++; 72 } 73 74 79 public static synchronized void disconnect(IDocument document) { 80 Assert.isNotNull(document); 81 Record record= (Record)fgFactory.get(document); 82 record.count--; 83 if (record.count == 0) 84 fgFactory.remove(document); 85 86 } 87 88 101 public static synchronized IDocumentUndoManager getDocumentUndoManager(IDocument document) { 102 Assert.isNotNull(document); 103 Record record= (Record)fgFactory.get(document); 104 if (record == null) 105 return null; 106 return record.undoManager; 107 } 108 109 } 110 | Popular Tags |