Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » DI problem with EmbeddedEditor
DI problem with EmbeddedEditor [message #1705018] Tue, 11 August 2015 12:59 Go to next message
Vladimir D is currently offline Vladimir DFriend
Messages: 22
Registered: January 2013
Junior Member
Hi everyone,

I'm building a new DSL from scratch and this is my first time using XText. Until now I've created a language by specifying the grammar, and it works as intended when I start new Eclipse instance. I have not changed anything manually except for the grammar itself. Everything else is generated by the framework.

The next step is to embed this editor in another plugin which is an Eclipse-based editor. Its a sort of graphical editor and on double click on some element I want to open a SWT/JFace dialog in which the DSL statements should be written. And now I have some problems with this part. For a while I'm trying out all these different solutions from old eclipse forum posts, forums, xtextcon presentations, some jface interation plugins with StyledText etc. For each of the tutorials I've tried I come to this error and cannot go past it:

!ENTRY org.eclipse.e4.ui.workbench 4 0 2015-08-11 14:39:23.536
!MESSAGE Internal Error
!STACK 0
com.google.inject.ProvisionException: Guice provision errors:

1) null returned by binding at org.eclipse.xtext.ui.shared.internal.SharedModule.configure(SharedModule.java:132)
 but org.eclipse.xtext.ui.editor.GlobalURIEditorOpener.workbench is not @Nullable
  while locating org.eclipse.ui.IWorkbench
    for field at org.eclipse.xtext.ui.editor.GlobalURIEditorOpener.workbench(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.GlobalURIEditorOpener
  while locating org.eclipse.xtext.ui.editor.IURIEditorOpener
  at org.eclipse.xtext.service.MethodBasedModule.configure(MethodBasedModule.java:75)
  while locating org.eclipse.xtext.ui.editor.IURIEditorOpener
    for field at org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.uriEditorOpener(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider
  while locating org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider
    for field at org.eclipse.xtext.ui.editor.XtextInformationProvider.hoverProvider(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.XtextInformationProvider
    for field at org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration.informationProvider(Unknown Source)
  while locating org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration

1 error
	at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:987)
	at org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory$Builder.withParent(EmbeddedEditorFactory.java:200)
	at anymap.dialogs.ExpressionDialog.createDialogArea(ExpressionDialog.java:58)
	at org.eclipse.jface.dialogs.Dialog.createContents(Dialog.java:768)
	at org.eclipse.jface.window.Window.create(Window.java:430)
	at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1096)
	at org.eclipse.jface.window.Window.open(Window.java:792)
	at anymap.states.SelectionState.openDialog(SelectionState.java:209)
	at anymap.states.SelectionState.execute(SelectionState.java:183)
	at anymap.listeners.CanvasMouseListener.mouseDoubleClick(CanvasMouseListener.java:43)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:196)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:159)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1488)


Here is the code where I try to inject the needed things. This code is based on the most recent code example I could find online.

 
package anymap.dialogs;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtext.resource.FileExtensionProvider;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.embedded.IEditedResourceProvider;
import org.eclipse.xtext.ui.resource.IResourceSetProvider;

import com.google.inject.Inject;

@SuppressWarnings("restriction")
public class FilterResourceProvider implements IEditedResourceProvider {

	@Inject
	private IResourceSetProvider resourceSetProvider;
	@Inject
	private FileExtensionProvider ext;
	
	@Override
	public XtextResource createResource() {
		ResourceSet resourceSet = resourceSetProvider.get(null);
		URI uri = URI.createURI("example/test1." + ext.getPrimaryFileExtension());
		XtextResource result = (XtextResource) resourceSet.createResource(uri);
		resourceSet.getResources().add(result);
		return result;
	}

}


package anymap.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor;
import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory;
import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorModelAccess;

import com.google.inject.Injector;

import anymap.language.assignment.ui.internal.FilterDSLActivator;

public class ExpressionDialog extends Dialog {
	public static int ASSIGNMENT = 0;
	public static int FILTER = 1;
	private Text txtError;
	private String value;
	private String type;
	private StyledText txtExpression;

