| Get Project Properties in ContentAssistProcessor [message #225808] |
Tue, 30 December 2008 15:27  |
Dominik Raymann 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] |
Fri, 02 January 2009 19:05   |
|
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 #228358 is a reply to message #227119] |
Wed, 25 February 2009 17:32   |
Dominik Raymann 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.01654 seconds