Eclipse XML-редактор в приложении RCP не работает - PullRequest
1 голос
/ 25 сентября 2019

Я пытаюсь использовать редактор XML Eclipse Default в моем приложении RCP.Я получил этот код от

https://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_on_something_that_is_not_a_file%3F

Итак, я создал StringStorage и StringInput, как указано в ссылке.

Запуск в Eclipse IDE для разработчиков RCP и RAP

Версия: 2019-06 (4.12.0) Идентификатор сборки: 20190614-1200

jdk1.8.0_121


import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;

public class StringStorage implements IStorage{

    private String string;

      StringStorage(String input) {
        this.string = input;
      }

      public InputStream getContents() throws CoreException {
        return new ByteArrayInputStream(string.getBytes());
      }

      public IPath getFullPath() {
        return null;
      }

      public Object getAdapter(Class adapter) {
        return null;
      }

      public String getName() {

        return string;
      }

      public boolean isReadOnly() {
        return true;
      }
}
import org.eclipse.core.resources.IStorage;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IStorageEditorInput;

public class StringInput implements IStorageEditorInput {
    private IStorage storage;
    StringInput(IStorage storage) {this.storage = storage;}
    public boolean exists() {return true;}
    public ImageDescriptor getImageDescriptor() {return null;}
    public String getName() {
       return storage.getName();
    }
    public IPersistableElement getPersistable() {return null;}
    public IStorage getStorage() {
       return storage;
    }
    public String getToolTipText() {
       return "String-based file: " + storage.getName();
    }
    public Object getAdapter(Class adapter) {
      return null;
    }
 }

Теперь вместо вызова идентификатора редактора "org.eclipse.ui.DefaultTextEditor "в ссылке.Я хочу вызвать пользовательский редактор, который я создал в расширениях plugin.xml.

Поскольку я хочу передать управление классу, который расширяет XMLMultiPageEditorPart, я получаю вид редактора XML на вкладке "дизайн" и "источник" в своем приложениипоказать файлы SCXML (State Chart XML)

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IStorage storage = new StringStorage((String)o);
IStorageEditorInput input = new StringInput(storage);
page.openEditor(input, "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart");

Это мой класс, расширяющий XMLMultiPageEditorPart

import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart;

public class MyXMLEditor  extends XMLMultiPageEditorPart {



}

Теперь я покажу вам часть plugin.xml

<editor

            contributorClass="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorActionBarContributor"
            default="true"
            id="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"
            name="XML_Editor.name"
            symbolicFontName="org.eclipse.wst.sse.ui.textfont">
            <class class="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart">
                <parameter name="org.eclipse.wst.sse.ui.unsupported_preferred_default" value="org.eclipse.wst.xml.core.xmlsource"/>
            </class>

            <contentTypeBinding
                contentTypeId="org.eclipse.core.runtime.xml" />
            <contentTypeBinding
                contentTypeId="org.eclipse.wst.xml.core.xmlsource" />
      </editor>

Для secondcontentType я получаю это желтое предупреждение >> Ссылочный идентификатор 'org.eclipse.wst.xml.core.xmlsource' в атрибуте 'contentTypeId' не найден

Наконец, это Manifest.mf

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: V2
Bundle-SymbolicName: generic.layer.editor.v2;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: .,
 ./lib/apache-commons-lang.jar,
 ./lib/ezmorph-1.0.6.jar,
 ./lib/org-apache-commons-logging.jar,
 ./lib/org.apache.commons.collections.jar,
 ./lib/commons-beanutils-1.9.2.jar,
 ./lib/commons-collections4-4.1.jar,
 ./lib/javax.json-1.0.jar,
 ./lib/json-lib-2.4-jdk15-sources.jar,
 ./lib/jdom-2.0.5-contrib.jar,
 ./lib/jdom-2.0.5-sources.jar,
 ./lib/jdom-2.0.5.jar,
 ./lib/mockito-core-2.13.0.jar,
 ./lib/dtd-xercesImpl.jar,
 lib/spring/spring-core-5.1.4.RELEASE.jar,
 lib/spring/spring-web-3.1.3.RELEASE.jar,
 lib/commons-logging-1.2.jar,
 lib/gson-2.8.2.jar,
 lib/javax.json-api.jar,
 lib/org.eclipse.wst.sse.ui_1.6.0.v201905291408.jar,
 lib/org.eclipse.wst.sse.core_1.2.100.v201901310548.jar,
 lib/org.eclipse.wst.xml.ui_1.2.300.v201904272112.jar
