use of org.eclipse.jface.text.source.SourceViewer in project eclipse.platform.text by eclipse.
the class CodeMiningDemo method main.
public static void main(String[] args) throws Exception {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("Code Mining demo");
ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
sourceViewer.setDocument(new Document("// Type class & new keyword and see references CodeMining\n" + "// Name class with a number N to emulate Nms before resolving the references CodeMining \n\n" + "class A\n" + "new A\n" + "new A\n\n" + "class 5\n" + "new 5\n" + "new 5\n" + "new 5"), new AnnotationModel());
// Add AnnotationPainter (required by CodeMining)
addAnnotationPainter(sourceViewer);
// Initialize codemining providers
((ISourceViewerExtension5) sourceViewer).setCodeMiningProviders(new ICodeMiningProvider[] { new ClassReferenceCodeMiningProvider(), new ClassImplementationsCodeMiningProvider() });
// Execute codemining in a reconciler
MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {
@Override
public void setDocument(IDocument document) {
((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
}
@Override
public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
}
@Override
public void reconcile(IRegion partition) {
((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
}
}, false);
reconciler.install(sourceViewer);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.jface.text.source.SourceViewer in project eclipse.platform.text by eclipse.
the class InlinedAnnotationDemo method main.
public static void main(String[] args) throws Exception {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("Inlined annotation demo");
// Create source viewer and initialize the content
ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
sourceViewer.setDocument(new Document("\ncolor:rgb(255, 255, 0)"), new AnnotationModel());
// Initialize inlined annotations support
InlinedAnnotationSupport support = new InlinedAnnotationSupport();
support.install(sourceViewer, createAnnotationPainter(sourceViewer));
// Refresh inlined annotation in none UI Thread with reconciler.
MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {
@Override
public void setDocument(IDocument document) {
Set<AbstractInlinedAnnotation> annotations = getInlinedAnnotation(sourceViewer, support);
support.updateAnnotations(annotations);
}
@Override
public void reconcile(IRegion partition) {
Set<AbstractInlinedAnnotation> anns = getInlinedAnnotation(sourceViewer, support);
support.updateAnnotations(anns);
}
@Override
public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
}
}, false);
reconciler.setDelay(1);
reconciler.install(sourceViewer);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.jface.text.source.SourceViewer in project linuxtools by eclipse.
the class SpecMergeViewer method configureTextViewer.
@Override
protected void configureTextViewer(TextViewer textViewer) {
if (textViewer instanceof SourceViewer) {
SpecfileEditor editor = new SpecfileEditor();
((SourceViewer) textViewer).configure(new SpecfileConfiguration(editor));
}
}
use of org.eclipse.jface.text.source.SourceViewer in project abstools by abstools.
the class ABSEditor method highlightLine.
/**
* highlights the given line as the current instruction point
* @param line the line the debugger is currently running in
*/
public void highlightLine(int line) {
IDocument doc = getDocumentProvider().getDocument(getEditorInput());
int lineOffset;
try {
lineOffset = doc.getLineOffset(line);
IResource resource = getResource();
if (resource != null) {
// can be null for files inside jars
resource.deleteMarkers(Constants.CURRENT_IP_MARKER, false, IResource.DEPTH_ZERO);
getSourceViewer().invalidateTextPresentation();
IMarker marker = resource.createMarker(Constants.CURRENT_IP_MARKER);
marker.setAttribute(IMarker.LINE_NUMBER, line);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
marker.setAttribute(IMarker.MESSAGE, "current instruction pointer");
}
if (getSourceViewer() instanceof SourceViewer) {
SourceViewer sourceviewer = (SourceViewer) getSourceViewer();
sourceviewer.setSelection(new TextSelection(lineOffset, 0), true);
// sourceviewer.refresh();
}
} catch (CoreException e) {
standardExceptionHandling(e);
} catch (BadLocationException e) {
standardExceptionHandling(e);
}
}
use of org.eclipse.jface.text.source.SourceViewer in project tmdm-studio-se by Talend.
the class ProcessResultsDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
try {
parent.getShell().setText(title);
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = (GridLayout) composite.getLayout();
layout.numColumns = 2;
((GridData) composite.getLayoutData()).widthHint = 800;
Label variableLabel = new Label(composite, SWT.NONE);
variableLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
variableLabel.setText(Messages.ProcessResultsDialog_PipelineVariables);
variablesCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
variablesCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1));
/*
* variablesCombo.addKeyListener( new KeyListener() { public void keyPressed(KeyEvent e) {} public void
* keyReleased(KeyEvent e) { if ((e.stateMask==0) && (e.character == SWT.CR)) {
* ProcessResultsPage.this.variablesViewer.setDocument(new Document(getText(variablesCombo.getText()))); }
* }//keyReleased }//keyListener );
*/
variablesViewer = new SourceViewer(composite, new VerticalRuler(10), SWT.V_SCROLL | SWT.H_SCROLL);
variablesViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1));
variablesViewer.configure(new TextSourceViewerConfiguration());
((GridData) variablesViewer.getControl().getLayoutData()).minimumHeight = 500;
final Button seeInBrowser = new Button(composite, SWT.PUSH);
seeInBrowser.setText(Messages.ProcessResultsDialog_display);
seeInBrowser.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String htmlContent = variablesViewer.getTextWidget().getText();
IFile file = FileProvider.createdTempFile(htmlContent, Messages.ProcessResultsDialog_temphtml, null);
File htmlFile = file.getLocation().toFile();
// $NON-NLS-1$
String SHARED_ID = "org.eclipse.ui.browser";
try {
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
if (WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.INTERNAL) {
support.createBrowser(IWorkbenchBrowserSupport.AS_EDITOR, file.getLocation().toPortableString(), null, null).openURL(htmlFile.toURL());
} else {
support.createBrowser(IWorkbenchBrowserSupport.AS_EXTERNAL, SHARED_ID, null, null).openURL(htmlFile.toURL());
}
} catch (Exception e1) {
log.error(e1.getMessage(), e1);
}
}
});
variablesCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
String output = variablesCombo.getText();
if (output.startsWith(TransformerMainPage.DEFAULT_DISPLAY)) {
// TransformerMainPage.DEFAULT_VAR+output.substring(TransformerMainPage.DEFAULT_DISPLAY.length());
output = DEFAULT_DISPLAY_TEXT;
}
String text = variablesCombo.getText();
if (text.equals(DEFAULT_DISPLAY_TEXT)) {
text = TransformerMainPage.DEFAULT_DISPLAY;
}
variablesViewer.setDocument(new Document(getText(text)));
// $NON-NLS-1$
seeInBrowser.setEnabled("html".equals(text));
}
});
variablesCombo.setFocus();
refreshData();
return composite;
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(this.getShell(), Messages._Error, Messages.bind(Messages.ProcessResultsDialog_ErrorMsg, e.getLocalizedMessage()));
return null;
}
}
Aggregations