Search in sources :

Example 46 with Browser

use of org.eclipse.swt.browser.Browser in project archi by archimatetool.

the class HintsView method createBrowser.

/**
 * Create the Browser if possible
 */
private Browser createBrowser(Composite parent) {
    Browser browser = null;
    try {
        browser = new Browser(parent, SWT.NONE);
        // Don't allow external hosts if set
        browser.addLocationListener(new LocationAdapter() {

            @Override
            public void changing(LocationEvent e) {
                if (!ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.HINTS_BROWSER_EXTERNAL_HOSTS_ENABLED)) {
                    e.doit = e.location != null && (// $NON-NLS-1$
                    e.location.startsWith("file:") || // $NON-NLS-1$
                    e.location.startsWith("data:") || // $NON-NLS-1$
                    e.location.startsWith("about:"));
                }
            }
        });
    } catch (SWTError error) {
        error.printStackTrace();
        // Remove junk child controls that might be created with failed load
        for (Control child : parent.getChildren()) {
            if (child != fTitleLabel) {
                child.dispose();
            }
        }
    }
    return browser;
}
Also used : SWTError(org.eclipse.swt.SWTError) Control(org.eclipse.swt.widgets.Control) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 47 with Browser

use of org.eclipse.swt.browser.Browser in project xtext-eclipse by eclipse.

the class XbaseInformationControl method createContent.

/**
 * Xbase - modification+ added detailPane
 */
@Override
protected void createContent(Composite parent) {
    fSashForm = new SashForm(parent, parent.getStyle());
    fSashForm.setOrientation(SWT.VERTICAL);
    fBrowser = new Browser(fSashForm, SWT.NONE);
    fBrowser.setJavascriptEnabled(false);
    Display display = getShell().getDisplay();
    ColorRegistry registry = JFaceResources.getColorRegistry();
    // $NON-NLS-1$
    Color foreground = registry.get("org.eclipse.ui.workbench.HOVER_FOREGROUND");
    // $NON-NLS-1$
    Color background = registry.get("org.eclipse.ui.workbench.HOVER_BACKGROUND");
    if (background != null && foreground != null) {
        fBrowser.setForeground(foreground);
        fBrowser.setBackground(background);
    } else {
        fBrowser.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
        fBrowser.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    }
    fBrowser.addProgressListener(new ProgressAdapter() {

        @Override
        public void completed(ProgressEvent event) {
            fCompleted = true;
        }
    });
    fBrowser.addOpenWindowListener(new OpenWindowListener() {

        @Override
        public void open(WindowEvent event) {
            // Cancel opening of new windows
            event.required = true;
        }
    });
    // Replace browser's built-in context menu with none
    fSashForm.setMenu(new Menu(getShell(), SWT.NONE));
    detailPaneComposite = createComposite(fSashForm, 1, 1, GridData.FILL_BOTH);
    Layout layout = detailPaneComposite.getLayout();
    if (layout instanceof GridLayout) {
        GridLayout gl = (GridLayout) layout;
        gl.marginHeight = 0;
        gl.marginWidth = 0;
        gl.numColumns = 1;
    }
    if (background != null && foreground != null) {
        detailPaneComposite.setForeground(foreground);
        detailPaneComposite.setBackground(background);
    } else {
        detailPaneComposite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
        detailPaneComposite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    }
    resourceProvider = new HoverEditedResourceProvider();
    embeddedEditor = xbaseHoverConfiguration.getEditorFactory().newEditor(resourceProvider).readOnly().processIssuesBy(new IValidationIssueProcessor() {

        @Override
        public void processIssues(List<Issue> issues, IProgressMonitor monitor) {
        }
    }).withParent(detailPaneComposite);
    Control viewerControl = embeddedEditor.getViewer().getControl();
    if (background != null && foreground != null) {
        viewerControl.setForeground(foreground);
        viewerControl.setBackground(background);
    } else {
        viewerControl.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
        viewerControl.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    }
    embeddedEditor.getDocument().setValidationJob(null);
    createTextLayout();
    parent.addDisposeListener(e -> {
        if (fTextLayout != null && !fTextLayout.isDisposed()) {
            fTextLayout.dispose();
        }
    });
}
Also used : Issue(org.eclipse.xtext.validation.Issue) Color(org.eclipse.swt.graphics.Color) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) IValidationIssueProcessor(org.eclipse.xtext.ui.editor.validation.IValidationIssueProcessor) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IXtextBrowserInformationControl(org.eclipse.xtext.ui.editor.hover.html.IXtextBrowserInformationControl) AbstractInformationControl(org.eclipse.jface.text.AbstractInformationControl) Control(org.eclipse.swt.widgets.Control) ColorRegistry(org.eclipse.jface.resource.ColorRegistry) TextLayout(org.eclipse.swt.graphics.TextLayout) Layout(org.eclipse.swt.widgets.Layout) GridLayout(org.eclipse.swt.layout.GridLayout) WindowEvent(org.eclipse.swt.browser.WindowEvent) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Menu(org.eclipse.swt.widgets.Menu) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) Browser(org.eclipse.swt.browser.Browser) Display(org.eclipse.swt.widgets.Display)

