DI problem with EmbeddedEditor [message #1705018] |
Tue, 11 August 2015 12:59 |
Vladimir D 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 #1705058 is a reply to message #1705053] |
Tue, 11 August 2015 16:27 |
|
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 |
|
@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
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 |
|
@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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03202 seconds