Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java6
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/PomEdits.java78
2 files changed, 61 insertions, 23 deletions
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java
index 6ea84a02..68b21cf6 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java
@@ -300,10 +300,10 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
try {
if (same) {
- PomEdits.performOnDOMDocument(currentFacade.getPom(), new PomEdits.CompoundOperation(manageOperation, removeVersionsOperation));
+ PomEdits.performOnDOMDocument(new PomEdits.OperationTuple(currentFacade.getPom(), new PomEdits.CompoundOperation(manageOperation, removeVersionsOperation)));
} else {
- PomEdits.performOnDOMDocument(targetFacade.getPom(), manageOperation);
- PomEdits.performOnDOMDocument(currentFacade.getPom(), removeVersionsOperation);
+ PomEdits.performOnDOMDocument(new PomEdits.OperationTuple(targetFacade.getPom(), manageOperation),
+ new PomEdits.OperationTuple(currentFacade.getPom(), removeVersionsOperation));
}
} catch(IOException e) {
MavenLogger.log("", e);
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/PomEdits.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/PomEdits.java
index 6845a022..6abcc867 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/PomEdits.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/PomEdits.java
@@ -1,13 +1,30 @@
package org.eclipse.m2e.editor.internal;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.core.commands.operations.ObjectUndoContext;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.m2e.core.internal.project.MavenMarkerManager;
+import org.eclipse.m2e.editor.internal.PomEdits.Operation;
+import org.eclipse.text.undo.DocumentUndoManagerRegistry;
+import org.eclipse.text.undo.IDocumentUndoManager;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML;
@@ -142,34 +159,55 @@ public class PomEdits {
* @throws IOException
* @throws CoreException
*/
- public static void performOnDOMDocument(IFile file, PomEdits.Operation operation) throws IOException, CoreException {
- assert file != null;
- assert operation != null;
- IDOMModel domModel = null;
- //TODO we might want to attempt iterating opened editors and somehow initialize those
- // that were not yet initialized. Then we could avoid saving a file that is actually opened, but was never used so far (after restart)
- try {
- domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(file);
- domModel.aboutToChangeModel();
+ public static void performOnDOMDocument(PomEdits.OperationTuple... fileOperations) throws IOException, CoreException {
+ for(OperationTuple tuple : fileOperations) {
+ IDOMModel domModel = null;
+ //TODO we might want to attempt iterating opened editors and somehow initialize those
+ // that were not yet initialized. Then we could avoid saving a file that is actually opened, but was never used so far (after restart)
+ try {
+ domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tuple.getFile());
+ domModel.aboutToChangeModel();
IStructuredTextUndoManager undo = domModel.getStructuredDocument().getUndoManager();
undo.beginRecording(domModel);
- try {
- operation.process(domModel.getDocument());
- } finally {
+ try {
+ tuple.getOperation().process(domModel.getDocument());
+ } finally {
undo.endRecording(domModel);
- domModel.changedModel();
- }
- } finally {
- if (domModel != null) {
- //saving shall only happen when the model is not held elsewhere (eg. in opened view)
- if (domModel.isSaveNeeded() && domModel.getReferenceCountForEdit() == 1) {
- domModel.save();
+ domModel.changedModel();
+ }
+ } finally {
+ if(domModel != null) {
+ //saving shall only happen when the model is not held elsewhere (eg. in opened view)
+ if(domModel.isSaveNeeded() && domModel.getReferenceCountForEdit() == 1) {
+ domModel.save();
+ }
+ domModel.releaseFromEdit();
}
- domModel.releaseFromEdit();
}
}
}
+ public static final class OperationTuple {
+ private final PomEdits.Operation operation;
+ private final IFile file;
+
+ public OperationTuple(IFile file, PomEdits.Operation operation) {
+ assert file != null;
+ assert operation != null;
+ this.file = file;
+ this.operation = operation;
+ }
+
+ public IFile getFile() {
+ return file;
+ }
+
+ public PomEdits.Operation getOperation() {
+ return operation;
+ }
+
+ }
+
/**
* operation to perform on top of the DOM document. see performOnDOMDocument()
* @author mkleint

Back to the top