我正在尝试在使用GEF4的Eclipse rcp应用程序中创建GEF4 FXView(或FXEditor)。我想构建一个类似于GEF4 MVC Logo Example的视图,这就是为什么我创建扩展FXView的视图的原因:
import java.util.List;
import org.eclipse.gef4.mvc.fx.MvcFxModule;
import org.eclipse.gef4.mvc.fx.ui.MvcFxUiModule;
import org.eclipse.gef4.mvc.fx.ui.parts.FXView;
import com.google.inject.Guice;
import com.google.inject.util.Modules;
public class MyView extends FXView {
public MyView() {
super(Guice.createInjector(Modules.override(new MvcFxModule())
.with(new MvcFxUiModule())));
}
@Override
protected List<? extends Object> getContents() {
// TODO Auto-generated method stub
return null;
}
}
但是它在运行时崩溃:
java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "com/google/inject/binder/AnnotatedBindingBuilder"
at com.myproject.ui.viewer2d.test.MyMvcFxModule.bindIHandlePartFactory(MyMvcFxModule.java:375)
MyMvcFxModule:
public class MyMvcFxModule extends MvcModule<Node> {
...
protected void bindIHandlePartFactory() {
// TODO: bind to viewer scope, otherwise stateful factories might not
// work properly
binder().bind(new TypeLiteral<IHandlePartFactory<Node>>() {
}).to(FXDefaultHandlePartFactory.class) // <---- error here
.in(AdaptableScopes.typed(FXViewer.class));
}
...
@Override
protected void configure() {
super.configure();
// bind default factories for handles and feedback
bindIHandlePartFactory(); // error
bindIFeedbackPartFactory(); // error
// error on next binding also
...
}
}
MANIFEST.MF(来自包含我的视图的插件项目)
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Viewer2D
Bundle-SymbolicName: com.myproject.ui.viewer2D
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.myproject.ui.viewer2d.Activator
Bundle-Vendor: ME
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.gef4.common,
org.eclipse.gef4.geometry,
org.eclipse.gef4.geometry.convert.fx,
org.eclipse.wb.core.lib,
org.eclipse.m2e.maven.runtime,
org.eclipse.gef4.mvc,
org.eclipse.gef4.mvc.fx,
org.eclipse.gef4.fx,
com.google.inject,
org.eclipse.gef4.mvc.examples,
org.eclipse.gef4.mvc.fx.ui,
org.eclipse.fx.javafx;bundle-version="2.2.0",
org.eclipse.gef4.fx.ui;bundle-version="0.1.0",
org.eclipse.gef4.mvc.ui;bundle-version="0.1.0",
org.eclipse.ui.views;bundle-version="3.7.100",
com.google.gson
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: com.google.inject;version="[1.3.0,2.0.0)",
com.google.inject.binder;version="[1.3.0,2.0.0)"
目标:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="Running Platform" sequenceNumber="8">
<locations>
<location path="${eclipse_home}" type="Profile"/>
</locations>
<includeBundles>
...
<plugin id="com.google.gerrit.common"/>
<plugin id="com.google.gerrit.prettify"/>
<plugin id="com.google.gerrit.reviewdb"/>
<plugin id="com.google.gson"/>
<plugin id="com.google.guava"/>
<plugin id="com.google.guava.source"/>
<plugin id="com.google.gwt.servlet"/>
<plugin id="com.google.gwtjsonrpc"/>
<plugin id="com.google.gwtorm"/>
<plugin id="com.google.inject"/>
<plugin id="com.google.inject.multibindings"/>
...
<plugin id="javax.activation"/>
<plugin id="javax.annotation"/>
<plugin id="javax.annotation.jre"/>
<plugin id="javax.annotation.source"/>
<plugin id="javax.el"/>
<plugin id="javax.el.source"/>
<plugin id="javax.inject"/>
<plugin id="javax.inject.source"/>
<plugin id="javax.servlet"/>
<plugin id="javax.servlet.jsp"/>
<plugin id="javax.servlet.jsp.source"/>
<plugin id="javax.servlet.source"/>
<plugin id="javax.xml"/>
<plugin id="javax.xml.bind"/>
<plugin id="javax.xml.stream"/>
...
<plugin id="org.eclipse.fx.core"/>
<plugin id="org.eclipse.fx.core.databinding"/>
<plugin id="org.eclipse.fx.core.databinding.source"/>
<plugin id="org.eclipse.fx.core.di"/>
<plugin id="org.eclipse.fx.core.di.context"/>
<plugin id="org.eclipse.fx.core.di.context.source"/>
<plugin id="org.eclipse.fx.core.di.source"/>
<plugin id="org.eclipse.fx.core.fxml"/>
<plugin id="org.eclipse.fx.core.fxml.source"/>
<plugin id="org.eclipse.fx.core.guice"/>
<plugin id="org.eclipse.fx.core.guice.source"/>
<plugin id="org.eclipse.fx.core.log4j"/>
<plugin id="org.eclipse.fx.core.log4j.source"/>
<plugin id="org.eclipse.fx.core.p2"/>
<plugin id="org.eclipse.fx.core.p2.source"/>
<plugin id="org.eclipse.fx.core.slf4j"/>
<plugin id="org.eclipse.fx.core.slf4j.source"/>
<plugin id="org.eclipse.fx.core.source"/>
<plugin id="org.eclipse.fx.emf.databinding"/>
<plugin id="org.eclipse.fx.emf.databinding.source"/>
<plugin id="org.eclipse.fx.emf.edit.ui"/>
<plugin id="org.eclipse.fx.emf.edit.ui.source"/>
<plugin id="org.eclipse.fx.formats.svg"/>
<plugin id="org.eclipse.fx.formats.svg.source"/>
<plugin id="org.eclipse.fx.javafx"/>
<plugin id="org.eclipse.fx.javafx.source"/>
<plugin id="org.eclipse.fx.osgi"/>
<plugin id="org.eclipse.fx.osgi.source"/>
<plugin id="org.eclipse.fx.osgi.util"/>
<plugin id="org.eclipse.fx.osgi.util.source"/>
<plugin id="org.eclipse.fx.ui.animation"/>
<plugin id="org.eclipse.fx.ui.animation.source"/>
<plugin id="org.eclipse.fx.ui.controls"/>
<plugin id="org.eclipse.fx.ui.controls.source"/>
<plugin id="org.eclipse.fx.ui.databinding"/>
<plugin id="org.eclipse.fx.ui.databinding.source"/>
<plugin id="org.eclipse.fx.ui.di"/>
<plugin id="org.eclipse.fx.ui.di.interopt"/>
<plugin id="org.eclipse.fx.ui.di.source"/>
<plugin id="org.eclipse.fx.ui.dialogs"/>
<plugin id="org.eclipse.fx.ui.dialogs.source"/>
<plugin id="org.eclipse.fx.ui.keybindings"/>
<plugin id="org.eclipse.fx.ui.keybindings.e4"/>
<plugin id="org.eclipse.fx.ui.keybindings.e4.source"/>
<plugin id="org.eclipse.fx.ui.keybindings.generic"/>
<plugin id="org.eclipse.fx.ui.keybindings.generic.source"/>
<plugin id="org.eclipse.fx.ui.keybindings.source"/>
<plugin id="org.eclipse.fx.ui.mobile"/>
<plugin id="org.eclipse.fx.ui.mobile.source"/>
<plugin id="org.eclipse.fx.ui.panes"/>
<plugin id="org.eclipse.fx.ui.panes.source"/>
<plugin id="org.eclipse.fx.ui.services"/>
<plugin id="org.eclipse.fx.ui.services.source"/>
<plugin id="org.eclipse.fx.ui.theme"/>
<plugin id="org.eclipse.fx.ui.theme.source"/>
<plugin id="org.eclipse.fx.ui.workbench.base"/>
<plugin id="org.eclipse.fx.ui.workbench.base.source"/>
<plugin id="org.eclipse.fx.ui.workbench.fx"/>
<plugin id="org.eclipse.fx.ui.workbench.fx.source"/>
<plugin id="org.eclipse.fx.ui.workbench.renderers.base"/>
<plugin id="org.eclipse.fx.ui.workbench.renderers.base.source"/>
<plugin id="org.eclipse.fx.ui.workbench.renderers.fx"/>
<plugin id="org.eclipse.fx.ui.workbench.renderers.fx.source"/>
<plugin id="org.eclipse.fx.ui.workbench.services"/>
<plugin id="org.eclipse.fx.ui.workbench.services.source"/>
<plugin id="org.eclipse.fx.ui.workbench3"/>
<plugin id="org.eclipse.gef"/>
<plugin id="org.eclipse.gef4.cloudio"/>
<plugin id="org.eclipse.gef4.cloudio.doc"/>
<plugin id="org.eclipse.gef4.cloudio.tests"/>
<plugin id="org.eclipse.gef4.cloudio.ui"/>
<plugin id="org.eclipse.gef4.common"/>
<plugin id="org.eclipse.gef4.common.doc"/>
<plugin id="org.eclipse.gef4.dot"/>
<plugin id="org.eclipse.gef4.dot.ui"/>
<plugin id="org.eclipse.gef4.fx"/>
<plugin id="org.eclipse.gef4.fx.doc"/>
<plugin id="org.eclipse.gef4.fx.ui"/>
<plugin id="org.eclipse.gef4.geometry"/>
<plugin id="org.eclipse.gef4.geometry.convert.fx"/>
<plugin id="org.eclipse.gef4.geometry.convert.swt"/>
<plugin id="org.eclipse.gef4.geometry.convert.swt.tests"/>
<plugin id="org.eclipse.gef4.geometry.doc"/>
<plugin id="org.eclipse.gef4.geometry.tests"/>
<plugin id="org.eclipse.gef4.graph"/>
<plugin id="org.eclipse.gef4.graph.doc"/>
<plugin id="org.eclipse.gef4.graph.source"/>
<plugin id="org.eclipse.gef4.graph.ui.source"/>
<plugin id="org.eclipse.gef4.graphics"/>
<plugin id="org.eclipse.gef4.graphics.doc"/>
<plugin id="org.eclipse.gef4.graphics.swt"/>
<plugin id="org.eclipse.gef4.graphics.swt.tests"/>
<plugin id="org.eclipse.gef4.graphics.tests"/>
<plugin id="org.eclipse.gef4.layout"/>
<plugin id="org.eclipse.gef4.layout.doc"/>
<plugin id="org.eclipse.gef4.layout.source"/>
<plugin id="org.eclipse.gef4.mvc"/>
<plugin id="org.eclipse.gef4.mvc.doc"/>
<plugin id="org.eclipse.gef4.mvc.examples"/>
<plugin id="org.eclipse.gef4.mvc.examples.logo"/>
<plugin id="org.eclipse.gef4.mvc.examples.logo.ui"/>
<plugin id="org.eclipse.gef4.mvc.fx"/>
<plugin id="org.eclipse.gef4.mvc.fx.ui"/>
<plugin id="org.eclipse.gef4.mvc.ui"/>
<plugin id="org.eclipse.gef4.swtfx" version="0.1.0.201408081506"/>
<plugin id="org.eclipse.gef4.swtfx" version="0.1.0.201311151505"/>
<plugin id="org.eclipse.gef4.swtfx.doc"/>
<plugin id="org.eclipse.gef4.swtfx.tests"/>
<plugin id="org.eclipse.gef4.zest.core"/>
<plugin id="org.eclipse.gef4.zest.core.source"/>
<plugin id="org.eclipse.gef4.zest.doc"/>
<plugin id="org.eclipse.gef4.zest.examples"/>
<plugin id="org.eclipse.gef4.zest.examples.graph"/>
<plugin id="org.eclipse.gef4.zest.examples.graph.ui"/>
<plugin id="org.eclipse.gef4.zest.fx"/>
<plugin id="org.eclipse.gef4.zest.fx.ui"/>
<plugin id="org.eclipse.gef4.zest.jface"/>
<plugin id="org.eclipse.gef4.zest.jface.source"/>
<plugin id="org.eclipse.gef4.zest.ui"/>
...
<plugin id="org.eclipse.ui"/>
<plugin id="org.eclipse.ui.browser"/>
<plugin id="org.eclipse.ui.browser.source"/>
<plugin id="org.eclipse.ui.cheatsheets"/>
<plugin id="org.eclipse.ui.cheatsheets.source"/>
<plugin id="org.eclipse.ui.console"/>
<plugin id="org.eclipse.ui.console.source"/>
<plugin id="org.eclipse.ui.editors"/>
<plugin id="org.eclipse.ui.editors.source"/>
<plugin id="org.eclipse.ui.externaltools"/>
<plugin id="org.eclipse.ui.externaltools.source"/>
<plugin id="org.eclipse.ui.forms"/>
<plugin id="org.eclipse.ui.forms.source"/>
<plugin id="org.eclipse.ui.ide"/>
<plugin id="org.eclipse.ui.ide.application"/>
<plugin id="org.eclipse.ui.ide.application.source"/>
<plugin id="org.eclipse.ui.ide.source"/>
<plugin id="org.eclipse.ui.intro"/>
<plugin id="org.eclipse.ui.intro.source"/>
<plugin id="org.eclipse.ui.intro.universal"/>
<plugin id="org.eclipse.ui.intro.universal.source"/>
<plugin id="org.eclipse.ui.monitoring"/>
<plugin id="org.eclipse.ui.monitoring.source"/>
<plugin id="org.eclipse.ui.navigator"/>
<plugin id="org.eclipse.ui.navigator.resources"/>
<plugin id="org.eclipse.ui.navigator.resources.source"/>
<plugin id="org.eclipse.ui.navigator.source"/>
<plugin id="org.eclipse.ui.net"/>
<plugin id="org.eclipse.ui.net.source"/>
<plugin id="org.eclipse.ui.source"/>
<plugin id="org.eclipse.ui.themes"/>
<plugin id="org.eclipse.ui.themes.source"/>
<plugin id="org.eclipse.ui.trace"/>
<plugin id="org.eclipse.ui.views"/>
<plugin id="org.eclipse.ui.views.log"/>
<plugin id="org.eclipse.ui.views.properties.tabbed"/>
<plugin id="org.eclipse.ui.views.properties.tabbed.source"/>
<plugin id="org.eclipse.ui.views.source"/>
<plugin id="org.eclipse.ui.win32"/>
<plugin id="org.eclipse.ui.win32.source"/>
<plugin id="org.eclipse.ui.workbench"/>
<plugin id="org.eclipse.ui.workbench.source"/>
<plugin id="org.eclipse.ui.workbench.texteditor"/>
<plugin id="org.eclipse.ui.workbench.texteditor.source"/>
...
</includeBundles>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
<nl>fr_FR</nl>
</environment>
<launcherArgs>
<vmArgs>-Dosgi.requiredJavaVersion=1.7 -Xms40m -Xmx512m</vmArgs>
</launcherArgs>
</target>
产品名称:
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>
<product name="PROJECT" uid="com.myproject.repository" id="com.myproject.application.PROJECT_PRODUCT" application="com.myproject.application.application" version="1.0.0.qualifier" useFeatures="false" includeLaunchers="true">
<configIni use="default">
</configIni>
<launcherArgs>
<programArgs>-clearPersistedState
</programArgs>
<vmArgs>-Dosgi.framework.extensions=org.eclipse.fx.osgi
</vmArgs>
<vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
</vmArgsMac>
</launcherArgs>
<windowImages/>
<launcher name="PROJECT">
<solaris/>
<win useIco="false">
<bmp/>
</win>
</launcher>
<vm>
<windows include="false">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8</windows>
</vm>
<plugins>
<plugin id="com.myproject.application"/>
<plugin id="com.google.guava"/>
<plugin id="com.google.inject"/>
<plugin id="com.google.inject.multibindings" fragment="true"/>
<plugin id="com.ibm.icu"/>
<plugin id="javax.annotation"/>
<plugin id="javax.inject"/>
<plugin id="javax.xml"/>
<plugin id="org.apache.batik.css"/>
<plugin id="org.apache.batik.util"/>
<plugin id="org.apache.batik.util.gui"/>
<plugin id="org.apache.commons.logging"/>
<plugin id="org.eclipse.core.commands"/>
<plugin id="org.eclipse.core.contenttype"/>
<plugin id="org.eclipse.core.databinding"/>
<plugin id="org.eclipse.core.databinding.beans"/>
<plugin id="org.eclipse.core.databinding.observable"/>
<plugin id="org.eclipse.core.databinding.property"/>
<plugin id="org.eclipse.core.expressions"/>
<plugin id="org.eclipse.core.filesystem"/>
<plugin id="org.eclipse.core.filesystem.java7" fragment="true"/>
<plugin id="org.eclipse.core.filesystem.win32.x86_64" fragment="true"/>
<plugin id="org.eclipse.core.jobs"/>
<plugin id="org.eclipse.core.resources"/>
<plugin id="org.eclipse.core.resources.win32.x86_64" fragment="true"/>
<plugin id="org.eclipse.core.runtime"/>
<plugin id="org.eclipse.core.runtime.compatibility.registry" fragment="true"/>
<plugin id="org.eclipse.e4.core.commands"/>
<plugin id="org.eclipse.e4.core.contexts"/>
<plugin id="org.eclipse.e4.core.di"/>
<plugin id="org.eclipse.e4.core.di.extensions"/>
<plugin id="org.eclipse.e4.core.services"/>
<plugin id="org.eclipse.e4.ui.bindings"/>
<plugin id="org.eclipse.e4.ui.css.core"/>
<plugin id="org.eclipse.e4.ui.css.swt"/>
<plugin id="org.eclipse.e4.ui.css.swt.theme"/>
<plugin id="org.eclipse.e4.ui.di"/>
<plugin id="org.eclipse.e4.ui.model.workbench"/>
<plugin id="org.eclipse.e4.ui.services"/>
<plugin id="org.eclipse.e4.ui.widgets"/>
<plugin id="org.eclipse.e4.ui.workbench"/>
<plugin id="org.eclipse.e4.ui.workbench.addons.swt"/>
<plugin id="org.eclipse.e4.ui.workbench.renderers.swt"/>
<plugin id="org.eclipse.e4.ui.workbench.swt"/>
<plugin id="org.eclipse.e4.ui.workbench3"/>
<plugin id="org.eclipse.emf.common"/>
<plugin id="org.eclipse.emf.databinding"/>
<plugin id="org.eclipse.emf.ecore"/>
<plugin id="org.eclipse.emf.ecore.change"/>
<plugin id="org.eclipse.emf.ecore.xmi"/>
<plugin id="org.eclipse.equinox.app"/>
<plugin id="org.eclipse.equinox.common"/>
<plugin id="org.eclipse.equinox.concurrent"/>
<plugin id="org.eclipse.equinox.ds"/>
<plugin id="org.eclipse.equinox.event"/>
<plugin id="org.eclipse.equinox.preferences"/>
<plugin id="org.eclipse.equinox.registry"/>
<plugin id="org.eclipse.equinox.util"/>
<plugin id="org.eclipse.fx.osgi" fragment="true"/>
<plugin id="org.eclipse.gef4.common"/>
<plugin id="org.eclipse.gef4.fx"/>
<plugin id="org.eclipse.gef4.fx.ui"/>
<plugin id="org.eclipse.gef4.geometry"/>
<plugin id="org.eclipse.gef4.geometry.convert.fx"/>
<plugin id="org.eclipse.gef4.mvc"/>
<plugin id="org.eclipse.gef4.mvc.examples"/>
<plugin id="org.eclipse.gef4.mvc.fx"/>
<plugin id="org.eclipse.gef4.mvc.fx.ui"/>
<plugin id="org.eclipse.gef4.mvc.ui"/>
<plugin id="org.eclipse.help"/>
<plugin id="org.eclipse.jface"/>
<plugin id="org.eclipse.jface.databinding"/>
<plugin id="org.eclipse.osgi"/>
<plugin id="org.eclipse.osgi.compatibility.state" fragment="true"/>
<plugin id="org.eclipse.osgi.services"/>
<plugin id="org.eclipse.swt"/>
<plugin id="org.eclipse.swt.win32.win32.x86_64" fragment="true"/>
<plugin id="org.eclipse.ui"/>
<plugin id="org.eclipse.ui.views"/>
<plugin id="org.eclipse.ui.workbench"/>
<plugin id="org.w3c.css.sac"/>
<plugin id="org.w3c.dom.events"/>
<plugin id="org.w3c.dom.smil"/>
<plugin id="org.w3c.dom.svg"/>
</plugins>
<features>
<feature id="org.eclipse.emf.ecore"/>
<feature id="org.eclipse.emf.common"/>
<feature id="com.myproject.feature" version="1.0.0.qualifier"/>
<feature id="org.eclipse.e4.rcp"/>
</features>
<configurations>
<plugin id="com.myproject.application" autoStart="false" startLevel="5" />
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="5" />
<plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" />
<plugin id="org.eclipse.equinox.ds" autoStart="true" startLevel="2" />
<plugin id="org.eclipse.equinox.event" autoStart="true" startLevel="2" />
<plugin id="org.eclipse.equinox.p2.reconciler.dropins" autoStart="true" startLevel="0" />
<plugin id="org.eclipse.equinox.simpleconfigurator" autoStart="true" startLevel="1" />
</configurations>
<preferencesInfo>
<targetfile overwrite="false"/>
</preferencesInfo>
<cssInfo>
</cssInfo>
</product>
运行 :
args : -os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -clearPersistedState
vm args : -Dosgi.requiredJavaVersion=1.7 -Xms40m -Xmx512m -Dosgi.framework.extensions=org.eclipse.fx.osgi
编辑:
最后,我通过在FireMvcModule中添加此绑定解决了我的问题:
FireView:
public FireView() {
super(Guice.createInjector(Modules.override(new FireMvcModule()).with(new FireMvcUiModule())));
}
FireMvcModule:
protected void bindIContentPartFactory() {
binder().bind(new TypeLiteral<IContentPartFactory<Node>>() {
}).toInstance(new FXLogoContentPartFactory());
}
protected void configure() {
super.configure();
bindIContentPartFactory();
}
最佳答案
请确保您的MANIFEST.MF不会通过Import-Package和Required-Bundle引用com.google.inject捆绑包。从软件包包列表中删除com.google.inject,因为软件包导入就足够了。
关于java - 如何使用注入(inject)器创建GEF4 FXView/FXEditor,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30300084/