How do i connect two views in an RCP Application - java

I am working on an RCP application, in which I want to connect 2 views so that when I click a node of TreeViewer in view1 the TableViewer in view2 must be populated.
I have 2 view classes namely ViewPart1(TreeViewer) and ViewPart2(TableViewer).
Can anyone help me out in achieving this?

Use the selection service.
In the view (view1) which is providing the selection you must set the selection provider to be the tree:
getSite().setSelectionProvider(viewer);
where viewer is a TreeViewer (or TableViewer) or something else that implements ISelectionProvider.
In the view which wants to see selections set up a listener:
ISelectionService selService = getSite().getWorkbenchWindow().getSelectionService();
selService.addSelectionListener(listener);
where listener is something that implements ISelectionListener.
Note: Your listener will be told about selection changes everywhere, it is up to you to sort out which ones you want to react to.

Related

ViewChangeEvent not triggered in a view that is contained in a TabSheet

In my Vaadin 8 application, I have a TabSheet, that contains several views. When I override the enter method in the first view of my TabSheet, and then I proceed to enter the view on my application, the method doesn't get called.
Do you have a Navigator, and have you registered the views for it? Navigator's navigateTo is what calls the enter. Registering views happens along these lines:
navigator.addView("", new InitialView());
navigator.addView("second", new SecondView());
Navigation also updates the URI fragment in your browser, and makes it possible to bookmark specific views and enter them via direct URL. See e.g. https://vaadin.com/docs/v8/framework/advanced/advanced-navigator for more information about Navigator.
TabSheet isn't the most trivial thing to use with Navigator and I'm afraid I don't have a ready-made example at hand, but I think it should be doable with a custom ViewDisplay and maybe SelectedTabChangeListener.
If you aren't interested in the Navigator approach, I suppose you could replace the View+enter with something along these lines, although if you need to know the previously selected tab you'll need to keep track of it yourself since this particular event isn't very informative:
tabSheet.addSelectedTabChangeListener(e -> {
((MyClass) tabSheet.getSelectedTab()).myMethod());
});

Events of Properties View in my own eclipse editor

I implemented a Properties View in my own editor in eclipse and I start this view using the code:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.ui.views.PropertySheet");
1) Are there listeners that are fired when properties view became visible or invisible, gain ou lost focus?
2) What code I use to know if properties view is closed?
3) What code I use to know if the properties view is opened but not visible? Like this image:
Figure 1
4) How can I know if it is visible and have focus? Like image:
Figure 2
5) And if it is visible and DONT have focus, like:
Figure 3
Use IPartListener2 to listen for all part events.
IPartService partService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService();
partService.addPartListener(listener);
You will get events for all parts so you will have to check the event is for your part. The listener gets events for all the state changes of a part (open, closed, activated, brought to top, ....)
There is also a very similar IPartListener but IPartListener2 should be used if possible.

Based on the MVP (Model View Presenter) how should I implement this?

I have a app on Google App Engine and I'm using GWT, and when the user goes to www.myapp.com/#show I need to show a graph, and in that page there is a button to search and add nodes to that graph, when the search Button is clicked I need to show a popup with the search form (it has several functions and dialogs).
Can I create a view for that page and another view for the popup and use the same presenter for both?
or What is the best way to implement that based on the pattern MVP?
MVC(Model View Controller) style tells that you have this three packages for Entities, UI, Controller classes. This help you organize your code and break it to plugins.
As for your question it is better if you can implement a CustomPopUp class in the View(UI) package and make it abstact. So PopUp could have as parameters the message the context or everything it needs to show the approprate message.
And you can pass CustomPopUp as private delegator to your UI classes who need to show popup messages.

Programmatically Perform Child View Click in ExpandableListView

I have an ExpandableListView implementation in my application and I am writing unit tests for it. I'm wondering how I can programmatically perform a click on the child view of an expandable header?
This is NOT a question about how to attach onChildClickListener() to the view. I've found many questions regarding that topic, but I already have that implemented and need to test the functionality of that code when the child view is clicked. I know that I can use the performClick() method to click on the header view to expand/collapse the contents, but I need to perform a click on the sublist of a header.
You can try with:
listView.setSelection(position);
but you have to consider this:
If in touch mode, the item will not be selected but it will still be
positioned appropriately. If the specified selection position is less
than 0, then the item at position 0 will be selected.
For more information you can visit the doc page.
I hope it helps.
Edit
As #RyanM appointed, setSelection just change the selection, but it doesn't perform the "click" action. You can perform the action through the function:
listView.performItemClick(goalListView, itemPosition, itemId);
You can find this function in the class AdapterView.
Sorry for the previous mistake to your answer.

How can I access the Tabbed Properties View in Eclipse programatically?

I'd like to get access to the Tabbed Properties View in order to change the displayed tab programatically. When the selection is changed, the default behaviour is to show the same tab for the new selection (if they share a tab descriptor) or else to show the last known tab for that selection. I need to be able to set the tab based on program conditions.
Thanks in advance.
You need to ask for IPropertySheetPage.class adapter from Properties View workbench part, then cast it to org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage in order to call setSelectedTab() on it.
Cheers,
Max

Categories