Java Code Examples for org.eclipse.ltk.core.refactoring.PerformChangeOperation#getUndoChange()

The following examples show how to use org.eclipse.ltk.core.refactoring.PerformChangeOperation#getUndoChange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChangeUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Performs the given change.
 * 
 * @return The undo change as produced by the refactoring's change.
 */
public static Change performChange(IWorkspace workspace, IProgressMonitor pm,
    Change change) throws CoreException {
  PerformChangeOperation performChangeOperation = new PerformChangeOperation(
      change);
  try {
    workspace.run(performChangeOperation, pm);
  } finally {
    if (!performChangeOperation.changeExecuted()) {
      change.dispose();
    }
  }

  return performChangeOperation.getUndoChange();
}
 
Example 2
Source File: TypeScriptDocumentProvider.java    From typescript.java with MIT License 4 votes vote down vote up
private void performSaveActions(IFile file, IDocument document, IProgressMonitor monitor,
		IPreferenceStore preferenceStore) {
	boolean runFormat = preferenceStore.getBoolean(TypeScriptUIPreferenceConstants.EDITOR_SAVE_ACTIONS_FORMAT);
	SubMonitor progress = SubMonitor.convert(monitor, (runFormat ? 10 : 0));
	if (!runFormat) {
		return;
	}

	IUndoManager manager = RefactoringCore.getUndoManager();

	CompositeChange saveActionsChange = new CompositeChange("Save Actions");
	List<Change> undoChanges = new ArrayList<>();
	boolean success = false;
	try {
		manager.aboutToPerformChange(saveActionsChange);

		// Format the file contents
		if (runFormat) {
			TextFileChange change = new TextFileChange("Format", file);
			try {
				IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(file.getProject());
				final IIDETypeScriptFile tsFile = tsProject.openFile(file, document);
				List<CodeEdit> codeEdits = tsFile.format(0, document.getLength()).get();
				change.setEdit(DocumentUtils.toTextEdit(codeEdits, document));
				change.initializeValidationData(new NullProgressMonitor());
				PerformChangeOperation performChangeOperation = new PerformChangeOperation(change);
				ResourcesPlugin.getWorkspace().run(performChangeOperation, progress.newChild(10));
				Change undoChange = performChangeOperation.getUndoChange();
				if (undoChange != null) {
					undoChanges.add(undoChange);
				}
			} catch (Exception e) {
				JSDTTypeScriptUIPlugin.log(e);
			}
		}

		success = true;
	} finally {
		manager.changePerformed(saveActionsChange, success);
	}

	// Add an undo change if possible
	if (!undoChanges.isEmpty()) {
		manager.addUndo(saveActionsChange.getName(), new CompositeChange(saveActionsChange.getName(),
				undoChanges.toArray(new Change[undoChanges.size()])));
	}
}