Search in sources :

Example 51 with SourceViewer

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

the class CSSSyntaxColoringPage method createContents.

protected Control createContents(final Composite parent) {
    initializeDialogUnits(parent);
    fDefaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    fDefaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    Composite pageComponent = createComposite(parent, 2);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.CSS_PREFWEBX_STYLES_HELPID);
    Link link = new Link(pageComponent, SWT.WRAP);
    link.setText(SSEUIMessages.SyntaxColoring_Link);
    link.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
        }
    });
    GridData linkData = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1);
    // only expand further if anyone else requires it
    linkData.widthHint = 150;
    link.setLayoutData(linkData);
    new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
    new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
    SashForm editor = new SashForm(pageComponent, SWT.VERTICAL);
    GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData2.horizontalSpan = 2;
    editor.setLayoutData(gridData2);
    SashForm top = new SashForm(editor, SWT.HORIZONTAL);
    Composite styleEditor = createComposite(top, 1);
    ((GridLayout) styleEditor.getLayout()).marginRight = 5;
    ((GridLayout) styleEditor.getLayout()).marginLeft = 0;
    createLabel(styleEditor, CSSUIMessages.SyntaxColoringPage_0);
    fStylesViewer = createStylesViewer(styleEditor);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalIndent = 0;
    Iterator iterator = fStyleToDescriptionMap.values().iterator();
    while (iterator.hasNext()) {
        gridData.widthHint = Math.max(gridData.widthHint, convertWidthInCharsToPixels(iterator.next().toString().length()));
    }
    gridData.heightHint = convertHeightInCharsToPixels(5);
    fStylesViewer.getControl().setLayoutData(gridData);
    Composite editingComposite = createComposite(top, 1);
    ((GridLayout) styleEditor.getLayout()).marginLeft = 5;
    createLabel(editingComposite, "");
    Button enabler = createCheckbox(editingComposite, CSSUIMessages.SyntaxColoringPage_2);
    enabler.setEnabled(false);
    enabler.setSelection(true);
    Composite editControls = createComposite(editingComposite, 2);
    ((GridLayout) editControls.getLayout()).marginLeft = 20;
    fForegroundLabel = createLabel(editControls, SSEUIMessages.Foreground_UI_);
    ((GridData) fForegroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    fForegroundLabel.setEnabled(false);
    fForegroundColorEditor = new ColorSelector(editControls);
    Button fForegroundColor = fForegroundColorEditor.getButton();
    GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fForegroundColor.setLayoutData(gd);
    fForegroundColorEditor.setEnabled(false);
    fForegroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(final AccessibleEvent e) {
            e.result = SSEUIMessages.Foreground_Color_Selector_Button;
        }
    });
    fBackgroundLabel = createLabel(editControls, SSEUIMessages.Background_UI_);
    ((GridData) fBackgroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    fBackgroundLabel.setEnabled(false);
    fBackgroundColorEditor = new ColorSelector(editControls);
    Button fBackgroundColor = fBackgroundColorEditor.getButton();
    gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fBackgroundColor.setLayoutData(gd);
    fBackgroundColorEditor.setEnabled(false);
    fBackgroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(final AccessibleEvent e) {
            e.result = SSEUIMessages.Background_Color_Selector_Button;
        }
    });
    fBold = createCheckbox(editControls, CSSUIMessages.SyntaxColoringPage_3);
    fBold.setEnabled(false);
    ((GridData) fBold.getLayoutData()).horizontalSpan = 2;
    fItalic = createCheckbox(editControls, CSSUIMessages.SyntaxColoringPage_4);
    fItalic.setEnabled(false);
    ((GridData) fItalic.getLayoutData()).horizontalSpan = 2;
    fStrike = createCheckbox(editControls, CSSUIMessages.SyntaxColoringPage_5);
    fStrike.setEnabled(false);
    ((GridData) fStrike.getLayoutData()).horizontalSpan = 2;
    fUnderline = createCheckbox(editControls, CSSUIMessages.SyntaxColoringPage_6);
    fUnderline.setEnabled(false);
    ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2;
    fClearStyle = new Button(editingComposite, SWT.PUSH);
    // $NON-NLS-1$ = "Restore Default"
    fClearStyle.setText(SSEUIMessages.Restore_Default_UI_);
    fClearStyle.setLayoutData(new GridData(SWT.BEGINNING));
    ((GridData) fClearStyle.getLayoutData()).horizontalIndent = 20;
    fClearStyle.setEnabled(false);
    Composite sampleArea = createComposite(editor, 1);
    ((GridLayout) sampleArea.getLayout()).marginLeft = 5;
    ((GridLayout) sampleArea.getLayout()).marginTop = 5;
    // $NON-NLS-1$ = "&Sample text:"
    createLabel(sampleArea, SSEUIMessages.Sample_text__UI_);
    fPreviewViewer = new SourceViewer(sampleArea, null, SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
    fText = fPreviewViewer.getTextWidget();
    GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData3.widthHint = convertWidthInCharsToPixels(20);
    gridData3.heightHint = convertHeightInCharsToPixels(5);
    gridData3.horizontalSpan = 2;
    fText.setLayoutData(gridData3);
    fText.setEditable(false);
    fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    fText.addKeyListener(getTextKeyListener());
    fText.addSelectionListener(getTextSelectionListener());
    fText.addMouseListener(getTextMouseListener());
    fText.addTraverseListener(getTraverseListener());
    setAccessible(fText, SSEUIMessages.Sample_text__UI_);
    fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForCSS.ContentTypeID_CSS);
    fDocument.set(getExampleText());
    initializeSourcePreviewColors(fPreviewViewer);
    fPreviewViewer.setDocument(fDocument);
    top.setWeights(new int[] { 1, 1 });
    editor.setWeights(new int[] { 1, 1 });
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.CSS_PREFWEBX_STYLES_HELPID);
    fStylesViewer.setInput(getStylePreferenceKeys());
    applyStyles();
    fStylesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (!event.getSelection().isEmpty()) {
                Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                activate(namedStyle);
                if (namedStyle == null)
                    return;
            }
        }
    });
    fForegroundColorEditor.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                String prefString = getOverlayStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[0];
                    // open color dialog to get new color
                    String newValue = ColorHelper.toRGBString(fForegroundColorEditor.getColorValue());
                    if (!newValue.equals(oldValue)) {
                        stylePrefs[0] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        fText.redraw();
                    }
                }
            }
        }
    });
    fBackgroundColorEditor.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                String prefString = getOverlayStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[1];
                    // open color dialog to get new color
                    String newValue = ColorHelper.toRGBString(fBackgroundColorEditor.getColorValue());
                    if (!newValue.equals(oldValue)) {
                        stylePrefs[1] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        fText.redraw();
                        activate(namedStyle);
                    }
                }
            }
        }
    });
    fBold.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[2];
                String newValue = String.valueOf(fBold.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[2] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fItalic.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[3];
                String newValue = String.valueOf(fItalic.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[3] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fStrike.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[4];
                String newValue = String.valueOf(fStrike.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[4] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fUnderline.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[5];
                String newValue = String.valueOf(fUnderline.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[5] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fClearStyle.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (fStylesViewer.getSelection().isEmpty())
                return;
            String namedStyle = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement().toString();
            getOverlayStore().setToDefault(namedStyle);
            applyStyles();
            fText.redraw();
            activate(namedStyle);
        }
    });
    return pageComponent;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SashForm(org.eclipse.swt.custom.SashForm) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) Iterator(java.util.Iterator) ColorSelector(org.eclipse.jface.preference.ColorSelector) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Link(org.eclipse.swt.widgets.Link)

