gpt4 book ai didi

java - 尝试多个透视图时,RCP 中未加载透视图

转载 作者:行者123 更新时间:2023-12-01 11:13:40 25 4
gpt4 key购买 nike

我正在创建一个 RCP 应用程序。我有一个 View 类 NewView。

public class NewView extends ViewPart {

private DataBindingContext m_bindingContext;
public static final String ID = "com.app.Editor.newView";
SaveNewFileBean bean = new SaveNewFileBean();
private StyledText text;

public NewView() {
}

@Override
public void createPartControl(Composite parent) {
text = new StyledText(parent, SWT.BORDER);
m_bindingContext = initDataBindings();
}

public String returnText(){
String textData = bean.getText();
return textData;
}

@Override
public void setFocus() {

}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue observeTextTextObserveWidget = WidgetProperties.text(SWT.Modify).observe(text);
IObservableValue textBeanObserveValue = PojoProperties.value("text").observe(bean);
bindingContext.bindValue(observeTextTextObserveWidget, textBeanObserveValue, null, null);
//
return bindingContext;
}
}

当我第一次运行应用程序时,我单击“新建菜单”,一切正常。但是,当我尝试再次单击“新建”来再次加载它时,它不会给出任何错误。但是,它也不加载视角。我的代码有问题吗?

谢谢!

编辑:新的是命令。 New 调用处理程序 NewFileHandler,后者又使用以下代码调用 NewView.java。

public class NewFileHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SwitchPerspectiveAction action = new SwitchPerspectiveAction();
action.run(NewFilePerspective.ID);
return null;
}
}

SwitchPerspectiveASction 类

public class SwitchPerspectiveAction extends Action {

public void run(String newPerspectiveID) {
if (PlatformUI.getWorkbench() != null) {
try {

PlatformUI.getWorkbench().showPerspective(newPerspectiveID,
PlatformUI.getWorkbench().getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
e.printStackTrace();
}
}
}

}

编辑:

我尝试使用此代码。

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
page.showView(OpenFilePerspective.ID, "1" , IWorkbenchPage.VIEW_ACTIVATE);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

给出错误。

org.eclipse.ui.PartInitException: Could not create view: com.app.Editor.openFileperspective:1
at org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:1275)
at org.eclipse.ui.internal.WorkbenchPage$14.run(WorkbenchPage.java:4208)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:4204)
at com.app.editor.handlers.OpenHandler.execute(OpenHandler.java:66)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:294)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
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.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:247)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:229)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:149)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:825)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:701)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$6(HandledContributionItem.java:685)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:613)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4172)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at com.app.editor.Application.start(Application.java:20)
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:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)

最佳答案

如果透视图已经打开,

showPerspective 不会执行任何操作。您不能使用它来打开同一 View 的多个副本。

如果您只想打开 View ,请使用:

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

IViewPart viewPart = page.showView("the view id");

请注意,这一次只会显示 View 的一个实例。

要关闭 View ,请使用:

page.hideView(viewPart);

您可以使用 View 的辅助 ID 显示 View 的多个副本:

page.showView("view id", "secondary id", IWorkbenchPage.VIEW_ACTIVATE);

不必在任何地方定义辅助 ID。它只需要对于您想要显示的每个 View 都是唯一的。

关于java - 尝试多个透视图时,RCP 中未加载透视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32095871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com