eclipse插件开发笔记

一个TableCombo简单示例,部门经理帮咱下的源码,然后咱自己发布了一下,可以用了。关于插件开发就不多说了,直接上例子(将本案例代码加到可以运行的eclipse插件项目即可)。

1、需要的东西

org.eclipse.nebula.widgets.tablecombo_1.0.0.201110222059.jar,将该包置于eclipse文件下的plugins中

这个是nebula项目中案例,现在好像木有jar包可以下,所以就将源码下下来自己打包发布,以供使用(后面一长串数字是eclipse打包的时候自己生成的,无影响使用,jar包及源码稍后提供下载)。

2、将该jar包作为插件添加到eclipse插件项目中,具体步骤如下:

(1)打开plugin.xml,选择Dependencies页面,选择Required Plug-ins 的“Add...”按钮,在弹出的对话框中输入“org.eclipse.nebula.widget.tablecombo”,选中插件双击即可完成添加

(2)示例代码

import java.util.ArrayList;
import java.util.List;

import org.eclipse.nebula.widgets.tablecombo.TableCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.graphics.Color;
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.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.ScrolledForm;

import com.plugindev.addressbook.bean.Model;
import com.plugindev.addressbook.util.ImageCache;
import com.plugindev.addressbook.util.ImageKeys;

public class OtherPage extends FormPage {

 private static List modelList;

 private int index;

 public OtherPage(FormEditor editor) {
  super(editor, "otherpage", "otherpage");

 }

 protected void createFormContent(final IManagedForm imanagedForm) {
  final ScrolledForm form = imanagedForm.getForm();
  form.setText("otherpage");
  form.setBackgroundImage(ImageCache.getInstance().getImage(
    ImageKeys.getImageDescriptor(ImageKeys.IMG_FORM_BG)));

  Composite composite = form.getBody();
  GridLayout layout = new GridLayout();
  layout.numColumns = 1;
  composite.setLayout(layout);
  GridData gd = new GridData();
  gd.horizontalSpan = 1;
  composite.setLayoutData(gd);

  TableCombo tc = new TableCombo(composite, SWT.BORDER | SWT.READ_ONLY);
  tc.setLayoutData(new GridData(150, SWT.DEFAULT));

  modelList = loadModel();

  // tell the TableCombo that I want 3 columns autosized with the
  // following column headers.
  tc.defineColumns(new String[] { "", "Id", "Description" }, new int[] {
    30, SWT.DEFAULT, SWT.DEFAULT });

  // 取第三列的值
  tc.setDisplayColumnIndex(2);

  // 显示表头
  tc.setShowTableHeader(true);

  // 加载数据
  loadThreeColumnDataset(tc.getTable());

 }

 /**
  * load a list of rows with 3 columns
  *
  * @return
  */
 private void loadThreeColumnDataset(final Table table) {
  List<TableItem> rowList = new ArrayList<TableItem>();

  int total = (modelList == null ? 0 : modelList.size());

  TableEditor[] editors = new TableEditor[total];

  final Button[] buttons = new Button[total];
  table.setLinesVisible(true);
  for (index = 0; index < total; index++) {

   TableItem ti = new TableItem(table, SWT.NONE);
   editors[index] = new TableEditor(table);
   buttons[index] = new Button(table, SWT.CHECK);
   buttons[index].setBackground(new Color(Display.getDefault(), 255,
     255, 255));
   editors[index].grabHorizontal = true;
   editors[index].setEditor(buttons[index], ti, 0);

   Model model = (Model) modelList.get(index);
   ti.setText(new String[] { "", model.getId() + "",
     model.getDescription() });
   // rowList.add(ti);
  }

  // return rowList;
 }

 /**
  * load the Model data.
  *
  * @return
  */
 @SuppressWarnings("unchecked")
 private static List loadModel() {
  List items = new ArrayList();
  items.add(new Model(1, "One"));
  items.add(new Model(2, "Two"));
  items.add(new Model(3, "Three"));
  items.add(new Model(4, "Four"));
  items.add(new Model(5, "Five"));
  items.add(new Model(6, "Six"));

  return items;
 }

}

注意:需要建立Model实体

属性自己定,只要和上面代码中model.getXXX()匹配就行

public class Model {

 private int id;

 private String description;

 public int getId() {
  return id;
 }

 public void setId(int id) {
  this.id = id;
 }

 public String getDescription() {
  return description;
 }

 public void setDescription(String description) {
  this.description = description;
 }

 public Model(int id, String description) {
  this.id = id;
  this.description = description;
 }

}

(3)效果如图

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
eclipse插件开发笔记源码是指开发eclipse插件时所记录的笔记的源代码。eclipse是一款功能强大的集成开发环境(IDE),它可以通过插件进行扩展,以满足不同开发需求。因此,eclipse插件开发笔记源码主要关注于开发插件的各个步骤、方法和技巧。 这份源码一般会包含以下内容: 1. 插件的创建和配置:插件开发笔记的源码通常包含插件项目的创建和配置信息,如插件的基本结构、项目依赖、插件的描述信息等。 2. 扩展点和扩展:源码中会记录如何定义扩展点,以及如何利用扩展点来扩展eclipse的功能。扩展点是eclipse插件开发中的核心概念,可以通过扩展点实现对eclipse的功能定制和扩展。 3. 视图、编辑器和视图部件的创建:eclipse插件开发笔记源码也会包含创建视图、编辑器和视图部件的相关代码。这些组件是插件中提供的用户界面元素,用于展示和处理数据。 4. 菜单和工具栏的添加:源码中会记录如何在eclipse中添加新的菜单、工具栏和快捷键等,以便快速访问插件的功能。 5. 功能实现和逻辑处理:源码中会包含插件功能的实现代码和相关的逻辑处理。比如,如何在插件中实现文件的读写操作,如何实现代码的自动完成等。 6. 测试和调试:源码中也会记录插件的测试和调试方法,以保证插件的稳定性和正确性。 总之,eclipse插件开发笔记源码是插件开发过程的记录和总结,帮助开发人员更好地理解和掌握eclipse插件开发的技术和方法。通过学习源码,开发人员可以更快地上手插件开发,提高开发效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值