---------------------------------------------------------------------------------------------------
学习: http://www.blogjava.net/youxia/archive/2006/11/28/84013.html
---------------------------------------------------------------------------------------------------
1. 新建 OleView:
package hellorcp.ole;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
public class OleView extends ViewPart {
public OleFrame frame;
public static final String ID = "hellorcp.view.OleView"; //$NON-NLS-1$
/**
* Create contents of the view part
*
* @param parent
*/
@Override
public void createPartControl(Composite parent) {
// 创建OleFrame对象
frame = new OleFrame(parent, SWT.NONE);
//
createActions();
initializeToolBar();
initializeMenu();
}
/**
* Create the actions
*/
private void createActions() {
// Create the actions
}
/**
* Initialize the toolbar
*/
private void initializeToolBar() {
IToolBarManager toolbarManager = getViewSite().getActionBars()
.getToolBarManager();
}
/**
* Initialize the menu
*/
private void initializeMenu() {
IMenuManager menuManager = getViewSite().getActionBars()
.getMenuManager();
}
@Override
public void setFocus() {
// Set the focus
}
}
2. 新建 OpenFileAction:
package hellorcp.ole;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class OpenFileAction implements IWorkbenchWindowActionDelegate {
IWorkbenchWindow window;
public void dispose() {
// TODO 自动生成方法存根
}
public void init(IWorkbenchWindow window) {
this.window = window;
}
public void run(IAction action) {
IViewReference[] vfs = window.getActivePage().getViewReferences();
IViewPart vw;
for (int i = 0; i < vfs.length; i++) {
vw = vfs[i].getView(false);
if (vw.getTitle().equals("使用Active X控件")) {
OleClientSite client = new OleClientSite(((OleView) vw).frame,
SWT.NONE, "Shell.Explorer.2");
client.doVerb(OLE.OLEIVERB_SHOW);
OleAutomation oa = new OleAutomation(client);
Variant str = new Variant("http://www.iteye.com/");
oa.invoke(104, new Variant[] { str });
}
}
}
public void selectionChanged(IAction action, ISelection selection) {
// TODO 自动生成方法存根
}
}
3. 修改 Perspective.java, 修改后:
package hellorcp;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
public class Perspective implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {
// FirstView
String editorArea = layout.getEditorArea();
// layout.addView("hellorcp.view.FirstView", IPageLayout.RIGHT, 0.2f,
// editorArea);
// SecondView
// layout.setEditorAreaVisible(false);
// layout.addView("hellorcp.view.SecondView", IPageLayout.RIGHT, 0.5f,
// editorArea);
// OleView
layout.addView("hellorcp.ole.OleView", IPageLayout.RIGHT, 0.5f,
editorArea);
}
}
4. 配置 plugin.xml:
1) action 配置片段:
<action class ="hellorcp.ole.OpenFileAction" icon ="icons/alt_window_16.gif" id ="hellorcp.ole.OpenFileAction" label ="Ole菜单项" menubarPath ="hellorcp.firstmenu/additions" style ="push" toolbarPath ="additions" tooltip ="Ole菜单项" />
2) view 配置片段:
<view class="hellorcp.ole.OleView" id="hellorcp.ole.OleView" name="使用Active X控件" />
5. 保存,运行(点击工具类第1个图标),效果如下: