Search in sources :

Example 26 with SourceViewer

use of org.eclipse.jface.text.source.SourceViewer in project webtools.sourceediting by eclipse.

the class ResultView method createViewer.

private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {

        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXSL();

        @Override
        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return baseConfiguration.getConfiguredContentTypes(sourceViewer);
        }

        @Override
        public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
            return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
        }
    };
    SourceViewer viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    // $NON-NLS-1$
    ((StructuredTextViewer) viewer).getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    viewer.configure(sourceViewerConfiguration);
    viewer.setEditable(false);
    return viewer;
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) StructuredTextViewerConfigurationXSL(org.eclipse.wst.xsl.ui.internal.StructuredTextViewerConfigurationXSL) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 27 with SourceViewer

use of org.eclipse.jface.text.source.SourceViewer in project webtools.sourceediting by eclipse.

the class XMLTemplatePreferencePage method doCreateViewer.

SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) {
    SourceViewer viewer = null;
    String contentTypeID = ContentTypeIdForXML.ContentTypeID_XML;
    viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    // $NON-NLS-1$
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(contentTypeID);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(viewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 28 with SourceViewer

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

the class SQLEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    setRangeIndicator(new DefaultRangeIndicator());
    // divides editor area and results/panels area
    resultsSash = UIUtils.createPartDivider(this, parent, resultSetOrientation.getSashOrientation() | SWT.SMOOTH);
    CSSUtils.setCSSClass(resultsSash, DBStyles.COLORED_BY_CONNECTION_TYPE);
    resultsSash.setSashWidth(5);
    UIUtils.setHelp(resultsSash, IHelpContextIds.CTX_SQL_EDITOR);
    Composite editorContainer;
    sqlEditorPanel = UIUtils.createPlaceholder(resultsSash, 3, 0);
    // Create left vertical toolbar
    createControlsBar(sqlEditorPanel);
    // Create editor presentations sash
    Composite pPlaceholder = null;
    if (extraPresentationDescriptor != null) {
        presentationSash = UIUtils.createPartDivider(this, sqlEditorPanel, ((resultSetOrientation.getSashOrientation() == SWT.VERTICAL) ? SWT.HORIZONTAL : SWT.VERTICAL) | SWT.SMOOTH);
        presentationSash.setSashWidth(5);
        presentationSash.setLayoutData(new GridData(GridData.FILL_BOTH));
        editorContainer = presentationSash;
        pPlaceholder = new Composite(presentationSash, SWT.NONE);
        pPlaceholder.setLayout(new FillLayout());
    } else {
        editorContainer = sqlEditorPanel;
    }
    super.createPartControl(editorContainer);
    getEditorControlWrapper().setLayoutData(new GridData(GridData.FILL_BOTH));
    // Create right vertical toolbar
    createPresentationSwitchBar(sqlEditorPanel);
    if (pPlaceholder != null) {
        switch(extraPresentationDescriptor.getActivationType()) {
            case HIDDEN:
                presentationSash.setMaximizedControl(presentationSash.getChildren()[SQL_EDITOR_CONTROL_INDEX]);
                break;
            case MAXIMIZED:
            case VISIBLE:
                extraPresentation.createPresentation(pPlaceholder, this);
                if (extraPresentationDescriptor.getActivationType() == SQLEditorPresentation.ActivationType.MAXIMIZED) {
                    if (presentationSash.getChildren()[EXTRA_CONTROL_INDEX] != null) {
                        presentationSash.setMaximizedControl(pPlaceholder);
                    }
                }
                break;
        }
    }
    getSite().setSelectionProvider(new DynamicSelectionProvider());
    DBPProject project = getProject();
    if (project != null && project.isRegistryLoaded()) {
        createResultTabs();
    } else {
        UIExecutionQueue.queueExec(this::createResultTabs);
    }
    setAction(ITextEditorActionConstants.SHOW_INFORMATION, null);
    SourceViewer viewer = getViewer();
    if (viewer != null) {
        StyledText textWidget = viewer.getTextWidget();
        if (textWidget != null) {
            textWidget.addModifyListener(this::onTextChange);
            textWidget.addFocusListener(new FocusAdapter() {

                @Override
                public void focusGained(FocusEvent e) {
                    refreshActions();
                }
            });
        }
    }
    SQLEditorFeatures.SQL_EDITOR_OPEN.use();
    // Start output reader
    new ServerOutputReader().schedule();
    updateExecutionContext(null);
    // Update controls
    UIExecutionQueue.queueExec(this::onDataSourceChange);
}
Also used : DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StyledText(org.eclipse.swt.custom.StyledText) GridData(org.eclipse.swt.layout.GridData) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) FillLayout(org.eclipse.swt.layout.FillLayout) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader)

