}
public void setFocus() {
treeViewer.getTree().setFocus();
}
}
Eclipse插件开发 - 深入理解菜单(Menu)功能及其扩展点(12)
时间:2011-10-22 IBM 敖建旺
Person 类的实现
如下代码清单 14 为 Person 类的实现,用于表示 MenuExample 视图中 TreeViewer 的一个节点,它 实现了 IActionFilter 接口,通过 testAttribute 来确定是否显示 / 隐藏菜单(其中 target 表示用 户选择的对象,name/value 对应于 plugin.xml 文件中 objectState 的 name/value).
清单 14. Person 类实现
public class Person implements IActionFilter {
private String firstName = "John";
private String lastName = "Doe";
protected int age = 37;
public Person[] children = new Person[0];
public Person parent = null;
public Person(String firstName, String lastName, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
public Person(String firstName, String lastName, int age, Person[] children) {
this(firstName, lastName, age);
this.children = children;
for (int i = 0; i < children.length; i++) {
children[i].parent = this;
}
}
public String getFirstName() {
return this.firstName;
}
public String getLastName() {
return this.lastName;
}
public static Person[] example() {
return new Person[] {
new Person("Dan", "Rubel", 38, new Person[] {
new Person("Beth", "Rubel", 8),
new Person("David", "Rubel", 3) }),
new Person("Eric", "Clayberg", 39, new Person[] {
new Person("Lauren", "Clayberg", 6),
new Person("Lee", "Clayberg", 4) }),
new Person("Mike", "Taylor", 52) };
}
public String toString() {
return firstName + " " + lastName;
}
public boolean testAttribute(Object target, String name, String value) {
if (target instanceof Person) {
Person person = (Person) target;
if (name.equals("firstName") && value.equals (person.getFirstName())) {
return true;
}
if (name.equals("lastName") && value.equals (person.getLastName())) {
return true;
}
}
return false;
}
}
Eclipse插件开发 - 深入理解菜单(Menu)功能及其扩展点(13)
时间:2011-10-22 IBM 敖建旺
总结
至此为止,已经把 Eclipse 菜单功能及其扩展点涉及到的类 / 接口 /API 进行了详细的说明,相信 读者已经有清晰的认识了。对于前面提到 popupMenus 方式创建上下文菜单,要 |