@Override protected SourceViewer createPatternViewer(Composite parent) { IDocument document= new Document(); JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools(); tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING); IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore(); JavaSourceViewer viewer= new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL, store); SimpleJavaSourceViewerConfiguration configuration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, false); viewer.configure(configuration); viewer.setEditable(false); viewer.setDocument(document); Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); viewer.getTextWidget().setFont(font); new JavaSourcePreviewerUpdater(viewer, configuration, store); Control control= viewer.getControl(); GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); control.setLayoutData(data); viewer.setEditable(false); return viewer; }
/** * Install this presenter on the given source viewer and background presentation * reconciler. * * @param sourceViewer the source viewer * @param backgroundPresentationReconciler the background presentation reconciler, * can be <code>null</code>, in that case {@link SemanticHighlightingPresenter#createPresentation(List, List)} * should not be called */ public void install(JavaSourceViewer sourceViewer, JavaPresentationReconciler backgroundPresentationReconciler) { fSourceViewer= sourceViewer; fPresentationReconciler= backgroundPresentationReconciler; fSourceViewer.prependTextPresentationListener(this); fSourceViewer.addTextInputListener(this); manageDocument(fSourceViewer.getDocument()); }
public void run() { if (viewer.isEditable()) { final Point selection= viewer.rememberSelection(); try { viewer.setRedraw(false); final String type= TextUtilities.getContentType(viewer.getDocument(), IJavaPartitions.JAVA_PARTITIONING, selection.x, true); if (type.equals(IDocument.DEFAULT_CONTENT_TYPE) && selection.y == 0) { viewer.setSelectedRange(range.getOffset(), range.getLength()); viewer.doOperation(ISourceViewer.FORMAT); viewer.setSelectedRange(selection.x, 1); viewer.doOperation(ISourceViewer.FORMAT); viewer.setRedraw(true); viewer.restoreSelection();
@Override public void lineGetSegments(BidiSegmentEvent event) { if (redraws()) { try { event.segments= getBidiLineSegments(getDocument(), baseLevel, widgetOffset2ModelOffset(event.lineOffset), event.lineText); } catch (BadLocationException e) { // don't touch the segments } } } });
/** * {@inheritDoc} * <p> * This is a performance optimization to reduce the computation of * the text presentation triggered by {@link #setVisibleDocument(IDocument)} * </p> * @see #prepareDelayedProjection() * @since 3.1 */ protected void setVisibleDocument(IDocument document) { if (fIsSetVisibleDocumentDelayed) { fIsSetVisibleDocumentDelayed= false; IDocument previous= getVisibleDocument(); enableProjection(); // will set the visible document if anything is folded IDocument current= getVisibleDocument(); // if the visible document was not replaced, continue as usual if (current != null && current != previous) return; } super.setVisibleDocument(document); }
/** * Creates a signature preview viewer in a parent composite with a 1-column GridLayout. * * @param parent the parent * @return the preview viewer * @since 3.9 */ public static JavaSourceViewer createSignaturePreview(Composite parent) { IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore(); JavaSourceViewer signaturePreview= new JavaSourceViewer(parent, null, null, false, SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP, store); signaturePreview.configure(new JavaSourceViewerConfiguration(JavaPlugin.getDefault().getJavaTextTools().getColorManager(), store, null, null)); StyledText textWidget= signaturePreview.getTextWidget(); textWidget.setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); textWidget.setAlwaysShowScrollBars(false); signaturePreview.adaptBackgroundColor(parent); signaturePreview.setDocument(new Document()); signaturePreview.setEditable(false); GridData gdata= new GridData(GridData.FILL_BOTH); gdata.widthHint= new PixelConverter(textWidget).convertWidthInCharsToPixels(50); gdata.heightHint= textWidget.getLineHeight() * 2; textWidget.setLayoutData(gdata); return signaturePreview; } }
@Override protected SourceViewer createSourceViewer(Composite parent) { IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore(); return new JavaSourceViewer(parent, null, null, false, SWT.LEFT_TO_RIGHT | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION, store); }
private void updatePreview(String text) { if (fSignaturePreview == null) return; if (text.length() == 0) text= "someMethodName"; //$NON-NLS-1$ int top= fSignaturePreview.getTextWidget().getTopPixel(); String signature; try { signature= fRefactoring.getSignature(text); } catch (IllegalArgumentException e) { signature= ""; //$NON-NLS-1$ } fSignaturePreview.getDocument().set(signature); fSignaturePreview.getTextWidget().setTopPixel(top); }
return; IDocument document= fSourceViewer.getDocument(); if (document == null) return; fSourceViewer.changeTextPresentation(textPresentation, false); else fSourceViewer.invalidateTextPresentation();
@Override public StyledText getTextWidget() { return super.getTextWidget(); }
StyledText textWidget= getTextWidget(); if (textWidget != null && !textWidget.isDisposed()) { Color foregroundColor= textWidget.getForeground(); initializeViewerColors();
protected void initializeViewerColors() { if (fPreferenceStore != null) { StyledText styledText= getTextWidget(); : createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay()); styledText.setForeground(color); : createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay()); styledText.setBackground(color); : createColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, styledText.getDisplay()); styledText.setSelectionForeground(color); : createColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, styledText.getDisplay()); styledText.setSelectionBackground(color);
public void doOperation(int operation) { if (getTextWidget() == null) return; switch (operation) { case CONTENTASSIST_PROPOSALS: long time= CODE_ASSIST_DEBUG ? System.currentTimeMillis() : 0; String msg= fContentAssistant.showPossibleCompletions(); if (CODE_ASSIST_DEBUG) { long delta= System.currentTimeMillis() - time; System.err.println("Code Assist (total): " + delta); //$NON-NLS-1$ } setStatusLineErrorMessage(msg); return; case QUICK_ASSIST: /* * XXX: We can get rid of this once the SourceViewer has a way to update the status line * https://bugs.eclipse.org/bugs/show_bug.cgi?id=133787 */ msg= fQuickAssistAssistant.showPossibleQuickAssists(); setStatusLineErrorMessage(msg); return; } super.doOperation(operation); }
public Object getAdapter(Class required) { if (SmartBackspaceManager.class.equals(required)) { if (getSourceViewer() instanceof JavaSourceViewer) { return ((JavaSourceViewer) getSourceViewer()).getBackspaceManager(); } } return super.getAdapter(required); }
public void resetVisibleRegion() { super.resetVisibleRegion(); // re-enable folding if ProjectionViewer failed to due so if (fPreferenceStore != null && fPreferenceStore.getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED) && !isProjectionMode()) enableProjection(); }
public void lineGetSegments(BidiSegmentEvent event) { if (redraws()) event.segments= getBidiLineSegments(event.lineOffset, event.lineText); } });
/** * Creates a signature preview viewer in a parent composite with a 1-column GridLayout. * * @param parent the parent * @return the preview viewer * @since 3.9 */ public static JavaSourceViewer createSignaturePreview(Composite parent) { IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore(); JavaSourceViewer signaturePreview= new JavaSourceViewer(parent, null, null, false, SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP, store); signaturePreview.configure(new JavaSourceViewerConfiguration(JavaPlugin.getDefault().getJavaTextTools().getColorManager(), store, null, null)); StyledText textWidget= signaturePreview.getTextWidget(); textWidget.setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); textWidget.setAlwaysShowScrollBars(false); signaturePreview.adaptBackgroundColor(parent); signaturePreview.setDocument(new Document()); signaturePreview.setEditable(false); GridData gdata= new GridData(GridData.FILL_BOTH); gdata.widthHint= new PixelConverter(textWidget).convertWidthInCharsToPixels(50); gdata.heightHint= textWidget.getLineHeight() * 2; textWidget.setLayoutData(gdata); return signaturePreview; } }
@Override protected SourceViewer createSourceViewer(Composite parent) { IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore(); return new JavaSourceViewer(parent, null, null, false, SWT.LEFT_TO_RIGHT | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION, store); }
private void updatePreview(String text) { if (fSignaturePreview == null) return; if (text.length() == 0) text= "someMethodName"; //$NON-NLS-1$ int top= fSignaturePreview.getTextWidget().getTopPixel(); String signature; try { signature= fRefactoring.getSignature(text); } catch (IllegalArgumentException e) { signature= ""; //$NON-NLS-1$ } fSignaturePreview.getDocument().set(signature); fSignaturePreview.getTextWidget().setTopPixel(top); }
@Override public void lineGetSegments(BidiSegmentEvent event) { if (redraws()) { try { event.segments= getBidiLineSegments(getDocument(), baseLevel, widgetOffset2ModelOffset(event.lineOffset), event.lineText); } catch (BadLocationException e) { // don't touch the segments } } } });