Eclipse插件开发的点点滴滴新公司做的是桌面应用程序,与之前一直在做的web页面 ,相差甚大。这篇文章是写于2022年10月底,这时在新公司已经入职了快三月 。写作目的是:国内对于eclipse插件开发相关的文档是少之又少,这三个月我们小组翻遍了国外文档,勉强将软件拼凑出并release出测试版本,为了方便同行以及自我学习,所以想把这几个月学到的eclipse rcp插件相关知识写下来 。
一、 Wizard部分Wizard 一般用于向导式对话框 ,eclipse的新建项目就是一个典型的wizard。wizard一般由几个wizard page 组成 ,通过按钮控制 上一页下一页完成取消。
文章插图
1.wizardpages
wizardpage1
package de.vogella.rcp.intro.wizards.wizard;import org.eclipse.jface.wizard.WizardPage;import org.eclipse.swt.SWT;import org.eclipse.swt.events.KeyEvent;import org.eclipse.swt.events.KeyListener;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Text;public class MyPageOne extends WizardPage {private Text text1;private Composite container;public MyPageOne() {super("First Page");setTitle("First Page");setDescription("Fake Wizard: First page");}@Overridepublic void createControl(Composite parent) {container = new Composite(parent, SWT.NONE);GridLayout layout = new GridLayout();container.setLayout(layout);layout.numColumns = 2;Label label1 = new Label(container, SWT.NONE);label1.setText("Put a value here.");text1 = new Text(container, SWT.BORDER | SWT.SINGLE);text1.setText("");text1.addKeyListener(new KeyListener() {@Overridepublic void keyPressed(KeyEvent e) {}@Overridepublic void keyReleased(KeyEvent e) {if (!text1.getText().isEmpty()) {setPageComplete(true);}}});GridData gd = new GridData(GridData.FILL_HORIZONTAL);text1.setLayoutData(gd);// required to avoid an error in the systemsetControl(container);setPageComplete(false);}public String getText1() {return text1.getText();}}
wizardpage2
①自定义wizardpage主要是继承JFACE 的 WizardPage ,并重写 createControl方法 。在createControl方法中,可以对你的向导页面组件进行布局、添加监听等动作 。②对于当前页面的标题、描述等信息,可以在构造函数中通过setTitle 和 setDescription方法来设置
package de.vogella.rcp.intro.wizards.wizard;import org.eclipse.jface.wizard.WizardPage;import org.eclipse.swt.SWT;import org.eclipse.swt.events.KeyEvent;import org.eclipse.swt.events.KeyListener;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Text;public class MyPageTwo extends WizardPage {private Text text1;private Composite container;public MyPageTwo() {super("Second Page");setTitle("Second Page");setDescription("Now this is the second page");setControl(text1);}@Overridepublic void createControl(Composite parent) {container = new Composite(parent, SWT.NONE);GridLayout layout = new GridLayout();container.setLayout(layout);layout.numColumns = 2;Label label1 = new Label(container, SWT.NONE);label1.setText("Say hello to Fred");text1 = new Text(container, SWT.BORDER | SWT.SINGLE);text1.setText("");text1.addKeyListener(new KeyListener() {@Overridepublic void keyPressed(KeyEvent e) {// TODO Auto-generated method stub}@Overridepublic void keyReleased(KeyEvent e) {if (!text1.getText().isEmpty()) {setPageComplete(true);}}});GridData gd = new GridData(GridData.FILL_HORIZONTAL);text1.setLayoutData(gd);Label labelCheck = new Label(container, SWT.NONE);labelCheck.setText("This is a check");Button check = new Button(container, SWT.CHECK);check.setSelection(true);// required to avoid an error in the systemsetControl(container);setPageComplete(false);}public String getText1() {return text1.getText();}}
经验总结扩展阅读
- Windows10 + Eclipse C/C++开发环境配置极简教程
- 提高工作效率的神器:基于前端表格实现Chrome Excel扩展插件
- 苹果手机红包秒收怎么设置(苹果红包插件黑科技)
- 从0开始写一个简单的vite hmr 插件
- 钩子 【pytest官方文档】解读-插件开发之hooks 函数
- 插件化编程之WebAPI统一返回模型
- 浅谈 Golang 插件机制
- 中 ?打造企业自己代码规范IDEA插件
- 分享一个Vue实现图片水平瀑布流的插件
- 手机里有个恶意广告插件怎样清除