Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » getting webcontent folder from IDataModel is not consistent
getting webcontent folder from IDataModel is not consistent [message #227547] Fri, 06 February 2009 12:15 Go to next message
Eclipse User
Originally posted by: ranjeev.backbase.com

Hello there,

I have issues to get the webcontent folder from IDataModel in a
consistent way if the folder value is renamed in the Web Project
Creation Wizard.

We have the following declaration in plugin.xml for our Project Facet,
which copies some files into WebContent folder of an Eclipse Web Project.

<extension
name="Client Edition"
id="xxx.project.facet.id"
point="org.eclipse.wst.common.project.facet.core.facets">
<project-facet id="xxx.facet.project.project-facet">
<label>Client Edition</label>
<category>
xxx.client.facet.category
</category>
</project-facet>
<project-facet-version
facet="xxx.client.bpc.facet.project.project-facet"
version="%project.facet.version">
</project-facet-version>

<action
facet="xxx.bpc.facet.project.project-facet"
id="xxx.facet.project.project-facet.install"
type="install"
version="%project.facet.version">
<delegate class="xxx.facet.actions.BpcClientInstallDelegate"/>
<config-factory
class="xxx.facet.actions.BpcClientActionConfigFactory"/>
</action>

</extension>



I have "xxx.facet.actions.BpcClientActionConfigFactory" which extends
SimpleWebFacetInstallDataModelProvider.

And in my execute method of BpcClientInstallDelegate which implements
IDelegate class, I have the method

public void execute(IProject project, IProjectFacetVersion version,
Object config, IProgressMonitor monitor) throws CoreException {
IDataModel model = (IDataModel) config;
problem here-->> String webContentFolder = (String)
model.getProperty("IStaticWebFacetInstallDataModelProperties.CONTENT_DIR ");


Now, I rename the webContent folder to "BlahContent" while creating
static web project.
If I debug and check the return value of the code:

String webContentFolder = (String)
model.getProperty("IStaticWebFacetInstallDataModelProperties.CONTENT_DIR ")

Sometimes I get webContentFolder value is "BlahContent" as renamed in
the Static Web Project Creation Wizard, but most of the other times, it
returns the default value, "webContent" !

Can somebody explain what is the issue? Looks like the listeners are not
initialised correctly sometimes!

Any help regarding this issue will be much appreciated

Regards
Ranjeev
Re: getting webcontent folder from IDataModel is not consistent [message #227548 is a reply to message #227547] Sat, 07 February 2009 01:03 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin Komissarchik
Messages: 940
Registered: July 2009
Senior Member
I would guess that the variance in behavior that you are seeing is due to
not specifying any constraints in your facet definition. Since you didn't
specify that your facet depends on the wst.web facet, the ordering between
invocation of wst.web's install delegate and your facet's install delegate
is not specified and can vary from one JVM instance to another.

Just add this to your <project-facet-version> declarations and I would
expect the behavior to stabilize.

<constraint>
<requires facet="wst.web"/>
</constraint>

However, there is another issue with what you are doing. Your current
approach will not work in the case where the project is already created
and the user goes to add your facet in project properties. The data model
property that you are trying to read is not going to be there.

Fortunately, there is a far easier solution to do what it looks like you
are trying to accomplish. Forget about
SimpleWebFacetInstallDataModelProvider or IDataModel properties. You don't
need any of that. By the time your delegate executes, you can use virtual
component API to get access to the content root directory.

IVirtualComponent vc = ComponentCore.createComponet( <IProject> );
IVirtualFolder vf = vc.getRootFolder();
IFolder folder = fv.getUnderlyingFolder();

Hope this helps,

- Konstantin
Re: getting webcontent folder from IDataModel is not consistent [message #227565 is a reply to message #227548] Mon, 09 February 2009 14:53 Go to previous message
Eclipse User
Originally posted by: ranjeev.backbase.com

Hello Konstantin,

Indeed the tips given by you worked!! I have applied the <contraint> and
then I use ComponentCore to get the webContent Folder. The facet is now
also applied to already created projects.

Thank you very much
Ranjeev

Konstantin Komissarchik wrote:
> I would guess that the variance in behavior that you are seeing is due
> to not specifying any constraints in your facet definition. Since you
> didn't specify that your facet depends on the wst.web facet, the
> ordering between invocation of wst.web's install delegate and your
> facet's install delegate is not specified and can vary from one JVM
> instance to another.
>
> Just add this to your <project-facet-version> declarations and I would
> expect the behavior to stabilize.
>
> <constraint>
> <requires facet="wst.web"/>
> </constraint>
>
> However, there is another issue with what you are doing. Your current
> approach will not work in the case where the project is already created
> and the user goes to add your facet in project properties. The data
> model property that you are trying to read is not going to be there.
>
> Fortunately, there is a far easier solution to do what it looks like you
> are trying to accomplish. Forget about
> SimpleWebFacetInstallDataModelProvider or IDataModel properties. You
> don't need any of that. By the time your delegate executes, you can use
> virtual component API to get access to the content root directory.
> IVirtualComponent vc = ComponentCore.createComponet( <IProject> );
> IVirtualFolder vf = vc.getRootFolder();
> IFolder folder = fv.getUnderlyingFolder();
>
> Hope this helps,
>
> - Konstantin
>
Previous Topic:empty server list :(
Next Topic:Publish deletes read-only files
Goto Forum:
  


Current Time: Tue Sep 16 21:45:43 GMT 2014

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

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