Example 48 with Browser

use of org.eclipse.swt.browser.Browser in project xtext-eclipse by eclipse.

the class XbaseInformationControl method isAvailable.

// ------------------ Original implementation
/**
 * Tells whether the SWT Browser widget and hence this information control is available.
 *
 * @param parent
 *            the parent component used for checking or <code>null</code> if none
 * @return <code>true</code> if this control is available
 */
public static boolean isAvailable(Composite parent) {
    if (!fgAvailabilityChecked) {
        try {
            Browser browser = new Browser(parent, SWT.NONE);
            browser.dispose();
            fgIsAvailable = true;
            Slider sliderV = new Slider(parent, SWT.VERTICAL);
            Slider sliderH = new Slider(parent, SWT.HORIZONTAL);
            int width = sliderV.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
            int height = sliderH.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
            fgScrollBarSize = new Point(width, height);
            sliderV.dispose();
            sliderH.dispose();
        } catch (SWTError er) {
            fgIsAvailable = false;
        } finally {
            fgAvailabilityChecked = true;
        }
    }
    return fgIsAvailable;
}
Also used : SWTError(org.eclipse.swt.SWTError) Slider(org.eclipse.swt.widgets.Slider) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Browser(org.eclipse.swt.browser.Browser)

Example 49 with Browser

use of org.eclipse.swt.browser.Browser in project mylyn.docs by eclipse.

the class MarkupEditor method createSourceViewer.