	/**
	 * Create the dialog.
	 * 
	 * @param parentShell
	 */
	public ExpressionDialog(Shell parentShell, int type, String value) {
		super(parentShell);
		setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE);
		this.type = (type == ASSIGNMENT) ? "Assignment" : "Filter";
		if (value != null) {
			this.value = value;
		}
	}

	/**
	 * Create contents of the dialog.
	 * 
	 * @param parent
	 */
	@SuppressWarnings({ "unused", "restriction" })
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		
		FilterDSLActivator activator = FilterDSLActivator.getInstance();
		Injector injector = activator.getInjector(FilterDSLActivator.ANYMAP_LANGUAGE_ASSIGNMENT_FILTERDSL);
		
		FilterResourceProvider provider = injector.getInstance(FilterResourceProvider.class);
		EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);
		
		EmbeddedEditor editor = factory.newEditor(provider).withParent(container);
		EmbeddedEditorModelAccess model = editor.createPartialEditor();		
		
		//....
		
		return container;
	}

	/**
	 * Create contents of the button bar.
	 * 
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
		createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
	}

       //...

}


If anyone knows what am I doing wrong, please help. Maybe I've skipped some obvious steps that have to be performed in order for DI to work. I'm new to this so i'm not really sure what to do.

Best Regards,
Vladimir

[Updated on: Tue, 11 August 2015 13:00]

Report message to a moderator

Re: DI problem with EmbeddedEditor [message #1705020 is a reply to message #1705018] Tue, 11 August 2015 13:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
This looks strange to me. did you debug configureIWorkbench in SharedStateModule

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DI problem with EmbeddedEditor [message #1705021 is a reply to message #1705020] Tue, 11 August 2015 13:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
P.S: i am not sure if xtext works in pure e4

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DI problem with EmbeddedEditor [message #1705022 is a reply to message #1705021] Tue, 11 August 2015 13:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
btw which xtext version do you use?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DI problem with EmbeddedEditor [message #1705025 is a reply to message #1705022] Tue, 11 August 2015 13:42 Go to previous messageGo to next message
Vladimir D is currently offline Vladimir DFriend
Messages: 22
Registered: January 2013
Junior Member
Hi Christian. Thanks for the fast response.

Yes you are right, I'm developing a pure e4 app, it has several plugins but I need the XText integrated only in one of them. I've debugged the SharedModule class the whole morning and the thing I found is that PlatformUI.isWorkbenchRunning() always returns null and that is the problem. But I'm not sure why is it so. I'm using "Xtext Complete SDK 2.9.0.v201507170721".

Re: DI problem with EmbeddedEditor [message #1705026 is a reply to message #1705025] Tue, 11 August 2015 13:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hi,

this is because of e4. but the binding should be optional, thus i do not understand the error message


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DI problem with EmbeddedEditor [message #1705028 is a reply to message #1705026] Tue, 11 August 2015 13:56 Go to previous messageGo to next message
Vladimir D is currently offline Vladimir DFriend
Messages: 22
Registered: January 2013
Junior Member
Sad Any ideas what else can I check or do?
Re: DI problem with EmbeddedEditor [message #1705039 is a reply to message #1705028] Tue, 11 August 2015 15:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
I dont have an idea i thought that dependeny is marked as optional

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DI problem with EmbeddedEditor [message #1705041 is a reply to message #1705039] Tue, 11 August 2015 15:19 Go to previous messageGo to next message
Vladimir D is currently offline Vladimir DFriend
Messages: 22
Registered: January 2013
Junior Member
One thing I've noticed is that in GlobalURIEditorOpener.java at https://github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/GlobalURIEditorOpener.java is in fact using Guice v4 API for marking the things as optional (@Inject(optional=true) while @Nullable is commented). Latest Eclipse is still using the bundled Guice v3 and this may be the problem.
Re: DI problem with EmbeddedEditor [message #1705047 is a reply to message #1705041] Tue, 11 August 2015 15:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hmmm i thought you use the guice shipped with xtext

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DI problem with EmbeddedEditor [message #1705051 is a reply to message #1705047] Tue, 11 August 2015 15:53 Go to previous messageGo to next message
Vladimir D is currently offline Vladimir DFriend
Messages: 22
Registered: January 2013
Junior Member
Yes, that is the one, the one that is bundled with XText, not Eclipse, sorry. To be precise I'm using "com.google.inject_3.0.0.v201312141243". I just downloaded and installed everything from scratch (clean Eclipse Mars, xtend bundled with xtext 2.8.4.v201508050135, new workspace) and it is still not working.
Re: DI problem with EmbeddedEditor [message #1705053 is a reply to message #1705051] Tue, 11 August 2015 15:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
I did a green field testcase and that worked

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DI problem with EmbeddedEditor [message #1705058 is a reply to message #1705053] Tue, 11 August 2015 16:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
public class Main {

public static void main(String[] args) {
Injector i = Guice.createInjector(new MainModule());
GlobalURIEditorOpener c = i.getInstance(GlobalURIEditorOpener.class);
}

private static class MainModule extends AbstractGenericModule {

public void configureSomeStuff(Binder binder) {
binder.bind(IStorage2UriMapper.class).to(IStorage2UriMapperIml.class);
}

}

public static class IStorage2UriMapperIml implements IStorage2UriMapper {

@Override
public Iterable<Pair<IStorage, IProject>> getStorages(URI uri) {
// TODO Auto-generated method stub
return null;
}

@Override
public URI getUri(IStorage storage) {
// TODO Auto-generated method stub
return null;
}

@Override
public Map<URI, IStorage> getAllEntries(IContainer container) {
// TODO Auto-generated method stub
return null;
}

}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DI problem with EmbeddedEditor [message #1705206 is a reply to message #1705058] Wed, 12 August 2015 19:34 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

@Inject(optional=true) marks the dependency as optinal, but not nullable. So Guice will be happy if there is *no binding* (that's why Christian's example app works), but it will throw an Exception if there is a provider binding that returns null (which is the case in our shared state module). The only way to make it work is to have the @Nullable annotation. That one was commented out some time ago, I think because of dependency hell Wink

So in short: This class will not work without a Workbench right now. Please file a bug for that.
Re: DI problem with EmbeddedEditor [message #1705207 is a reply to message #1705206] Wed, 12 August 2015 19:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
@Stefan

i dont get that

public void configureIWorkbench(Binder binder) {
		if (PlatformUI.isWorkbenchRunning()) {
			binder.bind(IWorkbench.class).toProvider(new Provider<IWorkbench>() {
				@Override
				public IWorkbench get() {
					return (PlatformUI.isWorkbenchRunning()) ? PlatformUI.getWorkbench() : null;
				}
			});
		}
	}


shouldnt the first if already return false? and thus the provider never be bound


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DI problem with EmbeddedEditor [message #1705557 is a reply to message #1705207] Mon, 17 August 2015 13:27 Go to previous message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

@christian You are looking at SharedStateModule, which has that guard. But the problem is in the SharedModule, which always binds the provider.
Previous Topic:Xtext and EMF Dynamic Templates
Next Topic:Problem in creating an Eclipse product for DSL
Goto Forum:
  


Current Time: Tue Mar 19 09:17:20 GMT 2024

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

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

Back to the top