use of org.eclipse.wst.xml.ui.internal.actions.CleanupDialogXML in project webtools.sourceediting by eclipse.
the class CleanupdocumentHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
ITextEditor textEditor = null;
if (editor instanceof ITextEditor)
textEditor = (ITextEditor) editor;
else {
Object o = editor.getAdapter(ITextEditor.class);
if (o != null)
textEditor = (ITextEditor) o;
}
if (textEditor != null) {
final ITextEditor finalTextEditor = textEditor;
Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell());
if (cleanupDialog.open() == Window.OK) {
// setup runnable
Runnable runnable = new Runnable() {
public void run() {
IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
if (cleanupProcessor != null) {
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForEdit(finalTextEditor.getDocumentProvider().getDocument(finalTextEditor.getEditorInput()));
if (model != null) {
cleanupProcessor.cleanupModel(model);
}
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
}
};
// TODO: make independent of 'model'.
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForEdit(textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()));
if (model != null) {
// begin recording
ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection();
model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength());
// tell the model that we are about to make a big
// model change
model.aboutToChangeModel();
// run
BusyIndicator.showWhile(textEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
}
} finally {
if (model != null) {
// tell the model that we are done with the big
// model
// change
model.changedModel();
// end recording
ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection();
model.endRecording(this, selection.getOffset(), selection.getLength());
model.releaseFromEdit();
}
}
}
}
return null;
}
Aggregations