Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Add xtext nature programmatically(Add xtext nature programmatically)
Add xtext nature programmatically [message #1742281] Thu, 01 September 2016 12:32 Go to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

I am using IXtextEditorCallback in my code. Then onwards when I am creating a project in editor it is not asking dialog to add xtext nature. Could you please tell me what to do?

class JPLEditorOnSave implements IXtextEditorCallback {

override afterCreatePartControl(XtextEditor editor) {}

override afterSave(XtextEditor editor) {
val IWorkspace workspace= ResourcesPlugin.getWorkspace();
val IPath location= Path.fromOSString(editor.resource.rawLocation.toFile.getAbsolutePath());
val IFile ifile= workspace.getRoot().getFileForLocation(location);
GenerationHandler.jpl2binExec(ifile)
}

override afterSetInput(XtextEditor xtextEditor) {}

override beforeDispose(XtextEditor editor) {}

override beforeSetInput(XtextEditor xtextEditor) {}

override onValidateEditorInputState(XtextEditor editor) {
return true
}
}
Re: Add xtext nature programmatically [message #1742282 is a reply to message #1742281] Thu, 01 September 2016 12:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
what is your actual question.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Add xtext nature programmatically [message #1742286 is a reply to message #1742282] Thu, 01 September 2016 12:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
( i assuemd you customized org.eclipse.xtext.builder.nature.NatureAddingEditorCallback half a your ago, did you change this again)

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Add xtext nature programmatically [message #1742290 is a reply to message #1742286] Thu, 01 September 2016 12:51 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Yes right. I am using the below code for disable it in ui module before.

override bindIXtextEditorCallback() {
JPLEditorOnSave
}

But how can I add xtext nature now?
Re: Add xtext nature programmatically [message #1742292 is a reply to message #1742290] Thu, 01 September 2016 12:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Copy the code that does that from there?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Add xtext nature programmatically [message #1742293 is a reply to message #1742292] Thu, 01 September 2016 13:01 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
class JPLEditorUiModule extends AbstractJPLEditorUiModule {
override configure(Binder binder) {
super.configure(binder);
binder.bind(String).annotatedWith(Names.named((XtextContentAssistProcessor.COMPLETION_AUTO_ACTIVATION_CHARS))).toInstance('>_');
}
def Class<? extends AbstractAntlrTokenToAttributeIdMapper> bindAbstractAntlrTokenToAttributeIdMapper() {
JPLAntlrTokenToAttributeIdMapper
}
def Class<? extends IValueConverterService> bindIValueConverterService() {
return CustomTerminalConverters;
}
override bindIXtextEditorCallback() {
JPLEditorOnSave
}
def Class<? extends ILinkingDiagnosticMessageProvider.Extended> bindILinkingDiagnosticMessageProvider() {
return JPLHyperlinkHelper;
}
}
Re: Add xtext nature programmatically [message #1742294 is a reply to message #1742293] Thu, 01 September 2016 13:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
No I mean : copy the logic from nature adding editor callback to your callback

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Add xtext nature programmatically [message #1742298 is a reply to message #1742294] Thu, 01 September 2016 13:33 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
I dont understand. You mean like this:

class JPLEditorOnSave implements IXtextEditorCallback {

override afterCreatePartControl(XtextEditor editor) {}

override afterSave(XtextEditor editor) {
val IWorkspace workspace= ResourcesPlugin.getWorkspace();
val IPath location= Path.fromOSString(editor.resource.rawLocation.toFile.getAbsolutePath());
val IFile ifile= workspace.getRoot().getFileForLocation(location);
GenerationHandler.jpl2binExec(ifile)
}

override afterSetInput(XtextEditor xtextEditor) {}

override beforeDispose(XtextEditor editor) {}

override beforeSetInput(XtextEditor xtextEditor) {}

override onValidateEditorInputState(XtextEditor editor) {
return true
}

public static class NullImpl implements IXtextEditorCallback {

override afterCreatePartControl(XtextEditor editor) {
}

override afterSave(XtextEditor editor) {
}

override afterSetInput(XtextEditor xtextEditor) {
}

override beforeDispose(XtextEditor editor) {
}

override beforeSetInput(XtextEditor xtextEditor) {
}

override onValidateEditorInputState(XtextEditor editor) {
return true
}
}
}
Re: Add xtext nature programmatically [message #1742300 is a reply to message #1742298] Thu, 01 September 2016 13:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
if you have a look at NatureAddingEditorCallback you will find these strange code :

public class NatureAddingEditorCallback extends IXtextEditorCallback.NullImpl {
	private static final String ADD_XTEXT_NATURE = "add_xtext_nature";
	@Inject
	private ToggleXtextNatureAction toggleNature;

	private @Inject DontAskAgainDialogs dialogs;

	@Override
	public void afterCreatePartControl(XtextEditor editor) {
		IResource resource = editor.getResource();
		if (resource != null && !toggleNature.hasNature(resource.getProject()) && resource.getProject().isAccessible()
				&& !resource.getProject().isHidden()) {
			String title = Messages.NatureAddingEditorCallback_MessageDialog_Title;
			String message = Messages.NatureAddingEditorCallback_MessageDialog_Msg0 + resource.getProject().getName()
					+ Messages.NatureAddingEditorCallback_MessageDialog_Msg1;
			boolean addNature = false;
			if (MessageDialogWithToggle.PROMPT.equals(dialogs.getUserDecision(ADD_XTEXT_NATURE))) {
				int userAnswer = dialogs.askUser(message, title, ADD_XTEXT_NATURE, editor.getEditorSite().getShell());
				if (userAnswer == IDialogConstants.YES_ID) {
					addNature = true;
				} else if (userAnswer == IDialogConstants.CANCEL_ID) {
					return;
				}
			} else if (MessageDialogWithToggle.ALWAYS.equals(dialogs.getUserDecision(ADD_XTEXT_NATURE))) {
				addNature = true;
			}
			if (addNature) {
				toggleNature.toggleNature(resource.getProject());
			}
		}
	}
}


this basically does 2 things

(1) ask the user
(2) add the nature


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Add xtext nature programmatically [message #1742301 is a reply to message #1742300] Thu, 01 September 2016 13:45 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Ok. But I am not at all doing with NatureAddingEditorCallback anywhere? So I need to added that code in class JPLEditorOnSave implements IXtextEditorCallback?

[Updated on: Thu, 01 September 2016 13:45]

Report message to a moderator

Re: Add xtext nature programmatically [message #1742302 is a reply to message #1742301] Thu, 01 September 2016 13:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Guess ....

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Add xtext nature programmatically [message #1742305 is a reply to message #1742302] Thu, 01 September 2016 14:26 Go to previous message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Ok
Previous Topic:[Solved] Xtext 2.10 - Cannot reference common JavaVMTypes in model
Next Topic:feature modeling plugin and oAW chain
Goto Forum:
  


Current Time: Sun Apr 18 07:03:54 GMT 2021

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

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

Back to the top