转载: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());
}
}
}
分享到:
相关推荐
Guide Winform using C# language
使用 npm install bootstrap-show-password-toggle 使用安装yarn add bootstrap-show-password-toggle用法在 CSS 中包含show-password-toggle.css 将输入的密码包装在input-group div 中,如下所示: <...
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...
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 ...
超好超棒的bootstrap-toggle-buttons用在网页很不错
2. 拖动这个iso文件,扔在“Quick_11_iso_esd_wim_TPM_toggle.bat”这个文件上面,放手,自动会启动这个bat脚本 3. 稍等一会,脚本提示“:D TPM patch added”,代表iso修改成功,里面的win11安装程序已被修改,直接...
npm install vue-js-toggle-button --save 进口 导入插件: import ToggleButton from 'vue-js-toggle-button' Vue . use ( ToggleButton ) 要么 导入组件: import { ToggleButton } from 'vue-js-toggle-button...
Laravel开发-laravel-feature-toggle Laravel 5包包装Joshuaestes/功能切换
开源项目-101Bas-hosts-toggle.zip,hosts-toggle - CLI application to easily toggle certain lines in your hostfile
Laravel开发-laravel-toggle-switch-button 为Laravel定制的拨动开关按钮发生器。
|----> menu_toggle.c -- 建立多值菜单和解释 REQ_TOGGLE_ITEM |----> menu_userptr.c -- 用户指针的用法 |----> menu_win.c -- 菜单和窗口结合的演示例子 panels | |----> panel_browse.c -- 通过 tab 浏览...
Atom-atom-toggle.zip,切换关键字切换,atom是一个用web技术构建的开源文本编辑器。
React原生切换开关用于 React Native 应用程序的可定制开关组件
特征启动应用程序时动态拉入功能切换设置功能切换的静态列表可选查询字符串支持以覆盖功能切换用法1.将模块以及功能切换选项添加到nuxt.config.js。 切换可以定义为功能或对象。作为功能module . exports = { ...
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-...
使用该库指令可以实现一个输出线圈随输入点接通而不断翻转状态,类似单按钮启停功能
React-Multi-Toggle是一种时尚轻巧的切换组件,扩展了复选框或单选按钮的功能 安装 可以作为安装 npm install react-multi-toggle 发展 示例可以在找到。 npm i npm start 在启用了“热模块重新加载”的...
link href =" videojs-captions-toggle.css " rel =" stylesheet " > < script src =" video.js " > </ script > < script src =" videojs-captions-toggle.js " > </ script > < ...
安装jest (需要Jest 23.FIXME +)和jest-watch-toggle-verbosity yarn add --dev jest jest-watch-toggle-verbosity # or with NPM npm install --save-dev jest jest-watch-toggle-verbosity 将其添加到您的Jest...
React-Bootstrap-切换 这是项目的react组件。 用法 您需要在应用程序中包含bootstrap css文件以及bootstrap2-toggle css文件。 如果您使用的是npm版本,则可以从这样的...import Toggle from 'react-bootstrap-toggle