当前位置: 首页 > backend >正文

Eclipse 插件开发 4 工具栏

Eclipse 插件开发 4 工具栏

  • 1 增加工具(push)
  • 2 增加工具(toggle)
  • 3 增加工具(radio)

位置locationURI备注
菜单栏menu:org.eclipse.ui.main.menu添加到传统菜单
工具栏toolbar:org.eclipse.ui.main.toolbar添加到工具栏
style 值含义显示效果
push普通按钮(默认)普通的点击按钮,点一下执行一次
toggle切换按钮有按下/弹起两种状态,比如"开关"
radio单选按钮多个按钮互斥选择,比如 “模式切换”

1 增加工具(push)

package com.xu.learn.handlers;import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.dialogs.MessageDialog;public class SampleHandler extends AbstractHandler {@Overridepublic Object execute(ExecutionEvent event) throws ExecutionException {IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);MessageDialog.openInformation(window.getShell(),"Learn","点击菜单弹框");return null;}
}
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin><extension point="org.eclipse.ui.menus"><menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar"><toolbar id="com.example.toolbar"><command commandId="com.example.commands.helloCommand" icon="icons/sample.png" tooltip="点我执行命令" label="按钮名称" style="push"></command></toolbar></menuContribution></extension><extension point="org.eclipse.ui.handlers"><handler class="com.xu.learn.handlers.SampleHandler" commandId="com.example.commands.helloCommand"></handler></extension></plugin>

在这里插入图片描述

2 增加工具(toggle)

package com.xu.learn.handlers;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.jface.commands.ToggleState;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.handlers.HandlerUtil;public class ToggleHandler extends AbstractHandler {private static final String STATS = "org.eclipse.ui.commands.toggleState";private static IPreferenceStore preferenceStore;public static void setPreferenceStore(IPreferenceStore store) {preferenceStore = store;}@Overridepublic Object execute(ExecutionEvent event) throws ExecutionException {Command command = event.getCommand();// 获取状态ToggleState state = (ToggleState) command.getState(STATS);if (state == null) {state = new ToggleState();command.addState(STATS, state);}// 打印状态boolean currentState = HandlerUtil.toggleCommandState(command);System.out.println("当前按钮状态:" + currentState);// 保存状态if (preferenceStore != null) {preferenceStore.setValue(STATS, currentState);}return null;}}
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin><extension point="org.eclipse.ui.commands"><command id="com.example.commands.toggleCommand" name="切换按钮命令"/></extension><extension point="org.eclipse.ui.handlers"><handler class="com.xu.learn.handlers.ToggleHandler" commandId="com.example.commands.toggleCommand"/></extension><extension point="org.eclipse.ui.menus"><menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar"><toolbar id="com.example.toolbar"><command commandId="com.example.commands.toggleCommand" icon="icons/sample.png" style="toggle" tooltip="开关按钮示例"/></toolbar></menuContribution></extension></plugin>

在这里插入图片描述

3 增加工具(radio)

package com.xu.learn.handlers;import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;public class RadioHandler extends AbstractHandler {@Overridepublic Object execute(ExecutionEvent event) throws ExecutionException {// 拿到参数String option = event.getParameter("option");System.out.println("当前选中的Radio按钮是:选项 " + option);// 这里可以根据 option 做不同处理if ("1".equals(option)) {// 选中了第一个} else if ("2".equals(option)) {// 选中了第二个} else if ("3".equals(option)) {// 选中了第三个}return null;}
}
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin><extension point="org.eclipse.ui.commands"><command id="com.example.commands.radioCommand" name="单选按钮命令"><commandParameter id="option" name="选项" optional="true"/></command></extension><extension point="org.eclipse.ui.handlers"><handler class="com.xu.learn.handlers.RadioHandler" commandId="com.example.commands.radioCommand"/></extension><extension point="org.eclipse.ui.menus"><menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar"><toolbar id="com.example.toolbar"><command commandId="com.example.commands.radioCommand" icon="icons/sample.png" label="选项1" style="radio"><parameter name="option" value="1"/></command><command commandId="com.example.commands.radioCommand" icon="icons/sample.png" label="选项2" style="radio"><parameter name="option" value="2"/></command><command commandId="com.example.commands.radioCommand" icon="icons/sample.png" label="选项3" style="radio"><parameter name="option" value="3"/></command></toolbar></menuContribution></extension></plugin>

在这里插入图片描述

http://www.xdnf.cn/news/2147.html

相关文章:

  • 华为云loT物联网介绍与使用
  • RD电子实验记录本选用贴士A-B-C
  • 用go从零构建写一个RPC(仿gRPC,tRPC)--- 版本1
  • 泰迪杯实战案例学习资料:生产线的故障自动识别和人员配置优化
  • Android7 Input(五)InputDispatcher
  • 实现从一个微信小程序跳转到另一个微信小程序
  • 优化 Nginx 配置主域名重定向与 Mongrel 规则迁移
  • 搭建动态SQL取数
  • 【计算机视觉】CV实战项目 -深度解析PaddleSegSharp:基于PaddleSeg的.NET图像分割解决方案
  • 【专题三】二分查找(2)
  • canvas画板!随意画!!
  • egg环境搭建
  • AT6850—GNSS卫星导航定位SOC芯片
  • 【OSG学习笔记】Day 9: 状态集(StateSet)与渲染优化 —— 管理混合、深度测试、雾效等渲染状态
  • LibAI Lab闪耀AI出海峰会:技术深耕与全球化增长的双重奏
  • Q2桥门式起重机司机考试复习重点
  • 告别手动映射:在 Spring Boot 3 中优雅集成 MapStruct
  • 前馈神经网络层
  • 罗德FSP13 FSP40频谱分析仪频率13.6GHz
  • ViTMAE:掩码自编码器是可扩展的视觉学习者
  • P4017 最大食物链计数-拓扑排序
  • 国标44496详细分析
  • org.apache.ibatis.plugin.Invocation 类详解
  • 树莓派4B+Ubuntu24.04 电应普超声波传感器串口输出 保姆级教程
  • 基于AI技术的高速公路交通引流系统设计与应用研究
  • kubernets集群的安装-node节点安装-(简单可用)-超详细
  • 智能电网第8期 | 视频监控与数据同传解决方案
  • wsl联通外网
  • SQL注入高级绕过手法汇总 重点
  • 神经发育过程中大脑临界状态的图神经网络分析方法