Bundle-Activator: generic.layer.editor.v2.Activator
Import-Package:  javax.xml.stream
 org.eclipse.core.resources,
 org.eclipse.core.runtime,
 org.eclipse.emf.common.util,
 org.eclipse.jface.text,
 org.eclipse.jface.text.information,
 org.eclipse.jface.text.source,
 org.eclipse.swt.widgets,
 org.eclipse.ui,
 org.eclipse.ui.editors.text,
 org.eclipse.ui.forms,
 org.eclipse.ui.forms.editor,
 org.eclipse.ui.forms.widgets,
 org.eclipse.ui.ide,
 org.eclipse.ui.internal.views.markers,
 org.eclipse.ui.navigator,
 org.eclipse.ui.navigator.resources,
 org.eclipse.ui.part,
 org.eclipse.ui.texteditor,
 org.eclipse.ui.views.contentoutline,
 org.eclipse.wst.sse.ui
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime;bundle-version="3.7.0",
 org.eclipse.ui.forms;bundle-version="3.5.100",
 org.eclipse.zest.core,
 org.eclipse.zest.layouts,
 org.eclipse.osgi.services,
 org.eclipse.core.resources;bundle-version="3.10.1",
 org.apache.commons.io;bundle-version="2.2.0",
 org.apache.commons.lang;bundle-version="2.6.0",
 org.junit, 
 org.eclipse.compare.core;bundle-version="3.6.100",
 org.eclipse.compare;bundle-version="3.7.101"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: 
 generic.layer.editor.v2.services,
 org.apache.commons.collections,
 org.apache.commons.collections.bag,
 org.apache.commons.collections.bidimap,
 org.apache.commons.collections.buffer,
 org.apache.commons.collections.collection,
 org.apache.commons.collections.comparators,
 org.apache.commons.collections.functors,
 org.apache.commons.collections.iterators,
 org.apache.commons.collections.keyvalue,
 org.apache.commons.collections.list,
 org.apache.commons.collections.map,
 org.apache.commons.collections.set,
 org.apache.commons.lang,
 org.apache.commons.lang.builder,
 org.apache.commons.lang.enum,
 org.apache.commons.lang.enums,
 org.apache.commons.lang.exception,
 org.apache.commons.lang.math,
 org.apache.commons.lang.mutable,
 org.apache.commons.lang.reflect,
 org.apache.commons.lang.text,
 org.apache.commons.lang.time,
 org.apache.commons.logging,
 org.apache.commons.logging.impl,
 org.eclipse.wst.sse.core,
 org.eclipse.wst.sse.ui,
 org.eclipse.wst.xml.ui
Bundle-Vendor: XILO

Когда я попытался загрузить свое представление с помощью файла .scxml и ожидать, что появится редактор Eclipse XML.Я получаю ниже erron на консоли.

!ENTRY org.eclipse.e4.ui.workbench 4 0 2019-09-26 11:21:12.102
!MESSAGE 
!STACK 0
java.lang.NullPointerException
    at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart$PageInitializationData.sendInitializationData(XMLMultiPageEditorPart.java:328)
    at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.createSourcePage(XMLMultiPageEditorPart.java:841)
    at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.createPages(XMLMultiPageEditorPart.java:770)
    at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:348)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:151)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:99)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:355)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:990)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:955)
    at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:124)
    at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:399)
    at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:318)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:105)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:74)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:56)
    at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:992)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:661)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$1.handleEvent(PartServiceImpl.java:104)
    at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
    at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
    at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:144)
    at org.eclipse.swt.widgets.Display.syncExec(Display.java:4889)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:212)
    at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
    at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
    at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
    at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
    at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
    at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:52)
    at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
    at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
    at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:173)
    at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:620)
    at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:584)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:769)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:401)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1188)
    at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3261)
    at org.eclipse.ui.internal.WorkbenchPage.access$25(WorkbenchPage.java:3176)
    at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:3158)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3153)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3117)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3098)
    at generic.layer.editor.v2.SCXMLView$1$1.run(SCXMLView.java:117)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:37)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:182)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4213)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3820)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
    at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
    at generic.layer.editor.v2.Application.start(Application.java:21)
    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:388)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1472)

Не могли бы вы указать, что я делаю неправильно.Пожалуйста, дайте мне знать, если вам нужна дополнительная информация.Ценю твою помощь.Спасибо

1 Ответ

0 голосов
/ 25 сентября 2019

Класс ожидает данных инициализации, объявленных его собственным расширением редактора: https://github.com/eclipse/webtools.sourceediting/blob/master/xml/bundles/org.eclipse.wst.xml.ui/plugin.xml#L324 (он контролирует, что происходит при открытии неподдерживаемого типа файла).На самом деле вам не нужно определять новый редактор, вы можете просто передать идентификатор существующего.

...