use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class TestStructuredTextEditor method testInitialReconciling.
/**
* Test receiving the initial reconcile notification when the editor opens
*/
public void testInitialReconciling() throws Exception {
IFile file = getOrCreateFile(PROJECT_NAME + "/" + "reconcilingtest.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);
} 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 testFocusedReconciling.
/**
* Test that an editor notifies reconciling listeners when the editor gets focus.
*/
public void testFocusedReconciling() throws Exception {
IFile file = getOrCreateFile(PROJECT_NAME + "/" + "focustest.xml");
IFile fileAlt = getOrCreateFile(PROJECT_NAME + "/" + "focustestAlt.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);
IDE.openEditor(activePage, fileAlt, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
Arrays.fill(state, -1);
IEditorPart editorPart = IDE.openEditor(activePage, file, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
assertEquals("Didn't get the original editor back.", editor, editorPart);
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 setUp.
protected void setUp() throws Exception {
if (!fIsSetup) {
// create project
createProject(PROJECT_NAME);
fFile = getOrCreateFile(PROJECT_NAME + "/" + FILE_NAME);
fIsSetup = true;
}
if (fIsSetup && fEditor == null) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
IEditorInput input = new FileEditorInput(fFile);
/*
* This should take care of testing init, createPartControl,
* beginBackgroundOperation, endBackgroundOperation methods
*/
IEditorPart part = page.openEditor(input, "org.eclipse.wst.sse.ui.StructuredTextEditor.test", true);
if (part instanceof StructuredTextEditor)
fEditor = (StructuredTextEditor) part;
else
assertTrue("Unable to open structured text editor", false);
}
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class TestJSPContentAssistComputers method getEditor.
/**
* <p>Given a <code>file</code> get an editor for it. If an editor has already
* been retrieved for the given <code>file</code> then return the same already
* open editor.</p>
*
* <p>When opening the editor it will also standardized the line
* endings to <code>\n</code></p>
*
* @param file open and return an editor for this
* @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
*/
private static StructuredTextEditor getEditor(IFile file) {
StructuredTextEditor editor = (StructuredTextEditor) fFileToEditorMap.get(file);
if (editor == null) {
try {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
IEditorPart editorPart = IDE.openEditor(page, file, true, true);
if (editorPart instanceof MultiPageEditorPart) {
MultiPageEditorPart xmlEditorPart = (MultiPageEditorPart) editorPart;
editor = xmlEditorPart.getAdapter(StructuredTextEditor.class);
} else if (editorPart instanceof StructuredTextEditor) {
editor = ((StructuredTextEditor) editorPart);
} else {
fail("Unable to open structured text editor: " + editorPart.getClass().getName());
}
if (editor != null) {
standardizeLineEndings(editor);
fFileToEditorMap.put(file, editor);
} else {
fail("Could not open editor for " + file);
}
} catch (Exception e) {
fail("Could not open editor for " + file + " exception: " + e.getMessage());
}
}
return editor;
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class TestJSPContentAssistComputers method runProposalTest.
/**
* <p>Run a proposal test by opening the given file and invoking content assist for
* each expected proposal count at the given line number and line character
* offset and then compare the number of proposals for each invocation (pages) to the
* expected number of proposals.</p>
*
* @param fileName
* @param lineNum
* @param lineRelativeCharOffset
* @param expectedProposalCounts
* @throws Exception
*/
private static void runProposalTest(String fileName, int lineNum, int lineRelativeCharOffset, int[] expectedProposalCounts) throws Exception {
IFile file = getFile(fileName);
StructuredTextEditor editor = getEditor(file);
StructuredTextViewer viewer = editor.getTextViewer();
int offset = viewer.getDocument().getLineOffset(lineNum) + lineRelativeCharOffset;
ICompletionProposal[][] pages = getProposals(viewer, offset, expectedProposalCounts.length);
verifyProposalCounts(pages, expectedProposalCounts);
}
Aggregations