Search in sources :

Example 1 with SimpleJavaSourceViewerConfiguration

use of org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration in project tdi-studio-se by Talend.

the class CodeView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    this.parent = parent;
    parent.setLayout(new FillLayout());
    ECodeLanguage language = LanguageManager.getCurrentLanguage();
    ISourceViewer viewer = null;
    final StyledText text;
    int styles = SWT.H_SCROLL | SWT.V_SCROLL;
    document = new Document();
    switch(language) {
        case JAVA:
            IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
            viewer = new JavaSourceViewer(parent, null, null, false, styles, store);
            viewer.setDocument(document);
            JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools();
            tools.setupJavaDocumentPartitioner(viewer.getDocument(), IJavaPartitions.JAVA_PARTITIONING);
            SimpleJavaSourceViewerConfiguration config = new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, true);
            viewer.configure(config);
            viewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));
            document = viewer.getDocument();
            break;
        // empty since only have java
        default:
    }
    viewer.setEditable(false);
    text = viewer.getTextWidget();
    // getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
    IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
    IAction wrapAction = new Action() {

        @Override
        public void run() {
            text.setWordWrap(isChecked());
        }
    };
    //$NON-NLS-1$
    wrapAction.setToolTipText("wrap");
    wrapAction.setChecked(false);
    //$NON-NLS-1$
    wrapAction.setImageDescriptor(ImageDescriptor.createFromFile(DesignerPlugin.class, "/icons/wrap.gif"));
    tbm.add(wrapAction);
    createMenu();
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) StyledText(org.eclipse.swt.custom.StyledText) SimpleJavaSourceViewerConfiguration(org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration) IAction(org.eclipse.jface.action.IAction) JavaTextTools(org.eclipse.jdt.ui.text.JavaTextTools) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DesignerPlugin(org.talend.designer.core.DesignerPlugin) JavaSourceViewer(org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 2 with SimpleJavaSourceViewerConfiguration

use of org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration in project xtext-xtend by eclipse.

the class DerivedSourceView method createSourceViewer.

@Override
protected SourceViewer createSourceViewer(Composite parent) {
    IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
    IOverviewRuler overviewRuler = new OverviewRuler(defaultMarkerAnnotationAccess, OVERVIEW_RULER_WIDTH, getSharedTextColors());
    AnnotationRulerColumn annotationRulerColumn = new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, defaultMarkerAnnotationAccess);
    @SuppressWarnings("unchecked") List<AnnotationPreference> annotationPreferences = markerAnnotationPreferences.getAnnotationPreferences();
    for (AnnotationPreference annotationPreference : annotationPreferences) {
        String key = annotationPreference.getVerticalRulerPreferenceKey();
        boolean showAnnotation = true;
        if (key != null && store.contains(key)) {
            showAnnotation = store.getBoolean(key);
        }
        if (showAnnotation) {
            annotationRulerColumn.addAnnotationType(annotationPreference.getAnnotationType());
        }
    }
    annotationRulerColumn.addAnnotationType(Annotation.TYPE_UNKNOWN);
    lineNumberRulerColumn = new LineNumberRulerColumn();
    CompositeRuler compositeRuler = new CompositeRuler();
    compositeRuler.addDecorator(0, annotationRulerColumn);
    compositeRuler.addDecorator(1, lineNumberRulerColumn);
    javaSourceViewer = new JavaSourceViewer(parent, compositeRuler, overviewRuler, true, SWT.V_SCROLL | SWT.H_SCROLL, store);
    javaSourceViewerConfiguration = new SimpleJavaSourceViewerConfiguration(JavaPlugin.getDefault().getJavaTextTools().getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, true) {

        @Override
        public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
            return new IInformationControlCreator() {

                @Override
                public IInformationControl createInformationControl(final Shell parent) {
                    return new DefaultInformationControl(parent, true);
                }
            };
        }

        @Override
        public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
            return new DefaultAnnotationHover();
        }
    };
    javaSourceViewer.configure(javaSourceViewerConfiguration);
    javaSourceViewer.setEditable(false);
    javaSourceViewer.showAnnotations(true);
    sourceViewerDecorationSupport = new SourceViewerDecorationSupport(javaSourceViewer, overviewRuler, defaultMarkerAnnotationAccess, getSharedTextColors());
    for (AnnotationPreference annotationPreference : annotationPreferences) {
        sourceViewerDecorationSupport.setAnnotationPreference(annotationPreference);
    }
    sourceViewerDecorationSupport.install(preferenceStoreAccess.getPreferenceStore());
    return javaSourceViewer;
}
Also used : LineNumberRulerColumn(org.eclipse.jface.text.source.LineNumberRulerColumn) SimpleJavaSourceViewerConfiguration(org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration) DefaultInformationControl(org.eclipse.jface.text.DefaultInformationControl) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) SourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport) IAnnotationHover(org.eclipse.jface.text.source.IAnnotationHover) IOverviewRuler(org.eclipse.jface.text.source.IOverviewRuler) IInformationControlCreator(org.eclipse.jface.text.IInformationControlCreator) AnnotationRulerColumn(org.eclipse.jface.text.source.AnnotationRulerColumn) Shell(org.eclipse.swt.widgets.Shell) IInformationControl(org.eclipse.jface.text.IInformationControl) JavaSourceViewer(org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer) OverviewRuler(org.eclipse.jface.text.source.OverviewRuler) IOverviewRuler(org.eclipse.jface.text.source.IOverviewRuler) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) DefaultAnnotationHover(org.eclipse.jface.text.source.DefaultAnnotationHover)

Aggregations

JavaSourceViewer (org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer)2 SimpleJavaSourceViewerConfiguration (org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 JavaTextTools (org.eclipse.jdt.ui.text.JavaTextTools)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 IToolBarManager (org.eclipse.jface.action.IToolBarManager)1 DefaultInformationControl (org.eclipse.jface.text.DefaultInformationControl)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 IInformationControl (org.eclipse.jface.text.IInformationControl)1 IInformationControlCreator (org.eclipse.jface.text.IInformationControlCreator)1 AnnotationRulerColumn (org.eclipse.jface.text.source.AnnotationRulerColumn)1 CompositeRuler (org.eclipse.jface.text.source.CompositeRuler)1 DefaultAnnotationHover (org.eclipse.jface.text.source.DefaultAnnotationHover)1 IAnnotationHover (org.eclipse.jface.text.source.IAnnotationHover)1 IOverviewRuler (org.eclipse.jface.text.source.IOverviewRuler)1 LineNumberRulerColumn (org.eclipse.jface.text.source.LineNumberRulerColumn)1 OverviewRuler (org.eclipse.jface.text.source.OverviewRuler)1