Getting Started with Eclipse RCP development study notes - 04. In Windows, use the Active X control

-------------------------------------------------- -------------------------------------------------

Study: http://www.blogjava.net/youxia/archive/2006/11/28/84013.html

-------------------------------------------------- -------------------------------------------------

1. New 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) {
                //  Create a OleFrame object
                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. New 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  Automatically generate method stub
        }

        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(" Use the active X control  ")) {
                                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.javaeye.com/");
                                oa.invoke(104, new Variant[] { str });
                        }
                }
        }

        public void selectionChanged(IAction action, ISelection selection) {
                // TODO  Automatically generate method stub
        }

}

3. Modify Perspective.java, revised:

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. Configuration plugin.xml:

1) action configuration snippet:

           <action
                                class ="hellorcp.ole.OpenFileAction"
                icon ="icons/alt_window_16.gif"
                id ="hellorcp.ole.OpenFileAction"
                    label ="Ole Menu items  "
                                menubarPath ="hellorcp.firstmenu/additions"
                style ="push"
                toolbarPath ="additions"
                tooltip ="Ole Menu items  " />

2) view configuration snippet:

         <view

                name=" Use the active X control  " />

5. Save, run (click on Tools first one icon), the effect is as follows:

Getting Started with Eclipse RCP development study notes - 04. In Windows, use the Active X control

分类:Java 时间:2010-04-14 人气:333
本文关键词:
分享到:
blog comments powered by Disqus

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.138 (s). 12 q(s)