blob: e8fa43fc3dcea1a44db571f454bf85d8f527c62c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.core.filebuffers.manipulation;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.text.edits.UndoEdit;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
/**
* Multi-text edit with progress reporting.
*
* @since 3.1
*/
public class MultiTextEditWithProgress extends MultiTextEdit {
IProgressMonitor fProgressMonitor;
private final String fTaskName;
public MultiTextEditWithProgress(String taskName) {
fTaskName= taskName;
}
/*
* @see TextEdit#apply(IDocument)
*/
public final UndoEdit apply(IDocument document, IProgressMonitor progressMonitor) throws MalformedTreeException, BadLocationException {
return apply(document, CREATE_UNDO | UPDATE_REGIONS, progressMonitor);
}
/*
* @see TextEdit#apply(IDocument, int)
*/
public final UndoEdit apply(IDocument document, int style, IProgressMonitor progressMonitor) throws MalformedTreeException, BadLocationException {
fProgressMonitor= progressMonitor;
try {
int count= getChildrenSize();
if ((style & TextEdit.UPDATE_REGIONS) != 0)
count= 2*count;
fProgressMonitor.beginTask(fTaskName, count);
try {
return super.apply(document, style);
} finally {
fProgressMonitor.done();
}
} finally {
fProgressMonitor= null;
}
}
@Override
protected void childDocumentUpdated() {
if (fProgressMonitor.isCanceled())
throw new OperationCanceledException();
fProgressMonitor.worked(1);
}
@Override
protected void childRegionUpdated() {
if (fProgressMonitor.isCanceled())
throw new OperationCanceledException();
fProgressMonitor.worked(1);
}
}
|