org.eclipse.swt.browser.Browser Java Examples

The following examples show how to use org.eclipse.swt.browser.Browser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AboutDialog.java    From http4e with Apache License 2.0 7 votes vote down vote up
protected Control createDialogArea( Composite parent){
   Composite composite = (Composite) super.createDialogArea(parent);

   Browser browser = new Browser(composite, SWT.NONE);
   browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

   try {
      String html = new String(ResourceUtils.getBundleResourceBytes(CoreConstants.PLUGIN_UI, "resources/about.html"));
      html = html.replaceAll("currentYear", ""+Calendar.getInstance().get(Calendar.YEAR));
      browser.setText(html);

   } catch (Exception e) {
      setErrorMessage(e.getLocalizedMessage());
   }
   return composite;
}
 
Example #2
Source File: HtmlViewer.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void createPartControl(final Composite parent) {
	final Composite compo = GamaToolbarFactory.createToolbars(this, parent);
	browser = new Browser(compo, SWT.NONE);
	browser.addProgressListener(new ProgressListener() {

		@Override
		public void changed(final ProgressEvent arg0) {}

		@Override
		public void completed(final ProgressEvent event) {
			checkButtons();
		}
	});
	parent.layout();
	openInput();
}
 
Example #3
Source File: ElexisEnvironmentLoginDialog.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create contents of the dialog.
 * 
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent){
	browser = new Browser(parent, SWT.NONE);
	browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	browser.setUrl(oauthService.getAuthorizationUrl());
	browser.addLocationListener(new LocationAdapter() {
		@Override
		public void changing(LocationEvent event){
			if (event.location.contains("localhost:11223/elexis-rcp-callback")) {
				// catch the callback, we're not using a local http server for this
				browser.setText("<HTML>Logging in ...</HTML>");
				parseCallback(event.location);
				event.doit = false;
			}
			super.changing(event);
		}
		
	});
	
	return parent;
}
 
Example #4
Source File: WebViewer.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Cancel the process
 * 
 * @param browser
 */
public static void cancel( Browser browser )
{
	if ( browser == null || browser.isDisposed( ) )
	{
		return;
	}

	try
	{
		browser.execute( "try { if( birtProgressBar ){ birtProgressBar.cancel(); } } catch(e){}" ); //$NON-NLS-1$
	}
	catch ( Exception e )
	{
		LogUtil.logError( e.getLocalizedMessage( ), e );
	}
}
 
Example #5
Source File: HtmlBrowserEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
	GridLayoutFactory.fillDefaults().numColumns(1).applyTo(parent);
	parent.setLayoutData(new GridData(GridData.FILL_BOTH));
	cmp = new Composite(parent, SWT.BORDER);
	GridLayoutFactory.fillDefaults().numColumns(1).applyTo(cmp);
	GridDataFactory.fillDefaults().grab(true, true).applyTo(cmp);
	
	browser = new Browser(cmp, SWT.NONE);
	browser.setLayoutData(new GridData(GridData.FILL_BOTH));
	browser.setUrl(htmlUrl);

	browser.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseDown(MouseEvent e) {
			getSite().getPart().setFocus();
			super.mouseDown(e);
		}
	});
}
 
Example #6
Source File: ExpandedContentManager.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * showExpandedContent( TransGraph graph )
 * 
 * @param graph
 *          TransGraph to create the web browser for. If the wev browser hasn't been created this will create one.
 *          Else it will just bring the web browser associated to this TransGraph to the top.
 */
public static void showExpandedContent( TransGraph graph ) {
  if ( graph == null ) {
    return;
  }
  Browser browser = getExpandedContentForTransGraph( graph );
  if ( browser == null ) {
    return;
  }
  if ( !isVisible( graph ) ) {
    maximizeExpandedContent( browser );
  }
  if ( Const.isOSX() && graph.isExecutionResultsPaneVisible() ) {
    graph.extraViewComposite.setVisible( false );
  }
  browser.moveAbove( null );
  browser.getParent().layout( true );
  browser.getParent().redraw();
}
 