Example 52 with SourceViewer

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

the class NewCSSTemplatesWizardPage method createViewer.

/**
 * Creates, configures and returns a source viewer to present the template
 * pattern on the preference page. Clients may override to provide a
 * custom source viewer featuring e.g. syntax coloring.
 *
 * @param parent
 *            the parent control
 * @return a configured source viewer
 */
private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {

        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationCSS();

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

        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$
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForCSS.ContentTypeID_CSS);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    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) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) StructuredTextViewerConfigurationCSS(org.eclipse.wst.css.ui.StructuredTextViewerConfigurationCSS) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 53 with SourceViewer

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

the class JSPSyntaxColoringPage method createContents.

protected Control createContents(final Composite parent) {
    initializeDialogUnits(parent);
    fDefaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    fDefaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    Composite pageComponent = createComposite(parent, 2);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.JSP_PREFWEBX_STYLES_HELPID);
    Link link = new Link(pageComponent, SWT.WRAP);
    link.setText(SSEUIMessages.SyntaxColoring_Link);
    link.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
        }
    });
    GridData linkData = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1);
    // only expand further if anyone else requires it
    linkData.widthHint = 150;
    link.setLayoutData(linkData);
    new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
    new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
    SashForm editor = new SashForm(pageComponent, SWT.VERTICAL);
    GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData2.horizontalSpan = 2;
    editor.setLayoutData(gridData2);
    SashForm top = new SashForm(editor, SWT.HORIZONTAL);
    Composite styleEditor = createComposite(top, 1);
    ((GridLayout) styleEditor.getLayout()).marginRight = 5;
    ((GridLayout) styleEditor.getLayout()).marginLeft = 0;
    createLabel(styleEditor, JSPUIMessages.SyntaxColoringPage_0);
    fStylesViewer = createStylesViewer(styleEditor);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalIndent = 0;
    Iterator iterator = fStyleToDescriptionMap.values().iterator();
    while (iterator.hasNext()) {
        gridData.widthHint = Math.max(gridData.widthHint, convertWidthInCharsToPixels(iterator.next().toString().length()));
    }
    gridData.heightHint = convertHeightInCharsToPixels(5);
    fStylesViewer.getControl().setLayoutData(gridData);
    Composite editingComposite = createComposite(top, 1);
    ((GridLayout) styleEditor.getLayout()).marginLeft = 5;
    // $NON-NLS-1$
    createLabel(editingComposite, "");
    Button enabler = createCheckbox(editingComposite, JSPUIMessages.SyntaxColoringPage_2);
    enabler.setEnabled(false);
    enabler.setSelection(true);
    Composite editControls = createComposite(editingComposite, 2);
    ((GridLayout) editControls.getLayout()).marginLeft = 20;
    fForegroundLabel = createLabel(editControls, SSEUIMessages.Foreground_UI_);
    ((GridData) fForegroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    fForegroundLabel.setEnabled(false);
    fForegroundColorEditor = new ColorSelector(editControls);
    Button fForegroundColor = fForegroundColorEditor.getButton();
    GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fForegroundColor.setLayoutData(gd);
    fForegroundColorEditor.setEnabled(false);
    fForegroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(final AccessibleEvent e) {
            e.result = SSEUIMessages.Foreground_Color_Selector_Button;
        }
    });
    fBackgroundLabel = createLabel(editControls, SSEUIMessages.Background_UI_);
    ((GridData) fBackgroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    fBackgroundLabel.setEnabled(false);
    fBackgroundColorEditor = new ColorSelector(editControls);
    Button fBackgroundColor = fBackgroundColorEditor.getButton();
    gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fBackgroundColor.setLayoutData(gd);
    fBackgroundColorEditor.setEnabled(false);
    fBackgroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(final AccessibleEvent e) {
            e.result = SSEUIMessages.Background_Color_Selector_Button;
        }
    });
    fBold = createCheckbox(editControls, JSPUIMessages.SyntaxColoringPage_3);
    fBold.setEnabled(false);
    ((GridData) fBold.getLayoutData()).horizontalSpan = 2;
    fItalic = createCheckbox(editControls, JSPUIMessages.SyntaxColoringPage_4);
    fItalic.setEnabled(false);
    ((GridData) fItalic.getLayoutData()).horizontalSpan = 2;
    fStrike = createCheckbox(editControls, JSPUIMessages.SyntaxColoringPage_5);
    fStrike.setEnabled(false);
    ((GridData) fStrike.getLayoutData()).horizontalSpan = 2;
    fUnderline = createCheckbox(editControls, JSPUIMessages.SyntaxColoringPage_6);
    fUnderline.setEnabled(false);
    ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2;
    fClearStyle = new Button(editingComposite, SWT.PUSH);
    // $NON-NLS-1$ = "Restore Default"
    fClearStyle.setText(SSEUIMessages.Restore_Default_UI_);
    fClearStyle.setLayoutData(new GridData(SWT.BEGINNING));
    ((GridData) fClearStyle.getLayoutData()).horizontalIndent = 20;
    fClearStyle.setEnabled(false);
    Composite sampleArea = createComposite(editor, 1);
    ((GridLayout) sampleArea.getLayout()).marginLeft = 5;
    ((GridLayout) sampleArea.getLayout()).marginTop = 5;
    // $NON-NLS-1$ = "&Sample text:"
    createLabel(sampleArea, SSEUIMessages.Sample_text__UI_);
    fPreviewViewer = new SourceViewer(sampleArea, null, SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
    fText = fPreviewViewer.getTextWidget();
    GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData3.widthHint = convertWidthInCharsToPixels(20);
    gridData3.heightHint = convertHeightInCharsToPixels(5);
    gridData3.horizontalSpan = 2;
    fText.setLayoutData(gridData3);
    fText.setEditable(false);
    // $NON-NLS-1$
    fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    fText.addKeyListener(getTextKeyListener());
    fText.addSelectionListener(getTextSelectionListener());
    fText.addMouseListener(getTextMouseListener());
    fText.addTraverseListener(getTraverseListener());
    setAccessible(fText, SSEUIMessages.Sample_text__UI_);
    fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForJSP.ContentTypeID_JSP);
    fDocument.set(getExampleText());
    initializeSourcePreviewColors(fPreviewViewer);
    fPreviewViewer.setDocument(fDocument);
    top.setWeights(new int[] { 1, 1 });
    editor.setWeights(new int[] { 1, 1 });
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.JSP_PREFWEBX_STYLES_HELPID);
    fStylesViewer.setInput(getStylePreferenceKeys());
    applyStyles();
    fStylesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (!event.getSelection().isEmpty()) {
                Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                activate(namedStyle);
                if (namedStyle == null)
                    return;
            }
        }
    });
    fForegroundColorEditor.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                String prefString = getOverlayStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[0];
                    // open color dialog to get new color
                    String newValue = ColorHelper.toRGBString(fForegroundColorEditor.getColorValue());
                    if (!newValue.equals(oldValue)) {
                        stylePrefs[0] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        fText.redraw();
                    }
                }
            }
        }
    });
    fBackgroundColorEditor.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                String prefString = getOverlayStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[1];
                    // open color dialog to get new color
                    String newValue = ColorHelper.toRGBString(fBackgroundColorEditor.getColorValue());
                    if (!newValue.equals(oldValue)) {
                        stylePrefs[1] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        fText.redraw();
                        activate(namedStyle);
                    }
                }
            }
        }
    });
    fBold.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[2];
                String newValue = String.valueOf(fBold.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[2] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fItalic.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[3];
                String newValue = String.valueOf(fItalic.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[3] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fStrike.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[4];
                String newValue = String.valueOf(fStrike.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[4] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fUnderline.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[5];
                String newValue = String.valueOf(fUnderline.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[5] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fClearStyle.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (fStylesViewer.getSelection().isEmpty())
                return;
            String namedStyle = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement().toString();
            getOverlayStore().setToDefault(namedStyle);
            applyStyles();
            fText.redraw();
            activate(namedStyle);
        }
    });
    return pageComponent;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SashForm(org.eclipse.swt.custom.SashForm) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) Iterator(java.util.Iterator) ColorSelector(org.eclipse.jface.preference.ColorSelector) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Link(org.eclipse.swt.widgets.Link)

Example 54 with SourceViewer

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

the class NewJSPTemplatesWizardPage method createViewer.

/**
 * Creates, configures and returns a source viewer to present the template
 * pattern on the preference page. Clients may override to provide a
 * custom source viewer featuring e.g. syntax coloring.
 *
 * @param parent
 *            the parent control
 * @return a configured source viewer
 */
private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {

        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationJSP();

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

        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$
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}
Also used : StructuredTextViewerConfigurationJSP(org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP) 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) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 55 with SourceViewer

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

the class NewJSPTemplatesWizardPage method doCreateViewer.

private SourceViewer doCreateViewer(Composite parent) {
    Label label = new Label(parent, SWT.NONE);
    label.setText(JSPUIMessages.NewJSPTemplatesWizardPage_5);
    GridData data = new GridData();
    data.horizontalSpan = 2;
    label.setLayoutData(data);
    SourceViewer viewer = createViewer(parent);
    viewer.setEditable(false);
    Control control = viewer.getControl();
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    data.heightHint = convertHeightInCharsToPixels(5);
    // [261274] - source viewer was growing to fit the max line width of the template
    data.widthHint = convertWidthInCharsToPixels(2);
    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) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData)

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