use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class StructuredTextEditor method beginBusyStateInternal.
private void beginBusyStateInternal() {
fBusyState = true;
startBusyTimer();
ISourceViewer viewer = getSourceViewer();
if (viewer instanceof StructuredTextViewer) {
((StructuredTextViewer) viewer).beginBackgroundUpdate();
}
showBusy(true);
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class ToggleLineCommentHandler method processAction.
/**
* @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction(
* org.eclipse.ui.texteditor.ITextEditor, org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument,
* org.eclipse.jface.text.ITextSelection)
*/
protected void processAction(ITextEditor textEditor, final IStructuredDocument document, ITextSelection textSelection) {
IStructuredModel model = null;
DocumentRewriteSession session = null;
boolean changed = false;
try {
// get text selection lines info
int selectionStartLine = textSelection.getStartLine();
int selectionEndLine = textSelection.getEndLine();
int selectionEndLineOffset = document.getLineOffset(selectionEndLine);
int selectionEndOffset = textSelection.getOffset() + textSelection.getLength();
// adjust selection end line
if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) {
selectionEndLine--;
}
// save the selection position since it will be changing
Position selectionPosition = null;
selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength());
document.addPosition(selectionPosition);
model = StructuredModelManager.getModelManager().getModelForEdit(document);
if (model != null) {
// makes it so one undo will undo all the edits to the document
model.beginRecording(this, SSEUIMessages.ToggleComment_label, SSEUIMessages.ToggleComment_description);
// keeps listeners from doing anything until updates are all done
model.aboutToChangeModel();
if (document instanceof IDocumentExtension4) {
session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
}
changed = true;
// get the display for the editor if we can
Display display = null;
if (textEditor instanceof StructuredTextEditor) {
StructuredTextViewer viewer = ((StructuredTextEditor) textEditor).getTextViewer();
if (viewer != null) {
display = viewer.getControl().getDisplay();
}
}
// create the toggling operation
IRunnableWithProgress toggleCommentsRunnable = new ToggleLinesRunnable(model.getContentTypeIdentifier(), document, selectionStartLine, selectionEndLine, display);
// if toggling lots of lines then use progress monitor else just run the operation
if ((selectionEndLine - selectionStartLine) > TOGGLE_LINES_MAX_NO_BUSY_INDICATOR && display != null) {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(display.getActiveShell());
dialog.run(false, true, toggleCommentsRunnable);
} else {
toggleCommentsRunnable.run(new NullProgressMonitor());
}
}
} catch (InvocationTargetException e) {
// $NON-NLS-1$
Logger.logException("Problem running toggle comment progess dialog.", e);
} catch (InterruptedException e) {
// $NON-NLS-1$
Logger.logException("Problem running toggle comment progess dialog.", e);
} catch (BadLocationException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Logger.logException("The given selection " + textSelection + " must be invalid", e);
} finally {
// clean everything up
if (session != null && document instanceof IDocumentExtension4) {
((IDocumentExtension4) document).stopRewriteSession(session);
}
if (model != null) {
model.endRecording(this);
if (changed) {
model.changedModel();
}
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class JSPELContentAssistTest method testELChosenProposalCompletion.
public void testELChosenProposalCompletion() throws Exception {
IFile file = getFile(FILE_1_PATH);
ICompletionProposal[] props = getCompletionProposals(file, TEST_1_DOC_LOC);
verifyProposals(props, TEST_1_EXPECTED_PROPS);
StructuredTextEditor editor = getEditor(file);
StructuredTextViewer viewer = editor.getTextViewer();
IDocument document = viewer.getDocument();
props[0].apply(document);
String inserted = document.get(TEST_1_DOC_LOC - 1, TEST_1_EXPECTED_PROPS[0].length());
assertEquals("The completed proposal " + inserted + " does not match the expected completion " + TEST_1_EXPECTED_PROPS[0], TEST_1_EXPECTED_PROPS[0], inserted);
editor.getSite().getPage().saveEditor(editor, false);
editor.close(false);
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class TestCSSContentAssistComputers method testAdditionalProposalInfo.
public void testAdditionalProposalInfo() throws Exception {
IFile file = getFile("test4.css");
StructuredTextEditor editor = getEditor(file);
StructuredTextViewer viewer = editor.getTextViewer();
int offset = viewer.getDocument().getLineLength(7) + 23;
ICompletionProposal[][] pages = getProposals(viewer, offset, 4);
assertTrue("Not enough pages", pages.length > 0);
ICompletionProposal[] proposals = pages[0];
for (int i = 0; i < proposals.length; i++) {
if (proposals[i] instanceof ICompletionProposalExtension5) {
Object obj = ((ICompletionProposalExtension5) proposals[i]).getAdditionalProposalInfo(null);
assertTrue("Additional info must be of type ProposalInfo", obj instanceof ProposalInfo);
ProposalInfo info = (ProposalInfo) obj;
assertNotNull("CSSMMNode for Proposal Info should not be null", info);
}
}
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class NewJSPTemplatesWizardPage method createViewer.
/**
* Creates, configures and returns a source viewer to present the template
* pattern on the preference page. Clients may override to provide a
* custom source viewer featuring e.g. syntax coloring.
*
* @param parent
* the parent control
* @return a configured source viewer
*/
private SourceViewer createViewer(Composite parent) {
SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {
StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationJSP();
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
return baseConfiguration.getConfiguredContentTypes(sourceViewer);
}
public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
}
};
SourceViewer 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(ContentTypeIdForJSP.ContentTypeID_JSP);
IDocument document = scratchModel.getStructuredDocument();
viewer.configure(sourceViewerConfiguration);
viewer.setDocument(document);
return viewer;
}
Aggregations