Search in sources :

Example 6 with SourceViewer

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();
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) MonoReconciler(org.eclipse.jface.text.reconciler.MonoReconciler) IRegion(org.eclipse.jface.text.IRegion) Shell(org.eclipse.swt.widgets.Shell) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

Example 7 with SourceViewer

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();
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) HashSet(java.util.HashSet) Set(java.util.Set) InlinedAnnotationSupport(org.eclipse.jface.text.source.inlined.InlinedAnnotationSupport) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) MonoReconciler(org.eclipse.jface.text.reconciler.MonoReconciler) IRegion(org.eclipse.jface.text.IRegion) Shell(org.eclipse.swt.widgets.Shell) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

Example 8 with SourceViewer

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));
    }
}
Also used : SpecfileConfiguration(org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileConfiguration) SourceViewer(org.eclipse.jface.text.source.SourceViewer) SpecfileEditor(org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor)

Example 9 with SourceViewer

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);
    }
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) CoreException(org.eclipse.core.runtime.CoreException) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IMarker(org.eclipse.core.resources.IMarker) IDocument(org.eclipse.jface.text.IDocument) IResource(org.eclipse.core.resources.IResource) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 10 with SourceViewer

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;
    }
}
Also used : VerticalRuler(org.eclipse.jface.text.source.VerticalRuler) SourceViewer(org.eclipse.jface.text.source.SourceViewer) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Document(org.eclipse.jface.text.Document) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IFile(org.eclipse.core.resources.IFile) File(java.io.File) TextSourceViewerConfiguration(org.eclipse.ui.editors.text.TextSourceViewerConfiguration)

Aggregations

SourceViewer (org.eclipse.jface.text.source.SourceViewer)67 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)39 IDocument (org.eclipse.jface.text.IDocument)26 GridData (org.eclipse.swt.layout.GridData)24 Label (org.eclipse.swt.widgets.Label)23 Composite (org.eclipse.swt.widgets.Composite)16 Document (org.eclipse.jface.text.Document)15 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)14 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)14 Control (org.eclipse.swt.widgets.Control)13 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 Button (org.eclipse.swt.widgets.Button)11 Iterator (java.util.Iterator)10 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)8 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8