`

eclilpse check 菜单 --Toggle Handler for Eclipse Commands_1

 
阅读更多
转载:http://eclipsesource.com/blogs/2009/01/15/toggling-a-command-contribution/
package de.ralfebert.rcputil;

import java.util.Map;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.State;
import org.eclipse.jface.menus.IMenuStateIds;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;

/**
* Use this handler for style=”toggle” command contributions. You need to
* declare a state like this to use this:
*
*
*
*
*
*
*
* The id=”STYLE” is chosen because of IMenuStateIds.STYLE – maybe this will
* work without any Handler Foo in later Eclipse versions.
*
* @author Ralf Ebert
*/
public abstract class ToggleHandler extends AbstractHandler implements IElementUpdater {

private String commandId;

public final Object execute(ExecutionEvent event) throws ExecutionException {
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
this.commandId = event.getCommand().getId();

State state = event.getCommand().getState(IMenuStateIds.STYLE);
if (state == null)
throw new ExecutionException(
“You need to declare a ToggleState with id=STYLE for your command to use ToggleHandler!”);
boolean currentState = (Boolean) state.getValue();
boolean newState = !currentState;
state.setValue(newState);
executeToggle(event, newState);
commandService.refreshElements(event.getCommand().getId(), null);

// return value is reserved for future apis
return null;
}

protected abstract void executeToggle(ExecutionEvent event, boolean newState);

public void updateElement(UIElement element, Map parameters) {
if (this.commandId != null) {
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(
ICommandService.class);
Command command = commandService.getCommand(commandId);
element.setChecked((Boolean) command.getState(IMenuStateIds.STYLE).getValue());
}
}

}
分享到:
评论

相关推荐

    toggle-switch-master_C#guide_

    "toggle-switch-master_C#guide_"这个标题暗示了我们将在C#环境下,特别是Winform应用程序中,学习如何创建和操作这种用户界面元素。让我们开始这段C#之旅。 首先,了解Windows Forms基础是必要的。Windows Forms是...

    Laravel开发-laravel-feature-toggle

    【Laravel开发-laravel-feature-toggle】是一个专注于在Laravel框架中实现特性切换(Feature Toggle)的包,由Joshuaestes开发。特性切换是一种软件开发实践,它允许开发者在不部署新代码的情况下,通过控制台或后台...

    react-native-toggle-switch:用于 React Native 应用程序的可定制开关组件

    "react-native-toggle-switch"是一个专门为React Native应用设计的可定制开关组件,它允许开发者轻松地在应用程序中添加开/关功能,同时可以根据项目需求进行样式调整。 1. **React Native基础**: React Native是...

    bootstrap-show-password-toggle:Bootstrap 表单的将密码显示为文本切换

    使用 npm install bootstrap-show-password-toggle 使用安装yarn add bootstrap-show-password-toggle用法在 CSS 中包含show-password-toggle.css 将输入的密码包装在input-group div 中,如下所示: <...

    jQuery html5 CSS3手机端右侧弹出3D导航菜单特效.zip

    input class="mdl-icon-toggle__input" type="checkbox" value="1" checked="checked"/><i class="mdl-icon-toggle__label icon--custom">中    <label class="mdl-icon-toggle mdl-js-icon-toggle mdl-js...

    bootstrap-toggle-buttons

    1. **引入依赖**:在页面中引入Bootstrap的CSS和JavaScript文件,以及jQuery库和Bootstrap Toggle Buttons的JavaScript和CSS文件。 2. **HTML结构**:在HTML中添加具有`data-toggle="toggle"`属性的按钮元素,例如:...

    Atom-atom-toggle,切换关键字。贡献T9MD/原子.zip

    Atom-atom-toggle是一款基于Atom文本编辑器的插件,它主要功能是实现关键字的快速切换。Atom是由GitHub开发的一款开源文本编辑器,采用Web技术构建,具有高度的可定制性和灵活性,深受开发者喜爱。这款插件是T9MD...

    react-dark-mode-toggle:React React的可爱黑暗模式切换按钮

    npm i react-dark-mode-toggle 使用 : yarn add react-dark-mode-toggle :sparkles: 用法 import React , { useState } from "react" ; import DarkModeToggle from "react-dark-mode-toggle" ; export default ...

    【win11安装神器】Quick_11_iso_esd_wim_TPM_toggle.bat 无视任何硬件要求安装Win11

    2. 拖动这个iso文件,扔在“Quick_11_iso_esd_wim_TPM_toggle.bat”这个文件上面,放手,自动会启动这个bat脚本 3. 稍等一会,脚本提示“:D TPM patch added”,代表iso修改成功,里面的win11安装程序已被修改,直接...

    开源项目-101Bas-hosts-toggle.zip

    开源项目-101Bas-hosts-toggle.zip,hosts-toggle - CLI application to easily toggle certain lines in your hostfile

    vue-js-toggle-button:Vue.js 2切换开关按钮-简单,漂亮,可自定义

    npm install vue-js-toggle-button --save 进口 导入插件: import ToggleButton from 'vue-js-toggle-button' Vue . use ( ToggleButton ) 要么 导入组件: import { ToggleButton } from 'vue-js-toggle-button...

    LEDTOGGLE_ledtoggle_

    标题 "LEDTOGGLE_ledtoggle_" 暗示我们讨论的主题是关于STM32F411 Nucleo开发板上实现LED灯闪烁的程序。STM32F411 Nucleo是一款基于ARM Cortex-M4内核的微控制器开发板,广泛应用于嵌入式系统设计。"LED TOGGLE"通常...

    S7-200SMART_库文件_翻转输出状态_toggle_单按钮启停功能.rar

    本资源“S7-200SMART_库文件_翻转输出状态_toggle_单按钮启停功能.rar”提供了一种巧妙的方法,通过库指令实现了一个简单的单按钮启停控制逻辑,这对于许多工业应用来说非常实用。 首先,我们需要了解S7-200SMART ...

    NCURSES-Programming 文档示例程序

    |----> menu_toggle.c -- 建立多值菜单和解释 REQ_TOGGLE_ITEM |----> menu_userptr.c -- 用户指针的用法 |----> menu_win.c -- 菜单和窗口结合的演示例子 panels | |----> panel_browse.c -- 通过 tab 浏览...

    nuxt-feature-toggle:nuxt功能切换模块

    特征启动应用程序时动态拉入功能切换设置功能切换的静态列表可选查询字符串支持以覆盖功能切换用法1.将模块以及功能切换选项添加到nuxt.config.js。 切换可以定义为功能或对象。作为功​​能module . exports = { ...

    react-native-toggle-element:React Native的开关切换组件。 您可以添加标题,图标,修改切换按钮的组件

    React-Native-Toggle元素安装yarn add react-native-toggle-element# or with npmnpm install react-native-toggle-element用法初始值import React , { useState } from 'react' ;import Toggle from 'react-native-...

    QT-Multi-language-dymantic-toggle.7z

    本资源“QT-Multi-language-dymantic-toggle.7z”提供了一个完整的示例,展示了如何在QT应用中实现简体中文和英文的多语言动态切换。 在QT应用中实现多语言功能,主要依赖于QT的国际化(i18n)支持。i18n是...

    8-07-14_MegaCLI for linux_windows

    LSIP200232870 (DFCT) Add a Gen2 to Gen3 toggle function and a check for the PCI speed to MegaSCU/CLI [ PR : LSIP200231423 ] LSIP200232927 (DFCT) Port PR 198414 to MR5.4 (Headless Boot) ...

    android开发--详解eclipse debug && eclipse快捷键

    ### Android开发——深入解析Eclipse调试与快捷键 #### 一、Eclipse Debugging详解 在Android开发过程中,使用Eclipse进行调试是非常重要的步骤之一。本文档将详细介绍Eclipse调试功能的基本使用方法,并提供一些...

Global site tag (gtag.js) - Google Analytics