当前位置: 首页 > 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;}}

在这里插入图片描述

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

相关文章:

  • WPS JS宏实现去掉文档中的所有空行
  • 深入解析Spring Boot与Redis集成:高效缓存实践
  • Ansible模块——设置软件仓库和安装软件包
  • Python海龟绘图(Turtle Graphics)核心函数和关键要点
  • 【Linux网络】内网穿透
  • 当语言模型学会犯错和改正:搜索流(SoS)方法解析
  • 兰亭妙微:用系统化思维重构智能座舱 UI 体验
  • 【Redis】零碎知识点(易忘 / 易错)总结回顾
  • linux标准库头文件解析
  • Go语言实现链式调用
  • vscode用python开发maya联动调试设置
  • 游戏引擎学习第288天:继续完成Brains
  • 98. 验证二叉搜索树
  • 信息系统项目管理师高级-软考高项案例分析备考指南(2023年案例分析)
  • 神经网络与深度学习第六章--循环神经网络(理论)
  • WebXR教学 07 项目5 贪吃蛇小游戏
  • 亲测有效!OGG 创建抽取进程报错 OGG-08241,如何解决?
  • 简单神经网络(ANN)实现:从零开始构建第一个模型
  • 【第二篇】 初步解析Spring Boot
  • 第9讲、深入理解Scaled Dot-Product Attention
  • 【漫话机器学习系列】264.内距(又称四分位差)Interquartile Range
  • 抽奖系统-抽奖
  • uni-app小程序登录后…
  • 数据分析_Python
  • arduino平台读取鼠标光电传感器
  • MATLAB学习笔记(七):MATLAB建模城市的雨季防洪排污的问题
  • Elasticsearch 性能优化面试宝典
  • LabVIEW声音与振动测量分析
  • STM32实战指南:SG90舵机控制原理与代码详解
  • Qt与Hid设备通信