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

西门子 Teamcenter13 Eclipse RCP 开发 1.2 工具栏 开关按钮

西门子 Teamcenter13 Eclipse RCP 开发 1.2 工具栏 开关按钮

  • 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.example.commands.helloCommand" icon="icons/sample.png" tooltip="开关按钮" label="开关按钮" style="toggle"></command></toolbar></menuContribution></extension><extension point="org.eclipse.ui.handlers"><handler class="com.xu.work.tool2.handlers.SampleHandler" commandId="com.example.commands.helloCommand"></handler></extension><extension point="org.eclipse.ui.commands"><command id="com.example.commands.toggleCommand" name="开关按钮"/></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.tool2.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.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;public class SampleHandler 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);IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);MessageDialog.openInformation(window.getShell(), "切换按钮", "切换按钮的状态是" + currentState);// 保存状态if (preferenceStore != null) {preferenceStore.setValue(STATS, currentState);}return null;}}

在这里插入图片描述

相关文章:

  • 在线教育本地化分发:代理IP实现区域访问控制与内容适配
  • MySQL表的约束(上)
  • 嵌入式学习笔记 - STM32定时器的输入通道与时钟源
  • Vue+Vite学习笔记
  • C语言查漏补缺
  • 2025年渗透测试面试题总结-安恒[实习]安全工程师(题目+回答)
  • 中级网络工程师知识点4
  • 灵光一现的问题和常见错误2
  • 芯片生态链深度解析(二):基础设备篇——人类精密制造的“巅峰对决”
  • 劳特巴赫trace32负载率测试
  • [YOLO模型](4)YOLO V3的介绍
  • 新的节能技术和一体化解决方案,推动工厂智能升级和产业转型
  • 开源RTOS(实时操作系统):nuttx 编译
  • MyBatis 核心组件源码分析
  • 车载诊断架构 --- 核心网关流控制机制需求
  • 一个指令,让任意 AI 快速生成思维导图
  • 【单机版OCR】清华TH-OCR v9.0免费版
  • Win11下轻松搭建wiki.js,Docker.desktop部署指南(mysql+elasticsearch+kibana+wiki.js)
  • 嘉立创EDA成图:文件管理
  • C++ 蓝桥 STEMA 真题模拟测试卷一
  • 中国纪检监察刊文:力戒形式主义官僚主义关键是要坚持实事求是
  • 国寿资产获批参与第三批保险资金长期投资改革试点
  • 张汝伦:康德和种族主义
  • KPL“王朝”诞生背后:AG和联赛一起迈向成熟
  • 金正恩观摩朝鲜人民军各兵种战术综合训练
  • 时隔4年多,这一次普京和泽连斯基能见面吗?