use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class ExtendedEditorDropTargetAdapter method drop.
/**
*/
public void drop(DropTargetEvent event) {
if (event.operations == DND.DROP_NONE)
return;
Transfer[] ts = getTransfers();
for (int i = 0; i < ts.length; i++) {
if (ts[i].isSupportedType(event.currentDataType)) {
if (doDrop(ts[i], event)) {
IEditorPart part = targetEditor;
if (targetEditor instanceof StructuredTextEditor) {
part = ((StructuredTextEditor) targetEditor).getEditorPart();
}
targetEditor.getSite().getPage().activate(part);
break;
}
}
}
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class CSSCodeFoldingTest 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, "org.eclipse.wst.css.core.csssource.source", true);
if (editorPart instanceof StructuredTextEditor) {
editor = ((StructuredTextEditor) editorPart);
standardizeLineEndings(editor);
} else {
fail("Unable to open structured text editor: " + editorPart.getClass().getName());
}
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 TestHTMLContentAssistComputers 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, "org.eclipse.wst.html.core.htmlsource.source", true);
if (editorPart instanceof MultiPageEditorPart) {
MultiPageEditorPart mpEditorPart = (MultiPageEditorPart) editorPart;
editor = mpEditorPart.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 ContentAssistTestUtilities method getProposals.
/**
* <p>
* Invoke content assist on the given editor at the given offset, for the given number of pages
* and return the results of each page
* </p>
*/
private static ICompletionProposal[][] getProposals(AbstractTextEditor editor, int offset, int pageCount) throws Exception {
ICompletionProposal[][] pages = null;
/* if JS editor
* else if HTML editor */
if (editor instanceof JavaEditor) {
// setup the viewer
ISourceViewer viewer = ((JavaEditor) editor).getViewer();
JavaScriptSourceViewerConfiguration configuration = new JavaScriptSourceViewerConfiguration(JavaScriptPlugin.getDefault().getJavaTextTools().getColorManager(), JavaScriptPlugin.getDefault().getCombinedPreferenceStore(), editor, IJavaScriptPartitions.JAVA_PARTITIONING);
ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
// get the processor
String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
// fire content assist session about to start
Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionBeginEvent", new Class[] { boolean.class });
privateFireSessionBeginEventMethod.setAccessible(true);
privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] { Boolean.TRUE });
// get content assist suggestions
pages = new ICompletionProposal[pageCount][];
for (int p = 0; p < pageCount; ++p) {
pages[p] = processor.computeCompletionProposals(viewer, offset);
}
// fire content assist session ending
Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
privateFireSessionEndEventMethod.setAccessible(true);
privateFireSessionEndEventMethod.invoke(contentAssistant, null);
} else if (editor instanceof StructuredTextEditor) {
// setup the viewer
StructuredTextViewer viewer = ((StructuredTextEditor) editor).getTextViewer();
StructuredTextViewerConfigurationHTML configuration = new StructuredTextViewerConfigurationHTML();
ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
viewer.configure(configuration);
viewer.setSelectedRange(offset, 0);
// get the processor
String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
// fire content assist session about to start
Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionBeginEvent", new Class[] { boolean.class });
privateFireSessionBeginEventMethod.setAccessible(true);
privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] { Boolean.TRUE });
// get content assist suggestions
pages = new ICompletionProposal[pageCount][];
for (int p = 0; p < pageCount; ++p) {
pages[p] = processor.computeCompletionProposals(viewer, offset);
}
// fire content assist session ending
Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
privateFireSessionEndEventMethod.setAccessible(true);
privateFireSessionEndEventMethod.invoke(contentAssistant, null);
}
return pages;
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class ContentAssistTestUtilities method getHTMLProposals.
/**
* <p>
* Returns the content assist proposals when invoked at the offset provided.
* </p>
*
* @param fileNum
* @param lineNum
* @param lineRelativeCharOffset
* @param numOfPages
*/
private static ICompletionProposal[][] getHTMLProposals(TestProjectSetup testProject, String filePath, int lineNum, int lineRelativeCharOffset, int numOfPages) throws Exception {
IFile file = testProject.getFile(filePath);
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
IEditorPart part = IDE.openEditor(page, file, "org.eclipse.wst.html.core.htmlsource.source");
StructuredTextEditor editor = (StructuredTextEditor) part.getAdapter(ITextEditor.class);
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
int offset = doc.getLineOffset(lineNum) + lineRelativeCharOffset;
ICompletionProposal[][] pages = getHTMLProposals(editor, offset, numOfPages);
return pages;
}
Aggregations