Search in sources :

Example 1 with ProjectionViewer

use of org.eclipse.jface.text.source.projection.ProjectionViewer in project dbeaver by serge-rider.

the class SQLEditorBase method createPartControl.

@Override
public void createPartControl(Composite parent) {
    setRangeIndicator(new DefaultRangeIndicator());
    super.createPartControl(new SQLEditorControl(parent, this));
    ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
    projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors());
    //$NON-NLS-1$
    projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error");
    //$NON-NLS-1$
    projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning");
    projectionSupport.install();
    viewer.doOperation(ProjectionViewer.TOGGLE);
    annotationModel = viewer.getProjectionAnnotationModel();
    // Symbol inserter
    {
        SQLSymbolInserter symbolInserter = new SQLSymbolInserter(this);
        DBPPreferenceStore preferenceStore = getActivePreferenceStore();
        boolean closeSingleQuotes = preferenceStore.getBoolean(SQLPreferenceConstants.SQLEDITOR_CLOSE_SINGLE_QUOTES);
        boolean closeDoubleQuotes = preferenceStore.getBoolean(SQLPreferenceConstants.SQLEDITOR_CLOSE_DOUBLE_QUOTES);
        boolean closeBrackets = preferenceStore.getBoolean(SQLPreferenceConstants.SQLEDITOR_CLOSE_BRACKETS);
        symbolInserter.setCloseSingleQuotesEnabled(closeSingleQuotes);
        symbolInserter.setCloseDoubleQuotesEnabled(closeDoubleQuotes);
        symbolInserter.setCloseBracketsEnabled(closeBrackets);
        ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer instanceof ITextViewerExtension) {
            ((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(symbolInserter);
        }
    }
}
Also used : ProjectionSupport(org.eclipse.jface.text.source.projection.ProjectionSupport) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) SQLSymbolInserter(org.jkiss.dbeaver.ui.editors.sql.util.SQLSymbolInserter) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 2 with ProjectionViewer

use of org.eclipse.jface.text.source.projection.ProjectionViewer in project dbeaver by serge-rider.

the class SQLEditorBase method reloadSyntaxRules.

public void reloadSyntaxRules() {
    // Refresh syntax
    SQLDialect dialect = getSQLDialect();
    syntaxManager.init(dialect, getActivePreferenceStore());
    ruleManager.refreshRules(getDataSource(), getEditorInput());
    Document document = getDocument();
    if (document != null) {
        IDocumentPartitioner partitioner = new FastPartitioner(new SQLPartitionScanner(dialect), SQLPartitionScanner.SQL_CONTENT_TYPES);
        partitioner.connect(document);
        document.setDocumentPartitioner(SQLPartitionScanner.SQL_PARTITIONING, partitioner);
        ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
        if (projectionViewer != null && projectionViewer.getAnnotationModel() != null && document.getLength() > 0) {
            //projectionViewer.getTextWidget().redraw();
            try {
                projectionViewer.reinitializeProjection();
            } catch (Throwable ex) {
                // We can catch OutOfMemory here for too big/complex documents
                //$NON-NLS-1$
                log.warn("Can't initialize SQL syntax projection", ex);
            }
        }
    }
    // Update configuration
    if (getSourceViewerConfiguration() instanceof SQLEditorSourceViewerConfiguration) {
        ((SQLEditorSourceViewerConfiguration) getSourceViewerConfiguration()).onDataSourceChange();
    }
    final IVerticalRuler verticalRuler = getVerticalRuler();
    if (verticalRuler != null) {
        verticalRuler.update();
    }
}
Also used : BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) SQLPartitionScanner(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLPartitionScanner) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer)

Example 3 with ProjectionViewer

use of org.eclipse.jface.text.source.projection.ProjectionViewer in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    super.createPartControl(parent);
    ProjectionViewer viewer = getProjectionViewer();
    projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors());
    projectionSupport.install();
    // turn projection mode on
    viewer.doOperation(ProjectionViewer.TOGGLE);
    annotationModel = viewer.getProjectionAnnotationModel();
    preferenceStore.addPropertyChangeListener(preferenceChangeListener);
}
Also used : ProjectionSupport(org.eclipse.jface.text.source.projection.ProjectionSupport) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer)

Example 4 with ProjectionViewer

use of org.eclipse.jface.text.source.projection.ProjectionViewer in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonEditor method doCreateSourceViewer.

protected ISourceViewer doCreateSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
    ProjectionViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles) {

        private IInformationPresenter outlinePresenter;

        @Override
        public void doOperation(int operation) {
            if (operation == OpenQuickOutlineHandler.QUICK_OUTLINE && outlinePresenter != null) {
                outlinePresenter.showInformation();
                return;
            }
            super.doOperation(operation);
        }

        @Override
        public boolean canDoOperation(int operation) {
            if (operation == OpenQuickOutlineHandler.QUICK_OUTLINE && outlinePresenter != null) {
                return true;
            }
            return super.canDoOperation(operation);
        }

        @Override
        public void configure(SourceViewerConfiguration configuration) {
            super.configure(configuration);
            if (configuration instanceof JsonSourceViewerConfiguration) {
                JsonSourceViewerConfiguration c = (JsonSourceViewerConfiguration) configuration;
                outlinePresenter = c.getOutlinePresenter(this);
                if (outlinePresenter != null) {
                    outlinePresenter.install(this);
                }
            }
        }
    };
    IFocusService focusService = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);
    if (focusService != null) {
        focusService.addFocusTracker(viewer.getTextWidget(), "com.reprezen.swagedit.editor.sourceViewer");
    }
    viewer.getTextWidget().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
        // detectOutlineLocationChanged();
        }
    });
    viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
    getSourceViewerDecorationSupport(viewer);
    return viewer;
}
Also used : YEditSourceViewerConfiguration(org.dadacoalition.yedit.editor.YEditSourceViewerConfiguration) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IInformationPresenter(org.eclipse.jface.text.information.IInformationPresenter) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) IFocusService(org.eclipse.ui.swt.IFocusService) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer)

Aggregations

ProjectionViewer (org.eclipse.jface.text.source.projection.ProjectionViewer)4 ProjectionSupport (org.eclipse.jface.text.source.projection.ProjectionSupport)2 YEditSourceViewerConfiguration (org.dadacoalition.yedit.editor.YEditSourceViewerConfiguration)1 IInformationPresenter (org.eclipse.jface.text.information.IInformationPresenter)1 FastPartitioner (org.eclipse.jface.text.rules.FastPartitioner)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 IFocusService (org.eclipse.ui.swt.IFocusService)1 BasicSQLDialect (org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect)1 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)1 SQLPartitionScanner (org.jkiss.dbeaver.ui.editors.sql.syntax.SQLPartitionScanner)1 SQLSymbolInserter (org.jkiss.dbeaver.ui.editors.sql.util.SQLSymbolInserter)1