use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class JSPCompletionProcessor method computeCompletionProposals.
/**
* The same as the normal <code>computeCompeltaionProposals</code> except the calculated
* java position is offset by the given extra offset.
*
* @param viewer
* the viewer whose document is used to compute the proposals
* @param documentPosition
* an offset within the document for which completions should
* be computed
* @param javaPositionExtraOffset
* the extra offset for the java position
* @return an array of completion proposals or <code>null</code> if no
* proposals are possible
*/
protected ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos, int javaPositionExtraOffset) {
initialize(pos);
JSPProposalCollector collector = null;
IDOMModel xmlModel = null;
try {
if (viewer instanceof StructuredTextViewer)
fViewer = (StructuredTextViewer) viewer;
xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(fViewer.getDocument());
IDOMDocument xmlDoc = xmlModel.getDocument();
if (fTranslationAdapter == null || xmlModel.getId() != fModelId) {
fTranslationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
fModelId = xmlModel.getId();
}
if (fTranslationAdapter != null) {
JSPTranslation translation = fTranslationAdapter.getJSPTranslation();
fJavaPosition = translation.getJavaOffset(getDocumentPosition()) + javaPositionExtraOffset;
if (DEBUG)
System.out.println(debug(translation));
try {
ICompilationUnit cu = translation.getCompilationUnit();
// or without a valid position
if (cu == null || -1 == fJavaPosition)
return new ICompletionProposal[0];
collector = getProposalCollector(cu, translation);
synchronized (cu) {
cu.codeComplete(fJavaPosition, collector, (WorkingCopyOwner) null);
}
} catch (CoreException coreEx) {
// a possible Java Model Exception due to not being a Web
// (Java) Project
coreEx.printStackTrace();
}
}
} catch (Exception exc) {
exc.printStackTrace();
// throw out exceptions on code assist.
} finally {
if (xmlModel != null) {
xmlModel.releaseFromRead();
}
}
ICompletionProposal[] results = new ICompletionProposal[0];
if (collector != null) {
results = collector.getJSPCompletionProposals();
if (results == null || results.length < 1)
fErrorMessage = JSPUIMessages.Java_Content_Assist_is_not_UI_;
}
return results;
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class CSSTemplatePreferencePage method doCreateViewer.
SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) {
SourceViewer viewer = null;
String contentTypeID = ContentTypeIdForCSS.ContentTypeID_CSS;
viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
// $NON-NLS-1$
viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(contentTypeID);
IDocument document = scratchModel.getStructuredDocument();
viewer.configure(viewerConfiguration);
viewer.setDocument(document);
return viewer;
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class FormattingTests method getConfiguredViewer.
/**
* @param document {@link IDocument} to display in the dummy viewer
* @param configuration {@link SourceViewerConfiguration} to configure the dummy viewer with
* @return a configured {@link ISourceViewer} using the given parameters
*/
private static ISourceViewer getConfiguredViewer(IDocument document, SourceViewerConfiguration configuration) {
ISourceViewer viewer = null;
assertNotNull("Could not get current display to run test with.", Display.getCurrent());
Shell shell = null;
if (PlatformUI.isWorkbenchRunning()) {
shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
} else {
shell = new Shell(Display.getCurrent());
}
Composite parent = new Composite(shell, SWT.NONE);
viewer = new StructuredTextViewer(parent, null, null, false, SWT.NONE);
viewer.setDocument(document);
viewer.configure(configuration);
return viewer;
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class TestViewerConfigurationJSP method setUpViewerConfiguration.
private void setUpViewerConfiguration() {
if (Display.getCurrent() != null) {
Shell shell = null;
Composite parent = null;
if (PlatformUI.isWorkbenchRunning()) {
shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
} else {
shell = new Shell(Display.getCurrent());
}
parent = new Composite(shell, SWT.NONE);
// dummy viewer
fViewer = new StructuredTextViewer(parent, null, null, false, SWT.NONE);
fConfig = new StructuredTextViewerConfigurationJSP();
} else {
fDisplayExists = false;
Logger.log(Logger.INFO, "Remember, viewer configuration tests are not run because workbench is not open (normal on build machine)");
}
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class DTDTemplatePreferencePage method doCreateViewer.
SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) {
SourceViewer viewer = null;
String contentTypeID = ContentTypeIdForDTD.ContentTypeID_DTD;
viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
// $NON-NLS-1$
viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(contentTypeID);
IDocument document = scratchModel.getStructuredDocument();
viewer.configure(viewerConfiguration);
viewer.setDocument(document);
return viewer;
}
Aggregations