作者:遗失的美好顺_599 | 来源:互联网 | 2023-06-28 18:53
进入run()的时候,我发现window是空值我就是想调用一个窗口而已这是我的TestViewActionpackagecom.test.action;importorg.ec
进入run()的时候,我发现window是空值
我就是想调用一个窗口而已
这是我的TestViewAction
package com.test.action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import com.test.view.MainView;
public class TestViewAction implements IWorkbenchWindowActionDelegate{
private IWorkbenchWindow window;
private IShellProvider is = null;
public TestViewAction(IWorkbenchWindow window){
this.window = window;
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void init(IWorkbenchWindow arg0) {
// TODO Auto-generated method stub
}
@Override
public void run(IAction arg0) {
// TODO Auto-generated method stub
window.getActivePage().findView("com.test.view.MainView");
}
@Override
public void selectionChanged(IAction arg0, ISelection arg1) {
// TODO Auto-generated method stub
}
}
plugin.xml
point="org.eclipse.ui.actionSets">
label="Sample Action Set"
visible="true"
id="com.test.actionSet">
label="&Test Action"
icon="icons/sample.gif"
class="com.test.action.TestViewAction"
tooltip="Hello, Eclipse world"
menubarPath="testMenu/testGroup"
toolbarPath="testGroup"
id="com.test.action.TestViewAction">
point="org.eclipse.ui.views">
class="com.test.view.MainView"
id="com.test.view.MainView"
name="mainView">
8 个解决方案
@Override
public void init(IWorkbenchWindow arg0) {
// TODO Auto-generated method stub
this.window = window;
}
另外好像必须有个无参构造函数的,系统创建对象的时候是用无参构造函数的。