eclipse RCP provider-select listener mode
effect
After clicking the item in the predefined instruction tree view, the clicked information is displayed in the instruction description view
Implementation
1. Add interface components to the event provider private void createTableViewer (Composite parent) and initialize the data
.
CustomMessageTreeViewer tv = new CustomMessageTreeViewer(parent,SWT.SINGLE | SWT.H_SCROLL);
tv.initData();
2. Set the selection provider of the current page as the TreeViewer object of the component in the event provider;
getViewSite().setSelectionProvider(tv.getTv());
3. The listener implements the ISelectionListener interface to process selection events
extends ViewPart implements ISelectionListener
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// TODO Auto-generated method stub
if(!selection.isEmpty()){
String msg;
CustomMessageItem item =(CustomMessageItem) ((IStructuredSelection) selection).getFirstElement();
msg=("action:[选择指令]"+item.getId()+item.getName()+",[文件]"+item.getFile());
if(label!=null){
label.setText(msg);
}
}
}
4. Monitor the registration selection event in the listener
private Label label;
@Override
public void createPartControl(Composite parent) {
// TODO Auto-generated method stub
label = new Label(parent, SWT.NONE);
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().addSelectionListener(this );
}
4B. Listen to the registration selection event in the listener (Method 2)
getSite().getPage().addSelectionListener(this);