下面列出了org.eclipse.ui.forms.widgets.ColumnLayout#org.eclipse.swt.browser.Browser 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
/**
* 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;
}
@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();
}
/**
* 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");
}
@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);
}
});
}
/**
* 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();
}
@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);
}
});
}
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 );
}
@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( "" );
}
/**
* 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$
}
/**
* 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 );
}
}
@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/");
}
/**
* 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;
}
@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);
}
}
@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);
}
}
/**
* 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();
}
});
}
/**
* {@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;
}
@Test
public void testCloseExpandedContentManager() throws Exception {
TransGraph transGraph = mock( TransGraph.class );
Browser browser = mock( Browser.class );
SashForm sashForm = mock( SashForm.class );
setupExpandedContentMocks( transGraph, browser, sashForm );
ExpandedContentManager.closeExpandedContent( transGraph );
verify( browser ).close();
verify( sashForm ).setWeights( new int[] { 3, 2, 1 } );
}
/**
* getExpandedContentForTransGraph
*
* @param graph
* a TransGraph object that will be interrogated for a web browser
* @return a web browser that is associated with the TransGraph or null if it has yet to be created.
*/
public static Browser getExpandedContentForTransGraph( TransGraph graph ) {
for ( Control control : graph.getChildren() ) {
if ( control instanceof Browser ) {
return (Browser) control;
}
}
return null;
}
/**
*
* @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);
}
}
/**
*
* @param browser
* The {@link Browser} instance to which this
* {@link ToolbarConfiguration} 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);
}
}
@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;
}
@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;
}
private Composite setupExpandedContentMocks( TransGraph transGraph, Browser browser, SashForm sashForm ) {
Spoon spoon = mock( Spoon.class );
Composite parent = mock( Composite.class );
TabSet tabSet = mock( TabSet.class );
TabItem tabItem = mock( TabItem.class );
ExpandedContentManager.spoonSupplier = () -> spoon;
when( spoon.getDesignParent() ).thenReturn( sashForm );
when( spoon.getTabSet() ).thenReturn( tabSet );
when( tabSet.getSelected() ).thenReturn( tabItem );
when( tabItem.getSashWeights() ).thenReturn( new int[] { 3, 2, 1 } );
when( transGraph.getChildren() ).thenReturn( new Control[]{ browser } );
when( browser.getParent() ).thenReturn( parent );
return parent;
}
private void buildTip() {
final Group group = new Group(this.shell, SWT.NONE);
final GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true);
gd.widthHint = 300;
gd.heightHint = 120;
group.setLayoutData(gd);
group.setText("Did you know");
final FillLayout fillLayout = new FillLayout();
fillLayout.marginWidth = 15;
group.setLayout(fillLayout);
this.tipArea = new Browser(group, SWT.BORDER);
fillTipArea();
}
protected
BrowserWrapperSWT(
Composite composite,
int style )
{
browser = new Browser( composite, style );
browser.setData( BrowserWrapperSWTFactory.BROWSER_KEY, true );
}
public void createTabForNeo4jConnection( final NeoConnection neoConnection ) throws Exception {
// SpoonPerspectiveManager.getInstance().activatePerspective(getClass());
final XulTabAndPanel tabAndPanel = createTab();
PropsUI props = PropsUI.getInstance();
final Composite comp = (Composite) tabAndPanel.panel.getManagedObject();
props.setLook( comp );
comp.setLayout( new FillLayout() );
Browser browser = new Browser( comp, SWT.NONE );
VariableSpace space = getVariableSpace();
String server = space.environmentSubstitute( neoConnection.getServer() );
String browserPortString = neoConnection.getBrowserPort();
if ( StringUtils.isEmpty(browserPortString)) {
browserPortString = "7474";
}
String browserPort = space.environmentSubstitute( browserPortString );
final String browseUrl = "http://" + server + ":"+browserPort+"/browser/";
LogChannel.GENERAL.logBasic( "Opening Neo4j Browser: "+browseUrl );
browser.setUrl( browseUrl );
setNameForTab( tabAndPanel.tab, neoConnection.getName() );
setActive( true );
comp.layout();
// Spoon.getInstance().enableMenus();
}
@Override
public void createPartControl(Composite parent) {
final Composite body = new Composite(parent, SWT.NONE);
body.setLayout(new FillLayout());
this.browser = new Browser(body, SWT.NONE);
if (getEditorInput() instanceof IFileEditorInput) {
setFileInput((IFileEditorInput) getEditorInput());
} else {
this.browser.setText("<html><body></body></html>");
}
}
protected void createFormContent(IManagedForm managedForm)
{
body = managedForm.getForm().getBody();
body.setLayout(new FillLayout());
browser = new Browser(body, SWT.NONE);
super.createFormContent(managedForm);
}
/**
* 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;
}