Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Get Attribute, Tag and Parent name
Get Attribute, Tag and Parent name [message #677037] Tue, 07 June 2011 11:32 Go to next message
MarcoGT  is currently offline MarcoGT Friend
Messages: 77
Registered: May 2011
Member
Hi all,

I am trying to get a kind of content assist for XML attributes.
At the moment I am working with the class org.eclipse.wst.xml.ui.internal.XMLTemplateCompletionProcessor.java

Is has a method addAttributeValueProposals. This method is called, of course, when content assist is invoked inside double quotes for attribute values.

The list of attribute values, in my case, is inside an external XML file.

For example:

<employee department=""

If the content assist is invoked, a list of possible department should be displayed inside the box.

If the question start to write something inside double quotes I can get what he writes using ContentAssistRequest.getMatchString; but what if the content assist is invoked without typing anything?

Here come the questions:

1) How do I get the name of the attribute? I also need the name of the tag which attribute belongs to and the name of the parent tag.

2) Then, with these data, I can build an XPath expression to query the external XML file (no problem here).

When I get my data back...how do I put them inside the content assist block?

Thanks a lot
Marco

EDIT: probably the names of the attribute and parent can be get using method always inside ContentAssistRequest, probably...

[Updated on: Tue, 07 June 2011 12:00]

Report message to a moderator

Re: Get Attribute, Tag and Parent name [message #677224 is a reply to message #677037] Tue, 07 June 2011 20:57 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

On 6/7/2011 7:32 AM, MarcoGT wrote:
> Hi all,
>
> I am trying to get a kind of content assist for XML attributes.
> At the moment I am working with the class
> org.eclipse.wst.xml.ui.internal.XMLTemplateCompletionProcessor.java

I hope you mean
org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor.

> Is has a method addAttributeValueProposals. This method is called, of
> course, when content assist is invoked inside double quotes for
> attribute values.
>
> The list of attribute values, in my case, is inside an external XML file.
>
> For example:
>
> <employee department=""
>
> If the content assist is invoked, a list of possible department should
> be displayed inside the box.
>
> If the question start to write something inside double quotes I can get
> what he writes using ContentAssistRequest.getMatchString; but what if
> the content assist is invoked without typing anything?

The match string will be empty.

> Here come the questions:
>
> 1) How do I get the name of the attribute? I also need the name of the
> tag which attribute belongs to and the name of the parent tag.

In
org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor#addAttributeValueProposals(ContentAssistRequest)
you'll see it walk backwords through the list of text regions in the tag
to find the attribute's name. The ContentAssistRequest contains the DOM
Node you're working on as well as its parent Node.
>
> Then, with these data, I can build an XPath expression to query the
> external XML file (no problem here).
>
> When I get my data back...how do I put them inside the content assist
> block?

You'll add the proposal using
ContentAssistRequest.addProposal(ICompletionProposal).

