Bug 142212 - Usability: linking Deployment Descriptor nodes with XML Editor nodes
Summary: Usability: linking Deployment Descriptor nodes with XML Editor nodes
Status: RESOLVED WONTFIX
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xml (show other bugs)
Version: 1.5   Edit
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: Future   Edit
Assignee: wst.xml CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2006-05-17 09:36 EDT by Kaloyan Raev CLA
Modified: 2009-09-30 23:31 EDT (History)
2 users (show)

See Also:


Attachments
Patch (5.12 KB, patch)
2006-05-17 09:37 EDT, Kaloyan Raev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kaloyan Raev CLA 2006-05-17 09:36:12 EDT
The Project Explorer view shows a "Deployment Descriptor: <project_name>" subtree node that represents the structure of the deployment descriptor xml for the corresponding J2EE project. For Web projects this is web.xml, for EJB projects - ejb-jar.xml and so on. Double-clicking on this node or its child node opens the deployment descriptor in an XML editor. This is ok, but this does not position the editor's cursor on the position that corresponds to the selected node in the Project Explorer view. For example, I would expect that if I double-click "Servlet Mapping (/foo - foo)" in the Web Deployment Descriptor in the Project Exlporer view then the web.xml file will be open and the XML Editor cursor will be positioned on the corresponding xml tag. 

Though this is not functional bug, it is important in terms of usability as deployment descriptors grow in size. 

A patch is attached that solves the described issue. Explanation about patch implementation follows. 

When the Deployment Descriptor node or its child node is double clicked then the invokation stack trace calls: 

  org.eclipse.jst.j2ee.internal.actions.OpenJ2EEResourceAction.openAppropriateEditor()
  
where we have (lines 96:98): 

    editor = page.openEditor(new FileEditorInput((IFile) r), currentDescriptor.getId());
    if (editor instanceof ISetSelectionTarget)
        ((ISetSelectionTarget) editor).selectReveal(getStructuredSelection());

The above code snippet opens the deployment descriptor xml file in the XML Editor represented by the following class: 

  org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart

Then it tries to call the "selectReveal()" method if the editor implements the ISetSelectionTarget interface. This call would position the cursor in the XML editor to the appropriate position. 

The problem is that the XMLMultiPageEditorPart does not implement ISetSelectionTarget. Here comes the patch. It actually implements the ISetSelectionTarget and its corresponding selectReveal() method in the XMLMultiPageEditorPart class. 

The following steps are done in the selectReveal(ISelection selection) method implementation: 
  1. Check if the provided "selection" is instance of IStructuredSelection.
  2. If yes, get the first element from the selection.
  3. If the first element is not null (non-empty selection) then try to get EMF2DOMAdapter from the object. 
  4. If the result is not null then call "EMF2DOMAdapter.getNode" to get the DOM node object that represents the selected EMF object in the Project Explorer view. 
  5. Construct new StructuredSelection from the DOM node. 
  6. Set the selection to the current active page of the editor. 

The most interesting step is number 3. There we try to get EMF2DOMAdapter from the selection. It turns out that the nodes in the deployment desciptor tree in the Project Explorer view has this adapter and it can be used by the XML Editor to translate the selected EMF object to DOM object. The object that implements the Node interface also implements IndexedRegion and can be used to construct new StructuredSelection that is understandable by the XML editor.
Comment 1 Kaloyan Raev CLA 2006-05-17 09:37:02 EDT
Created attachment 41717 [details]
Patch
Comment 2 David Williams CLA 2006-05-25 13:50:24 EDT
Since you've provided a patch, I'll try to take a look before 1.5 is completely frozen ... adding Chuck to CC as an interested party. 

Comment 3 David Williams CLA 2007-09-04 01:06:52 EDT
Nitin, please triage, and reassign as needed. 
Comment 4 Nitin Dahyabhai CLA 2007-09-05 04:29:11 EDT
Kaloyan, it's a good idea, but any selection being sent to a part should be done with the domain objects that that part expects--in our case either an IStructuredSelection of IDOMNodes or an ITextSelection.  Can OpenJ2EEResourceAction be altered to send selection to the editor on those terms?
Comment 5 David Carver CLA 2009-03-19 20:53:29 EDT
Kaloyan, can you address the issues that Nitin raised and provide a new patch.  I'm tentatively marking this as future, until we can look at it further.  If you can get this patch updated, we might be able to address in the 3.2 time frame.

Also, I'm changing this to an enhancement since currently it works as designed.
Comment 6 Nitin Dahyabhai CLA 2009-09-30 23:31:08 EDT
Resolving as wontfix from lack of response.  Please reopen if you want to pursue this.