`
qq123zhz
  • 浏览: 527002 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

eclipse 获得透视图切换事件

 
阅读更多
/*******************************************************************************
 * Copyright (c) 2008, Ralf Ebert
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Ralf Ebert nor the names of its contributors may
 *       be used to endorse or promote products derived from this software without
 *       specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Ralf Ebert ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Ralf Ebert BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/
package de.ralfebert.rcp.tools.preferredperspective;

/**
 * Let Workbench parts implement this interface if you want
 * {@link PreferredPerspectivePartListener} to automatically activate the
 * preferred perspective on part activation.
 */
public interface IPrefersPerspective {

    /**
     * @return the preferred perspective of this part or null if no perspective
     *         is preferred.
     */
    String getPreferredPerspectiveId();

}Add PreferredPerspectivePartListener to your application. This class is responsible for switching the perspective upon activation of a part implementing IPrefersPerspective.

/*******************************************************************************
 * Copyright (c) 2008, Ralf Ebert
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Ralf Ebert nor the names of its contributors may
 *       be used to endorse or promote products derived from this software without
 *       specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Ralf Ebert ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Ralf Ebert BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/
package de.ralfebert.rcp.tools.preferredperspective;

import java.util.logging.Logger;

import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;

/**
 * PreferredPerspectivePartListener is to be registered using the extension
 * point "org.eclipse.ui.startup". It will register itself as listener for the
 * activation of parts. When a part which implements IPrefersPerspective is
 * activated it will activate the preferred perspective of this part.
 */
public class PreferredPerspectivePartListener implements IPartListener, IStartup {

    private static final Logger log = Logger.getLogger(PreferredPerspectivePartListener.class);

    public void partActivated(IWorkbenchPart part) {
        refresh(part);
    }

    public static void refresh(final IWorkbenchPart part) {
        if (!(part instanceof IPrefersPerspective)) {
            return;
        }

        final IWorkbenchWindow workbenchWindow = part.getSite().getPage().getWorkbenchWindow();

        IPerspectiveDescriptor activePerspective = workbenchWindow.getActivePage().getPerspective();
        final String preferredPerspectiveId = ((IPrefersPerspective) part)
                .getPreferredPerspectiveId();

        if (preferredPerspectiveId == null) {
            return;
        }

        if (activePerspective == null || !activePerspective.getId().equals(preferredPerspectiveId)) {
            // Switching of the perspective is delayed using Display.asyncExec
            // because switching the perspective while the workbench is
            // activating parts might cause conflicts.
            Display.getCurrent().asyncExec(new Runnable() {

                public void run() {
                    log.debug("Switching to preferred perspective " + preferredPerspectiveId
                            + " for " + part.getClass());
                    try {
                        workbenchWindow.getWorkbench().showPerspective(preferredPerspectiveId,
                                workbenchWindow);
                    } catch (WorkbenchException e) {
                        log.warn("Could not switch to preferred perspective "
                                + preferredPerspectiveId + " for " + part.getClass(), e);
                    }
                }

            });
        }

    }

    public void earlyStartup() {
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                try {
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                            .addPartListener(new PreferredPerspectivePartListener());
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }

        });
    }

    public void partBroughtToTop(IWorkbenchPart part) {
        // nothing to do
    }

    public void partClosed(IWorkbenchPart part) {
        // nothing to do
    }

    public void partDeactivated(IWorkbenchPart part) {
        // nothing to do
    }

    public void partOpened(IWorkbenchPart part) {
        // nothing to do
    }

}

 

<extension point="org.eclipse.ui.startup">
   <startup class="de.ralfebert.rcp.tools.preferredperspective.PreferredPerspectivePartListener"/>
</extension>

 

 

引用地址:http://www.ralfebert.de/blog/eclipsercp/auto_perspective_switch/

http://eclipse.dzone.com/articles/disable-or-enable-actions-sets

 

分享到:
评论

相关推荐

    RCP自定义透视图切换按钮的右键菜单

    代码demo和ppt介绍;用org.eclipse.ui.presentationFactories扩展点RCP自定义透视图切换按钮的右键菜单,去除Editor的右键菜单和关闭按钮;

    eclipse 开发c/c++

    这些插件将 C/C++ 透视图添加到 Eclipse 工作台(Workbench)中, 现在后者可以用许多视图和向导以及高级编辑和调试支持来支持 C/C++ 开发。 由于其复杂性,CDT 被分成几个组件,它们都采用独立插件的形式。 每个...

    oomph:我习惯用于Eclipse IDE的Eclipse Oomph设置

    FlasH的Eclipse设置 设置安装程序 如果您使用的是Windows:只...将透视图切换到“ Dev”(无论如何已将其设置为默认值)。 即使在安装过程中已选择键盘布局,也将其切换为IntelliJ(首选项-&gt;常规-&gt;键)。 包含什么 适用

    快速上手Eclipse Eclipse快捷键指南.doc

    * 全局上一个透视图:Ctrl+Shift+F8 * 全局下一个编辑器:Ctrl+F6 * 全局下一个视图:Ctrl+F7 * 全局下一个透视图:Ctrl+F8 三、导航作用域功能快捷键 * Java 编辑器打开结构:Ctrl+F3 * 全局打开类型:Ctrl+Shift...

    Eclipse_Swt_Jface_核心应用_部分19

    1.3 Eclipse的诞生 3 1.4 Eclipse贡献SWT工具包 5 1.4.1 SWT的结构 6 1.4.2 SWT所支持的操作系统 6 1.5 Sun AWT/Swing与Eclipse SWT 7 1.5.1 Swing与SWT的比较 7 1.5.2 SWT的优势和不足 8 1.6 SWT与...

    安卓软件制作及JAVA讲解(经典)

    透视图可以切换不同的界面布局,方便用户在多种常用的功能模块下工作。透视图保存了当前的菜单栏、工具栏按钮以及视图的大小、位置、显示与否的所有状态,可以在下次切换回来时恢复原来的布局。 五、视图(View) ...

    eclipse快捷

    Eclipse 快捷键大全 Eclipse 是一个功能强大且广泛使用的集成开发环境(IDE),它提供了许多实用的快捷键来提高开发效率...* Ctrl+Shift+F8:全局上一个透视图 * Ctrl+F6:全局下一个编辑器 * Ctrl+F7:全局下一个视图

    eclipse快捷键大全

    全局 上一个透视图 Ctrl+Shift+F8 全局 下一个编辑器 Ctrl+F6 全局 下一个视图 Ctrl+F7 全局 下一个透视图 Ctrl+F8 文本编辑器 显示标尺上下文菜单 Ctrl+W 全局 显示视图菜单 Ctrl+F10 全局 显示系统菜单 Alt+- 导航...

    ChessGame:象棋游戏 SD1-TRI1

    自述文件 弹出项目 - 2014 年 12 月 SET07102 上的学生 ... 切换回 JavaEE 透视图: 在项目资源管理器中; 打开 DWP/Java Resource/src/pup/ChessGameServlet.java 您可能会发现项目有编译错误——下一步可

    osate-plugin:OSATE插件

    Sireum OSATE插件该存储库包含Sireum 插件,该插件将AADL实例模型转换为 ,然后转换为下游Sireum工具(如 。开发人员安装该插件可以使用OSATE发行(以下安装方向... 切换到插件开发透视图:窗口-&gt;透视图-&gt;打开透视图-

    async_debugger_demo:Scala IDE的异步调试器入门指南

    ##入门将此项目克隆到本地计算机下载启动Eclipse 切换到“调试”透视图转到窗口菜单选择“打开透视图”菜单项,然后在其下方选择“调试” 将“异步堆栈”选项卡添加到您的Eclipse窗格中(如果尚不存在) 转到窗口...

    《MyEclipse 6 Java 开发中文教程》前10章

    3.1.3 透视图(Perspective)切换器 52 3.1.4 视图(View) 53 3.1.5 上下文菜单(Context Menu) 55 3.1.6 状态栏(Status Bar) 55 3.1.7 编辑器(Editor) 55 3.2 常见概念和操作 56 3.2.1 项目(Project) 56 ...

    Android 4游戏编程入门经典

     10.3 透视投影:越近则越大  10.4 z-buffer:化混乱为有序  10.4.1 完善上一个例子  10.4.2 混合:身后空无一物  10.4.3 z-buffer精度与z-fighting  10.5 定义3d网格  10.5.1 立方体:3d中的“helloworld” ...

    android游戏编程入门

     10.3 透视投影:越近则越大 409  10.4 z-buffer:化混乱为有序 411  10.4.1 完善上一个例子 412  10.4.2 混合:身后空无一物 413  10.4.3 z-buffer精度与  z-fighting 416  10.5 定义3D网格 417  10.5.1 ...

Global site tag (gtag.js) - Google Analytics