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

西门子 Teamcenter13 Eclipse RCP 开发 1.3 工具栏 单选按钮

西门子 Teamcenter13 Eclipse RCP 开发 1.3 工具栏 单选按钮

  • 1 配置文件
  • 2 插件控制
  • 3 命令框架

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

1 配置文件

<?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.xu.work.tool.bar" icon="icons/sample.png" label="单选按钮1" style="radio"><parameter name="option" value="1"/></command><command commandId="com.xu.work.tool.bar" icon="icons/sample.png" label="单选按钮2" style="radio"><parameter name="option" value="2"/></command><command commandId="com.xu.work.tool.bar" icon="icons/sample.png" label="单选按钮3" style="radio"><parameter name="option" value="3"/></command></toolbar></menuContribution></extension><extension point="org.eclipse.ui.commands"><command id="com.xu.work.tool.bar" name="工具栏:单选按钮" defaultHandler="com.xu.work.tool3.handlers.SampleHandler"><commandParameter id="option" name="选项" optional="false"/></command></extension></plugin>

2 插件控制

package com.xu.work.tool2;import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;/*** 插件激活器类,控制插件的生命周期*/
public class Activator extends AbstractUIPlugin {/*** 插件ID常量,通常与MANIFEST.MF中的Bundle-SymbolicName一致*/public static final String PLUGIN_ID = "com.xu.work.tool2"; //$NON-NLS-1$/*** 单例实例引用*/private static Activator plugin;/*** 构造函数*/public Activator() {}/*** 插件启动时调用*/@Overridepublic void start(BundleContext context) throws Exception {super.start(context);plugin = this;// 在这里注册监听器、服务、加载配置等}/*** 插件停止时调用*/@Overridepublic void stop(BundleContext context) throws Exception {plugin = null;super.stop(context);}/*** 返回此插件的共享实例** @return 共享实例*/public static Activator getDefault() {return plugin;}}

3 命令框架

package com.xu.work.tool3.handlers;import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.State;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.RadioState;public class SampleHandler extends AbstractHandler {// 按钮idprivate static final String RADIO_COMMEND_ID = "com.xu.work.tool.bar";@Overridepublic Object execute(ExecutionEvent event) throws ExecutionException {// 获取选项参数String option = event.getParameter("option");// 获取命令服务和RadioStateICommandService service = PlatformUI.getWorkbench().getService(ICommandService.class);State state = service.getCommand(RADIO_COMMEND_ID).getState(RadioState.STATE_ID);// 获取当前状态值String currentValue = state != null ? (String)state.getValue() : null;// 只在真正选择新选项时显示对话框(避免取消选择时的对话框)// 如果当前值与新选项不同,说明这是一个真正的选择操作if (option != null && !option.equals(currentValue)) {// 显示消息对话框Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();MessageDialog.openInformation(shell, "单选按钮", "您点击了单选按钮 " + option);}// 更新按钮状态if (state != null) {state.setValue(option);}return null;}
}

在这里插入图片描述

相关文章:

  • NDS3211HV单路H.264/HEVC/HD视频编码器
  • Dockerfile学习指南
  • 端到端自动驾驶系统实战指南:从Comma.ai架构到PyTorch部署
  • AI517 AI本地部署 docker微调(失败)
  • 车载以太网驱动智能化:域控架构设计与开发实践
  • ECS/GEM是半导体制造业的标准通信协议中host和equipment的区别是什么,在交互过程中,如何来定位角色谁为host,谁为equipment
  • C# 中的锁
  • 数字万用表与指针万用表使用方法及注意事项
  • 上集:一个前端的血泪复仇记 —— 静态部署的胜利
  • 调用DeepSeek系列模型问答时,输出只有</think>标签,而没有<think>标签
  • CANoe CAPL TCP DoIP通信问题
  • 【springboot+vue3的前后端分离项目实现支付宝的沙箱支付】
  • 使用instance着色
  • 边缘计算:物联网的“加速器”与“守护者”
  • Postman遇到脚本不支持replaceIn函数
  • 3D个人简历网站 4.小岛
  • BootCDN介绍(Bootstrap主导的前端开源项目免费CDN加速服务)
  • 【技巧】GoogleChrome浏览器开发者模式查看dify接口
  • DeepSeek赋能电商,智能客服机器人破解大型活动人力困境
  • AtomicInteger
  • 柬埔寨果农:期待柬埔寨榴莲走进中国市场
  • 河南一女子被医院强制带走治疗,官方通报:当值医生停职
  • 七猫征文大赛颁出112万奖金,非遗题材作品斩获金奖
  • 广西百色“致富果”:高品质芒果直供香港,带动近五千户增收
  • 讲一个香港儿童的故事,《劏房的天空》获“周庄杯”特等奖
  • 专访|韩国世宗研究所中国研究中心主任:李在明若上台将推行均衡外交