public class InfoView extends ViewPart {
private TransactionsView transactionsView;
public void createPartControl(Composite parent) {
getSite().getWorkbenchWindow().getPartService().addPartListener(partListener);
}
private IPartListener partListener = new IPartListener() {
public void partOpened(IWorkbenchPart part) {
if (part instanceof TransactionsView) {
transactionsView = (TransactionsView)part;
}
}
}
private void myOwnFunction() {
if (transactionsView != null) {
transactionsView.getTransactions();
}
}
}
That's all there is to it. When your view is created in createPartControl() tell Eclipse to add a listener that gets notified whenever a part-related event occurs and you'll know when the TransactionsView is opened. Some other part events you can listen to are:
public void partClosed(IWorkbenchPart part){}
public void partActivated(IWorkbenchPart part) {}
public void partBroughtToTop(IWorkbenchPart part) {}
public void partDeactivated(IWorkbenchPart part) {}
You'll have to make sure InfoView gets added to the perspective before TransactionsView otherwise the TransactionsView will be created before you add the listener and you won't get the notification.
Keywords for beloved Google:
eclipse swt
communicate betweeen views
call functions in another view
reference to another view
access another view's members
access another view's variables