Search in sources :

Example 61 with SourceViewer

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

the class XMLStylePage3 method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
@Override
public void createControl(Composite parent) {
    changed = false;
    final Display display = parent.getDisplay();
    FillLayout fillLayout = new FillLayout();
    fillLayout.type = SWT.VERTICAL;
    parent.setLayout(fillLayout);
    CompositeRuler ruler = new CompositeRuler(3);
    LineNumberRulerColumn lineNumbers = new LineNumberRulerColumn();
    // SWT.COLOR_INFO_BACKGROUND));
    lineNumbers.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
    // SWT.COLOR_INFO_FOREGROUND));
    lineNumbers.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    lineNumbers.setFont(JFaceResources.getTextFont());
    ruler.addDecorator(0, lineNumbers);
    viewer = new SourceViewer(parent, ruler, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.getTextWidget().setFont(JFaceResources.getTextFont());
    SourceViewerConfiguration conf = new SourceViewerConfiguration();
    viewer.configure(conf);
    SLDTransformer trans = new SLDTransformer();
    trans.setIndentation(2);
    String xml;
    try {
        xml = trans.transform(getParent().getStyle());
    } catch (TransformerException e) {
        // $NON-NLS-1$
        xml = "Error: " + e.getMessage();
    }
    IDocument doc = new Document();
    doc.set(xml);
    doc.addDocumentListener(new IDocumentListener() {

        @Override
        public void documentChanged(DocumentEvent event) {
            changed = true;
        }

        @Override
        public void documentAboutToBeChanged(DocumentEvent event) {
        // ignore
        }
    });
    viewer.setInput(doc);
    setControl(viewer.getControl());
}
Also used : LineNumberRulerColumn(org.eclipse.jface.text.source.LineNumberRulerColumn) SourceViewer(org.eclipse.jface.text.source.SourceViewer) IDocumentListener(org.eclipse.jface.text.IDocumentListener) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentEvent(org.eclipse.jface.text.DocumentEvent) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) SLDTransformer(org.geotools.xml.styling.SLDTransformer) TransformerException(javax.xml.transform.TransformerException) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

Example 62 with SourceViewer

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

the class EditTemplateDialog method createEditor.

private SourceViewer createEditor(Composite parent) {
    SourceViewer viewer = createViewer(parent);
    int numberOfLines = viewer.getDocument().getNumberOfLines();
    if (numberOfLines < 7) {
        numberOfLines = 7;
    } else if (numberOfLines > 14) {
        numberOfLines = 14;
    }
    Control control = viewer.getControl();
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = convertWidthInCharsToPixels(80);
    data.heightHint = convertHeightInCharsToPixels(numberOfLines);
    control.setLayoutData(data);
    return viewer;
}
Also used : Control(org.eclipse.swt.widgets.Control) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) GridData(org.eclipse.swt.layout.GridData)

Example 63 with SourceViewer

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