Example #7
Source File: HtmlBrowserEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
	GridLayoutFactory.fillDefaults().numColumns(1).applyTo(parent);
	parent.setLayoutData(new GridData(GridData.FILL_BOTH));
	cmp = new Composite(parent, SWT.BORDER);
	GridLayoutFactory.fillDefaults().numColumns(1).applyTo(cmp);
	GridDataFactory.fillDefaults().grab(true, true).applyTo(cmp);
	
	browser = new Browser(cmp, SWT.NONE);
	browser.setLayoutData(new GridData(GridData.FILL_BOTH));
	browser.setUrl(htmlUrl);

	browser.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseDown(MouseEvent e) {
			getSite().getPart().setFocus();
			super.mouseDown(e);
		}
	});
}
 
Example #8
Source File: XbaseInformationControl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: PythonEditor.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@Override
protected void createFormContent(IManagedForm mform) {
	var form = UI.formHeader(mform, getTitle(), Icon.PYTHON.get());
	var tk = mform.getToolkit();
	var body = UI.formBody(form, tk);
	body.setLayout(new FillLayout());
	try {
		browser = new Browser(body, SWT.NONE);
		browser.setJavascriptEnabled(true);
		UI.onLoaded(browser,
				HtmlFolder.getUrl("python.html"), this::initScript);
	} catch (Exception e) {
		Logger log = LoggerFactory.getLogger(getClass());
		log.error("failed to create browser in Python editor", e);
	}
}
 
Example #10
Source File: WebViewer.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Displays the specified url using eclipse SWT browser.
 * 
 * @param report
 *            report report
 * @param format
 *            report format
 * @param browser
 *            SWT browser instance
 * @param servletName
 *            servlet name to viewer report
 * @deprecated
 */
public static void display( String report, String format, Browser browser,
		String servletName )
{
	checkAdapter( );

	startWebApp( DEFAULT_WEBAPP.getName( ), report );
	browser.setUrl( createURL( DEFAULT_WEBAPP.getName( ),
			servletName,
			report,
			format,
			null,
			null,
			null,
			null ) + "&" + random.nextInt( ) ); //$NON-NLS-1$
}
 
Example #11
Source File: ODDBView.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void createPartControl(Composite parent){
	browser = new Browser(parent, SWT.NONE);
	browser.addLocationListener(new LocationAdapter() {
		
		@Override
		public void changed(LocationEvent arg0){
			String text = getText(arg0.location);
			System.out.println(text);
		}
		
	});
	// browser.setUrl("http://ch.oddb.org");
	browser.setUrl("http://santesuisse.oddb.org/");
	
}
 
Example #12
Source File: ReportViewer.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@Override
protected void createFormContent(IManagedForm mform) {
	ScrolledForm form = mform.getForm();
	Composite comp = form.getBody();
	comp.setLayout(new FillLayout());
	try {
		Browser b = new Browser(comp, SWT.NONE);
		b.setJavascriptEnabled(true);
		UI.onLoaded(b, HtmlFolder.getUrl("report.html"), () -> {
			Gson gson = new Gson();
			String json = gson.toJson(report);
			String command = "setData(" + json + ")";
			b.execute(command);
		});
	} catch (Exception e) {
		Logger log = LoggerFactory.getLogger(getClass());
		log.error("failed to load report in browser", e);
	}
}
 
Example #13
Source File: StaticHTMLViewer.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void createBrowserSection( Composite parent )
{
	browserContainer = toolkit.createComposite( parent );
	browserContainer.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	GridLayout layout = new GridLayout( );
	layout.marginHeight = 0;
	layout.marginWidth = 0;
	layout.horizontalSpacing = 0;
	layout.verticalSpacing = 0;
	layout.numColumns = 1;
	browserContainer.setLayout( layout );

	browser = new Browser( browserContainer, SWT.NONE );
	browser.setLayoutData( new GridData( GridData.FILL_BOTH ) );

	browser.addLocationListener( new ReportLocationListener( this ) );
	sashForm.setMaximizedControl( browserContainer );
}
 
