use of org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener in project webtools.sourceediting by eclipse.
the class DocumentRegionProcessor method removeReconcilingListener.
public void removeReconcilingListener(ISourceReconcilingListener listener) {
Set listeners = new HashSet(Arrays.asList(fReconcileListeners));
listeners.remove(listener);
fReconcileListeners = (ISourceReconcilingListener[]) listeners.toArray(new ISourceReconcilingListener[listeners.size()]);
}
use of org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener 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.reconcile.ISourceReconcilingListener 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.reconcile.ISourceReconcilingListener 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.reconcile.ISourceReconcilingListener in project webtools.sourceediting by eclipse.
the class StructuredTextEditor method addReconcilingListeners.
private void addReconcilingListeners(SourceViewerConfiguration config, StructuredTextViewer stv) {
try {
List reconcilingListeners = new ArrayList(fReconcilingListeners.length);
String[] ids = getConfigurationPoints();
for (int i = 0; i < ids.length; i++) {
// $NON-NLS-1$
reconcilingListeners.addAll(ExtendedConfigurationBuilder.getInstance().getConfigurations("sourceReconcilingListener", ids[i]));
}
fReconcilingListeners = (ISourceReconcilingListener[]) reconcilingListeners.toArray(new ISourceReconcilingListener[reconcilingListeners.size()]);
} catch (ClassCastException e) {
// $NON-NLS-1$
Logger.log(Logger.ERROR, "Configuration has a reconciling listener that does not implement ISourceReconcilingListener.");
}
IReconciler reconciler = config.getReconciler(stv);
if (reconciler instanceof DocumentRegionProcessor) {
for (int i = 0; i < fReconcilingListeners.length; i++) ((DocumentRegionProcessor) reconciler).addReconcilingListener(fReconcilingListeners[i]);
}
}
Aggregations