nt[]{url});
下面,贴出本文例子中的视图的代码和菜单Action的代码,在写这篇文章之前,我一直在 探索怎样从菜单控制视图,后来发现是这样:
window.getActivePage.getViewReferences();
虽然我不知道Eclipse中Page的概念究竟是什么,但是只要能找到我要操作的视图就可以 了。视图的代码如下:
OleView.java
1package cn.blogjava.youxia.views;
2
3import org.eclipse.jface.action.IMenuManager;
4import org.eclipse.jface.action.IToolBarManager;
5import org.eclipse.swt.SWT;
6import org.eclipse.swt.widgets.Composite;
7import org.eclipse.ui.part.ViewPart;
8import org.eclipse.swt.ole.win32.OleFrame;
9
10public class OleView extends ViewPart {
11 public OleFrame frame;
12
13 public static final String ID = "cn.blogjava.youxia.views.OleView"; // $NON-NLS-1$
14
15 /** *//**
16 * Create contents of the view part
17 * @param parent
18 */
19 @Override
20 public void createPartControl(Composite parent) {
21 frame = new OleFrame(parent, SWT.NONE);
22
23 //
24 createActions();
25 initializeToolBar();
26 initializeMenu();
27 }
28
29 /** *//**
30 * Create the actions
31 */
32 private void createActions() {
33 // Create the actions
34 }
35
36 /** *//**
37 * Initialize the toolbar
38 */
39 private void initializeToolBar() {
40 IToolBarManager toolbarManager = getViewSite().getActionBars()
41 .getToolBarManager();
42 }
43
44 /** *//**
45 * Initialize the menu
46 */
47 private void initializeMenu() {
48 IMenuManager menuManager = getViewSite().getActionBars()
49 .getMenuManager();
50 }
51
52 @Override
53 public void setFocus() {
54 // Set the focus
55 }
56
57}
58
使用Eclipse RCP进行桌面程序开发(四):在Windows中使用Active X控件(4)
时间:2011-04-13 海边沫沫
在这个视图中,我创建了OleFrame对象,并让它是public的,至于OleClientSite和 OleAutomation对象,我们在点击菜单项后创建。菜单动作的代码如下:
OpenFileAction.java
1package cn.blogjava.youxia.actions;
2
3
4import org.eclipse.jface.action.IAction;
5import org.eclipse.jface.viewers.ISelection;
6import org.eclipse.swt.SWT;
7import org.eclipse.swt.ole.win32.OLE;
8import org.eclipse.swt.ole.win32.OleClientSite;
9import org.eclipse.ui.IWorkbenchWindow;
10import org.eclipse.ui.IWorkbenchWindowActionDelegate;
11import org.eclipse.ui.*;
12import cn.blogjava.youxia.views.*;
13import org.eclipse.swt.ole.win32.OleAutomation;
14import org.eclipse.swt.ole.win32.Variant;
15
16public class OpenFileAction implements IWorkbenchWindowActionDelegate {
17
18 IWorkbenchWindow window;
19
20 public void dispose() {
21 // TODO 自动生成方法存根
22
23 }
24
25 public void init(IWorkbenchWindow window) {
26 // TODO 自动生成方法存根
27 this.window = window;
28
29 }
30
31 public void run(IAction action) {
32 // TODO 自动生成方法存根
33
34 IViewReference[] vfs = window.getActivePage().getViewReferences ();
35 IViewP
|