the class MarkupViewerPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    colorRegistry = new Colors();
    colorRegistry.put(WHITE, new RGB(255, 255, 255));
    Composite composite = new Composite(parent, SWT.NULL);
    GridLayoutFactory.fillDefaults().margins(5, 5).numColumns(1).applyTo(composite);
    Label label = new Label(composite, SWT.WRAP);
    label.setText(Messages.MarkupViewerPreferencePage_appearanceInfo);
    GridDataFactory.fillDefaults().applyTo(label);
    Preferences preferences = WikiTextUiPlugin.getDefault().getPreferences();
    Composite viewerContainer = new Composite(composite, SWT.BORDER);
    GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(1).applyTo(viewerContainer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewerContainer);
    {
        sourceViewer = new SourceViewer(viewerContainer, new VerticalRuler(0), SWT.WRAP | SWT.V_SCROLL);
        GridDataFactory.fillDefaults().grab(true, true).applyTo(sourceViewer.getControl());
        Document document = new Document(preferences.getMarkupViewerCss());
        CssPartitioner partitioner = new CssPartitioner();
        partitioner.connect(document);
        document.setDocumentPartitioner(partitioner);
        sourceViewer.setDocument(document);
        CssConfiguration configuration = new CssConfiguration(colorRegistry);
        sourceViewer.configure(configuration);
    }
    label = new Label(composite, SWT.WRAP);
    label.setText(Messages.MarkupViewerPreferencePage_preview);
    GridDataFactory.fillDefaults().applyTo(label);
    applyDialogFont(composite);
    Composite previewViewerContainer = new Composite(composite, SWT.BORDER);
    GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(1).applyTo(previewViewerContainer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(previewViewerContainer);
    {
        previewViewer = new HtmlViewer(previewViewerContainer, new VerticalRuler(0), SWT.WRAP | SWT.V_SCROLL);
        previewViewer.getTextWidget().setBackground(colorRegistry.get(WHITE));
        GridDataFactory.fillDefaults().grab(true, true).applyTo(previewViewer.getControl());
        htmlViewerConfiguration = new HtmlViewerConfiguration(previewViewer);
        previewViewer.configure(htmlViewerConfiguration);
        previewViewer.getTextWidget().setEditable(false);
        previewViewer.setStylesheet(preferences.getStylesheet());
        if (JFaceResources.getFontRegistry().hasValueFor(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_DEFAULT_FONT)) {
            previewViewer.getTextWidget().setFont(JFaceResources.getFontRegistry().get(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_DEFAULT_FONT));
        }
        if (JFaceResources.getFontRegistry().hasValueFor(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_MONOSPACE_FONT)) {
            previewViewer.setDefaultMonospaceFont(JFaceResources.getFontRegistry().get(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_MONOSPACE_FONT));
        }
        previewViewer.setHtml(createPreviewHtml());
        sourceViewer.getDocument().addDocumentListener(new IDocumentListener() {

            public void documentAboutToBeChanged(DocumentEvent event) {
            }

            public void documentChanged(DocumentEvent event) {
                schedulePreviewUpdate();
            }
        });
    }
    return composite;
}
Also used : VerticalRuler(org.eclipse.jface.text.source.VerticalRuler) CssConfiguration(org.eclipse.mylyn.internal.wikitext.ui.util.css.editor.CssConfiguration) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) HtmlViewerConfiguration(org.eclipse.mylyn.wikitext.ui.viewer.HtmlViewerConfiguration) IDocumentListener(org.eclipse.jface.text.IDocumentListener) Label(org.eclipse.swt.widgets.Label) CssPartitioner(org.eclipse.mylyn.internal.wikitext.ui.util.css.editor.CssPartitioner) RGB(org.eclipse.swt.graphics.RGB) Document(org.eclipse.jface.text.Document) DocumentEvent(org.eclipse.jface.text.DocumentEvent) Preferences(org.eclipse.mylyn.internal.wikitext.ui.editor.preferences.Preferences) HtmlViewer(org.eclipse.mylyn.wikitext.ui.viewer.HtmlViewer)

Example 64 with SourceViewer

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

the class ErlangConsolePage method createControl.

/**
 * @wbp.parser.entryPoint
 */