@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
    sourceViewerConfiguration.initializeDefaultFonts();
    tabFolder = new CTabFolder(parent, SWT.BOTTOM);
    {
        sourceTab = new CTabItem(tabFolder, SWT.NONE);
        updateSourceTabLabel();
        viewer = new MarkupProjectionViewer(tabFolder, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles | SWT.WRAP);
        sourceTab.setControl(((Viewer) viewer).getControl());
        tabFolder.setSelection(sourceTab);
    }
    try {
        previewTab = new CTabItem(tabFolder, SWT.NONE);
        previewTab.setText(Messages.MarkupEditor_preview);
        previewTab.setToolTipText(Messages.MarkupEditor_preview_tooltip);
        browser = new Browser(tabFolder, SWT.NONE);
        // bug 260479: open hyperlinks in a browser
        browser.addLocationListener(new LocationListener() {

            public void changed(LocationEvent event) {
                event.doit = false;
            }

            public void changing(LocationEvent event) {
                // if it looks like an absolute URL
                if (event.location.matches("([a-zA-Z]{3,8})://?.*")) {
                    // $NON-NLS-1$
                    // workaround for browser problem (bug 262043)
                    // $NON-NLS-1$
                    int idxOfSlashHash = event.location.indexOf("/#");
                    if (idxOfSlashHash != -1) {
                        // allow javascript-based scrolling to work
                        if (!event.location.startsWith("file:///#")) {
                            // $NON-NLS-1$
                            event.doit = false;
                        }
                        return;
                    }
                    // workaround end
                    event.doit = false;
                    try {
                        PlatformUI.getWorkbench().getBrowserSupport().createBrowser(// $NON-NLS-1$
                        "org.eclipse.ui.browser").openURL(new URL(event.location));
                    } catch (Exception e) {
                        new URLHyperlink(new Region(0, 1), event.location).open();
                    }
                }
            }
        });
        previewTab.setControl(browser);
    } catch (SWTError e) {
        // disable preview, the exception is probably due to the internal browser not being available
        if (previewTab != null) {
            previewTab.dispose();
            previewTab = null;
        }
        logPreviewTabUnavailable(e);
    }
    tabFolder.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent selectionevent) {
            widgetSelected(selectionevent);
        }

        public void widgetSelected(SelectionEvent selectionevent) {
            if (isShowingPreview()) {
                updatePreview();
            }
        }
    });
    viewer.getTextWidget().addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            updateOutlineSelection();
        }
    });
    viewer.getTextWidget().addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (isRelevantKeyCode(e.keyCode)) {
                updateOutlineSelection();
            }
        }

        private boolean isRelevantKeyCode(int keyCode) {
            // for some reason not all key presses result in a selection change
            switch(keyCode) {
                case SWT.ARROW_DOWN:
                case SWT.ARROW_LEFT:
                case SWT.ARROW_RIGHT:
                case SWT.ARROW_UP:
                case SWT.PAGE_DOWN:
                case SWT.PAGE_UP:
                    return true;
            }
            return false;
        }
    });
    viewer.getTextWidget().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            updateOutlineSelection();
        }
    });
    IFocusService focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
    if (focusService != null) {
        focusService.addFocusTracker(viewer.getTextWidget(), MarkupEditor.EDITOR_SOURCE_VIEWER);
    }
    viewer.getTextWidget().setData(MarkupLanguage.class.getName(), getMarkupLanguage());
    viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
    getSourceViewerDecorationSupport(viewer);
    updateDocument();
    if (preferencesListener == null) {
        preferencesListener = new IPropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent event) {
                if (viewer.getTextWidget() == null || viewer.getTextWidget().isDisposed()) {
                    return;
                }
                if (isFontPreferenceChange(event)) {
                    viewer.getTextWidget().getDisplay().asyncExec(new Runnable() {

                        public void run() {
                            reloadPreferences();
                        }
                    });
                }
            }
        };
        WikiTextUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(preferencesListener);
    }
    return viewer;
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Viewer(org.eclipse.jface.viewers.Viewer) IFocusService(org.eclipse.ui.swt.IFocusService) CTabItem(org.eclipse.swt.custom.CTabItem) URL(java.net.URL) KeyEvent(org.eclipse.swt.events.KeyEvent) URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) LocationListener(org.eclipse.swt.browser.LocationListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) SWTError(org.eclipse.swt.SWTError) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) SWTException(org.eclipse.swt.SWTException) Point(org.eclipse.swt.graphics.Point) Region(org.eclipse.jface.text.Region) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Browser(org.eclipse.swt.browser.Browser) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 50 with Browser

use of org.eclipse.swt.browser.Browser in project n4js by eclipse.

the class TypeInformationPopup method createDialogArea.

@Override
protected Control createDialogArea(final Composite parent) {
    final Object layoutData = parent.getLayoutData();
    if (layoutData instanceof GridData) {
        ((GridData) layoutData).heightHint = DEFAULT_SIZE.x;
        ((GridData) layoutData).widthHint = DEFAULT_SIZE.y;
    }
    final Browser browser = new Browser(parent, NONE);
    browser.setText(html);
    return browser;
}
Also used : GridData(org.eclipse.swt.layout.GridData) Browser(org.eclipse.swt.browser.Browser)

Aggregations

Browser (org.eclipse.swt.browser.Browser)117 Shell (org.eclipse.swt.widgets.Shell)40 FillLayout (org.eclipse.swt.layout.FillLayout)29 Composite (org.eclipse.swt.widgets.Composite)29 Display (org.eclipse.swt.widgets.Display)29 GridData (org.eclipse.swt.layout.GridData)28 Test (org.junit.Test)26 GridLayout (org.eclipse.swt.layout.GridLayout)20 LocationEvent (org.eclipse.swt.browser.LocationEvent)18 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)18 Point (org.eclipse.swt.graphics.Point)18 IOException (java.io.IOException)16 SWTError (org.eclipse.swt.SWTError)16 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)14 WindowEvent (org.eclipse.swt.browser.WindowEvent)14 Label (org.eclipse.swt.widgets.Label)14 URL (java.net.URL)13 LocationAdapter (org.eclipse.swt.browser.LocationAdapter)13 LocationListener (org.eclipse.swt.browser.LocationListener)13 ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)13