Search in sources :

Example 1 with TextSourceViewerConfiguration

use of org.eclipse.ui.editors.text.TextSourceViewerConfiguration in project tmdm-studio-se by Talend.

the class ProcessResultsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    try {
        parent.getShell().setText(title);
        Composite composite = (Composite) super.createDialogArea(parent);
        GridLayout layout = (GridLayout) composite.getLayout();
        layout.numColumns = 2;
        ((GridData) composite.getLayoutData()).widthHint = 800;
        Label variableLabel = new Label(composite, SWT.NONE);
        variableLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
        variableLabel.setText(Messages.ProcessResultsDialog_PipelineVariables);
        variablesCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
        variablesCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1));
        /*
             * variablesCombo.addKeyListener( new KeyListener() { public void keyPressed(KeyEvent e) {} public void
             * keyReleased(KeyEvent e) { if ((e.stateMask==0) && (e.character == SWT.CR)) {
             * ProcessResultsPage.this.variablesViewer.setDocument(new Document(getText(variablesCombo.getText()))); }
             * }//keyReleased }//keyListener );
             */
        variablesViewer = new SourceViewer(composite, new VerticalRuler(10), SWT.V_SCROLL | SWT.H_SCROLL);
        variablesViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1));
        variablesViewer.configure(new TextSourceViewerConfiguration());
        ((GridData) variablesViewer.getControl().getLayoutData()).minimumHeight = 500;
        final Button seeInBrowser = new Button(composite, SWT.PUSH);
        seeInBrowser.setText(Messages.ProcessResultsDialog_display);
        seeInBrowser.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                String htmlContent = variablesViewer.getTextWidget().getText();
                IFile file = FileProvider.createdTempFile(htmlContent, Messages.ProcessResultsDialog_temphtml, null);
                File htmlFile = file.getLocation().toFile();
                // $NON-NLS-1$
                String SHARED_ID = "org.eclipse.ui.browser";
                try {
                    IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
                    if (WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.INTERNAL) {
                        support.createBrowser(IWorkbenchBrowserSupport.AS_EDITOR, file.getLocation().toPortableString(), null, null).openURL(htmlFile.toURL());
                    } else {
                        support.createBrowser(IWorkbenchBrowserSupport.AS_EXTERNAL, SHARED_ID, null, null).openURL(htmlFile.toURL());
                    }
                } catch (Exception e1) {
                    log.error(e1.getMessage(), e1);
                }
            }
        });
        variablesCombo.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                String output = variablesCombo.getText();
                if (output.startsWith(TransformerMainPage.DEFAULT_DISPLAY)) {
                    // TransformerMainPage.DEFAULT_VAR+output.substring(TransformerMainPage.DEFAULT_DISPLAY.length());
                    output = DEFAULT_DISPLAY_TEXT;
                }
                String text = variablesCombo.getText();
                if (text.equals(DEFAULT_DISPLAY_TEXT)) {
                    text = TransformerMainPage.DEFAULT_DISPLAY;
                }
                variablesViewer.setDocument(new Document(getText(text)));
                // $NON-NLS-1$
                seeInBrowser.setEnabled("html".equals(text));
            }
        });
        variablesCombo.setFocus();
        refreshData();
        return composite;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(this.getShell(), Messages._Error, Messages.bind(Messages.ProcessResultsDialog_ErrorMsg, e.getLocalizedMessage()));
        return null;
    }
}
Also used : VerticalRuler(org.eclipse.jface.text.source.VerticalRuler) SourceViewer(org.eclipse.jface.text.source.SourceViewer) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Document(org.eclipse.jface.text.Document) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IFile(org.eclipse.core.resources.IFile) File(java.io.File) TextSourceViewerConfiguration(org.eclipse.ui.editors.text.TextSourceViewerConfiguration)

Example 2 with TextSourceViewerConfiguration

use of org.eclipse.ui.editors.text.TextSourceViewerConfiguration in project ecf by eclipse.

the class ChatComposite method createStyledTextWidget.

private StyledText createStyledTextWidget(Composite parent) {
    try {
        final SourceViewer result = new SourceViewer(parent, null, null, true, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI | SWT.READ_ONLY);
        result.configure(new TextSourceViewerConfiguration(EditorsUI.getPreferenceStore()));
        result.setDocument(new Document());
        return result.getTextWidget();
    } catch (final Exception e) {
        // $NON-NLS-1$
        ClientPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, ClientPlugin.PLUGIN_ID, IStatus.WARNING, MessageLoader.getString("ChatComposite.NO_HYPERLINKING"), e));
        return new StyledText(parent, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI | SWT.READ_ONLY);
    } catch (final NoClassDefFoundError e) {
        // $NON-NLS-1$
        ClientPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, ClientPlugin.PLUGIN_ID, IStatus.WARNING, MessageLoader.getString("ChatComposite.NO_HYPERLINKING"), e));
        return new StyledText(parent, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI | SWT.READ_ONLY);
    }
}
Also used : SourceViewer(org.eclipse.jface.text.source.SourceViewer) StyledText(org.eclipse.swt.custom.StyledText) IOException(java.io.IOException) TextSourceViewerConfiguration(org.eclipse.ui.editors.text.TextSourceViewerConfiguration)

Aggregations

SourceViewer (org.eclipse.jface.text.source.SourceViewer)2 TextSourceViewerConfiguration (org.eclipse.ui.editors.text.TextSourceViewerConfiguration)2 File (java.io.File)1 IOException (java.io.IOException)1 IFile (org.eclipse.core.resources.IFile)1 Document (org.eclipse.jface.text.Document)1 VerticalRuler (org.eclipse.jface.text.source.VerticalRuler)1 StyledText (org.eclipse.swt.custom.StyledText)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 IWorkbenchBrowserSupport (org.eclipse.ui.browser.IWorkbenchBrowserSupport)1