Example #14
Source File: ExpandedContentManagerTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testShowTransformationBrowserh() {
  TransGraph transGraphMock = mock( TransGraph.class );
  Control control1 = mock( Control.class );
  Control control2 = mock( Control.class );
  Browser browser = mock( Browser.class );
  SashForm sash = mock( SashForm.class );
  when( sash.getWeights() ).thenReturn( new int[] { 277, 722 } );
  Composite comp1 = mock( Composite.class );
  Composite comp2 = mock( Composite.class );
  Composite comp3 = mock( Composite.class );
  Composite comp4 = mock( Composite.class );
  when( browser.getParent() ).thenReturn( comp1 );
  when( comp1.getParent() ).thenReturn( comp2 );
  when( comp2.getParent() ).thenReturn( comp3 );
  when( comp3.getParent() ).thenReturn( sash );
  when( comp4.getParent() ).thenReturn( sash );
  Control[] children = new Control[] { control1, control2, browser };
  when( transGraphMock.getChildren() ).thenReturn( children );
  ExpandedContentManager.createExpandedContent( transGraphMock, "" );
  verify( browser ).setUrl( "" );
}
 
Example #15
Source File: UI.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Bind the given function with the given name to the `window` object of the
 * given browser.
 */
public static void bindFunction(Browser browser, String name,
		Function<Object[], Object> fn) {
	if (browser == null || name == null || fn == null)
		return;
	BrowserFunction func = new BrowserFunction(browser, name) {
		@Override
		public Object function(Object[] args) {
			try {
				return fn.apply(args);
			} catch (Exception e) {
				Logger log = LoggerFactory.getLogger(UI.class);
				log.error("failed to execute browser function " + name, e);
				return null;
			}
		}
	};
	browser.addDisposeListener(e -> {
		if (!func.isDisposed()) {
			func.dispose();
		}
	});
}
 
Example #16
Source File: BibtexEditor.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a browser for downloading the document which the bibtex entry
 * refers to. This only works if there is an URL or DOI in the bibtex entry.
 */
protected void createWebpage() {
	if (document.getUrl() == null && document.getDoi() == null) {
		return;
	}
	Composite localParent = getContainer();
	if (localParent == null) {
		localParent = parent;
	}
	Composite webcomposite = new Composite(localParent, SWT.NONE);
	FillLayout layout = new FillLayout();
	webcomposite.setLayout(layout);
	browser = new Browser(webcomposite, SWT.NONE);
	browser.setLayout(layout);
	webindex = addPage(webcomposite);
	setPageText(webindex, "Webpage");
}
 
Example #17
Source File: KompendiumView.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createPartControl(Composite parent){
	browser = new Browser(parent, SWT.NONE);
	browser.addLocationListener(new LocationAdapter() {
		
		@Override
		public void changed(LocationEvent arg0){
			String text = browser.getText();
			// System.out.println(text);
		}
		
	});
	browser.setUrl("http://www.compendium.ch/search/de"); //$NON-NLS-1$
	
}
 
Example #18
Source File: UZWizardComposite.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void initialBrowser(String url, String cookie) {
	if(cookie != null) {
		 this.browser = new Browser(this, 0);
	      ((Browser)this.browser).setJavascriptEnabled(true);
	}else {
		 this.browser = new Browser(this, 0);
	      ((Browser)this.browser).setJavascriptEnabled(true);
	      ((Browser)this.browser).setUrl(url);
	}
}
 
Example #19
Source File: CustomBrowserInformationControl.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #20
Source File: RichTextEditorConfiguration.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 *
 * @param browser
 *            The {@link Browser} instance to which this
 *            {@link RichTextEditorConfiguration} should be connected to.
 */
public void setBrowser(Browser browser) {
	this.browser = browser;

	// if a browser is set we ensure that the registered custom buttons
	// are registered and already registered BrowserFunctions are disposed
	for (ToolbarButton button : this.customButtons) {
		addToolbarButton(button);
	}
}
 
Example #21
Source File: HtmlDialog.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
   Composite c = (Composite) super.createDialogArea(parent);
   b = new Browser(c, SWT.BORDER);
   GridData gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
   b.setLayoutData(gd);
   b.setText(html);
   b.setSize(500, 500);
   if (listener != null) {
      b.addLocationListener(listener);
   }
   b.setMenu(pageOverviewGetPopup());

   return c;
}
 
