Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 95336 - clean up ModelQuery extensions to make them easier to reuse
Summary: clean up ModelQuery extensions to make them easier to reuse
Status: CLOSED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xml (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Craig Salter CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-16 00:18 EDT by Craig Salter CLA
Modified: 2005-06-27 12:38 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Craig Salter CLA 2005-05-16 00:18:20 EDT
Some clean up is required to reorganize the modelQuery extension points to make
them easier to use.
Comment 1 Craig Salter CLA 2005-05-16 14:39:45 EDT
In the past we've utilized some rather ugly tricks to extend the schema driven
guided editing.  I've recently done some work to clean up this extension
mechanism an implement it as an ‘experimental’ extension point that may be
useful to other plugin developers that need to provide similar capabilities.  We
currently make use of this extension for editing WSDL and XML Schema files in
order to provide additional ‘possible values’ for attributes and to provide some
filtering to constrain spurious suggestions where ‘any elements’ occur. 

I’ll try to explain how this works.  Of course this extension point should be
considered purely experimental!

In the xml.core plugin the ModelQuery is used to ask grammar related questions
about a DOM (e.g. what can go here, what values can this attribute have etc). 
The ModelQuery extensions can be used to augment the behaviour of the ModelQuery
in order to capture additional constraints of your language that can’t be
captured in a static XML Schema or DTD grammar.

Here’s a snippet of plugin.xml where I’ve specified a modelQueryExtension.  Note
that an optional namespace attribute can also be specified in order to further
refine where your extension is applicable.

<!-- this extension point is used to augment the ModelQuery to provide schema
specific guided editing -->
<extension point="org.eclipse.wst.xml.core.modelQueryExtensions">
  <modelQueryExtension		
class="org.eclipse.wst.xsd.ui.internal.text.XSDModelQueryExtension"
	contentType="org.eclipse.wst.xsd.contentmodel.xsdsource">
   </modelQueryExtension>
</extension>


The ‘class’ specified by the plugin.xml needs to subclass the abstract
ModelQueryExtension class.  It can then override one or more of the methods
shown below.

public abstract class ModelQueryExtension
{ 
  // this method is used to provide possible values for an attribute
  // usually this is used to constrain an ‘xsd:string’ type to provide
  // a dynamic list of possible values
  //   
  public String[] getAttributeValues(Element ownerElement, String namespace,
String name)

  // this method is used to provide possible values for an element’s text
  // usually this is used to constrain an ‘xsd:string’ type to provide
  // a dynamic list of possible values
  //   
  public String[] getElementValues(Node parentNode, String namespace, String name)

// this method is used to filter child elements, this can be used to add
//additional constraints when an elements content model is described with
//‘wild cards (i.e. ‘xsd:any’) 

  public boolean isApplicableChildElement(Node parentNode, String namespace, 
}


NOTE: At the time of this posting this code hasn’t been released yet so you’ll
need to grab the latest xml.core plugin from HEAD (and perhaps the xml.ui plugin
to use an example) in order to play with this.
Comment 2 Craig Salter CLA 2005-05-16 15:01:43 EDT
I've cleaned up our WSDL and XMLSchema editors to use this extension point.  I
suspect some work will be required in the future to make this extension point
fit in with more 'ui specific' extension points (such as a content assist
extension point).  That may mean this extension point will 'morph' into
something significantly different in the future.  Now that the ModelQuery
extension related code is cleaned up, the WSDL and XML Schema editors are better
positioned for any such future changes.
Comment 3 Craig Salter CLA 2005-06-27 12:38:38 EDT
mass closing verified bugs I own