[jbosstools-issues] [JBoss JIRA] (JBIDE-14320) JSPMultiPageEditor.getDocumentProvider().getDocument(input) returns null

Victor Rubezhny (JIRA) jira-events at lists.jboss.org
Fri Apr 26 13:12:53 EDT 2013


    [ https://issues.jboss.org/browse/JBIDE-14320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770460#comment-12770460 ] 

Victor Rubezhny commented on JBIDE-14320:
-----------------------------------------

There is no way to get the Document from a Document Adapter by the original Editor Input provided.

There is a fix for issue [JBIDE-1809 (VPE doesn't shows anything when we open file from local edition history)|https://issues.jboss.org/browse/JBIDE-1809] that replaces the original Editor Input in the editor by another one. So, you'll never get the Document back from the Document Adapter by an original Editor Input provided. See the code below:

{code:title=VpeEditorPart.createPartControl(Composite) line: 520}
IEditorInput input = getEditorInput();
if (!( input instanceof IModelObjectEditorInput) && input instanceof IStorageEditorInput) {
	input = new StorageRevisionEditorInputAdapter((IStorageEditorInput) input);
}
{code}

In other cases (even if fix for JBIDE-1809 is removed) the same thing (replacing the original Editor Input by a new one) may happen in JSPMultiPageEditor itself depending on the type of Editor Input provided.

So, the most correct way to get the Document is to ask Editor's Viewer for its Document or call getAdapter(IDocument.class) method of ITextEditor instance.
                
> JSPMultiPageEditor.getDocumentProvider().getDocument(input) returns null
> ------------------------------------------------------------------------
>
>                 Key: JBIDE-14320
>                 URL: https://issues.jboss.org/browse/JBIDE-14320
>             Project: Tools (JBoss Tools)
>          Issue Type: Bug
>          Components: browsersim, jsp/jsf/xml/html source editing
>    Affects Versions: 4.1.0.Beta1
>            Reporter: Yahor Radtsevich
>            Assignee: Victor Rubezhny
>             Fix For: 4.1.0.Beta1
>
>
> In BrowserSim we [use|https://github.com/jbosstools/jbosstools-vpe/blob/master/plugins/org.jboss.tools.vpe.browsersim.eclipse/src/org/jboss/tools/vpe/browsersim/eclipse/callbacks/ViewSourceCallback.java#L108] the following code to view the source code of currently opened page.
> This code opens a default html editor with given {{content}}.
> Everything is working fine, unless {{JSPMultiPageEditor}} is the default html editor.
> In the case with {{JSPMultiPageEditor}}, the method {{JSPMultiPageEditor.getDocumentProvider().getDocument(input)}} returns {{null}} and blanck editor is shown.
> {code}
> private void openInMemoryHtmlEditor(String content, String name, String toolTip) {
> 	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
> 	IWorkbenchPage page = window != null ? window.getActivePage() : null;
> 	if (page != null) {
> 		try {
> 			IEditorDescriptor editorDescriptor = PlatformUI.getWorkbench()
> 					.getEditorRegistry().getDefaultEditor("view-source.html"); // get default editor for .html //$NON-NLS-1$
> 			String editorId;
> 			if (editorDescriptor != null && editorDescriptor.isInternal()) {
> 				editorId = editorDescriptor.getId();
> 			} else {
> 				editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
> 			}
> 			IStorage storage = new StringStorage("", // see the long comment below to know why an empty storage is created //$NON-NLS-1$
> 					"view-source.html"); // .html extension is needed to enable code highlighting in the WTP HTML editor //$NON-NLS-1$
> 			IStorageEditorInput input = new StringInput(storage, name, toolTip);
> 			IEditorPart editor = page.openEditor(input, editorId);
> 			
> 			/* We change content of the editor AFTER the editor is created
> 			 * as a workaround for the following WTP bug.
> 			 * The essence of the bug is that if given HTML page contains a link
> 			 * to an external DTD, then WTP HTML editor tries to access this DTD before the editor
> 			 * is created and freezes UI.
> 			 * See http://www.eclipse.org/forums/index.php/m/639937/
> 			 */
> 			IDocument doc = null;
> 			ITextEditor textEditor = null;
> 			if (editor instanceof ITextEditor) {
> 				textEditor = (ITextEditor) editor;
> 			} else {
> 				textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
> 			}
> 			
> 			if (textEditor != null) {
> 				doc = textEditor.getDocumentProvider().getDocument(input);// <<<<----- THE PROBLEM APPEARS HERE
> 			}
> 			if (doc != null) {
> 				doc.set(content);
> 				editor.doSave(null); // reset resource-changed marker
> 			}
> 		} catch (PartInitException e) {
> 			Activator.logError(e.getMessage(), e);
> 		}
> 	} else {
> 		Activator.logError("Cannot obtain workbench page", null);
> 	}
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jbosstools-issues mailing list