1 11 package org.eclipse.core.filebuffers.manipulation; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.core.runtime.OperationCanceledException; 15 16 import org.eclipse.text.edits.MalformedTreeException; 17 import org.eclipse.text.edits.MultiTextEdit; 18 import org.eclipse.text.edits.TextEdit; 19 import org.eclipse.text.edits.UndoEdit; 20 21 import org.eclipse.jface.text.BadLocationException; 22 import org.eclipse.jface.text.IDocument; 23 24 29 public class MultiTextEditWithProgress extends MultiTextEdit { 30 31 IProgressMonitor fProgressMonitor; 32 private final String fTaskName; 33 34 public MultiTextEditWithProgress(String taskName) { 35 fTaskName= taskName; 36 } 37 38 41 public final UndoEdit apply(IDocument document, IProgressMonitor progressMonitor) throws MalformedTreeException, BadLocationException { 42 return apply(document, CREATE_UNDO | UPDATE_REGIONS, progressMonitor); 43 } 44 45 48 public final UndoEdit apply(IDocument document, int style, IProgressMonitor progressMonitor) throws MalformedTreeException, BadLocationException { 49 fProgressMonitor= progressMonitor; 50 try { 51 52 int count= getChildrenSize(); 53 if ((style & TextEdit.UPDATE_REGIONS) != 0) 54 count= 2*count; 55 56 fProgressMonitor.beginTask(fTaskName, count); 57 try { 58 return super.apply(document, style); 59 } finally { 60 fProgressMonitor.done(); 61 } 62 63 } finally { 64 fProgressMonitor= null; 65 } 66 } 67 68 71 protected void childDocumentUpdated() { 72 if (fProgressMonitor.isCanceled()) 73 throw new OperationCanceledException(); 74 fProgressMonitor.worked(1); 75 } 76 77 80 protected void childRegionUpdated() { 81 if (fProgressMonitor.isCanceled()) 82 throw new OperationCanceledException(); 83 fProgressMonitor.worked(1); 84 } 85 } 86 | Popular Tags |