eclipseRCP深入浅出(学习总结)2015.08.25

<span style="font-size:18px;">1、</span>
public class AddContactAction extends Action implements 
	ISelectionListener,ActionFactory.IWorkbenchAction {
	private final IWorkbenchWindow window;
	public static String ID = "com.eclipsercp.hyperbola.addContact";
	private IStructuredSelection selection;

	public AddContactAction(IWorkbenchWindow window){
		this.window = window;
		setId(ID);
		setText("&Add Contact...");
		setToolTipText("Add a Contact to your Contacts list.");
		setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
				"com.eclipsercp.hyperbola", IImageKeys.ADD_CONTACT));
		window.getSelectionService().addSelectionListener(this);
	}
	
	public void dispose(){
		window.getSelectionService().removeSelectionListener(this);
	}
	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {

	}

}
<span style="font-size:18px;">这是添加联系人的action,其中ID有两个作用,首先能够唯一标识一个action,其次在<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;">ApplicationActionBarAdvisor的<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;"> fillMenuBar()方法进行注册action时会用到这个ID。</span></span></span>
<span style="font-size:18px;"><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;"><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;">2、action会注册到selection listener中,可以看到AddContactAction是实现了ISelectionListener接口的,当treeviewer中的元素被选中时,selectionChanged()方法就会通知对应的action:</span></span></span>
<span style="font-size:18px;"><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;"><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 18px; line-height: 26px;"></span></span></span><pre name="code" class="java">@Override
	public void selectionChanged(IWorkbenchPart part, ISelection incoming) {
		//selection containing elements
		if(incoming instanceof IStructuredSelection){
			selection = (IStructuredSelection)incoming;
			setEnabled(selection.size() == 1 &&
					selection.getFirstElement()instanceof ContactsGroup);
		}else {
			//other selections(containing text or other kinds)
			setEnabled(false);
		}
	}


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值