Eclipse插件開發(fā)的點(diǎn)點(diǎn)滴滴新公司做的是桌面應(yīng)用程序,與之前一直在做的web頁面 ,相差甚大。這篇文章是寫于2022年10月底,這時(shí)在新公司已經(jīng)入職了快三月 。寫作目的是:國內(nèi)對(duì)于eclipse插件開發(fā)相關(guān)的文檔是少之又少,這三個(gè)月我們小組翻遍了國外文檔,勉強(qiáng)將軟件拼湊出并release出測(cè)試版本,為了方便同行以及自我學(xué)習(xí),所以想把這幾個(gè)月學(xué)到的eclipse rcp插件相關(guān)知識(shí)寫下來 。
一、 Wizard部分Wizard 一般用于向?qū)綄?duì)話框 ,eclipse的新建項(xiàng)目就是一個(gè)典型的wizard。wizard一般由幾個(gè)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方法中,可以對(duì)你的向?qū)ы撁娼M件進(jìn)行布局、添加監(jiān)聽等動(dòng)作 。②對(duì)于當(dāng)前頁面的標(biāo)題、描述等信息,可以在構(gòu)造函數(shù)中通過setTitle 和 setDescription方法來設(shè)置
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();}}經(jīng)驗(yàn)總結(jié)擴(kuò)展閱讀
- Windows10 + Eclipse C/C++開發(fā)環(huán)境配置極簡(jiǎn)教程
- 提高工作效率的神器:基于前端表格實(shí)現(xiàn)Chrome Excel擴(kuò)展插件
- 蘋果手機(jī)紅包秒收怎么設(shè)置(蘋果紅包插件黑科技)
- 從0開始寫一個(gè)簡(jiǎn)單的vite hmr 插件
- 鉤子 【pytest官方文檔】解讀-插件開發(fā)之hooks 函數(shù)
- 插件化編程之WebAPI統(tǒng)一返回模型
- 淺談 Golang 插件機(jī)制
- 中 ?打造企業(yè)自己代碼規(guī)范IDEA插件
- 分享一個(gè)Vue實(shí)現(xiàn)圖片水平瀑布流的插件
- 手機(jī)里有個(gè)惡意廣告插件怎樣清除
