Skip to main content



      Home
Home » Newcomers » Newcomers » Display HTML file in EditorPart
Display HTML file in EditorPart [message #869369] Thu, 03 May 2012 05:51 Go to next message
Eclipse UserFriend
Hi,

I'm new to eclipse plugin development. I'm trying to create a plugin which will generate a report in the form of HTML and display it to the user. I've added a button to eclipse and am able to generate an HTML file. I'm also able to add a ViewPart where I'm displaying some textual information to the user. Now the problem is how to display the HTML file automatically, as soon as I click the plugin button.

index.php/fa/9218/0/

Currently in the createPartControl method of my view when I use the following code I'm able to display the HTML file in the ViewPart:
Browser browser = new Browser(parent, SWT.NONE);
browser.setUrl(dataPath + "/Result.html");

where parent is the parent control of the view and dataPath is the path to the HTML file.

My requirement is to add a new tab in the EditorPart and display the HTML file over there. Any suggestion in this regard will be highly appreciated.

Thank You in advance.
-Alok

[Updated on: Thu, 03 May 2012 05:53] by Moderator

Re: Display HTML file in EditorPart [message #869543 is a reply to message #869369] Thu, 03 May 2012 10:55 Go to previous messageGo to next message
Eclipse UserFriend
Once you have the handle to your file (IFile), you can use one of the org.eclipse.ui.ide.IDE.openEditor(..) methods.
Re: Display HTML file in EditorPart [message #869732 is a reply to message #869543] Fri, 04 May 2012 01:13 Go to previous messageGo to next message
Eclipse UserFriend
Thanks a lot for the reply Michael. I was able to display the file using IDE.openEditor
Re: Display HTML file in EditorPart [message #869755 is a reply to message #869732] Fri, 04 May 2012 04:25 Go to previous messageGo to next message
Eclipse UserFriend
Continuing on this, on using IDE.openEditor the html file by default opens in Design mode. My requirement is to only display the html file and not let the user edit it, ie to open the html file in preview mode.

I'm using the following code to display the file:

IFile input = selectedProject.getFile("Result.html");
if(input.exists()) {
	IWorkbench wb = PlatformUI.getWorkbench();
	IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
	IWorkbenchPage page = win.getActivePage();
	IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry()
				.getDefaultEditor(input.getName());
	IDE.openEditor(page, input, desc.getId());
}

Is there any way I can display the file in preview mode only.

Thanks in advance.
-Alok
Re: Display HTML file in EditorPart [message #870162 is a reply to message #869755] Mon, 07 May 2012 01:46 Go to previous message
Eclipse UserFriend
I got a workaround to this problem. First I'm scanning the list of all available Editors and then selecting the Web Browser from that list. I'm using the following code:
IEditorDescriptor[] desc_arr = PlatformUI.getWorkbench().getEditorRegistry().getEditors(input.getName());
String descID = "";
for(int i=0; i<desc_arr.length; i++) {
	if(desc_arr[i].getLabel().equalsIgnoreCase("Web Browser")) {
		descID = desc_arr[i].getId();
		break;
	}
}
if(descID == "")  //Open using default Editor
	IDE.openEditor(page, input);
else
	IDE.openEditor(page, input, descID);

Is there any better way of doing it?

Regards,
-Alok
Previous Topic:Error messages
Next Topic:Problem with german Babel language pack for eclipse
Goto Forum:
  


Current Time: Mon Jul 21 10:36:44 EDT 2025

Powered by FUDForum. Page generated in 0.08547 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top