Example 29 with SourceViewer

use of org.eclipse.jface.text.source.SourceViewer in project hale by halestudio.

the class TypeStructureTray method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(page);
    // retrieve the types
    final Collection<? extends TypeDefinition> types = this.types.getTypes();
    // heading
    Label caption = new Label(page, SWT.NONE);
    switch(schemaSpace) {
        case SOURCE:
            caption.setText("Source structure");
            break;
        case TARGET:
            caption.setText("Target structure");
            break;
    }
    caption.setFont(JFaceResources.getHeaderFont());
    // create tree viewer
    PatternFilter patternFilter = new SchemaPatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    final FilteredTree filteredTree = new TreePathFilteredTree(page, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    TreeViewer tree = filteredTree.getViewer();
    tree.setUseHashlookup(true);
    StyledDefinitionLabelProvider labelProvider = new StyledDefinitionLabelProvider(tree);
    tree.setLabelProvider(labelProvider);
    IContentProvider contentProvider = createContentProvider(tree);
    tree.setContentProvider(contentProvider);
    GridDataFactory.fillDefaults().grab(true, true).hint(280, 400).applyTo(filteredTree);
    tree.setComparator(new DefinitionComparator());
    // set input
    if (types.size() == 1) {
        tree.setInput(types.iterator().next());
    } else {
        tree.setInput(types);
    }
    /*
		 * Groovy specific part
		 */
    // caption
    Label example = new Label(page, SWT.NONE);
    switch(schemaSpace) {
        case SOURCE:
            example.setText("Examples: Access variables");
            break;
        case TARGET:
            example.setText("Example: Build instance");
            break;
        default:
            example.setText("Example");
    }
    // source viewer
    final SourceViewer viewer = new SourceViewer(page, null, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
    final IColorManager colorManager = new GroovyColorManager();
    SourceViewerConfiguration configuration = new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_TARGET, BINDING_BUILDER, BINDING_INDEX, BINDING_SOURCE, BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT), null);
    viewer.configure(configuration);
    GridDataFactory.fillDefaults().grab(true, false).hint(200, 130).applyTo(viewer.getControl());
    // make sure the color manager is disposed
    viewer.getControl().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            colorManager.dispose();
        }
    });
    // react to tree selection changes
    tree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IDocument doc = new Document();
            GroovySourceViewerUtil.setupDocument(doc);
            String example = null;
            if (!event.getSelection().isEmpty()) {
                switch(schemaSpace) {
                    case SOURCE:
                        example = createSourceSample(event.getSelection(), types);
                        break;
                    case TARGET:
                        example = createTargetSample(event.getSelection(), types);
                        break;
                }
            }
            if (example == null || example.isEmpty()) {
                switch(schemaSpace) {
                    case SOURCE:
                        doc.set("// Please select schema elements to access");
                        break;
                    case TARGET:
                        doc.set("// Please select which schema elements\n// to include in the instance to build");
                        break;
                    default:
                        doc.set("// Please select one or more schema elements");
                }
            } else {
                doc.set(example);
            }
            viewer.setDocument(doc);
        }
    });
    tree.setSelection(StructuredSelection.EMPTY);
    return page;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) IContentProvider(org.eclipse.jface.viewers.IContentProvider) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) GroovyColorManager(eu.esdihumboldt.hale.ui.util.groovy.GroovyColorManager) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) IColorManager(eu.esdihumboldt.hale.ui.util.IColorManager) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) IDocument(org.eclipse.jface.text.IDocument)