Example #22
Source File: PDFViewingPage.java    From tlaplus with MIT License 5 votes vote down vote up
protected void createFormContent(IManagedForm managedForm)
{
    body = managedForm.getForm().getBody();
    body.setLayout(new FillLayout());
    browser = new Browser(body, SWT.NONE);

    super.createFormContent(managedForm);
}
 
Example #23
Source File: UZWizardComposite.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void registerFunction(String funcName, final IScriptHandler handler) {
	new org.eclipse.swt.browser.BrowserFunction((Browser)getBrowser(), funcName) {
	    public Object function(Object[] arguments) {
	        return handler.handle(arguments);
	    }
	};
}
 
Example #24
Source File: CreateXMPPAccountWizardPage.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void performHelp() {
  Shell shell = new Shell(getShell());
  shell.setText("Saros XMPP Accounts");
  shell.setLayout(new GridLayout());
  shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

  Browser browser = new Browser(shell, SWT.NONE);
  browser.setUrl("https://www.saros-project.org/documentation/setup-xmpp.html");
  browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

  shell.open();
}
 
Example #25
Source File: BrowserTab.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public Composite createTabFolderPage(CTabFolder tabFolder) {
	tabFolderPage = new Composite(tabFolder, SWT.NONE);
	tabFolderPage.setLayout(new FillLayout());
	browser = new Browser(tabFolderPage, SWT.NONE);
	hookOpenListner();
	return tabFolderPage;
}
 
Example #26
Source File: HtmlDialog.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Control createDialogArea(Composite parent) {
	final Composite parent2 = (Composite) super.createDialogArea(parent);
	parent2.setLayout(new FillLayout());
	final Browser browser = new Browser(parent2, SWT.NONE);
	browser.setUrl(url);
	return parent2;
}
 
Example #27
Source File: WebViewer.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static void display( String webappName, String report,
		Browser browser, Map params )
{
	startWebApp( webappName, report );
	browser.setUrl( createURL( webappName, report, params )
			+ "&" + random.nextInt( ) ); //$NON-NLS-1$
}
 
Example #28
Source File: EmbeddedBrowserFactory.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Must run on UI thread
 * 
 * @return
 */
private boolean test( )
{
	// !remove OS check, see bugzilla#270189
	// if ( !Constants.OS_WIN32.equalsIgnoreCase( Platform.getOS( ) )
	// && !Constants.OS_LINUX.equalsIgnoreCase( Platform.getOS( ) ) )
	// {
	// return false;
	// }
	
	if ( !tested )
	{
		tested = true;
		Shell sh = new Shell( );
		try
		{
			new Browser( sh, SWT.NONE );
			available = true;
		}
		catch ( SWTError se )
		{
			if ( se.code == SWT.ERROR_NO_HANDLES )
			{
				// Browser not implemented
				available = false;
			}
		}
		catch ( Exception e )
		{
			// Browser not implemented
		}
		if ( sh != null && !sh.isDisposed( ) )
			sh.dispose( );
	}
	return available;
}
 
Example #29
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Must run on UI thread
 * 
 * @return
 */
private static boolean test( )
{
	if ( !Constants.OS_WIN32.equalsIgnoreCase( Platform.getOS( ) )
			&& !Constants.OS_LINUX.equalsIgnoreCase( Platform.getOS( ) ) )
	{
		return false;
	}
	if ( !embeddedBrowserTested )
	{
		embeddedBrowserTested = true;
		Shell sh = new Shell( );
		try
		{
			new Browser( sh, SWT.NONE );
			embeddedBrowserAvailable = true;
		}
		catch ( SWTError se )
		{
			if ( se.code == SWT.ERROR_NO_HANDLES )
			{
				// Browser not implemented
				embeddedBrowserAvailable = false;
			}
		}
		catch ( Exception e )
		{
			// Browser not implemented
		}
		if ( sh != null && !sh.isDisposed( ) )
		{
			sh.dispose( );
		}
	}
	return embeddedBrowserAvailable;
}
 
Example #30
Source File: InputParameterHtmlDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param parent
 *            The parent shell
 * @param title
 *            The title of the dialog
 */
public InputParameterHtmlDialog( Shell parent, String title, String uri,
		Browser target )
{
	super( parent );
	this.title = title;
	this.uri = uri;
	//this.target = target;
}