Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Automatically adding Xtext nature to project
Automatically adding Xtext nature to project [message #1060791] Tue, 28 May 2013 12:46 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi,

I'm using a GMF editor with xtext. In order to get xtext running corectly, it's necessary to add the xtext nature to the project. Is there way to do this automatically when I create a new gmf diagram. Therefor I'm using the following creation wizard:

<extension point="org.eclipse.ui.newWizards" id="creation-wizard">
    <category
        id="org.eclipse.ui.PLDev"
        name="Prod">
     </category>
     <wizard
       name="Prod"
       icon="icons/PldWizard.png"
       category="org.eclipse.ui.PLDev"
       class="pld.diagram.part.PldCreationWizard"
       id="pld.diagram.part.PldCreationWizardID">
       <description>Creates a new Productline</description>
      </wizard>
   </extension>


Is there a chance to extend the creation wizard in order to add a xtext nature to the project?
Re: Automatically adding Xtext nature to project [message #1060796 is a reply to message #1060791] Tue, 28 May 2013 12:54 Go to previous messageGo to next message
Claudio Heeg is currently offline Claudio HeegFriend
Messages: 75
Registered: April 2013
Member
I'm a little confused as to what you want to achieve precisely, but as far as programmatically adding the nature to a project goes, this thread came to mind:
http://www.eclipse.org/forums/index.php/m/718205/
Especially the two lines mentioned during the last post may be of interest?

From what I understand you have both a textual Xtext file and a graphical representation of it. Where and when do you want to add the nature now, automatically?
Re: Automatically adding Xtext nature to project [message #1060799 is a reply to message #1060791] Tue, 28 May 2013 12:56 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1192
Registered: July 2009
Senior Member
Hi,

in the PldCreationWizard class, you should be able to obtain the project, inspect its natures and add the Xtext nature if necessary.

Alex
Re: Automatically adding Xtext nature to project [message #1060982 is a reply to message #1060791] Wed, 29 May 2013 12:19 Go to previous message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
thx for the suggestions, it's working great now. For those looking also for this, here is the code:

ISelectionService selectionService = workbench.getActiveWorkbenchWindow().getSelectionService();
   if (selection instanceof IStructuredSelection) {
      Object element = ((IStructuredSelection) selection).getFirstElement();
      if (element instanceof IResource) {
	 IProject project = ((IResource) element).getProject();
	 try {
	   if (!project.hasNature("org.eclipse.xtext.ui.shared.xtextNature")) {
	      IProjectDescription description = project.getDescription();
	      description.setNatureIds(new String[] { "org.eclipse.xtext.ui.shared.xtextNature" });
	      project.setDescription(description, null);
	   }
	 } catch (CoreException e) {
	   e.printStackTrace();
         }
      }
   }


Cheers,
Phil
Previous Topic:Correct Indentation
Next Topic:"a registered resource factory is needed" error with absolute path
Goto Forum:
  


Current Time: Sat Oct 01 08:39:35 GMT 2016

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

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