use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class TestStructuredTextEditor method testModificationReconciling.
/**
* Test that modifications to the editor's content will notify reconciling listeners
*/
public void testModificationReconciling() throws Exception {
IFile file = getOrCreateFile(PROJECT_NAME + "/" + "reconcilingmodificationtest.xml");
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final int[] state = new int[2];
Arrays.fill(state, -1);
ISourceReconcilingListener listener = new ISourceReconcilingListener() {
int mod = 0;
public void reconciled(IDocument document, IAnnotationModel model, boolean forced, IProgressMonitor progressMonitor) {
state[1] = mod++;
}
public void aboutToBeReconciled() {
state[0] = mod++;
}
};
IEditorPart editor = IDE.openEditor(activePage, file, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
try {
assertTrue("Not a StructuredTextEditor", editor instanceof StructuredTextEditor);
addReconcilingListener((StructuredTextEditor) editor, listener);
waitForReconcile(state);
assertTrue("Initial: Reconciling did not complete in a timely fashion", state[0] != -1 && state[1] != -1);
assertTrue("Initial: aboutToBeReconciled not invoked first (" + state[0] + ")", state[0] == 0);
assertTrue("Initial: reconciled not invoked after aboutToBeReconciled (" + state[1] + ")", state[1] == 1);
IDocument document = ((StructuredTextEditor) editor).getDocumentProvider().getDocument(editor.getEditorInput());
assertTrue("Editor doesn't have a document", document != null);
document.set("<?xml version=\"1.0\" ?>");
Arrays.fill(state, -1);
waitForReconcile(state);
assertTrue("Modified: Reconciling did not complete in a timely fashion", state[0] != -1 && state[1] != -1);
assertTrue("Modified: aboutToBeReconciled not invoked first (" + state[0] + ")", state[0] == 2);
assertTrue("Modified: reconciled not invoked after aboutToBeReconciled (" + state[1] + ")", state[1] == 3);
} finally {
if (editor != null && activePage != null) {
activePage.closeEditor(editor, false);
}
}
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class TestStructuredTextEditor method testGetSetEditorPart.
public void testGetSetEditorPart() {
fEditor.setEditorPart(null);
assertTrue("Unable to set editor part", true);
IEditorPart part = fEditor.getEditorPart();
assertTrue("Did not get expected editor part", part instanceof StructuredTextEditor);
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class CleanupDocumentHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
ITextEditor textEditor = null;
if (editorPart instanceof ITextEditor)
textEditor = (ITextEditor) editorPart;
else {
Object o = editorPart.getAdapter(ITextEditor.class);
if (o != null)
textEditor = (ITextEditor) o;
}
if (textEditor != null) {
final ITextEditor editor = textEditor;
CleanupDialogHTML cleanupDialog = new CleanupDialogHTML(editor.getSite().getShell());
cleanupDialog.setisXHTMLType(isXHTML(editor));
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(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
if (model != null) {
if ((cleanupProcessor instanceof AbstractStructuredCleanupProcessor) && (editor instanceof StructuredTextEditor)) {
((AbstractStructuredCleanupProcessor) cleanupProcessor).cleanupModel(model, ((StructuredTextEditor) editor).getTextViewer());
} else {
cleanupProcessor.cleanupModel(model);
}
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
}
};
// TODO: make independent of 'model'.
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
if (model != null) {
// begin recording
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
// $NON-NLS-1$ //$NON-NLS-2$
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(editor.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) editor.getSelectionProvider().getSelection();
model.endRecording(this, selection.getOffset(), selection.getLength());
model.releaseFromEdit();
}
}
}
}
return null;
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class ToggleLineCommentHandler method processAction.
/**
* @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction(
* org.eclipse.ui.texteditor.ITextEditor, org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument,
* org.eclipse.jface.text.ITextSelection)
*/
protected void processAction(ITextEditor textEditor, final IStructuredDocument document, ITextSelection textSelection) {
IStructuredModel model = null;
DocumentRewriteSession session = null;
boolean changed = false;
try {
// get text selection lines info
int selectionStartLine = textSelection.getStartLine();
int selectionEndLine = textSelection.getEndLine();
int selectionEndLineOffset = document.getLineOffset(selectionEndLine);
int selectionEndOffset = textSelection.getOffset() + textSelection.getLength();
// adjust selection end line
if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) {
selectionEndLine--;
}
// save the selection position since it will be changing
Position selectionPosition = null;
selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength());
document.addPosition(selectionPosition);
model = StructuredModelManager.getModelManager().getModelForEdit(document);
if (model != null) {
// makes it so one undo will undo all the edits to the document
model.beginRecording(this, SSEUIMessages.ToggleComment_label, SSEUIMessages.ToggleComment_description);
// keeps listeners from doing anything until updates are all done
model.aboutToChangeModel();
if (document instanceof IDocumentExtension4) {
session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
}
changed = true;
// get the display for the editor if we can
Display display = null;
if (textEditor instanceof StructuredTextEditor) {
StructuredTextViewer viewer = ((StructuredTextEditor) textEditor).getTextViewer();
if (viewer != null) {
display = viewer.getControl().getDisplay();
}
}
// create the toggling operation
IRunnableWithProgress toggleCommentsRunnable = new ToggleLinesRunnable(model.getContentTypeIdentifier(), document, selectionStartLine, selectionEndLine, display);
// if toggling lots of lines then use progress monitor else just run the operation
if ((selectionEndLine - selectionStartLine) > TOGGLE_LINES_MAX_NO_BUSY_INDICATOR && display != null) {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(display.getActiveShell());
dialog.run(false, true, toggleCommentsRunnable);
} else {
toggleCommentsRunnable.run(new NullProgressMonitor());
}
}
} catch (InvocationTargetException e) {
// $NON-NLS-1$
Logger.logException("Problem running toggle comment progess dialog.", e);
} catch (InterruptedException e) {
// $NON-NLS-1$
Logger.logException("Problem running toggle comment progess dialog.", e);
} catch (BadLocationException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Logger.logException("The given selection " + textSelection + " must be invalid", e);
} finally {
// clean everything up
if (session != null && document instanceof IDocumentExtension4) {
((IDocumentExtension4) document).stopRewriteSession(session);
}
if (model != null) {
model.endRecording(this);
if (changed) {
model.changedModel();
}
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class JSPELContentAssistTest method testELChosenProposalCompletion.
public void testELChosenProposalCompletion() throws Exception {
IFile file = getFile(FILE_1_PATH);
ICompletionProposal[] props = getCompletionProposals(file, TEST_1_DOC_LOC);
verifyProposals(props, TEST_1_EXPECTED_PROPS);
StructuredTextEditor editor = getEditor(file);
StructuredTextViewer viewer = editor.getTextViewer();
IDocument document = viewer.getDocument();
props[0].apply(document);
String inserted = document.get(TEST_1_DOC_LOC - 1, TEST_1_EXPECTED_PROPS[0].length());
assertEquals("The completed proposal " + inserted + " does not match the expected completion " + TEST_1_EXPECTED_PROPS[0], TEST_1_EXPECTED_PROPS[0], inserted);
editor.getSite().getPage().saveEditor(editor, false);
editor.close(false);
}
Aggregations