@Override
public void createControl(final Composite parent) {
    setBackgroundColors();
    composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    final SashForm sashForm = new SashForm(composite, SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    consoleOutputViewer = new SourceViewer(sashForm, null, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.READ_ONLY);
    consoleOutputText = consoleOutputViewer.getTextWidget();
    consoleOutputText.setFont(JFaceResources.getTextFont());
    bgcolor = DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR);
    consoleOutputText.setBackground(bgcolor);
    DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(event -> {
        if (event.getProperty().equals(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR)) {
            final Color color = DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR);
            consoleOutputText.setBackground(color);
            consoleInputText.setBackground(color);
        }
    });
    consoleOutputText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final KeyEvent e) {
            if (e.stateMask == 0 && e.character != '\0') {
                consoleInputText.setFocus();
                consoleInputText.append("" + e.character);
                consoleInputText.setCaretOffset(consoleInputText.getText().length());
            }
            e.doit = true;
        }
    });
    final IPreferenceStore store = ErlideUIPlugin.getDefault().getPreferenceStore();
    final IColorManager colorManager = new ColorManager();
    consoleOutputViewer.setDocument(fDoc);
    consoleOutputViewer.configure(new ErlangConsoleSourceViewerConfiguration(store, colorManager, backend));
    consoleInputViewer = new SourceViewer(sashForm, null, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    consoleInputText = consoleInputViewer.getTextWidget();
    consoleInputViewer.setDocument(new Document());
    consoleInputViewer.configure(new ErlangConsoleSourceViewerConfiguration(store, colorManager, backend));
    sashForm.setWeights(new int[] { 2, 1 });
    final Label helpLabel = new Label(composite, SWT.NONE);
    helpLabel.setText("To send the input to the console: press Enter at the end of an expression." + "Ctrl/Cmd-arrows navigate the input history.");
    helpLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    final ModifyListener modifyListener = e -> {
        final String consoleText = ErlangConsolePage.trimInput(consoleInputText.getText());
        final boolean atEndOfInput = consoleText.endsWith(".") && consoleInputText.getCaretOffset() >= consoleText.length();
        if (atEndOfInput) {
            final boolean inputComplete = isInputComplete();
            if (inputComplete) {
                consoleInputText.setBackground(bgColor_Ok);
            }
        } else {
            consoleInputText.setBackground(bgcolor);
        }
    };
    // consoleInput.addModifyListener(modifyListener);
    consoleInputText.addCaretListener(event -> modifyListener.modifyText(null));
    consoleInputText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final KeyEvent e) {
            final boolean ctrlOrCommandPressed = (e.stateMask & SWT.MOD1) == SWT.MOD1;
            final String conText = ErlangConsolePage.trimInput(consoleInputText.getText());
            final boolean atEndOfInput = consoleInputText.getCaretOffset() >= conText.length() && conText.endsWith(".");
            e.doit = true;
            if (e.keyCode == 13 && (ctrlOrCommandPressed || atEndOfInput)) {
                final boolean inputComplete = isInputComplete();
                if (inputComplete) {
                    sendInput();
                }
            } else if (ctrlOrCommandPressed && e.keyCode == SWT.SPACE) {
                consoleInputViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
            } else if (ctrlOrCommandPressed && e.keyCode == SWT.ARROW_UP) {
                e.doit = false;
                history.prev();
                final String s = history.get();
                if (s != null) {
                    consoleInputText.setText(s);
                    consoleInputText.setSelection(consoleInputText.getText().length());
                }
            } else if (ctrlOrCommandPressed && e.keyCode == SWT.ARROW_DOWN) {
                e.doit = false;
                history.next();
                final String s = history.get();
                if (s != null) {
                    consoleInputText.setText(s);
                    consoleInputText.setSelection(consoleInputText.getText().length());
                }
            }
        }
    });
    consoleInputText.setFont(consoleOutputText.getFont());
    consoleInputText.setBackground(consoleOutputText.getBackground());
    consoleInputText.setWordWrap(true);
    consoleInputText.setFocus();
    // end layout
    final IDocumentListener documentListener = new IDocumentListener() {

        @Override
        public void documentAboutToBeChanged(final DocumentEvent event) {
        }

        @Override
        public void documentChanged(final DocumentEvent event) {
            final int end = consoleOutputViewer.getDocument().getLength();
            consoleOutputViewer.setSelectedRange(end, end);
            consoleOutputViewer.revealRange(end, 0);
        }
    };
    addDocumentListener(documentListener);
    // $NON-NLS-1$
    final String id = "#ContextMenu";
    // if (getConsole().getType() != null) {
    // id = getConsole().getType() + "." + id; //$NON-NLS-1$
    // }
    // $NON-NLS-1$
    fMenuManager = new MenuManager("#ContextMenu", id);
    fMenuManager.setRemoveAllWhenShown(true);
    fMenuManager.addMenuListener(this::contextMenuAboutToShow);
    final Menu menu = fMenuManager.createContextMenu(getControl());
    getControl().setMenu(menu);
    createActions();
    configureToolBar(getSite().getActionBars().getToolBarManager());
    getSite().registerContextMenu(id, fMenuManager, consoleOutputViewer);
    getSite().setSelectionProvider(consoleOutputViewer);
    consoleOutputViewer.getSelectionProvider().addSelectionChangedListener(selectionChangedListener);
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) SashForm(org.eclipse.swt.custom.SashForm) IColorManager(org.erlide.ui.util.IColorManager) StyledText(org.eclipse.swt.custom.StyledText) IAction(org.eclipse.jface.action.IAction) Page(org.eclipse.ui.part.Page) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Nullable(org.eclipse.jdt.annotation.Nullable) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) IConsoleView(org.eclipse.ui.console.IConsoleView) Map(java.util.Map) KeyEvent(org.eclipse.swt.events.KeyEvent) Widget(org.eclipse.swt.widgets.Widget) IBackendShell(org.erlide.runtime.shell.IBackendShell) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IAdaptable(org.eclipse.core.runtime.IAdaptable) IUpdate(org.eclipse.ui.texteditor.IUpdate) Separator(org.eclipse.jface.action.Separator) IDebugPreferenceConstants(org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants) PlatformUI(org.eclipse.ui.PlatformUI) MenuManager(org.eclipse.jface.action.MenuManager) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) Display(org.eclipse.swt.widgets.Display) DocumentEvent(org.eclipse.jface.text.DocumentEvent) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) List(java.util.List) SWT(org.eclipse.swt.SWT) ParserException(org.erlide.engine.services.parsing.ParserException) Label(org.eclipse.swt.widgets.Label) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IConsoleHelpContextIds(org.eclipse.ui.internal.console.IConsoleHelpContextIds) StringUtils(org.erlide.util.StringUtils) HashMap(java.util.HashMap) JFaceResources(org.eclipse.jface.resource.JFaceResources) RuntimeHelper(org.erlide.engine.services.parsing.RuntimeHelper) ArrayList(java.util.ArrayList) ConsoleResourceBundleMessages(org.eclipse.ui.internal.console.ConsoleResourceBundleMessages) FindReplaceAction(org.eclipse.ui.texteditor.FindReplaceAction) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocumentListener(org.eclipse.jface.text.IDocumentListener) ResourceBundle(java.util.ResourceBundle) RGB(org.eclipse.swt.graphics.RGB) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) GridData(org.eclipse.swt.layout.GridData) IWorkbenchActionConstants(org.eclipse.ui.IWorkbenchActionConstants) ErlideUIPlugin(org.erlide.ui.internal.ErlideUIPlugin) IConsoleConstants(org.eclipse.ui.console.IConsoleConstants) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) DebugUIPlugin(org.eclipse.debug.internal.ui.DebugUIPlugin) IActionBars(org.eclipse.ui.IActionBars) SourceViewer(org.eclipse.jface.text.source.SourceViewer) IBackend(org.erlide.backend.api.IBackend) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) ModifyListener(org.eclipse.swt.events.ModifyListener) ActionFactory(org.eclipse.ui.actions.ActionFactory) Menu(org.eclipse.swt.widgets.Menu) ColorManager(org.erlide.ui.util.ColorManager) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) Color(org.eclipse.swt.graphics.Color) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IColorManager(org.erlide.ui.util.IColorManager) IDocumentListener(org.eclipse.jface.text.IDocumentListener) Label(org.eclipse.swt.widgets.Label) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentEvent(org.eclipse.jface.text.DocumentEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IColorManager(org.erlide.ui.util.IColorManager) ColorManager(org.erlide.ui.util.ColorManager)

Example 65 with SourceViewer

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

the class ErlTemplatePreferencePage method createViewer.

@Override
protected SourceViewer createViewer(final Composite parent) {
    final SourceViewer viewer = ErlangSourceViewer.createErlangPreviewer(parent, null, null, null, "");
    // new SourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL
    // | SWT.H_SCROLL);
    // final SourceViewerConfiguration configuration= new
    // SourceViewerConfiguration();
    // viewer.configure(configuration);
    final IDocument document = new Document();
    viewer.setDocument(document);
    return viewer;
}
Also used : SourceViewer(org.eclipse.jface.text.source.SourceViewer) ErlangSourceViewer(org.erlide.ui.editors.erl.ErlangSourceViewer) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument)

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