Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Suppress Add Xtext Nature Dialogue causes Problem (Suppress Add Xtext Nature Dialogue causes Problem to load the cross referenced Dsl elements)
Suppress Add Xtext Nature Dialogue causes Problem [message #1456525] Thu, 30 October 2014 12:58 Go to next message
Kunal Khaware is currently offline Kunal KhawareFriend
Messages: 41
Registered: December 2013
Location: Hyderabad,India
Member

Hi,
I have added below code to suppress Add to Xtext Nature dialogue
import org.eclipse.core.resources.IResource;
import org.eclipse.xtext.builder.nature.ToggleXtextNatureAction;
import org.eclipse.xtext.ui.editor.AbstractDirtyStateAwareEditorCallback;
import org.eclipse.xtext.ui.editor.XtextEditor;

import com.google.inject.Inject;

@SuppressWarnings("restriction")
public class CustomNatureAddingEditorCallback extends AbstractDirtyStateAwareEditorCallback
{
	
	@Inject
	private ToggleXtextNatureAction toggleNature;

	@Override
	public void afterCreatePartControl(XtextEditor editor) {
		super.afterCreatePartControl(editor);
		IResource resource = editor.getResource();
		toggleNature.toggleNature(resource.getProject());
	}

}

and added this CustomNatureAddingEditorCallback to My XtextProject XtextProjectUiModel.java.

I am getting an unusual issue is after adding this, the cross reference Dsl elements are loaded .
I have added this code to suppress dialogues to parent DslProject and the Cross Reference DSL project doesnot have the suppress code as that DSL file never gets Opened in Editor.

This is unusual because, it shows inconsistency in loading the cross Reference Dsl ie sometimes it does and other times it doesn't.

Any idea,what could be causing this?

Cheers
Kunal
Re: Suppress Add Xtext Nature Dialogue causes Problem [message #1456583 is a reply to message #1456525] Thu, 30 October 2014 14:03 Go to previous message
Kunal Khaware is currently offline Kunal KhawareFriend
Messages: 41
Registered: December 2013
Location: Hyderabad,India
Member

Hi,
I got it resolved by adding the code like this :
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.xtext.ui.XtextProjectHelper;
import org.eclipse.xtext.ui.editor.AbstractDirtyStateAwareEditorCallback;
import org.eclipse.xtext.ui.editor.XtextEditor;

@SuppressWarnings("restriction")
public class CustomNatureAddingEditorCallback extends AbstractDirtyStateAwareEditorCallback
{
	

	@Override
	public void afterCreatePartControl(XtextEditor editor) {
		super.afterCreatePartControl(editor);
		IResource resource = editor.getResource();
		 if (resource != null && !XtextProjectHelper.hasNature(resource.getProject()) && resource.getProject().isAccessible() &&
				 !resource.getProject().isHidden()) {
				toggleNature(resource.getProject());
				  }
	}

	private void toggleNature(IProject project) {
		try {
			IProjectDescription desc = project.getDescription();
			String[] natureIds = desc.getNatureIds();
			if(natureIds.length==0){
				String[] natureId = new String[1];
				natureId[0]=XtextProjectHelper.NATURE_ID;
				natureIds=natureId;
			}else
			{
			natureIds[natureIds.length+1]=XtextProjectHelper.NATURE_ID;
			}
			desc.setNatureIds(natureIds);
			project.setDescription(desc, null);
			
		} catch (CoreException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}

[Updated on: Thu, 30 October 2014 14:03]

Report message to a moderator

Previous Topic:Unable to load the cross referenced Dsl elements.
Next Topic:Finding all uses of fields/methods/variables in a xbase model
Goto Forum:
  


Current Time: Thu Apr 25 16:24:38 GMT 2024

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

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

Back to the top