use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class DTDCodeFoldingTest method testAddNode.
/**
* <p><b>TEST:</b> that folding annotations are updated after node is removed</p>
* Removed because it keeps failing during builds but running locally and smoke testing
* presents no problems.
*/
/*public void testRemoveNode() throws Exception {
IFile file = getFile("DTDFoldingTest1.dtd");
StructuredTextEditor editor = getEditor(file);
try {
StructuredTextViewer viewer = editor.getTextViewer();
IDocument doc = viewer.getDocument();
doc.replace(337, 159, "");
editor.doSave(null);
final List expectedPositions = new ArrayList();
expectedPositions.add(new Position(1110, 28));
expectedPositions.add(new Position(39, 296));
expectedPositions.add(new Position(1140, 234));
expectedPositions.add(new Position(339, 751));
expectedPositions.add(new Position(1092, 17));
waitForReconcileThenVerify(viewer, expectedPositions);
} catch(BadLocationException e) {
fail("Test is broken, replace location has become invalid.\n" + e.getMessage());
}
}*/
/**
* <p><b>TEST:</b> that folding annotations are updated after node is added</p>
*/
public void testAddNode() throws Exception {
IFile file = getFile("DTDFoldingTest2.dtd");
StructuredTextEditor editor = getEditor(file);
try {
StructuredTextViewer viewer = editor.getTextViewer();
IDocument doc = viewer.getDocument();
String newNodeText = "<!ATTLIST BDO\n" + "%coreattrs;\t\t\t\t-- id, class, style, title --\n" + "lang\t%LanguageCode;\t#IMPLIED\t-- language code --\n" + "dir\t(ltr|rtl)\t#REQUIRED\t-- directionality --\n" + ">\n";
doc.replace(597, 0, newNodeText);
editor.doSave(null);
List expectedPositions = new ArrayList();
expectedPositions.add(new Position(1454, 234));
expectedPositions.add(new Position(498, 906));
expectedPositions.add(new Position(39, 296));
expectedPositions.add(new Position(1406, 17));
expectedPositions.add(new Position(337, 159));
expectedPositions.add(new Position(1424, 28));
waitForReconcileThenVerify(viewer, expectedPositions);
} catch (BadLocationException e) {
fail("Test is broken, add location has become invalid.\n" + e.getMessage());
}
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class DTDCodeFoldingTest 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>
*
* @param file open and return an editor for this
* @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
*/
private 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 StructuredTextEditor) {
editor = ((StructuredTextEditor) editorPart);
standardizeLineEndings(editor);
} else {
fail("Unable to open structured text editor");
}
if (editor != null) {
fFileToEditorMap.put(file, editor);
} else {
fail("Could not open viewer 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 DTDCodeFoldingTest method testInitFolding.
/**
* <p><b>TEST:</b> the initially placed folding annotations</p>
*/
public void testInitFolding() throws Exception {
IFile file = getFile("DTDFoldingTest1.dtd");
StructuredTextEditor editor = getEditor(file);
List expectedPositions = new ArrayList();
expectedPositions.add(new Position(1299, 234));
expectedPositions.add(new Position(39, 296));
expectedPositions.add(new Position(498, 751));
expectedPositions.add(new Position(1251, 17));
expectedPositions.add(new Position(1269, 28));
expectedPositions.add(new Position(337, 159));
waitForReconcileThenVerify(editor.getTextViewer(), expectedPositions);
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class XMLTableTreeActionBarContributor method getModelForEditorPart.
/**
* @deprecated - not to be used
*/
protected IStructuredModel getModelForEditorPart(IEditorPart targetEditor) {
IStructuredModel result = null;
if (editorPart instanceof XMLMultiPageEditorPart) {
StructuredTextEditor textEditor = ((XMLMultiPageEditorPart) targetEditor).getTextEditor();
result = (textEditor != null) ? textEditor.getModel() : null;
}
return result;
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class XMLFindOccurencesHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
ITextEditor textEditor = null;
boolean okay = false;
if (editor instanceof ITextEditor)
textEditor = (ITextEditor) editor;
else {
Object o = editor.getAdapter(ITextEditor.class);
if (o != null)
textEditor = (ITextEditor) o;
}
if (textEditor != null) {
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
if (document != null) {
ITextSelection textSelection = getTextSelection(textEditor);
FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection);
if (findOccurrenceProcessor != null) {
if (textEditor.getEditorInput() instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile();
okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file);
}
}
}
}
if (okay) {
// clear status message
PlatformStatusLineUtil.clearStatusLine();
} else {
// $NON-NLS-1$
String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0;
if (textEditor instanceof StructuredTextEditor) {
PlatformStatusLineUtil.displayTemporaryErrorMessage(((StructuredTextEditor) textEditor).getTextViewer(), errorMessage);
} else {
PlatformStatusLineUtil.displayErrorMessage(errorMessage);
PlatformStatusLineUtil.addOneTimeClearListener();
}
}
return null;
}
Aggregations