--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Get Attribute, Tag and Parent name [message #677303 is a reply to message #677224] Wed, 08 June 2011 06:08 Go to previous messageGo to next message
MarcoGT  is currently offline MarcoGT Friend
Messages: 77
Registered: May 2011
Member
Nitin Dahyabhai wrote on Tue, 07 June 2011 16:57
On 6/7/2011 7:32 AM,

I hope you mean
org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor.


I saw that this class in no longer used (it is deprecated) and it suggests to use XMLStructuredContentAssistProcessor
The called method when invoking content assist on an attribute values is XMLTemplatesCompletionProposaleComputer.addAttributeValueProposals, not that one in XMLContentAssistProcessor that, as said, is deprecated.

I mean, when calling the Content Assistant the called method is XMLTemplatesCompletionProposaleComputer.addAttributeValueProposals (I tried to put breakpoints and System.out.print and this is the method that is invoked)
See also here: http://wiki.eclipse.org/New_Help_for_Old_Friends_V#Content_Assist (in the "Deprecated" section).

The new class is XMLStructuredContentAssistProcessor but it is very different from XMLContentAssistProcessor, for example there is not method addAttributeValueProposals. The same is for the super classes.

AbstractContentAssistProcessor, which is extended by XMLContentAssistProcessor is deprecated and it is suggested to use StructuredContentAssistProcessor.

So, which method get the attribute name, tag and parent tag name?
The method you told me (org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor#addAttributeValueProposals(ContentAssistRequest) ) is inside a deprecated class.

Quote:

The match string will be empty.


Ok, but of course I can make as well an XPath query to my external XML file using the attribute name, tag name a parent tag name, right?

Quote:

In
org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor#addAttributeValueProposals(ContentAssistRequest)
you'll see it walk backwords through the list of text regions in the tag
to find the attribute's name. The ContentAssistRequest contains the DOM
Node you're working on as well as its parent Node.


As before, this class is deprecated too, the "new" one is "StructuredContentAssistProcessor"

Quote:

You'll add the proposal using
ContentAssistRequest.addProposal(ICompletionProposal).


If I do:

List proposals = new ArrayList();
proposals.add(xpr.read(MY_XPATH_EXPRESSION, XPathConstants.STRING));
ICompletionProposal result = (ICompletionProposal) proposals;
contentAssistRequest.addProposal(result);


I get a cast error at the third line.

One more thing: if I call the content assist inside "attribute value position", is also possible to get the list of all the attributes inside that element, if any, with their values?


Thanks
Marco

[Updated on: Wed, 08 June 2011 13:00]

Report message to a moderator

Re: Get Attribute, Tag and Parent name [message #677434 is a reply to message #677303] Wed, 08 June 2011 14:25 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Strange how that shows up empty in Thunderbird.

You should look at the AbstractXMLModelQueryCompletionProposalComputer if you're just looking to steer clear of deprecated classes. It uses a newer extension point, though.

As for which methods give you the tag, attribute, and parent tag names, you have the DOM Nodes available to you through the ContentAssistRequest, as well as the raw parsed information. I suggest you read through the APIs to find what information is available to you during the content assist operation. As for the code snippet, I would expect that you can't cast a java.util.List to an ICompletionProposal. You'll find the creation and use of our CustomCompletionProposal class in the proposal computer to use as an example, although I expect you could implement one yourself.


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Get Attribute, Tag and Parent name [message #677437 is a reply to message #677434] Wed, 08 June 2011 14:29 Go to previous messageGo to next message
MarcoGT  is currently offline MarcoGT Friend
Messages: 77
Registered: May 2011
Member
Hello!

Yes, wouldn't like to use the deprecated class.

Ok, I will give a look to AbstractXMLModelQueryCompletionProposalComputer and how it works.

Ok for the attribute name.

That'all, for the moment.

Thanks
Marco
Re: Get Attribute, Tag and Parent name [message #677717 is a reply to message #677437] Thu, 09 June 2011 08:30 Go to previous messageGo to next message
MarcoGT  is currently offline MarcoGT Friend
Messages: 77
Registered: May 2011
Member
Some questions:

what does the map caseInsensitiveMap contain?
I thought it contained only the attributes of the element where the content assist is called, but, for example I have:

<employee name="" surname="" age="" address" />


And the length is 13...why?

Another question: to test my code, at the moment, I am using Invoice.xml that can be found in the XMLExample project inside Eclipse.

Inside AbstractXMLModelQueryCompletionProposalComputer class there is this condition:

if ((attrDecl != null) && (attrDecl.getAttrType() != null)) 

// here it creates the suggestion

else {
}

// use CustomCompletionProposal


The question is: why if I call content assistant for attribute value inside Invoice.xml it goes inside the else, and if I call it from my XML file it goes through the first if?

attrDecl is defined as:

attrDecl = (CMAttributeDeclaration) allAttributes.getNamedItem(attributeName);


Thanks a lot
Marco

[Updated on: Thu, 09 June 2011 11:06]

Report message to a moderator

Re: Get Attribute, Tag and Parent name [message #684294 is a reply to message #677717] Wed, 15 June 2011 11:25 Go to previous messageGo to next message
MarcoGT  is currently offline MarcoGT Friend
Messages: 77
Registered: May 2011
Member
One question about deploy:

at the moment I am working on org.eclipse.wst.xml.ui

If a export (using the wizard) this source I will obtain a JAR file called org.eclipse.wst.xml.ui.XYZ where XYZ is the plugin qualifier.

Now, I tried to copy this plugin inside the plugin folder (after having removed the default one) but I do not have anymore the XML editor (nor default, nor the mine).

I tried also to give to the exported plugin the same qualifier, but it does not work.

Where am I wrong?

Do I have to edit the file features.xml inside eclipse/feature/org.eclipse.wst.xml.ui?

Thanks
Marco

[Updated on: Wed, 15 June 2011 12:04]

Report message to a moderator

Re: Get Attribute, Tag and Parent name [message #684331 is a reply to message #677037] Wed, 15 June 2011 12:26 Go to previous messageGo to next message
MarcoGT  is currently offline MarcoGT Friend
Messages: 77
Registered: May 2011
Member
One question:

I am trying to deploy the plugin.
As I wrote I checked-out sources from Eclipse CVS and worked on them.

If I used the modified plugin starting it as "Eclipse Application" it works fine.

I have used the export wizard, copy the jar file inside the eclipse/plugin folders but it does not work. If I go in Help->About Eclipse and look for the loaded plugins I see that the default one is loaded, not the mine.

The plugin is org.eclipse.wst.xml.ui; the name is, of course, the same as the default one, only the qualifier is different.

Do I have to modify the features.xml in eclipse/features/org.eclipse.wst.xml.ui?

Where am I wrong?

Thanks
Marco
Re: Get Attribute, Tag and Parent name [message #684594 is a reply to message #684294] Wed, 15 June 2011 21:34 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

On 6/15/2011 7:25 AM, MarcoGT wrote:
> One question about deploy:
>
> at the moment I am working on org.eclipse.wst.xml.ui
>
> If a export (using the wizard) this source I will obtain a JAR file
> called org.eclipse.wst.xml.ui.XYZ where XYZ is the plugin qualifier.
>
> Now, I tried to copy this plugin inside the plugin folder (after having
> removed the default one) but I do not have anymore the XML editor (nor
> default, nor the mine).
>
> I tried also to give to the exported plugin the same qualifier, but it
> does not work.
>
> Where am I wrong?

Our plug-in is signed. Are you working on a patch you'll be submitting?

--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Get Attribute, Tag and Parent name [message #684714 is a reply to message #684594] Thu, 16 June 2011 05:14 Go to previous messageGo to next message
MarcoGT  is currently offline MarcoGT Friend
Messages: 77
Registered: May 2011
Member
No, I will not submit it.

So, do I have to sign it?
Re: Get Attribute, Tag and Parent name [message #686162 is a reply to message #684714] Mon, 20 June 2011 15:23 Go to previous message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

On 6/16/2011 1:14 AM, MarcoGT wrote:
> No, I will not submit it.
>
> So, do I have to sign it?

That's a detail of deployment that I'm not an expert on, apart from
having seen my own updated plug-ins be ignored when a previous signed
version was installed.

--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Previous Topic:Unable to create a web service client
Next Topic:JSDT jQuery plugin
Goto Forum:
  


Current Time: Tue Apr 16 18:14:39 GMT 2024

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

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

Back to the top