Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » Get Project Properties in ContentAssistProcessor
Get Project Properties in ContentAssistProcessor [message #225808] Tue, 30 December 2008 20:27 Go to next message
Dominik Raymann is currently offline Dominik RaymannFriend
Messages: 37
Registered: July 2009
Member
Hi there,

I implemented a little plugin to extend content assistance and
validation for HTML files. Everything works fine so far: I extended
StructuredTextViewerConfigurationHTML and returned my own
ContentAssistProcessor.

However, the possible proposals are dependent on some project specific
properties (at least in some cases). I understand how to store these
properties on the project resource, but I don't know how to get to the
IProject resource from my ContentAssistProcessor. In
IContentAssistProcessor.computeCompletionProposals there is a
ITextViewer object and in my
StructuredTextViewerConfiguration.getContentAssistProcessors a
ISourceViewer object as parameter, but I don't see a way to get to the
project resource from there. Can anybody help?

Thanks in advance and a happy 2009,

Dominik
Re: Get Project Properties in ContentAssistProcessor [message #225855 is a reply to message #225808] Sat, 03 January 2009 00:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

Dominik Raymann wrote:
> Hi there,
>
> I implemented a little plugin to extend content assistance and
> validation for HTML files. Everything works fine so far: I extended
> StructuredTextViewerConfigurationHTML and returned my own
> ContentAssistProcessor.
>
> However, the possible proposals are dependent on some project specific
> properties (at least in some cases). I understand how to store these
> properties on the project resource, but I don't know how to get to the
> IProject resource from my ContentAssistProcessor. In
> IContentAssistProcessor.computeCompletionProposals there is a
> ITextViewer object and in my
> StructuredTextViewerConfiguration.getContentAssistProcessors a
> ISourceViewer object as parameter, but I don't see a way to get to the
> project resource from there. Can anybody help?

I suspect you need to access it through the bundle getWorkspace()
method, and then get then check the appropriate project. You might also
be able to get the project from the IDocument for the particular file or
the EditorPart.

Dave
Re: Get Project Properties in ContentAssistProcessor [message #227119 is a reply to message #225855] Thu, 22 January 2009 19:07 Go to previous messageGo to next message
Dominik Raymann is currently offline Dominik RaymannFriend
Messages: 37
Registered: July 2009
Member
David Carver schrieb:
> Dominik Raymann wrote:
>> Hi there,
>>
>> I implemented a little plugin to extend content assistance and
>> validation for HTML files. Everything works fine so far: I extended
>> StructuredTextViewerConfigurationHTML and returned my own
>> ContentAssistProcessor.
>>
>> However, the possible proposals are dependent on some project specific
>> properties (at least in some cases). I understand how to store these
>> properties on the project resource, but I don't know how to get to the
>> IProject resource from my ContentAssistProcessor. In
>> IContentAssistProcessor.computeCompletionProposals there is a
>> ITextViewer object and in my
>> StructuredTextViewerConfiguration.getContentAssistProcessors a
>> ISourceViewer object as parameter, but I don't see a way to get to the
>> project resource from there. Can anybody help?
>
> I suspect you need to access it through the bundle getWorkspace()
> method, and then get then check the appropriate project. You might also
> be able to get the project from the IDocument for the particular file or
> the EditorPart.
>
> Dave

Thanks for your answer. However, I don't see how I can access my bundle
from my ContentAssistProcessor (or my validator). Do I have to pass a
reference to it somehow? Could you give an example?

I also don't know how to get to the project from the IDocument as a
starting point. Does anybody have an example? I think this should be a
quite common problem, shouldn't it?

Dominik
Re: Get Project Properties in ContentAssistProcessor [message #228358 is a reply to message #227119] Wed, 25 February 2009 22:32 Go to previous messageGo to next message
Dominik Raymann is currently offline Dominik RaymannFriend
Messages: 37
Registered: July 2009
Member
Just in case anybody has found this thread while googling for an answer
to a question similar to mine:

I found a way to get the actual file of a IDocument (if there is an
associated WST model). I can't remember where I found the code, I think
it's from a Spring Plugin. You can easily get the project afterwards by
calling the getProject() method of the file afterwards. I don't know
whether it is the best way, but it seems to work. So here we go:

public static final IFile getFile(IDocument document) {
IFile resource = null;
String baselocation = null;
if (document != null) {
IStructuredModel model = null;
try {
model = org.eclipse.wst.sse.core.StructuredModelManager
..getModelManager().getExistingModelForRead(document);
if (model != null) {
baselocation = model.getBaseLocation();
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
if (baselocation != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath filePath = new Path(baselocation);
if (filePath.segmentCount() > 0) {
resource = root.getFile(filePath);
}
}
return resource;
}

Dominik Raymann schrieb:
> David Carver schrieb:
>> Dominik Raymann wrote:
>>> Hi there,
>>>
>>> I implemented a little plugin to extend content assistance and
>>> validation for HTML files. Everything works fine so far: I extended
>>> StructuredTextViewerConfigurationHTML and returned my own
>>> ContentAssistProcessor.
>>>
>>> However, the possible proposals are dependent on some project specific
>>> properties (at least in some cases). I understand how to store these
>>> properties on the project resource, but I don't know how to get to the
>>> IProject resource from my ContentAssistProcessor. In
>>> IContentAssistProcessor.computeCompletionProposals there is a
>>> ITextViewer object and in my
>>> StructuredTextViewerConfiguration.getContentAssistProcessors a
>>> ISourceViewer object as parameter, but I don't see a way to get to the
>>> project resource from there. Can anybody help?
>>
>> I suspect you need to access it through the bundle getWorkspace()
>> method, and then get then check the appropriate project. You might
>> also be able to get the project from the IDocument for the particular
>> file or the EditorPart.
>>
>> Dave
>
> Thanks for your answer. However, I don't see how I can access my bundle
> from my ContentAssistProcessor (or my validator). Do I have to pass a
> reference to it somehow? Could you give an example?
>
> I also don't know how to get to the project from the IDocument as a
> starting point. Does anybody have an example? I think this should be a
> quite common problem, shouldn't it?
>
> Dominik
Re: Get Project Properties in ContentAssistProcessor [message #228366 is a reply to message #228358] Thu, 26 February 2009 01:52 Go to previous message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 2333
Registered: July 2009
Senior Member
Just don't forget to check whether that file exists. The base
location of the model will be the file system location if you've
opened a file from outside of the workspace.

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


---
Nitin Dahyabhai
Eclipse WTP, IBM
Previous Topic:Missing Dependent Project on Java EE Module Dependencies Page
Next Topic:Re: Weblogic 10 integration issue in Eclipse 3.4.1
Goto Forum:
  


Current Time: Mon Nov 24 12:30:50 GMT 2014

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

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