Example 30 with SourceViewer

use of org.eclipse.jface.text.source.SourceViewer in project dbeaver by dbeaver.

the class SQLEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    setRangeIndicator(new DefaultRangeIndicator());
    // divides editor area and results/panels area
    resultsSash = UIUtils.createPartDivider(this, parent, resultSetOrientation.getSashOrientation() | SWT.SMOOTH);
    CSSUtils.setCSSClass(resultsSash, DBStyles.COLORED_BY_CONNECTION_TYPE);
    resultsSash.setSashWidth(5);
    UIUtils.setHelp(resultsSash, IHelpContextIds.CTX_SQL_EDITOR);
    Composite editorContainer;
    sqlEditorPanel = UIUtils.createPlaceholder(resultsSash, 3, 0);
    // Create left vertical toolbar
    createControlsBar(sqlEditorPanel);
    // Create editor presentations sash
    Composite pPlaceholder = null;
    if (extraPresentationDescriptor != null) {
        presentationSash = UIUtils.createPartDivider(this, sqlEditorPanel, ((resultSetOrientation.getSashOrientation() == SWT.VERTICAL) ? SWT.HORIZONTAL : SWT.VERTICAL) | SWT.SMOOTH);
        presentationSash.setSashWidth(5);
        presentationSash.setLayoutData(new GridData(GridData.FILL_BOTH));
        editorContainer = presentationSash;
        pPlaceholder = new Composite(presentationSash, SWT.NONE);
        pPlaceholder.setLayout(new FillLayout());
    } else {
        editorContainer = sqlEditorPanel;
    }
    super.createPartControl(editorContainer);
    getEditorControlWrapper().setLayoutData(new GridData(GridData.FILL_BOTH));
    // Create right vertical toolbar
    createPresentationSwitchBar(sqlEditorPanel);
    if (pPlaceholder != null) {
        switch(extraPresentationDescriptor.getActivationType()) {
            case HIDDEN:
                presentationSash.setMaximizedControl(presentationSash.getChildren()[SQL_EDITOR_CONTROL_INDEX]);
                break;
            case MAXIMIZED:
            case VISIBLE:
                extraPresentation.createPresentation(pPlaceholder, this);
                if (extraPresentationDescriptor.getActivationType() == SQLEditorPresentation.ActivationType.MAXIMIZED) {
                    if (presentationSash.getChildren()[EXTRA_CONTROL_INDEX] != null) {
                        presentationSash.setMaximizedControl(pPlaceholder);
                    }
                }
                break;
        }
    }
    getSite().setSelectionProvider(new DynamicSelectionProvider());
    DBPProject project = getProject();
    if (project != null && project.isRegistryLoaded()) {
        createResultTabs();
    } else {
        UIExecutionQueue.queueExec(this::createResultTabs);
    }
    setAction(ITextEditorActionConstants.SHOW_INFORMATION, null);
    SourceViewer viewer = getViewer();
    if (viewer != null) {
        StyledText textWidget = viewer.getTextWidget();
        if (textWidget != null) {
            textWidget.addModifyListener(this::onTextChange);
            textWidget.addFocusListener(new FocusAdapter() {

                @Override
                public void focusGained(FocusEvent e) {
                    refreshActions();
                }
            });
        }
    }
    SQLEditorFeatures.SQL_EDITOR_OPEN.use();
    // Start output reader
    new ServerOutputReader().schedule();
    updateExecutionContext(null);
    // Update controls
    UIExecutionQueue.queueExec(this::onDataSourceChange);
}
Also used : DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StyledText(org.eclipse.swt.custom.StyledText) GridData(org.eclipse.swt.layout.GridData) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) FillLayout(org.eclipse.swt.layout.FillLayout) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader)

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